SA-MP Forums Archive
/slap slaps you above ID 0 not the player being slapped - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: /slap slaps you above ID 0 not the player being slapped (/showthread.php?tid=558960)



/slap slaps you above ID 0 not the player being slapped - Wizardking - 20.01.2015

Hi guys I have a problem with my /slap command, when I use /slap on someone it slaps them above ID 0 not above themselves if you know what I mean.

pawn Код:
CMD:slap(playerid, params[])
{
new targetid;
new Float:x, Float:y, Float:z;
GetPlayerPos(targetid, x, y, z);
if(sscanf(params,"u", targetid)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /slap [id]");
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_GREY, "ERROR: Invalid ID.");
SetPlayerPos(targetid, x, y, z+5);
SendClientMessage(targetid, COLOR_GREY, "You have been slapped.");
return 1;
}



Re: /slap slaps you above ID 0 not the player being slapped - Threshold - 20.01.2015

It's because you are using 'GetPlayerPos' before you assign a value to 'targetid'.
pawn Код:
new targetid; //targetid = 0
new Float:x, Float:y, Float:z; //x = 0.0, y = 0.0, z = 0.0
GetPlayerPos(targetid, x, y, z); //GetPlayerPos(0, x, y, z);
if(sscanf(params, ...) //targetid = params
//...
SetPlayerPos(targetid, x, y, z);
If you get what I mean... the correct code:
pawn Код:
CMD:slap(playerid, params[])
{
    new targetid, Float:x, Float:y, Float:z;
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /slap [id]");
    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_GREY, "ERROR: Invalid ID.");
    GetPlayerPos(targetid, x, y, z);
    SetPlayerPos(targetid, x, y, z + 5);
    SendClientMessage(targetid, COLOR_GREY, "You have been slapped.");
    return 1;
}