Loosing a Variable
#1

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.
Reply
#2

kindly don't post same thread two times.

OT: give us more detail please.
Reply
#3

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 ?
Reply
#4

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..
Reply
#5

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.
Reply
#6

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?
Reply
#7

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.
Reply
#8

Yes i want to give money and score to the last that inevent=1 + event= enabled.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)