Problem with slap command -
ZamaXor - 26.10.2010
Okay here is a slap command dropped from Ladmin. The problem is that when i type slap it slaps me. I dont see the USE . I tried to do this and i see the USE but i cant slap anyone.
Код:
if(strlen(params)) return SendClientMessage(playerid, red, "USE: /slap [playerid] [reason/with]");
pawn Код:
COMMAND:slap(playerid, params[])
{
if(PlayerInfo[playerid][LoggedIn] == 1)
{
if(PlayerInfo[playerid][Level] >= 2)
{
new tmp[256], tmp2[256], Index; tmp = strtok(params,Index), tmp2 = strtok(params,Index);
if(!strlen(params)) return SendClientMessage(playerid, red, "USE: /slap [playerid] [reason/with]");
new player1, playername[MAX_PLAYER_NAME], adminname[MAX_PLAYER_NAME], string[128];
player1 = strval(tmp);
if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID)
{
GetPlayerName(player1, playername, sizeof(playername));
GetPlayerName(playerid, adminname, sizeof(adminname));
new Float:Health;
new Float:x, Float:y, Float:z;
GetPlayerHealth(player1,Health);
SetPlayerHealth(player1,Health-25);
GetPlayerPos(player1,x,y,z);
SetPlayerPos(player1,x,y,z+5);
PlayerPlaySound(playerid,1190,0.0,0.0,0.0);
PlayerPlaySound(player1,1190,0.0,0.0,0.0);
if(strlen(tmp2))
{
format(string,sizeof(string),"* You have been slapped by %s Reason%s",adminname,params[2]);
SendClientMessage(player1,COLOR_LRED,string);
format(string,sizeof(string),"You have slapped: %s Reason:%s)",playername,params[2]);
return SendClientMessage(playerid,red,string);
}
else
{
format(string,sizeof(string),"You have been slapped by %s ",adminname);
SendClientMessage(player1,red,string);
format(string,sizeof(string),"You have slapped: %s ",playername);
return SendClientMessage(playerid,orag,string);
}
}
else return SendClientMessage(playerid, red, "Player is not connected.");
}
else return SendClientMessage(playerid,red,"You are not admin");
}
else return SendClientMessage(playerid,red,"You are not logged into your account.");
}
Re: Problem with slap command - [L3th4l] - 26.10.2010
Since you are using zcmd, i also suggest sscanf. here's a quick view on how it works.
COMMAND: ( or CMD
pawn Код:
CMD:slap(playerid, params[])
{
new PID, Float:X, Float:Y, Float:Z;
if(sscanf(params, "r", PID)) return /* Send Error Message < PlayerID >*/;
GetPlayerPos(PID, X, Y, Z);
SetPlayerPos(PID, X, Y, Z + 10);
return 1;
}
^ You don't actually need sscanf for that simple script.
Sorry for not fixing your code, but i hate reading code like that :P
Re: Problem with slap command -
Crayon - 26.10.2010
Theres a lot wrong with your command. First you're using 256 bytes for two strings each. You don't need that much!
Second of all, you're forgetting the whole point of zcmd.
Processing speed + short amount of scripting.
Third, as stated above it's best to use sscanf with zcmd, it makes things much more easy for the usage.
Try this for the first part only, you'll need to add in the reason part.
pawn Код:
command(slap, playerid, params[])
{
new id, Float:x, Float:y, Float:z;
if(PlayerInfo[playerid][Level] < 2)
return false;
if(sscanf(params, "u", id))
return SendClientMessage(playerid, COLOR_WHITE, "USE: /slap [playerid] [reason/with]");
if(!IsPlayerConnectedEx(id))
return SendClientMessage(playerid, COLOR_WHITE, "You need to login to use that command.");
GetPlayerPos(id, x, y, z);
SetPlayerPos(id, x, y, z+5);
format(string, sizeof(string), "You have slapped player %s!", GetName(id));
SendClientMessage(playerid, COLOR_WHITE, string);
format(string, sizeof(string), "Administrator %s has slapped you!", GetName(playerid));
SendClientMessage(id, COLOR_RED, string);
return 1;
}
From there you can edit it to your liking. This is just a shorter way I believe, and much more organized
Edit: I'm not the best guy at scripting but I'll attempt trying to add in the reason part.
pawn Код:
command(slap, playerid, params[])
{
new id, reason[105], Float:x, Float:y, Float:z;
if(PlayerInfo[playerid][Level] < 2)
return false;
if(sscanf(params, "u", id))
return SendClientMessage(playerid, COLOR_WHITE, "USE: /slap [playerid] [reason/with]");
if(!IsPlayerConnectedEx(id))
return SendClientMessage(playerid, COLOR_WHITE, "You need to login to use that command.");
GetPlayerPos(id, x, y, z);
SetPlayerPos(id, x, y, z+5);
format(string, sizeof(string), "You have slapped player %s for reason: %s", GetName(id), reason);
SendClientMessage(playerid, COLOR_WHITE, string);
format(string, sizeof(string), "Administrator %s has slapped you for reason: %s", adminname, reason);
SendClientMessage(id, COLOR_RED, string);
return 1;
}
Sorry if I made any mistakes. I'm still new to scripting
Re: Problem with slap command -
Crayon - 26.10.2010
RealCop228 Helped me, here is a fixed version of my script;
http://pastebin.com/B0ubqQZa