*** Terrible Title Removed
#1

PHP код:
/*------------------------*\
| Maths script by Zezombia |
\*------------------------*/
#include <a_samp>
#define yellow 0xFFFF00AA
#define red 0xFF0000AA
#define green 0x33FF33AA
forward Maths();
new 
answer;
new 
answered;
new 
score;
new 
timer;
new 
timerset;
public 
OnPlayerCommandText(playeridcmdtext[])
{
        new 
cmd[256], idx;
        
cmd strtok(cmdtextidx);
        if (
strcmp("/answer"cmdtrue) == 0)
        {
                new 
tmp[256], cmdidstring[256], pname[MAX_PLAYER_NAME];
                
tmp strtok(cmdtextidx);
                if(!
strlen(tmp)) return SendClientMessage(playeridred"USAGE: /Answer [answer]");
                
cmdid strval(tmp);
                if(
cmdid answer || cmdid answer)
                {
                        
SendClientMessage(playeridred"Wrong answer!");
                }
                if(
cmdid == answer && answered == 0)
                {
                        
GetPlayerName(playeridpnamesizeof(pname));
                        
format(stringsizeof(string), "%s has won %d score for answering the math question '%d'!"pnamescorecmdid);
                        
SendClientMessageToAll(greenstring);
                        
GivePlayerMoney(playerid10000);
                        
answered 1;
                        
SetPlayerScore(playeridGetPlayerScore(playerid) + score);
                        
score 0;
                        return 
1;
                }
                else if(
cmdid == answer && answered == 1)
                {
                        
SendClientMessage(playeridred"To late!");
                }
                return 
1;
        }
        if (
strcmp("/startmaths"cmdtrue) == 0)
        {
                if(
IsPlayerAdmin(playerid) == 0) return SendClientMessage(playeridred"You are not an RCON admin");
                new 
tmp[256], cmdidstring[256];
                
tmp strtok(cmdtextidx);
                if(!
strlen(tmp)) return SendClientMessage(playeridred"USAGE: /Startmaths [timer (seconds)]");
                
cmdid strval(tmp);
                
KillTimer(timer);
                
timerset cmdid 1000;
                
timer SetTimer("Maths"timerset1);
                
format(stringsizeof(string), "Maths started, timer set to every %d seconds"cmdid);
                
SendClientMessage(playeridyellowstring);
                return 
1;
        }
        if (
strcmp("/stopmaths"cmdtrue) == 0)
        {
                if(
IsPlayerAdmin(playerid) == 0) return SendClientMessage(playeridred"You are not an RCON admin");
                
KillTimer(timer);
                
SendClientMessage(playeridyellow"Maths stopped");
                return 
1;
        }
        return 
0;
}
public 
Maths()
{
        new 
string[256], addsubtext1[10], addsubtext2[10];
        new 
temp1;
        new 
number1 random(100);
        new 
number2 random(100);
        new 
number3 random(100);
        new 
addsubnumb1 random(2);
        new 
addsubnumb2 random(2);
        if(
addsubnumb1 == 0)
        {
                
score score 10;
                
format(addsubtext1sizeof(addsubtext1), "-");
                
temp1 number1 number2;
        }
        else if(
addsubnumb1 == 1)
        {
                
score score 5;
                
format(addsubtext1sizeof(addsubtext1), "+");
                
temp1 number1 number2;
        }
        if(
addsubnumb2 == 0)
        {
                
score score 10;
                
format(addsubtext2sizeof(addsubtext2), "-");
                
answer temp1 number3;
        }
        else if(
addsubnumb2 == 1)
        {
                
score score 5;
                
format(addsubtext2sizeof(addsubtext2), "+");
                
answer temp1 number3;
        }
        
format(stringsizeof(string), "MATHS: %d%s%d%s%d - /answer to answer this question! Worth %d score!"number1addsubtext1number2addsubtext2number3score);
        
SendClientMessageToAll(yellowstring);
        
answered 0;
        return 
1;
}
strtok(const string[], &index)
{
        new 
length strlen(string);
        while ((
index length) && (string[index] <= ' '))
        {
                
index++;
        }
        new 
offset index;
        new 
result[20];
        while ((
index length) && (string[index] > ' ') && ((index offset) < (sizeof(result) - 1)))
        {
                
result[index offset] = string[index];
                
index++;
        }
        
result[index offset] = EOS;
        return 
result;

guys i downloaded this math code from samp forum but i want that the player type answer in his/her chat without /answer cmd.Any help for this??
Reply
#2

Use OnPlayerText callback and string compare function in if statement.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)