03.04.2011, 13:37
Nice
ok thanks in strcmp it's only playerid so i don't understand it now i know thanks
|
if(strcmp(cmd, "/givecash", true) == 0)
{
new tmp[256];
new string[128];
new playermoney;
new sendername[MAX_PLAYER_NAME];
new giveplayer[MAX_PLAYER_NAME];
new giveplayerid, moneys;
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, red, "USAGE: /givecash [playerid] [amount]");
return 1;
}
giveplayerid = strval(tmp);
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, red, "USAGE: /givecash [playerid] [amount]");
return 1;
}
moneys = strval(tmp);
//printf("givecash_command: %d %d",giveplayerid,moneys);
if (IsPlayerConnected(giveplayerid))
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
playermoney = GetPlayerMoney(playerid);
if (moneys > 0 && playermoney >= moneys)
{
GivePlayerMoney(playerid, (0 - moneys));
GivePlayerMoney(giveplayerid, moneys);
format(string, sizeof(string), "You gave %s(player: %d), $%d.", giveplayer,giveplayerid, moneys);
SendClientMessage(playerid, green, string);
format(string, sizeof(string), "You got $%d from %s(player: %d).", moneys, sendername, playerid);
SendClientMessage(giveplayerid, green, string);
PlayerPlaySound(playerid,1084,0.0,0.0,0.0);
printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
}
else
{
SendClientMessage(playerid, red, "You dont have so much ;)");
}
}
else
{
format(string, sizeof(string), "%d not found.", giveplayerid);
SendClientMessage(playerid, red, string);
}
return 1;
}
new cmd[256];
cmd = strtok(cmdtext, idx);
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[256];
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/givecash", true) == 0)
{
new tmp[256];
new string[128];
new playermoney;
new sendername[MAX_PLAYER_NAME];
new giveplayer[MAX_PLAYER_NAME];
new giveplayerid, moneys;
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, red, "USAGE: /givecash [playerid] [amount]");
return 1;
}
giveplayerid = strval(tmp);
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, red, "USAGE: /givecash [playerid] [amount]");
return 1;
}
moneys = strval(tmp);
//printf("givecash_command: %d %d",giveplayerid,moneys);
if (IsPlayerConnected(giveplayerid))
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
playermoney = GetPlayerMoney(playerid);
if (moneys > 0 && playermoney >= moneys)
{
GivePlayerMoney(playerid, (0 - moneys));
GivePlayerMoney(giveplayerid, moneys);
format(string, sizeof(string), "You gave %s(player: %d), $%d.", giveplayer,giveplayerid, moneys);
SendClientMessage(playerid, green, string);
format(string, sizeof(string), "You got $%d from %s(player: %d).", moneys, sendername, playerid);
SendClientMessage(giveplayerid, green, string);
PlayerPlaySound(playerid,1084,0.0,0.0,0.0);
printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
}
else
{
SendClientMessage(playerid, red, "You dont have so much ;)");
}
}
else
{
format(string, sizeof(string), "%d not found.", giveplayerid);
SendClientMessage(playerid, red, string);
}
return 1;
} // And if u have return 0; here. Than the bracket
COMMAND:givemoney(playerid, params[])
{
if (IsPlayerAdmin(playerid))
{
new
toplayerid, // the player we want to give money to
amount;
// extracting player's ID and amount from params
if (!sscanf(params, "ui", toplayerid, amount))
{
if (toplayerid != INVALID_PLAYER_ID)
{
new
message[40];
GivePlayerMoney(toplayerid, amount);
format(message, sizeof(message), "You got $%d from admin!", amount);
SendClientMessage(toplayerid, 0x00FF00FF, message);
}
else SendClientMessage(playerid, 0xFF0000FF, "That player is not connected");
}
else SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /givemoney <playerid> <amount>");
}
else SendClientMessage(playerid, 0xFF0000FF, "Only admins can use this command!");
return 1;
}
//Command
COMMAND:roll(playerid, params[])
{
new value=strval(params);
if(value<=0) return SendClientMessage(playerid,0xFF0000FF,"You must put in a value between 1 and 99");
if(value>=100)return SendClientMessage(playerid,0xFF0000FF,"You must put in a value between 1 and 99");
new tmpstr[32];
GetPlayerName(playerid,tmpstr,24);
format(tmpstr,32,"%s rolled a dice (1-%02d) - Dice landed on %d",tmpstr,value,random(value));
return SendClientMessageToAll(0xFFFF55FF,tmpstr);
}
When the command only has 1 parameter, there's absolutely no need to use sscanf. Running sscanf is like running multiple conditionals based on the parameters given and the parameters requested.
For example, if you're looking for an integer, you would use something like this: pawn Code:
|