AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Best way to store variables relating to players? (https://forums.alliedmods.net/showthread.php?t=174884)

ceribik 12-26-2011 23:05

Best way to store variables relating to players?
 
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.

McFlurry 12-26-2011 23:34

Re: Best way to store variables relating to players?
 
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.

ceribik 12-27-2011 00:41

Re: Best way to store variables relating to players?
 
I'm surprised sourcepawn has enums. They should work great.

Thanks for the help :)


All times are GMT -4. The time now is 12:55.

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