PDA

View Full Version : [TF2] Confused by variables and such


DJ Data
10-30-2014, 15:05
Hey there.

I'm making a system which allows players to ready up or unready. Once all players are ready, it executes a code.
The only way i see this being possible is to check if a variable isReady is true on a certain player. I have no idea how to define a certain variable on 1 single client.

Any help is appreciated.

11530
10-30-2014, 15:30
Do you mean an array of boolean values?

new bool:isReady[MAXPLAYERS+1];

DJ Data
10-30-2014, 16:01
Could you go further into detail? As i said, i'm genuinely confused as to how arrays work and so on.
I've seen this before [MAXPLAYERS+1] but i dont understand what it does nor the logic behind it.

Thanks.

thecount
10-30-2014, 16:02
Yeah, build an array of boolean values.

new bool:isReady[MAXPLAYERS + 1];
stock onReady(any:client){
isReady[client] = true;
}
stock onUnready(any:client){
isReady[client] = false;
}
stock bool:isEveryoneReady(){
for(new i=1;i<=MaxClients;i++){
if(IsClientInGame(i) && !isReady[i]){
return false;
}
}
return true;
}

Powerlord
10-30-2014, 16:11
When you say ready/unready, do you mean via the MvM or Tournament interface, or making something up yourself?

DJ Data
10-30-2014, 16:42
Making yourself ready, all sourcemod side.

Anyways, here is what i got from this post so far.


the handle is called somewhere up here, dw.

public OnPluginStart()
{
//Ready/Not Ready
RegConsoleCmd("sm_ready", Command_Ready);
RegConsoleCmd("sm_unready", Command_NotReady);
}

public Action:Command_Ready(client, args)
{
isReady[client] = true;

new String:nick[64];
GetClientName(client, nick, sizeof(nick));

CPrintToChatAll("{black}[{cyan}e{white}Source{black}]{green} &s is ready.", nick);
}

public Command_NotReady(client, args)
{
isReady[client] = false;

new String:nick[64];
GetClientName(client, nick, sizeof(nick));

CPrintToChatAll("{black}[{cyan}e{white}Source{black}]{red} &s is not ready.", nick);
}

stock bool:isEveryoneReady()
{
for(new i=1;i<=MaxClients;i++)
{
if(IsClientInGame(i) && !isReady[i])
{
return false;
}
else if(IsClientInGame(i) && !isReady[i])
{
CPrintToChatAll("{black}[{cyan}e{white}Source{black}]{gold} All players are ready, waiting for Admin verification.")
}
}
return true;
}

Kolapsicle
10-30-2014, 16:46
It's worth remembering that MAXPLAYERS is a simple define in clients.inc which is automatically included when you #include <sourcemod>

#define MAXPLAYERS 65 /**< Maximum number of players SourceMod supports */

new bool:MyBool[MAXPLAYERS]; // I'm fairly sure that +1 is no longer needed as MAXPLAYERS is defined as 65 instead of 64 like it used to be, please correct me if I'm wrong.

public Action:MyFunction(client, args) // Random function that each client in the server can call.
{
MyBool[client] = true; // Set MyBool to true for the client at this given index (The client who called MyFunction).
}What we've done here is created a boolean that holds a true or false for each client (individual of each other) in the server.

thecount
10-30-2014, 16:48
Or you could just use my code. I basically built the whole thing for him. He just has to put it in the spots he wants it.

DJ Data
10-30-2014, 16:58
Or you could just use my code. I basically built the whole thing for him. He just has to put it in the spots he wants it.

I did, check above.
Just want to know if i did it right :S

thecount
10-30-2014, 17:03
I did, check above.
Just want to know if i did it right :S

Oh ok, didn't see that

thecount
10-30-2014, 17:11
if(IsClientInGame(i) && !isReady[i])
{
return false;
}
else if(IsClientInGame(i) && !isReady[i])
{
CPrintToChatAll("{black}[{cyan}e{white}Source{black}]{gold} All players are ready, waiting for Admin verification.")
}

Ok, well this doesn't make sense. It checks if the player is in the game and if they're not ready, then it returns false. Then you checked for the same thing again to print a message. I think you meant to check if all players are ready, then print the message. Also, the isEveryoneReady() doesn't fire by itself to check. You need to incorporate it into your code.

So, this might be what you wanted instead.


public OnPluginStart()
{
//Ready/Not Ready
RegConsoleCmd("sm_ready", Command_Ready);
RegConsoleCmd("sm_unready", Command_NotReady);
}

public Action:Command_Ready(client, args)
{
isReady[client] = true;

new String:nick[64];
GetClientName(client, nick, sizeof(nick));

CPrintToChatAll("{black}[{cyan}e{white}Source{black}]{green} &s is ready.", nick);
isEveryoneReady();
return Plugin_Handled;
}

public Command_NotReady(client, args)
{
isReady[client] = false;

new String:nick[64];
GetClientName(client, nick, sizeof(nick));

CPrintToChatAll("{black}[{cyan}e{white}Source{black}]{red} &s is not ready.", nick);
return Plugin_Handled;
}

stock bool:isEveryoneReady()
{
for(new i=1;i<=MaxClients;i++)
{
if(IsClientInGame(i) && !isReady[i])
{
return false;
}
}
CPrintToChatAll("{black}[{cyan}e{white}Source{black}]{gold} All players are ready, waiting for Admin verification.")
return true;
}

Chdata
10-31-2014, 02:28
It's worth remembering that MAXPLAYERS is a simple define in clients.inc which is automatically included when you #include <sourcemod>

#define MAXPLAYERS 65 /**< Maximum number of players SourceMod supports */

new bool:MyBool[MAXPLAYERS]; // I'm fairly sure that +1 is no longer needed as MAXPLAYERS is defined as 65 instead of 64 like it used to be, please correct me if I'm wrong.

public Action:MyFunction(client, args) // Random function that each client in the server can call.
{
MyBool[client] = true; // Set MyBool to true for the client at this given index (The client who called MyFunction).
}What we've done here is created a boolean that holds a true or false for each client (individual of each other) in the server.

TBH... for TF2, is there any server that even goes above 33-34 players?

DJ Data
10-31-2014, 07:59
TBH... for TF2, is there any server that even goes above 33-34 players?

Never heard of 34 o.O

asherkin
10-31-2014, 08:13
+1 is used to make indexing easier, you need it if you want to use client indexes directly to access the array (CS:S and CS:GO go up to 65 clients, 64 players + SourceTV).

Powerlord
10-31-2014, 09:34
Never heard of 34 o.O

TF2 clients start having issues around that point.