SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 25/09/2018, 12:08 PM   #1
GameOvr
Huge Clucker
 
GameOvr's Avatar
 
Join Date: Jun 2018
Posts: 298
Reputation: 9
Default How to get the highest score and give him a prize

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
GameOvr is offline   Reply With Quote
Old 25/09/2018, 06:35 PM   #2
Electrifying
Big Clucker
 
Join Date: Sep 2018
Location: Pernambuco
Posts: 173
Reputation: 2
Default Re: How to get the highest score and give him a prize

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;
}
Electrifying is offline   Reply With Quote
Old 26/09/2018, 03:33 AM   #3
GameOvr
Huge Clucker
 
GameOvr's Avatar
 
Join Date: Jun 2018
Posts: 298
Reputation: 9
Default Re: How to get the highest score and give him a prize

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
GameOvr is offline   Reply With Quote
Old 26/09/2018, 03:44 AM   #4
d3Pedro
Huge Clucker
 
Join Date: Apr 2012
Location: darkness
Posts: 321
Reputation: 94
Default Re: How to get the highest score and give him a prize

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.
d3Pedro is offline   Reply With Quote
Old 26/09/2018, 07:49 AM   #5
GameOvr
Huge Clucker
 
GameOvr's Avatar
 
Join Date: Jun 2018
Posts: 298
Reputation: 9
Default Re: How to get the highest score and give him a prize

Thanks for all, can someone tell me what is the difference between
Code:
i--
and
--i
GameOvr is offline   Reply With Quote
Old 26/09/2018, 09:26 AM   #6
XStormiest
Gangsta
 
Join Date: Jun 2012
Location: Continent: Europe, Country: Romania, City: Buzau
Posts: 558
Reputation: 46
Default Re: How to get the highest score and give him a prize

Code:
--i // It decreases the value first and then asign it to the variable
The other one works the other way around.
__________________
XStormiest is offline   Reply With Quote
Old 26/09/2018, 11:12 AM   #7
CodeStyle175
Banned
 
Join Date: Apr 2014
Posts: 455
Reputation: 35
Default Re: How to get the highest score and give him a prize

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

CodeStyle175 is offline   Reply With Quote
Old 27/09/2018, 09:55 AM   #8
TheToretto
Gangsta
 
TheToretto's Avatar
 
Join Date: Jul 2015
Posts: 584
Reputation: 66
Default Re: How to get the highest score and give him a prize

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--
TheToretto is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the highest score of all players? MOSensei Scripting Help 1 25/05/2015 11:11 AM
Highest score! Zhoom Scripting Help 8 03/03/2012 06:31 AM
Getting the IDs of the player with highest score Skiaffo Help Archive 2 27/03/2011 09:59 AM
how to get the highest score in the server? Rocky Balboa Help Archive 8 23/08/2010 05:22 PM
Player with Highest Score[HELP] Tigerbeast11 Help Archive 4 17/12/2009 08:38 AM


All times are GMT. The time now is 10:28 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.