[Help]Slap CMD
#1

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!
Reply
#2

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

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;
}
Reply
#4

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
Reply
#5

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.
Reply
#6

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
Reply
#7

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?
Reply
#8

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;
}
Reply
#9

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.
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)