#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 OnGameModeInit()
{
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;
Amazing,I was wondering how to do that,good job!
I'll try adding letters in my server,thanks! |
new CO[4]; // Contest Option
public NewContest()
{
new string[128];
CO[0] = MINIMUM_VALUE + random(MAXIMUM_VALUE-MINIMUM_VALUE);
CO[1] = MINIMUM_VALUE + random(MAXIMUM_VALUE-MINIMUM_VALUE);
CO[2] = MINIMUM_VALUE + random(MAXIMUM_VALUE-MINIMUM_VALUE);
CO[3] = MINIMUM_VALUE + random(MAXIMUM_VALUE-MINIMUM_VALUE);
format(string,sizeof string,"~w~ Contest starting ~n~~r~ %d - %d - %d - %d",CO[0],CO[1],CO[2],CO[3]);
GameTextForAll(string,12000,6);
SetTimer("ChooseFromRandom",12000,0);
return 1;
}
forward ChooseFromRandom();
public ChooseFromRandom()
{
ContestAnswer = CO[random(4)];
format(string,sizeof(string),"~w~Type the below number to win the contest! ~n~~g~%d",ContestAnswer);
GameTextForAll(string,10000,6);
return 1;
}
new Questions[][] = {
{"What is the capital of Sudan?"},
{"What is that last name of the president of the United States?"},
{"Where is the World Championship of football held in 2010?"}
};
new Answers[][] = {
{"Jartum"},
{"Obama"},
{"South Africa"}
};
public OnPlayerText(playerid,text)
{
if(!strcmp(text,Answers[ContestAnswer],true))
{
OnPlayerWinContest(playerid);
}
return 1;
}
new mQuests[][] = {
{
{"How much is 12+7?"},
{"How much is 8x91?"},
{"How much is 100-91.381?"},
{"What is the square root of 100?"}
};
new mAnswers[][] = {
{"19"},
{"728"},
{"8.619"},
{"10"}
};
public OnPlayerText(playerid,text)
{
if(!strcmp(text,mAnswers[ContestAnswer],true))
{
OnPlayerWinContest(playerid);
}
return 1;
}