Bet command
#1

Hi there, im working on my bet command.
This is what I got so far:

pawn Код:
if(strcmp("/bet", cmdtext, true) == 0)
    {
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
    {
    SendClientMessage(playerid, COLOR_WHITE, "USAGE: /bet [amount] [color (red or black)]");
    return 1;
    }
    new rand = random(2);
    new amount;
    amount = strval(tmp);
    if(rand >= 0)
    if(strcmp(tmp, "red", true) == 0)
    {
    GivePlayerMoney(playerid, amount);
    format(string, sizeof(string), "RED WINS: You win %d dollars !",amount);
    SendClientMessage(playerid, COLOR_WHITE, string);
    return 1;
    }
    else if(strcmp(tmp, "black", true) == 0)
    {
    GivePlayerMoney(playerid, -amount);
    format(string, sizeof(string), "BLACK WINS: You lose %d dollars !",amount);
    SendClientMessage(playerid, COLOR_WHITE, string);
    return 1;
    }
    if(rand >=1)
    if(strcmp(tmp, "black", true) == 0)
    {
    GivePlayerMoney(playerid, amount);
    format(string, sizeof(string), "BLACK WINS: You win %d dollars !",amount);
    SendClientMessage(playerid, COLOR_WHITE, string);
    return 1;
    }
    else if(strcmp(tmp, "red", true) == 0)
    {
    GivePlayerMoney(playerid, -amount);
    format(string, sizeof(string), "RED WINS: You lose %d dollars !",amount);
    SendClientMessage(playerid, COLOR_WHITE, string);
    return 1;
    }
}
It compiles fine, but the problem is, when I type for example /bet 1000 red ingame, it gives me UNKNOWN command, anyone out there who knows the solution?

thx in advance
Reply
#2

Use sscanf.
Reply
#3

Quote:
Originally Posted by 0rb
Use sscanf.
Be more specific please
Reply
#4

https://sampwiki.blast.hk/wiki/Sscanf
Reply
#5

I already got that. How to use it?
Reply
#6

Search.
Reply
#7

Quote:
Originally Posted by еddy
Search.
I can't find how to use SSCANF in this case.
I already searched but didn't find anything that helped
Reply
#8

Here you have some infos about sscanf: https://sampwiki.blast.hk/wiki/Fast_Commands#sscanf
Reply
#9

Still didn't get it how I should use it here though.
Reply
#10

You use strtok so u cant use cmdtext only cmd
Код:
if(strcmp(cmd,"/bet", true) == 0)
{
	tmp = strtok(cmdtext, idx);
	if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /bet [amount] [color (red or black)]");
	new amount = strval(tmp);
	tmp = strtok(cmdtext, idx);
	new rand = random(2);
	if(!rand)
	{
		if(strcmp(tmp, "red", true) == 0)
		{
			GivePlayerMoney(playerid, amount);
			format(string, sizeof(string), "RED WINS: You win %d dollars !",amount);
			SendClientMessage(playerid, COLOR_WHITE, string);
		}
		else if(strcmp(tmp, "black", true) == 0)
		{
			GivePlayerMoney(playerid, -amount);
			format(string, sizeof(string), "BLACK WINS: You lose %d dollars !",amount);
			SendClientMessage(playerid, COLOR_WHITE, string);
		}
	}else{
		if(strcmp(tmp, "black", true) == 0)
		{
			GivePlayerMoney(playerid, amount);
			format(string, sizeof(string), "BLACK WINS: You win %d dollars !",amount);
			SendClientMessage(playerid, COLOR_WHITE, string);
		}
		else if(strcmp(tmp, "red", true) == 0)
		{
			GivePlayerMoney(playerid, -amount);
			format(string, sizeof(string), "RED WINS: You lose %d dollars !",amount);
			SendClientMessage(playerid, COLOR_WHITE, string);
		}
	}
	return 1;
}
:>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)