Player variables
#1

Is there a way to increase the value of a variable for each player..

For example..

Player types /yes
increases that one players value to 1
another player types /yes
also increases only his value to 1
Reply
#2

new Variable[MAX_PLAYERS];

/yes

Variable[playerid]++;
Reply
#3

SetPVarInt(playerid, "yesvar", GetPVarInt(playerid, "yesvar") +1);
Reply
#4

Code:
new variable[MAX_PLAYERS];

// Now on the command: /yes

variable[playerid] += 1;  // Increases the actual value in +1
Reply
#5

Thanks all, Also im pretty new to scripting atm but im just developing a small unique script which will be easier to test using a player variable (i think) But once i've released it i'll update it to using an array (Also think)

And also im getting a few errors.. Heres my script (Blanked out as i don't want anyone copying my idea until i release it)

pawn Code:
CMD:XXX (playerid, params[])
    {
    if(IsPlayerInRangeOfPoint(playerid, XXXXXXXXXXX))
    {
    CreateObject(XXXXXXXXXXXXXXXXXXXXXXXXXXXX);
    pVariable[playerid] ++;
    }
    return 1;
    }
Now heres the errors i get..


Code:
C:\Users\Scripting.Ash-PC\Desktop\Roleplay\filterscripts\xxx.pwn(245) : error 017: undefined symbol "pVariable"
C:\Users\Scripting.Ash-PC\Desktop\Roleplay\filterscripts\xxx.pwn(245) : warning 215: expression has no effect
C:\Users\Scripting.Ash-PC\Desktop\Roleplay\filterscripts\xxx.pwn(245) : error 001: expected token: ";", but found "]"
C:\Users\Scripting.Ash-PC\Desktop\Roleplay\filterscripts\xxx.pwn(245) : error 029: invalid expression, assumed zero
C:\Users\Scripting.Ash-PC\Desktop\Roleplay\filterscripts\xxx.pwn(245) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Weird because i did define my variable and also set the value to 0..

new pVariable=0[MAX_PLAYERS];
Reply
#6

Initializing an array has a different syntax than that of regular variables:
pawn Code:
new pVariable[MAX_PLAYERS] = { 0, ... };
Though that isn't necessarily needed, as all Pawn variables default to 0.
Reply
#7

You cannot use this and get it works.
pawn Code:
new pVariable=0[MAX_PLAYERS];
You should define it as a global variable and set a value after, either inside a callback/custom function or command.
pawn Code:
// Global variable
new
    pVariable[ MAX_PLAYERS ]
;

// OnPlayerConnect
pVariable[ playerid ] = 0;

// There you want to increase the value by one
pVariable[ playerid ]++;
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)