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

Best way to store variables relating to players?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ceribik
SourceMod Donor
Join Date: Dec 2007
Old 12-26-2011 , 23:05   Best way to store variables relating to players?
Reply With Quote #1

I'm used to OOP languages where I can do stuff like:
Code:
player.MyVar = blah
But as far as I can tell, there's no equivalent way to do this in SoucePawn (besides keyvalues, but their use is limited).

The next best thing I could think of is to store the info in arrays, but that would require over a dozen arrays per person and it would be a PITA to manage them as players constantly connect and disconnect.

(on that note, are there multidimensional arrays in sourcepawn, e.g. array[foo][bar]? )

Is there a better way of handling this?


Cheers.

Last edited by ceribik; 12-26-2011 at 23:06.
ceribik is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 12-26-2011 , 23:34   Re: Best way to store variables relating to players?
Reply With Quote #2

An easy way to store stuff and access named variables for each player would be enums, before I show you how I'll tell you that multidimensional arrays are possible in SourcePawn.
Example.
PHP Code:
enum PlayerInfo
{
    
Name,
    
SomeNumber
};

new 
player[MAXPLAYERS][PlayerInfo]; 
This makes it easy to manage each player. You can access each players info through their index, an example.
PHP Code:
public OnClientConnected(client)
{
    
player[client][SomeNumber] = GetRandomInt(0MAXPLAYERS);

Now the SomeNumber array index within player is a random number between 0 and 65.
enums are really just enumerated names that start with 0, so SomeNumber is really just index 1.
__________________

Last edited by McFlurry; 12-26-2011 at 23:36.
McFlurry is offline
Send a message via Skype™ to McFlurry
ceribik
SourceMod Donor
Join Date: Dec 2007
Old 12-27-2011 , 00:41   Re: Best way to store variables relating to players?
Reply With Quote #3

I'm surprised sourcepawn has enums. They should work great.

Thanks for the help
ceribik 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 15:53.


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