I want a script that checks the score and announces a winner.
#1

I am making a Deathmatch Server and I want some script that after a certain ammount of time it automatically checks each player's score/money and the one with the most score/money wins. The winner's name is displayed together with the amount of score/money. A Few seconds after the winner is declared, the Gamemode restarts automatically and a new Deathmatch round starts.

I did some searching and I found this script. Who posted it said, that this script checks the score/money and declares a winner every 30 minutes. I don't want to spend 30 minutes just to test it. So I changed #define TIME_IN_MINUTES 30 to #define TIME_IN_MINUTES 5. But as I am still learning I don't know if this was the right thing to do in order to change the time.

I even tried to change this line but always encountered errors:

SetTimer("ScoreCalculator",TIME_IN_MINUTES * 60000, true);

So what I am asking is whether this piece of script is any good, if it is what do i do to change the time, and if not, is there anything else i can do to obtain the same result as this script.

Thanks in advance.

Код:
#include <a_samp> //Necessary file which holds all of SA:MP's native functions.

#define FILTERSCRIPT //This is a filterscript, so define it as one.
#if defined FILTERSCRIPT //If we defined this as a filterscript (we did, see above line)

#define TIME_IN_MINUTES 30 //30 minutes from when the server starts, everybodies scores will be calculated and a winner will be announced.
#define RESET_SCORE true //When the round ends, do you want everybody's cash to be set to $0?

public OnFilterScriptInit() //When the script starts.
{
    SetTimer("ScoreCalculator",TIME_IN_MINUTES * 60000, true); //Set a timer to calculate scores with the function 'ScoreCalculator()'.
}

#endif //Prevent nasty 'expected '#endif' but found -EOF-' errors.

stock ScoreCalculator() //Our new function.
{
new WinningPlayer, WinningScore; //2 new integer variable's which will hold our winner's score and his id.
for(new i = 0; i != MAX_PLAYERS; i++) //Make a loop to look at every connected player's amount of money, and compare them.
{
if(IsPlayerConnected(i)) //If 'i' is connected.
{
if(GetPlayerMoney(i) > WinningScore) //If i's money is higher than the highest known amount of money so far.
{
WinningScore = GetPlayerMoney(i); //Set the variable 'WinningScore' to the amount of money that 'i' has.
WinningPlayer = i; //Set the 'WinningPlayer' variable to the id (playerid) of i.
}
}
}

new string[200]; //A new string variable which will be sent to everybody after being formatted.
GetPlayerName(WinningPlayer,string,MAX_PLAYER_NAME); //Get the winning player's name.
format(string, sizeof(string), "ATTENTION: Player '%s' has won the round with $%d.",string,WinningScore); //Format our string, with the player's name and his score.
SendClientMessageToAll(0x33CCFFAA,string); //Send the announcement to everybody in lightblue.

#if RESET_SCORE == true //If you want everybody's cash to be restored after the round is won.
for(new i = 0; i != MAX_PLAYERS; i++) //Make a loop to go through all the players.
{
if(IsPlayerConnected(i)) //If 'i' is connected.
{
SetPlayerMoney(i, 2000); //Set i's money to $0.
}
}
SendClientMessageToAll(0x33CCFFAA,"ATTENTION: You're cash has been set to $0 as a new round has begun."); //After the loop is finished, let everybody know that their cash has been reset.

#endif //Prevent nasty 'expected '#endif' but found -EOF-' errors.

}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)