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
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 #1

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 #2

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 #3

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 #4

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


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