02.04.2011, 21:26
Hi guys. I thought trying to use strtok... only once I think. So, I made 2 cmds. Should these work IG (I have not installed GTA :P)?
xD (MILAN 3 - 0 INTER omg !! FORCA MILAN)
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[128], idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/pay", true) == 0) {
new tmp[128], tmp2[128];
tmp = strtok(cmdtext, idx);
tmp2 = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_ORANGE, "Syntax Error: /pay [playerid] [amount]");
return 1;
}
if(!strlen(tmp2)) {
SendClientMessage(playerid, COLOR_ORANGE, "Syntax Error: /pay [playerid] [amount]");
return 1;
}
new id, v;
id = strval(tmp);
v = strval(tmp2);
if(GetPlayerMoney(playerid) < v) {
SendClientMessage(playerid, COLOR_GREY, "You can't afford that much!");
return 1;
}
new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
GetPlayerName(id, name2, MAX_PLAYER_NAME);
format(string, sizeof(string), "You have sent $%i to %s", v, name2);
SendClientMessage(playerid, COLOR_TAN, string);
format(string, sizeof(string), "You have received $%i from %s", v, name);
SendClientMessage(id, COLOR_TAN, string);
GivePlayerMoney(id, v);
GivePlayerMoney(playerid, 0 - v);
return 1;
}
if(strcmp(cmd, "/sethealth", true) == 0) {
new tmp[128], tmp2[128];
tmp = strtok(cmdtext, idx);
tmp2 = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_ORANGE, "Syntax Error: /sethealth [playerid] [amount]");
return 1;
}
if(!strlen(tmp2)) {
SendClientMessage(playerid, COLOR_ORANGE, "Syntax Error: /sethealth [playerid] [amount]");
return 1;
}
new id, v;
id = strval(tmp);
v = strval(tmp2);
if(id == INVALID_PLAYER_ID) {
SendClientMessage(playerid, COLOR_GREY, "Error: Player not found");
return 1;
}
if(!IsPlayerAdmin(playerid)) {
SendClientMessage(playerid, COLOR_BRIGHTRED, "You have no acces to this command");
return 1;
}
SetPlayerHealth(id, v);
return 1;
}
return 0;
}