Hi all,
I decided to have a go at a ready up system, but I can't get it to work properly. For some reason, it works fine when I'm on my own, and fine with 2 people. But when there are around 3 or more people on the server, it will just not work - no debug message in the console or anything, just not work :/
I can't figure this out....any help would be great.
Here's my code thus far:
PHP Code:
//sdk tools
#include <sourcemod>
#include <sdktools>
//plugin version
#define PLUGIN_VERSION "0"
//plugin info
public Plugin:myinfo =
{
name = "Jackpf's Readyup",
author = "jackpf",
description = "Readyup mode",
version = PLUGIN_VERSION,
url = "http://jackpf.co.uk"
}
//cvar handles
new handle:ReadyPanel = INVALID_HANDLE;
new handle:ReadyUp = INVALID_HANDLE;
new bool:ready_clients[MAXPLAYERS + 1];
//plugin setup
public OnPluginStart()
{
ReadyUp = CreateConVar("sm_readyup_mode", "0", "", FCVAR_NOTIFY | FCVAR_PLUGIN);
RegAdminCmd("sm_readyup", Ready_Up, ADMFLAG_BAN);
RegConsoleCmd("say", Is_Ready);
}
public Action:Ready_Up(client, args)
{
for(new i = 1; i <= GetClientCount(); i++)
{
if(IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i))
{
DebugPrint("Setting client %i as not ready", i);
ready_clients[i] = false;
}
}
DebugPrint("Freezing game");
Freeze_Game();
DebugPrint("Creating panels");
Create_Panels();
return Plugin_Handled;
}
Create_Panels()
{
DebugPrint("Creating panels");
ReadyPanel = CreatePanel();
SetPanelTitle(ReadyPanel, "Ready Players");
DebugPrint("Grouping ready players");
DrawPanelText(ReadyPanel, "READY");
for(new i = 1; i <= GetClientCount(); i++)
{
if(!IsFakeClient(i))
{
if(IsClientConnected(i) && IsClientInGame(i) && ready_clients[i])
{
DebugPrint("Client %i is ready", i);
new string:Name[128];
GetClientInfo(i, "name", Name, sizeof(Name));
DrawPanelText(ReadyPanel, Name);
}
}
}
DebugPrint("Grouping unready players");
DrawPanelText(ReadyPanel, "UNREADY");
for(new i = 1; i <= GetClientCount(); i++)
{
if(!IsFakeClient(i))
{
if(IsClientConnected(i) && IsClientInGame(i) && !ready_clients[i])
{
DebugPrint("Client %i is not ready", i);
new string:Name[128];
GetClientInfo(i, "name", Name, sizeof(Name));
DrawPanelText(ReadyPanel, Name);
}
}
}
DebugPrint("Sending panel to clients");
for(new i = 1; i <= GetClientCount(); i++)
SendPanelToClient(ReadyPanel, i, Panel_Handle, MENU_TIME_FOREVER);
CloseHandle(ReadyPanel);
}
public Panel_Handle(Handle:menu, MenuAction:action, param1, param2)
{
return;
}
public Action:Is_Ready(client, args)
{
new string:arg1[1024];
GetCmdArg(1, arg1, sizeof(arg1));
if(strcmp(arg1, "!ready", false) == 0 || strcmp(arg1, "!unready", false) == 0)
{
DebugPrint("Someone has said they are (un)ready");
if(strcmp(arg1, "!ready", false) == 0)
{
DebugPrint("Client %i is ready", client);
ready_clients[client] = true;
}
else if(strcmp(arg1, "!unready", false) == 0)
{
DebugPrint("Client %i is unready", client);
ready_clients[client] = false;
}
DebugPrint("Recreating panels");
Create_Panels();
DebugPrint("Checking ready status");
if(Check_Ready_Status())
{
DebugPrint("All players ready - unfreezing game");
Unfreeze_Game();
}
else
DebugPrint("All players not ready");
return Plugin_Handled;
}
return Plugin_Continue;
}
Check_Ready_Status()
{
new bool:all_ready = true;
for(new i = 1; i <= GetClientCount() && i <= MAXPLAYERS; i++)
if(IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i))
if(!ready_clients[i])
all_ready = false;
return all_ready;
}
Freeze_Game()
{
DebugPrint("Freezing game");
SetConVarFlags(FindConVar("god"), GetConVarFlags(FindConVar("god")) & ~FCVAR_NOTIFY & ~FCVAR_CHEAT);
SetConVarInt(FindConVar("god"), 1);
SetConVarFlags(FindConVar("god"), GetConVarFlags(FindConVar("god")) | FCVAR_NOTIFY | FCVAR_CHEAT);
SetConVarInt(FindConVar("director_no_mobs"), 1);
SetConVarInt(FindConVar("director_ready_duration"), 0);
SetConVarInt(FindConVar("z_common_limit"), 0);
SetConVarInt(FindConVar("sv_alltalk"), 1);
SetConVarInt(FindConVar("z_ghost_delay_max"), 0);
SetConVarInt(FindConVar("z_ghost_delay_min"), 0);
for(new i = 1; i <= GetClientCount(); i++)
if(IsClientConnected(i))
SetEntityMoveType(i, MOVETYPE_NONE);
}
Unfreeze_Game()
{
DebugPrint("Unfreezing game");
SetConVarFlags(FindConVar("god"), GetConVarFlags(FindConVar("god")) & ~FCVAR_NOTIFY);
SetConVarInt(FindConVar("god"), 0);
SetConVarFlags(FindConVar("god"), GetConVarFlags(FindConVar("god")) | FCVAR_NOTIFY);
ResetConVar(FindConVar("director_no_mobs"));
ResetConVar(FindConVar("director_ready_duration"));
ResetConVar(FindConVar("z_common_limit"));
SetConVarInt(FindConVar("sv_alltalk"), 0);
ResetConVar(FindConVar("z_ghost_delay_max"));
ResetConVar(FindConVar("z_ghost_delay_min"));
for(new i = 1; i <= GetClientCount(); i++)
if(IsClientConnected(i))
SetEntityMoveType(i, MOVETYPE_WALK);
}
#define DEBUG 1
DebugPrint(const string:message[], any:...)
{
decl String:buffer[192];
VFormat(buffer, sizeof(buffer), message, 2);
if(DEBUG == 1)
PrintToChatAll(buffer);
else
PrintToServer(buffer);
}
If someone could tell me why it isn't working all the time, or point me in the right direction, that'd be awesome.
Thanks,
Jack.