Raised This Month: $51 Target: $400
 12% 

Ready Up System - not working


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jackpf
Senior Member
Join Date: Dec 2009
Location: Uhm...
Old 12-25-2009 , 22:13   Ready Up System - not working
Reply With Quote #1

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_UpADMFLAG_BAN);
    
    
RegConsoleCmd("say"Is_Ready);
}

public 
Action:Ready_Up(clientargs)
{
    for(new 
1<= 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 
1<= 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"Namesizeof(Name));
                
DrawPanelText(ReadyPanelName);
            }
        }
    }
    
DebugPrint("Grouping unready players");
    
DrawPanelText(ReadyPanel"UNREADY");
    for(new 
1<= 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"Namesizeof(Name));
                
DrawPanelText(ReadyPanelName);
            }
        }
    }
    
    
DebugPrint("Sending panel to clients");
    for(new 
1<= GetClientCount(); i++)
        
SendPanelToClient(ReadyPaneliPanel_HandleMENU_TIME_FOREVER);
 
    
CloseHandle(ReadyPanel);
}

public 
Panel_Handle(Handle:menuMenuAction:actionparam1param2)
{
    return;
}

public 
Action:Is_Ready(clientargs)
{
    new 
string:arg1[1024];
    
GetCmdArg(1arg1sizeof(arg1));
    
    if(
strcmp(arg1"!ready"false) == || 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 
1<= GetClientCount() && <= MAXPLAYERSi++)
        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 
1<= GetClientCount(); i++)
        if(
IsClientConnected(i))
            
SetEntityMoveType(iMOVETYPE_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 
1<= GetClientCount(); i++)
        if(
IsClientConnected(i))
            
SetEntityMoveType(iMOVETYPE_WALK);
}

#define DEBUG 1

DebugPrint(const string:message[], any:...)
{
    
decl String:buffer[192];
    
    
VFormat(buffersizeof(buffer), message2);
    
    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.
jackpf is offline
Downtown1
Veteran Member
Join Date: Mar 2004
Old 12-26-2009 , 03:43   Re: Ready Up System - not working
Reply With Quote #2

GetClientCount() will return how many clients there are on the server, but it doesn't mean it will return the highest client id.

So you could e.g. have 3 clients with client IDs 1, 2, 8. Then your loops will never get the last client. Use MaxClients instead

Code:
for (new i = 1; i < MaxClients; i++)
BTW you do know there is this already? http://forums.alliedmods.net/showthread.php?t=84086 Why reinvent the wheel?
Downtown1 is offline
jackpf
Senior Member
Join Date: Dec 2009
Location: Uhm...
Old 12-26-2009 , 08:29   Re: Ready Up System - not working
Reply With Quote #3

ahh, that makes sense. I'll try it out tonight

And yeah, i have noticed your mod, and have "reused" small portions of it in mine (hope you dont mind) i just prefer using something ive made myself rather than something someone else has. Where's the fun in that? :p

Thanks for your hekp,
Jack
jackpf is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode