SA-MP Forums Archive
[Help]Slap CMD - 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: [Help]Slap CMD (/showthread.php?tid=303334)



[Help]Slap CMD - xRandomGuy - 12.12.2011

Hello, I'm using 'zcmd' and 'sscnaf' and I've tried making a slap command.
When I'm compiling the gamemode there's no Error nor Warning, but it keeps giving me the "Stay within the world boundaries" crash when I'm trying to spawn ingame.
Here's the command:
PHP код:
CMD:slap(playeridparams[])
{
new 
message[128];
if(
IsPlayerAdmin(playerid)) return SendClientMessage(playeridCOLOR_RED"NOPE!");
new 
Float:xFloat:yFloat:z;
if(
sscanf(params"u"params[0])) return SendClientMessage(playerid0xFFFFFFFFAA"USAGE: /slap [playerid]");
if(!
IsPlayerConnected(params[0])) return SendClientMessage(playerid,COLOR_WHITE"SERVER: Wrong ID / player has just quit.");
GetPlayerPos(params[0], xyz);
SetPlayerPos(params[0], xyz+5);
PlayerPlaySound(params[0], 1130xyz+5);
format(messagesizeof(message),""COL_RED"[AdmSlap]: "COL_WHITE"%s was slapped by %s.",GetName(params[0]), GetName(playerid));
SendClientMessageToAll(COLOR_WHITEmessage);
return 
1;

Help please!


Re: [Help]Slap CMD - Storm203 - 13.12.2011

Instead of using "params[0]", define a new variable to store the playerid of the person youre going to slap.


Re: [Help]Slap CMD - [HiC]TheKiller - 13.12.2011

params[0] isn't going to actually return their player id, it's in string format. You will need to use strval(params).
pawn Код:
CMD:slap(playerid, params[])
{
    new id = strval(params);
    new message[128];
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "NOPE!");
    new Float:x, Float:y, Float:z;
    if(!params[0])) return SendClientMessage(playerid, 0xFFFFFFFFAA, "USAGE: /slap [playerid]");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_WHITE, "SERVER: Wrong ID / player has just quit.");
    GetPlayerPos(id, x, y, z);
    SetPlayerPos(id, x, y, z+5);
    PlayerPlaySound(id, 1130, x, y, z+5);
    format(message, sizeof(message),""COL_RED"[AdmSlap]: "COL_WHITE"%s was slapped by %s.",GetName(id),     GetName(playerid));
    SendClientMessageToAll(COLOR_WHITE, message);
    return 1;
}



Re: [Help]Slap CMD - grand.Theft.Otto - 13.12.2011

RandomGuy, your line says:

pawn Код:
if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "NOPE!");
That says if the player IS and admin, it will return the error. Make sure you add an exclamation mark (means ' NOT ' in pawn language)

pawn Код:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "NOPE!");
https://sampwiki.blast.hk/wiki/Control_Structures#Operators


Re: [Help]Slap CMD - xRandomGuy - 13.12.2011

Thanks guys but it still crashes my server, there must be something wrong with the gamemode since I have used this exact same command on another server a few weeks ago and it worked perfectly. If anyone knows why I'm experiencing that "Stay within the world boundaries" crash when using that command, please help.


Re: [Help]Slap CMD - SomebodyAndMe - 13.12.2011

pawn Код:
COMMAND:slap(playerid,params[])
{
    new OtherPlayer, Msg[170], Name[24], Message[150], OtherPlayerName[24], Float:x, Float:y, Float:z;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "[ERROR]: You don't have access!");
    else if(sscanf(params, "rs[170]", OtherPlayer, Message)) return SendClientMessage(playerid,0xFFFFFFFF, "SYNTAX: /slap <name/id> <reason>");
    GetPlayerName(playerid, Name, sizeof(Name));
    GetPlayerName(OtherPlayer, OtherPlayerName, sizeof(OtherPlayerName));
    format(Msg, sizeof(Msg), "{FF6600}%s {FFFFFF}slaps {FF6600}%s {FFFFFF}because: {FF6600}%s", Name, OtherPlayerName, Message);
    SendClientMessageToAll(0xFFFFFFFF, Msg);
    GetPlayerPos(OtherPlayer, x, y, z);
    SetPlayerPos(OtherPlayer, x, y, z+5);

    return 1;
}
Untested


Re: [Help]Slap CMD - suhrab_mujeeb - 13.12.2011

