PDA

View Full Version : [TF2][Help]Array or enum: which to use in my case?


cidra
06-19-2016, 06:39
Hi. I want to create a sort of sheet that keeps the players' info for my plugin.
My idea was to make 18 arrays for the 18 in-game users (Highlander mode)
Each array has 4 integers:
1. userid
2. team (1 = red; 2= blu)
3. class (1 = scout; 2=soldier; etc...)
4. BOT (1 = no; 2 = yes)

These variables will be refreshed everytime someone joins a class, leaves the match or does some specified command.
This would let the plugin recognize the Bots with a specified class or team and would make a sort of filter for some commands of my choice.
Do you think an array is a good thing for this case? Or should i use something else?
Thank you, and sorry if this question is a blasphemy to SourcePawn language: i just got into it :oops:

Chaosxk
06-19-2016, 16:16
Should be in the scripting section.

As for your question, array will be fine. Using an array with enum will make it easier to work with. Something like this.

enum userData
{
userid = 0,
team,
class,
bot
};

int userArray[MAXPLAYERS + 1][userData]; //Creates an array for each client with enums

public void OnClientPostAdminCheck(int client)
{
userArray[client][userid] = GetClientUserId(client); //Gets the user id and set the array
userArray[client][bot] = IsFakeClient(client) ? 2 : 1; //If client is a bot set array to 2 otherwise 1
}

cidra
06-20-2016, 08:57
Should be in the scripting section.

As for your question, array will be fine. Using an array with enum will make it easier to work with. Something like this.

enum userData
{
userid = 0,
team,
class,
bot
};

int userArray[MAXPLAYERS + 1][userData]; //Creates an array for each client with enums

public void OnClientPostAdminCheck(int client)
{
userArray[client][userid] = GetClientUserId(client); //Gets the user id and set the array
userArray[client][bot] = IsFakeClient(client) ? 2 : 1; //If client is a bot set array to 2 otherwise 1
}

That was really helpful, thank you.
But how can i get the userid of a player who has, for example, value 1 on class, value 3 on team and value 2 on bot?
And also, i don't understand very well the point of enum: what's the difference between array and enum in this case?

good_live
06-20-2016, 09:21
An enum is just a enumaration, which means it's assigning a string a number (Counting upwards from 0 as the word enumation implicates). In your exampel userid = 0, team = 1, class = 3 and so on. You don' need the enum. It just makes it easier to read the code.

The array is a way to store the informations (as you maybe know).

So to access a clients userid you could write userArray[client][userid] or userArray[client][0]
that would be the same.

cidra
06-20-2016, 10:02
An enum is just a enumaration, which means it's assigning a string a number (Counting upwards from 0 as the word enumation implicates). In your exampel userid = 0, team = 1, class = 3 and so on. You don' need the enum. It just makes it easier to read the code.

The array is a way to store the informations (as you maybe know).

So to access a clients userid you could write userArray[client][userid] or userArray[client][0]
that would be the same.

This is part of a plugin i'm working on:
public ScoutMenuHandler(Handle:menu, MenuAction:action, client, param2)
{
if (action == MenuAction_Select)
{

char info[32];
GetMenuItem(menu, param2, info, sizeof(info));
if (StrEqual(info, "1"))
{
if (userArray[userid][1][3][bot] == 2)
{
//do stuff (kick)
}
else
{
//do other stuff (print a message in chat)
}
}

}
else if (action == MenuAction_Cancel && param2 == MenuCancel_ExitBack)
{
Menu_Test1(client);
}
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
}
I want to check if client with class "1" (Scout) and team 3 (Blu) has value 3 at "bot" column (Is a bot)
If he is a bot then kick him using the id on the first column.
As i said this is in highlander mode, so there will be only one per class.
How can i do this? Should i use a while command?

Chaosxk
06-20-2016, 14:25
I'm very confused at what your trying to accomplish.

This is a menu handler than clients can select, a bot can't select from a menu. So in this case every time someone selects from the menu the "bot" value will always be false (Player is never a bot).

Are you trying to loop through every client and kick all the bots when client selects "1"?

friagram
06-22-2016, 01:23
I generally use an enum for array organization

enum {
CLIENT_BITFLAGS
CLIENT_LOADED
CLIENT_TIMESTAMP

CLIENT_ARRAY_SIZE
};

new g_clientarray[MAXPLAYERS+1][CLIENT_ARRAY_SIZE]

then do like

public OnClientPostAdminCheck (client)
{
g_clientarray[client][CLIENT_LOADED] = 1
}