How to get the highest score and give him a prize
#1

Hello, I have a small GunGame system, My idea is to give the player who has the highest level after 10mins has passed(it has 30 lvls xD) if 2 or more has the highest we must wait until 1 get the highest and give him the price but idk how to do that part my code is like this

Code:
CMD:start gg (only for admins)
//otherinfo
SetTimer("ENDGG", 100000, false);

-----------------------
public ENDGG();
//IDK how to do this part as i want in the description my var is   "lvl[MAX_PLAYERS]" (there are 30 lvls)
help me guys
Reply
#2

Code:
forward ENDGG();
public ENDGG()
{
	static i;
	for( i = GetMaxPlayers() - 1; i > -1; --i) //Create a loop
	{
		if(IsPlayerConnected(i))
		{
			if(lvl[i] == 30)
			{
				//your price here... can be whatever you want
				SetPlayerScore(i, GetPlayerScore(i)+10);
			}
		}
	}

return 1;
}

//ONGAMEMODEINIT

public OnGameModeInit()
{
	SetTimer("ENDGG", 600000, 1 /*1 if you want to repeat, 0 if you don't want to*/);
	return 1;
}
Reply
#3

Quote:
Originally Posted by Electrifying
View Post
Code:
forward ENDGG();
public ENDGG()
{
	static i;
	for( i = GetMaxPlayers() - 1; i > -1; --i) //Create a loop
	{
		if(IsPlayerConnected(i))
		{
			if(lvl[i] == 30)
			{
				//your price here... can be whatever you want
				SetPlayerScore(i, GetPlayerScore(i)+10);
			}
		}
	}

return 1;
}

//ONGAMEMODEINIT

public OnGameModeInit()
{
	SetTimer("ENDGG", 600000, 1 /*1 if you want to repeat, 0 if you don't want to*/);
	return 1;
}
but as I see in this It only check wheather that someone is lvl 30 and give him a prize but that's not what I want *READ THE MAIN POST WELL
Reply
#4

PHP Code:
new playergotprize[MAX_PLAYERS]; //make sure you save this where you save player stats
forward ENDGG();
public 
ENDGG()
{
    static 
i;
    for( 
GetMaxPlayers() - 1> -1; --i//Create a loop
    
{
        if(
IsPlayerConnected(i))
        {

            if(
lvl[i] == 30 && playergotprize[i] == 0)
            {
                
//your price here... can be whatever you want
                
SetPlayerScore(iGetPlayerScore(i)+10);
                
playergotprize[i] = 1;
            }
        }
    }

return 
1;
}

//ONGAMEMODEINIT

public OnGameModeInit()
{
    
SetTimer("ENDGG"600000/*1 if you want to repeat, 0 if you don't want to*/);
    return 
1;

Make sure you save/load that variable i did on top.
Reply
#5

Thanks for all, can someone tell me what is the difference between
Code:
i--
and
--i
Reply
#6

Code:
--i // It decreases the value first and then asign it to the variable
The other one works the other way around.
Reply
#7

PHP Code:
new lastScore=-1,
    
lastUser;
foreach(
Player,i){
    if(
lastScore User[i][Score]){
        
lastUser=i;
        
lastScore=User[i][Score];
    }

Reply
#8

new i = 1;
printf'ing i++ will give you 1 the first time, second print will give you 2, it reads the actual variable's value then increments it, ++i does the opposite, it increments it then print or whatever you wanna do with it. Same thing for --i & i--
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)