23.07.2014, 13:39
Why are you using foreach to code commands?
Use this format below to do so (You'll need sscanf):
Use this format below to do so (You'll need sscanf):
pawn Код:
cmd(tk, playerid, params[])
{
new lookupid;
sscanf(params, "?<CELLMIN_ON_MATCHES=1>U(-1)", lookupid);
if(lookupid == -1)
{
// No player was entered.
}
else if(lookupid == cellmin)
{
// Multiple matches found.
}
else if(lookupid == INVALID_PLAYER_ID)
{
// Entered player is not connected.
}
else
{
// Found just one player.
}
return 1;
}
pawn Код:
cmd(tk, playerid, params[])
{
new lookupid;
sscanf(params, "?<CELLMIN_ON_MATCHES=1>U(-1)", lookupid);
if(lookupid == -1) return SendClientMessage(playerid, -1, "Usage: /tk (id/name).");
else if(lookupid == cellmin) return SendClientMessage(playerid, -1, "Multiple matches found for the specific phrase.");
else if(lookupid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "That player isn't connected to the server right now.");
else
{
new string[144], pwl = GetPlayerWantedLevel(lookupid);
if(!IsCop(playerid)) return SendClientMessage(playerid, COLOR_RED, "Only Cops/Army can use this command.");
if(GetDistanceBetweenPlayers(playerid, lookupid) > 4) return SendClientMessage(playerid, COLOR_RED, "That player is too far away to Ticket.");
else if(pwl == 1)
{
format(string, sizeof(string), "[COP ACTION] You have been fined by officer %s. You have been charged $1,000", PlayerInfo(playerid));
SendClientMessage(lookupid, COLOR_DODGERBLUE, string);
format(string, sizeof(string), "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(lookupid));
SendClientMessage(playerid, COLOR_DODGERBLUE, string);
format(string, sizeof(string), "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(lookupid));
SendCopMessage(string);
SetPlayerWantedLevel(lookupid, 0);
IncreaseScore(playerid, 1);
GivePlayerMoney(playerid, 2500);
GivePlayerMoney(lookupid, -1000);
}
else if(pwl == 2)
{
format(string, sizeof(string), "[COP ACTION] You have been fined by officer %s. You have been charged $2,000", PlayerInfo(playerid));
SendClientMessage(lookupid, COLOR_DODGERBLUE, string);
format(string, sizeof(string), "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(lookupid));
SendClientMessage(playerid, COLOR_DODGERBLUE, string);
format(string, sizeof(string), "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(lookupid));
SendCopMessage(string);
SetPlayerWantedLevel(lookupid, 0);
IncreaseScore(playerid, 1);
GivePlayerMoney(playerid, 2500);
GivePlayerMoney(lookupid, -2000);
}
else if(pwl == 3)
{
format(string, sizeof(string), "[COP ACTION] You have been fined by officer %s. You have been charged $3,000", PlayerInfo(playerid));
SendClientMessage(lookupid, COLOR_DODGERBLUE, string);
format(string, sizeof(string), "[COP ACTION] You have fined %s. You have recieved a collection prize.", PlayerInfo(lookupid));
SendClientMessage(playerid, COLOR_DODGERBLUE, string);
format(string, sizeof(string), "[DISPATCH] Officer %s has fined %s. He is no longer wanted.", PlayerInfo(playerid), PlayerInfo(lookupid));
SendCopMessage(string);
SetPlayerWantedLevel(lookupid, 0);
IncreaseScore(playerid, 1);
GivePlayerMoney(playerid, 2500);
GivePlayerMoney(lookupid, -3000);
}
else
{
if(pwl == 0) return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"player is innocent!");
else if(pwl == 4) return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
else if(pwl == 5) return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
else if(pwl == 6) return SendClientMessage(playerid, COLOR_YELLOW, "["COL_GREY"Error"COL_YELLOW"]"COL_GREY":"COL_LRED"You only can give ticket to wanted players of 1 to 3!");
}
}
return 1;
}