[ Snippet ] Can you work out this?

Started by BigcaT_, May 02, 2015, 01:01 PM

Previous topic - Next topic

BigcaT_

Well My friend came up with this idea at first. -- Ask the players some math questions, if they work out, then server will give some money as reward.

1. Add these to onscriptload.
NewTimer("chatmsg", 120000, 0);
ChatGame <- false;
ChatResult <- 0;
        // if you don't want to make a timer, you can also make a command to call chatmsg.
2. Add this function .
function chatmsg()
{
if ( GetPlayers() > 0 )
{
ChatGame = true;
local beisuan = random(1,10000), suan = random(1,9999), snake = random (1,3), bdc;
switch (snake)
    {
case 1: bdc = "+"; break;
case 2: bdc = "-"; break;
case 3: bdc = "x"; break;
}
Message("Chat Game Start! The first player who type the result of [#06FA16]'" + (beisuan+bdc+suan) + "' will reward 200$.");
switch (bdc)
{
case "+": ChatResult = beisuan + suan; break;
case "-": ChatResult = beisuan - suan; break;
case "x": ChatResult = beisuan * suan; break;
}
}
}
3.Finally, check if player works out the result.
function onPlayerChat( player, arguments )
{
if ( ChatGame == true )
{
    if ( IsNum(arguments) )
{
if ( ChatResult == arguments.tointeger() )
{
Message( player.Name + " Worked out the result! Reward: 200$.");
player.Cash += 200;
ChatGame = false;
}
}
}
}
 

// if u don't have random function, then add this
function random(start, finish)
{
 local t = ((rand() % (finish - start)) + start);
 return t;
}

Enjoy it! :P