Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #define CONTESTTIME 3 //Amounts of minutes till a new contest is started, regardless of the current contest is won or not.
- #define MINIMUM_VALUE 2000000 //The minimum value that the contest number may be.
- #define MAXIMUM_VALUE 8000000 //The maximum value that the contest number may be.
- #define CONTEST_PRIZE 5000 // The prize in dollars that the player will win, if he types the answer first.
- forward NewContest(); //This'll be called when a new contest begins.
- forward OnPlayerWinContest(playerid); //This is for when a player wins the contest.
- new ContestAnswer = -1; //Minus 1 (-1). We're using this to show that there's no contest running.
- public OnFilterScriptInit()
- {
- SetTimer("NewContest",(1000*60*CONTESTTIME),1); // Sets the timer in minutes. Timers are in millseconds, and 1000 milliseconds is equal to a second. That multiplies with 60, making it one minute. That once again multiplies with the 'CONTESTTIME' you've defined, making it in the amount of minutes you want.
- //Rest of your code here, like AddPlayerClass();
- return 1;
- }
- public NewContest()
- {
- new string[128]; //We're creating a new string here to inform players of the new number.
- ContestAnswer = MINIMUM_VALUE + random(MAXIMUM_VALUE-MINIMUM_VALUE);
- /* Contest Answer: The number that a player must type to win the contest.
- Minimum_value: The minimum amount, so the number won't be lower then that.
- 'random' picks a random number, but to make sure it doesn't exceeds the maximum value, it substracts the minimum value from it.
- Reason for the 'random': MAXIMUM_VALUE is defined as 8000000. MINIMUM_VALUE is defined as 2000000. The minimum number is already 2000000, and if the the 'random' function also puts out 8000000 (The max value), it'll be able to put out numbers above the MAXIMUM_VALUE. */
- format(string,sizeof string,"A new contest has started. Whoever types %d as first, wins $%d.",ContestAnswer,CONTEST_PRIZE); // This formats a string. More information about strings can be found in the link under this code.
- SendClientMessageToAll(0x00FFFFFF,string); // Color '0x00FFFFFF' is lightblue. The 'string' has just been formatted by us, see the line above. This informs the players that whoever types the contest number first, wins a prize.
- return 1;
- }
- public OnPlayerText(playerid,text[])
- {
- if(strval(text) == ContestAnswer && ContestAnswer != -1) // Checks if the text the player has typed is equal to the Contest Answer, but isn't -1.
- {
- OnPlayerWinContest(playerid); // This'll direct the script to the OnPlayerWinContest callback.
- }
- return 1;
- }
- public OnPlayerWinContest(playerid)
- {
- new pName[MAX_PLAYER_NAME],string[128]; // A pName variable for the player's name, and a string to output.
- GetPlayerName(playerid,pName,sizeof pName); //Get's the player's name.
- format(string,sizeof string,"Player %s has won the contest and has won %d!",pName,CONTEST_PRIZE);
- SendClientMessageToAll(0x00FFFFFF,string); //Same color, and it outputs a string.
- GivePlayerMoney(playerid,CONTEST_PRIZE);
- ContestAnswer = -1;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment