removing a value from a variable - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: removing a value from a variable (
/showthread.php?tid=274298)
removing a value from a variable -
SpankMe2 - 05.08.2011
Hey Guys,
So ive just came across this question i cant find a answer to.
If I create a variable called players to see how meny is online so i can divide the amount of players online by the amount of players that want HappyHour to run so like a votng system
I know how to add to variable you use this
pawn Код:
PlayerInfo[playerid][Players]++;
So how do I take away from that variable
and how can i divide that varible by 2 and get half to make the happy hour variable reach half its value before the votes for Happy Hour reach the level where it starts#
Thanks in advance.
Re: removing a value from a variable -
MadeMan - 05.08.2011
Quote:
Originally Posted by SpankMe2
So how do I take away from that variable
|
pawn Код:
PlayerInfo[playerid][Players]--
Quote:
Originally Posted by SpankMe2
how can i divide that varible by 2
|
pawn Код:
PlayerInfo[playerid][Players]/2
Re: removing a value from a variable -
SpankMe2 - 05.08.2011
Quote:
Originally Posted by MadeMan
pawn Код:
PlayerInfo[playerid][Players]--
pawn Код:
PlayerInfo[playerid][Players]/2
|
Thanks + its that simple
oh and the script was fixed last night it was one line up from where you removed that other bracket so Thanks for you help there to
Re: removing a value from a variable -
Basicz - 05.08.2011
Like this?
pawn Код:
new
iPlayerCounts = -1
;
public OnPlayerConnect( playerid )
{
if ( iPlayerCounts < 0 )
iPlayerCounts = 0;
else
iPlayerCounts ++; // Increase the iPlayerCounts, you could do " iPlayerCounts += 1; "
return 1;
}
public OnPlayerDisconnect( playerid, reason )
{
if ( iPlayerCounts > -1 )
iPlayerCounts --; // Take away the variable, you could use " iPlayerCounts -= 1; "
return 1;
}
stock dividePlayersByTwo( )
return iPlayerCounts / 2; // Divides iPlayerCounts by Two.
stock startHappyHour( )
{
if ( ( dividePlayersByTwo( ) ) < 5 ) // if ( ( iPlayerCounts /2 ) < 5 )
return GameTextForAll( "Not enough players", 3000, 3 );
return 1;
}
If I understand, you are asking this.