Loosing 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)
+--- Thread: Loosing a Variable (
/showthread.php?tid=586831)
Loosing a Variable -
Rodri99 - 25.08.2015
How to make that the last (winner player) on the event get automatic score and money?
So the last player online with inevent=1 ?
Thanks to all,
Rodri.
Re: Loosing a Variable -
SpikY_ - 25.08.2015
kindly don't post same thread two times.
OT: give us more detail please.
Re: Loosing a Variable -
Rodri99 - 25.08.2015
The last player in game with inevent[playerid]=1; need to get auto money and score, but how count if in server there are 1 player with inevent = 1 ?
Re: Loosing a Variable -
SKAzini - 25.08.2015
Essentially you need a player variable "inevent" which defines if the player is in the event or not. You need to set this variable when you add the player to the minigame, and unset it when they're out.
Then you just simply check how many are in the game, and perform actions based on that information.
Код:
timer.. {
new amount = 0;
new lastpid = -1;
foreach.. {
if (inevent[player]) {
amount++;
lastpid = player;
}
}
if (amount <= 1) {
if (amount == 1) {
// give lastpid the rewards
}
// reset the game
}
}
Keep in mind that it's ages since I've coded in PAWN, it's mostly Java nowadays..
Re: Loosing a Variable -
Tamer - 25.08.2015
pawn Код:
for(new i=0; i <= GetPlayerPoolSize(); i++)
{
if(IsPlayerConnected(i) && inevent[i] == 1)
{
// code
break;
}
}
If you use foreach, then replace your loop.
Quote:
Originally Posted by SKAzini
snip
|
I want to point out that using INVALID_PLAYER_ID instead of -1 will make the code much more organized and readable.
Also, there's no need to count the player amount, atleast that's not how I would do it.
Re: Loosing a Variable -
SKAzini - 25.08.2015
Quote:
Originally Posted by Tamer
Also, there's no need to count the player amount, atleast that's not how I would do it.
|
But how are you gonna determine if the player is the last in the game then? Or am I missing something?
Re: Loosing a Variable -
Tamer - 25.08.2015
Quote:
Originally Posted by SKAzini
But how are you gonna determine if the player is the last in the game then? Or am I missing something?
|
As far as I understood, he wants to know which player is left in the event and give him the event rewards, which means finding the player that has the variable set to 1.
Oh but, if he will constantly check if there are people left, then he has to do yours. The code I posted will only work if he knows the event ended and there is only one player left.
Re: Loosing a Variable -
Rodri99 - 25.08.2015
Yes i want to give money and score to the last that inevent=1 + event= enabled.