Quote:
Originally Posted by SomebodyAndMe
Посмотреть сообщение
pawn Код:
COMMAND:slap(playerid,params[])
{
    new OtherPlayer, Msg[170], Name[24], Message[150], OtherPlayerName[24], Float:x, Float:y, Float:z;
    if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "[ERROR]: You don't have access!");
    else if(sscanf(params, "rs[170]", OtherPlayer, Message)) return SendClientMessage(playerid,0xFFFFFFFF, "SYNTAX: /slap <name/id> <reason>");
    GetPlayerName(playerid, Name, sizeof(Name));
    GetPlayerName(OtherPlayer, OtherPlayerName, sizeof(OtherPlayerName));
    format(Msg, sizeof(Msg), "{FF6600}%s {FFFFFF}slaps {FF6600}%s {FFFFFF}because: {FF6600}%s", Name, OtherPlayerName, Message);
    SendClientMessageToAll(0xFFFFFFFF, Msg);
    GetPlayerPos(OtherPlayer, x, y, z);
    SetPlayerPos(OtherPlayer, x, y, z+5);

    return 1;
}
Untested
Quote:
Originally Posted by grand.Theft.Otto
Посмотреть сообщение
RandomGuy, your line says:

pawn Код:
if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "NOPE!");
That says if the player IS and admin, it will return the error. Make sure you add an exclamation mark (means ' NOT ' in pawn language)

pawn Код:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "NOPE!");
https://sampwiki.blast.hk/wiki/Control_Structures#Operators
I guess you don't understand the difference between (IsPlayerAdmin(playerid)) and (!IsPlayerAdmin(playerid)).
Why would you send a message to the admins saying "[ERROR]: You don't have access!" or is it not for the admins?


Re: [Help]Slap CMD - SomebodyAndMe - 13.12.2011

Oh lol sorry:
pawn Код:
COMMAND:slap(playerid,params[])
{
    new OtherPlayer, Msg[170], Name[24], Message[150], OtherPlayerName[24], Float:x, Float:y, Float:z;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "[ERROR]: You don't have access!");
    else if(sscanf(params, "rs[170]", OtherPlayer, Message)) return SendClientMessage(playerid,0xFFFFFFFF, "SYNTAX: /slap <name/id> <reason>");
    GetPlayerName(playerid, Name, sizeof(Name));
    GetPlayerName(OtherPlayer, OtherPlayerName, sizeof(OtherPlayerName));
    format(Msg, sizeof(Msg), "{FF6600}%s {FFFFFF}slaps {FF6600}%s {FFFFFF}because: {FF6600}%s", Name, OtherPlayerName, Message);
    SendClientMessageToAll(0xFFFFFFFF, Msg);
    GetPlayerPos(OtherPlayer, x, y, z);
    SetPlayerPos(OtherPlayer, x, y, z+5);

    return 1;
}



Re: [Help]Slap CMD - shitbird - 13.12.2011

Quote:
Originally Posted by SomebodyAndMe
Посмотреть сообщение
Oh lol sorry:
pawn Код:
COMMAND:slap(playerid,params[])
{
    new OtherPlayer, Msg[170], Name[24], Message[150], OtherPlayerName[24], Float:x, Float:y, Float:z;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "[ERROR]: You don't have access!");
    else if(sscanf(params, "rs[170]", OtherPlayer, Message)) return SendClientMessage(playerid,0xFFFFFFFF, "SYNTAX: /slap <name/id> <reason>");
    GetPlayerName(playerid, Name, sizeof(Name));
    GetPlayerName(OtherPlayer, OtherPlayerName, sizeof(OtherPlayerName));
    format(Msg, sizeof(Msg), "{FF6600}%s {FFFFFF}slaps {FF6600}%s {FFFFFF}because: {FF6600}%s", Name, OtherPlayerName, Message);
    SendClientMessageToAll(0xFFFFFFFF, Msg);
    GetPlayerPos(OtherPlayer, x, y, z);
    SetPlayerPos(OtherPlayer, x, y, z+5);

    return 1;
}
You might want to rewrite that code, as you're wasting bytes and memory.
128 characters is the max. limit of text that can be sent through the chat.


Re: [Help]Slap CMD - grand.Theft.Otto - 13.12.2011

Quote:
Originally Posted by suhrab_mujeeb
Посмотреть сообщение
I guess you don't understand the difference between (IsPlayerAdmin(playerid)) and (!IsPlayerAdmin(playerid)).
Why would you send a message to the admins saying "[ERROR]: You don't have access!" or is it not for the admins?
Of course I understand the difference ?

His slap command makes it obvious that it's for admins, so he needs !IsPlayerAdmin, then it will return the error if they aren't an admin.