Pour mon serveur jail, je veux installer le plugins pour devenir chef des gardiens, j'ai donc trouver deux plugins intéressant, mais les deux se complète, et je veux donc les assemblés afin qu'il ne fassent plus qu'un.
Le premier permet d'afficher au début du round un menu avec la question "Voulez-vous devenir le chef des gardiens ?" et les réponse "1. Oui, 2. Non", s'il y a plusieurs gardiens qui veulent être chef alors le plugins fait un random sur les candidats au poste de chef de gardiens.
Le deuxième permet d'avoir les commandes pour devenir chef ou démissionner, très pratique quand le premier chef des gardiens est mort pour qu'un autre gardien prenne le relais, et aussi pour démissionné, s'il na pas envie d'y être. Quand le chef parle dans le chat, à côté il y a marquer chef (pratique pour le différencier des autres gardiens.
Ce que je n'arrive pas à faire, c'est quand la sélection de vote au début du round, ce là ne prend pas effet avec les commandes, donc un gardien qui fait !c pourra devenir gardien (on se retrouve donc avec 2 gardiens), de plus quand le chef à était sélectionné (après qu'il est appuyait sur 1 par erreur", s'il tape !pc, la commande n'a aucun effet, de plus s'il parle dans le chat le [Chef] à côter n'apparait pas. En revanche si on effectue tout avec les commandes elles communiquent entre elle comme dans l'original.
Je vous donne donc ci-dessous le mélange des deux codes afin de pouvoir m'aider à résoudre se problème.
Citation:
#include <sourcemod>#include <sdktools>
#include <cstrike>
#define PLUGIN_VERSION "3.0.1"
new Warden = -1;
new Handle:g_cVar_mnotes = INVALID_HANDLE;
new Handle:g_fward_onBecome = INVALID_HANDLE;
new Handle:g_fward_onRemove = INVALID_HANDLE;
new bool:g_bWantsCaptain[MAXPLAYERS+1] = {false, ...};
new bool:g_bSomebodyChose = false;
public Plugin:myinfo = {
name = "Jailbreak Warden",
author = "ecca",
description = "Jailbreak Warden script",
version = PLUGIN_VERSION,
url = "ffac.eu"
name = "Jail Captain",
author = "necavi",
description = "Jail Captain!",
version = "0.1",
url = "http://necavi.com"
};
public OnPluginStart()
{
// Initialize our phrases
LoadTranslations("warden.phrases");
// Register our public commands
RegConsoleCmd("sm_w", BecomeWarden);
RegConsoleCmd("sm_warden", BecomeWarden);
RegConsoleCmd("sm_uw", ExitWarden);
RegConsoleCmd("sm_unwarden", ExitWarden);
RegConsoleCmd("sm_c", BecomeWarden);
RegConsoleCmd("sm_commander", BecomeWarden);
RegConsoleCmd("sm_pc", ExitWarden);
RegConsoleCmd("sm_uncommander", ExitWarden);
// Register our admin commands
RegAdminCmd("sm_rw", RemoveWarden, ADMFLAG_GENERIC);
RegAdminCmd("sm_rc", RemoveWarden, ADMFLAG_GENERIC);
// Hooking the events
HookEvent("round_start", roundStart); // For the round start
HookEvent("player_death", playerDeath); // To check when our warden dies :)
HookEvent("round_start",Event_RoundStart);
// For our warden to look some extra cool
AddCommandListener(HookPlayerChat, "say");
// May not touch this line
CreateConVar("sm_warden_version", PLUGIN_VERSION, "The version of the SourceMod plugin JailBreak Warden, by ecca", FCVAR_REPLICATED|FCVAR_SPONLY|FCVAR_PLUGIN|FCVAR_N OTIFY|FCVAR_DONTRECORD);
g_cVar_mnotes = CreateConVar("sm_warden_better_notifications", "0", "0 - disabled, 1 - Will use hint and center text", FCVAR_PLUGIN, true, 0.0, true, 1.0);
g_fward_onBecome = CreateGlobalForward("warden_OnWardenCreated", ET_Ignore, Param_Cell);
g_fward_onRemove = CreateGlobalForward("warden_OnWardenRemoved", ET_Ignore, Param_Cell);
}
public Event_RoundStart(Handle:event,const String:name[],bool:dontBroadcast)
{
g_bSomebodyChose = false;
if(!GetConVarBool(g_fward_onBecome))
return;
new Handle:menu = INVALID_HANDLE;
for(new i=1;i<MaxClients;i++)
{
if(ValidPlayer(i)&&GetClientTeam(i)==CS_TEAM_CT)
{
menu = CreateMenu(MenuHandler_CaptainChoice);
SetMenuTitle(menu, "%T", "Menu_Title", i);
new String:text[64];
Format(text, sizeof(text), "%T", "Yes", i);
AddMenuItem(menu, "yes", text);
Format(text, sizeof(text), "%T", "No", i);
AddMenuItem(menu, "nothing", text);
SetMenuExitButton(menu, false);
DisplayMenu(menu,i,15);
}
}
CreateTimer(15.0,CheckCaptain);
return;
}
public Action:CheckCaptain(Handle:timer,any:data)
{
if(!g_bSomebodyChose)
return Plugin_Handled;
new bool:chosen = false;
new random;
do {
random = GetRandomInt(1,MaxClients);
if(ValidPlayer(random)&&g_bWantsCaptain[random])
{
PrintToChatAll("[Faction] %t","Captain_Chosen",random);
chosen = true;
}
}
while(!chosen);
return Plugin_Continue;
}
public MenuHandler_CaptainChoice(Handle:menu, MenuAction:action, client, param2)
{
if (action == MenuAction_End)
{
CloseHandle(menu);
} else if(action == MenuAction_Select)
{
decl String:choice[16];
GetMenuItem(menu,param2,choice,sizeof(choice));
if(strcmp(choice,"yes")==0)
{
g_bWantsCaptain[client]=true;
g_bSomebodyChose = true;
}
}
}
stock bool:ValidPlayer(i,bool:check_alive=false)
{
if(i>0 && i<=MaxClients && IsClientConnected(i) && IsClientInGame(i))
{
if(check_alive && !IsPlayerAlive(i))
{
return false;
}
return true;
}
return false;
}
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
CreateNative("warden_exist", Native_ExistWarden);
CreateNative("warden_iswarden", Native_IsWarden);
CreateNative("warden_set", Native_SetWarden);
CreateNative("warden_remove", Native_RemoveWarden);
RegPluginLibrary("warden");
return APLRes_Success;
}
public Action:BecomeWarden(client, args)
{
if (Warden == -1) // There is no warden , so lets proceed
{
if (GetClientTeam(client) == 3) // The requested player is on the Counter-Terrorist side
{
if (IsPlayerAlive(client)) // A dead warden would be worthless >_<
{
SetTheWarden(client);
}
else // Grr he is not alive -.-
{
PrintToChat(client, "[Faction] %t", "warden_playerdead");
}
}
else // Would be wierd if an terrorist would run the prison wouldn't it :p
{
PrintToChat(client, "[Faction] %t", "warden_ctsonly");
}
}
else // The warden already exist so there is no point setting a new one
{
PrintToChat(client, "[Faction] %t", "warden_exist", Warden);
}
}
public Action:ExitWarden(client, args)
{
if(client == Warden) // The client is actually the current warden so lets proceed
{
PrintToChatAll("[Faction] %t", "warden_retire", client);
if(GetConVarBool(g_cVar_mnotes))
{
PrintCenterTextAll("[Faction] %t", "warden_retire", client);
PrintHintTextToAll("[Faction] %t", "warden_retire", client);
}
Warden = -1; // Open for a new warden
SetEntityRenderColor(client, 255, 255, 255, 255); // Lets remove the awesome color
}
else // Fake dude!
{
PrintToChat(client, "[Faction] %t", "warden_notwarden");
}
}
public Action:roundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
Warden = -1; // Lets remove the current warden if he exist
}
public Action:playerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid")); // Get the dead clients id
if(client == Warden) // Aww damn , he is the warden
{
PrintToChatAll("[Faction] %t", "warden_dead", client);
if(GetConVarBool(g_cVar_mnotes))
{
PrintCenterTextAll("[Faction] %t", "warden_dead", client);
PrintHintTextToAll("[Faction] %t", "warden_dead", client);
}
SetEntityRenderColor(client, 255, 255, 255, 255); // Lets give him the standard color back
Warden = -1; // Lets open for a new warden
}
}
public OnClientDisconnect(client)
{
if(client == Warden) // The warden disconnected, action!
{
PrintToChatAll("[Faction] %t", "warden_disconnected");
if(GetConVarBool(g_cVar_mnotes))
{
PrintCenterTextAll("[Faction] %t", "warden_disconnected", client);
PrintHintTextToAll("[Faction] %t", "warden_disconnected", client);
}
Warden = -1; // Lets open for a new warden
}
}
public Action:RemoveWarden(client, args)
{
if(Warden != -1) // Is there an warden at the moment ?
{
RemoveTheWarden(client);
}
else
{
PrintToChatAll("[Faction] %t", "warden_noexist");
}
return Plugin_Handled; // Prevent sourcemod from typing "unknown command" in console
}
public Action:HookPlayerChat(client, const String:command[], args)
{
if(Warden == client && client != 0) // Check so the player typing is warden and also checking so the client isn't console!
{
new String:szText[256];
GetCmdArg(1, szText, sizeof(szText));
if(szText[0] == '/' || szText[0] == '@' || IsChatTrigger()) // Prevent unwanted text to be displayed.
{
return Plugin_Handled;
}
if(IsClientInGame(client) && IsPlayerAlive(client) && GetClientTeam(client) == 3) // Typing warden is alive and his team is Counter-Terrorist
{
PrintToChatAll("[Chef] %N : %s", client, szText);
return Plugin_Handled;
}
}
return Plugin_Continue;
}
public SetTheWarden(client)
{
PrintToChatAll("[Faction] %t", "warden_new", client);
if(GetConVarBool(g_cVar_mnotes))
{
PrintCenterTextAll("[Faction] %t", "warden_new", client);
PrintHintTextToAll("[Faction] %t", "warden_new", client);
}
Warden = client;
SetEntityRenderColor(client, 0, 0, 255, 255);
SetClientListeningFlags(client, VOICE_NORMAL);
Forward_OnWardenCreation(client);
}
public RemoveTheWarden(client)
{
PrintToChatAll("[Faction] %t", "warden_removed", client, Warden);
if(GetConVarBool(g_cVar_mnotes))
{
PrintCenterTextAll("[Faction] %t", "warden_removed", client);
PrintHintTextToAll("[Faction] %t", "warden_removed", client);
}
SetEntityRenderColor(Warden, 255, 255, 255, 255);
Warden = -1;
Forward_OnWardenRemoved(client);
}
public Native_ExistWarden(Handle:plugin, numParams)
{
if(Warden != -1)
return true;
return false;
}
public Native_IsWarden(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
if(!IsClientInGame(client) && !IsClientConnected(client))
ThrowNativeError(SP_ERROR_INDEX, "Client index %i is invalid", client);
if(client == Warden)
return true;
return false;
}
public Native_SetWarden(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
if (!IsClientInGame(client) && !IsClientConnected(client))
ThrowNativeError(SP_ERROR_INDEX, "Client index %i is invalid", client);
if(Warden == -1)
{
SetTheWarden(client);
}
}
public Native_RemoveWarden(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
if (!IsClientInGame(client) && !IsClientConnected(client))
ThrowNativeError(SP_ERROR_INDEX, "Client index %i is invalid", client);
if(client == Warden)
{
RemoveTheWarden(client);
}
}
public Forward_OnWardenCreation(client)
{
Call_StartForward(g_fward_onBecome);
Call_PushCell(client);
Call_Finish();
}
public Forward_OnWardenRemoved(client)
{
Call_StartForward(g_fward_onRemove);
Call_PushCell(client);
Call_Finish();
}