Raised This Month: $ Target: $400
 0% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
cidra
Junior Member
Join Date: Jun 2016
Location: Italy
Old 06-19-2016 , 06:39   [TF2][Help]Array or enum: which to use in my case?
Reply With Quote #1

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

Last edited by cidra; 06-19-2016 at 15:06. Reason: New question. Don't want to open another topic when this is still on the 1st page.
cidra is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 06-19-2016 , 16:16   Re: [TF2][Help]Array or enum: which to use in my case?
Reply With Quote #2

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.

Code:
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
}
__________________

Last edited by Chaosxk; 06-19-2016 at 16:20.
Chaosxk is offline
cidra
Junior Member
Join Date: Jun 2016
Location: Italy
Old 06-20-2016 , 08:57   Re: [TF2][Help]Array or enum: which to use in my case?
Reply With Quote #3

Quote:
Originally Posted by Chaosxk View Post
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.

Code:
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?
cidra is offline
good_live
AlliedModders Donor
Join Date: Oct 2013
Old 06-20-2016 , 09:21   Re: [TF2][Help]Array or enum: which to use in my case?
Reply With Quote #4

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
HTML Code:
userArray[client][userid]
or
HTML Code:
userArray[client][0]
that would be the same.
good_live is offline
cidra
Junior Member
Join Date: Jun 2016
Location: Italy
Old 06-20-2016 , 10:02   Re: [TF2][Help]Array or enum: which to use in my case?
Reply With Quote #5

Quote:
Originally Posted by good_live View Post
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
HTML Code:
userArray[client][userid]
or
HTML Code:
userArray[client][0]
that would be the same.
This is part of a plugin i'm working on:
Code:
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?
cidra is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 06-20-2016 , 14:25   Re: [TF2][Help]Array or enum: which to use in my case?
Reply With Quote #6

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"?
__________________
Chaosxk is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 06-22-2016 , 01:23   Re: [TF2][Help]Array or enum: which to use in my case?
Reply With Quote #7

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
}
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Reply


Thread Tools
Display Modes

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 21:35.


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