[Tutorial] How to make typing contests
#1

Here's a li'l tut for you guys about making typing contests.

We'll start with what a typing contest it:
A typing contest is a sort of "Mini Mini-game", in which the player has to type the shown numbers as quick as possible, and whoever does this first wins the contest, and gets a prize.

We'll start by defining what we'll need later.

Put on top of the script, but under your #includes, the following:

pawn Код:
#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.
I hope you all understood that.
Place the following things at OnGameModeInit(), or if you're using a filterscript OnFilterScriptInit()

pawn Код:
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;
}
That might be a bit complicated though, you may ask questions about it here.
We'll skip a few lines now, we'll be doing the "NewContest" and the "OnPlayerContestWin" callbacks here. If you're unsure where to put it, put it completely down at your script.

I'll show you how to do the NewContest() callback now.

pawn Код:
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;
That's actually maths. Questions in this thread please.

Now the last things, the "OnPlayerWinContest(playerid)" callback (YAY). This is called when a player types the random number. But to do so, we first must check what he has typed. Here's what you'll need to put at OnPlayerText:

pawn Код:
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;
}
Don't compile it after this, it'll give you errors. If you still compiled it, don't think about fixing it if you don't know what to do.

Last past, "OnPlayerWinContest".

pawn Код:
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;
I hope that'll get you going. About those strings: https://sampwiki.blast.hk/wiki/Format

Questions are allowed to be asked.

For a FilterScript, go to this link: http://pastebin.com/gTxiz2hx

Picture to let you guys see that in any case, the FS works:
Reply
#2

Like a reaction game right? thats sweet!
Reply
#3

Amazing,I was wondering how to do that,good job!

I'll try adding letters in my server,thanks!
Reply
#4

Pretty cool tut Hiddos Nice
Reply
#5

would be cool if it where Gametext and you could se the random patterns in the text like:

in red colorrandom numbers ofc)
4748954
3489089
4534895
4548954

and after a amount of time it chooses one of them and becomes green, first player to type the number wins!
just a thought Good job
Reply
#6

Quote:
Originally Posted by O_x
Посмотреть сообщение
Amazing,I was wondering how to do that,good job!

I'll try adding letters in my server,thanks!
Random letters? That'd be LoL if it'd actually made an existing word.
Also, I just came up with this idea without actually knowing if this worked. I've done it with random checkpoints as well, a random checkpoint spawns on the map (Pre-defined co-ords ofc.) and whoever enters it first wins.

@Cameltoe: It's possible, here's an example how you might do it, if I'm understanding you correctly.

pawn Код:
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;
}
Or something like that.
Reply
#7

i'll test when i get home, thx btw
Reply
#8

Would be cool also to find a secret word or something like


Giving 500000 to the first person to say the Capital of Sudan

(contest creator already typed Jarturm)
Reply
#9

Easy enough as well ^^

pawn Код:
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;
}
Reply
#10

Hey dude would something like this work?
pawn Код:
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;
}
Those are,of course,really easy and simple questions,but they are just random and are for demonstration only.
But again,will it work?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)