Slap command help
#1

Hello, I'm getting loads of warnings as I attempt to make a slap command. Help would be highly appriciated!

pawn Код:
CMD:slap(playerid, params[])
{
    new id, string[128], Float: PPos[3], reason[128];
    if(PlayerInfo[playerid][Level] < 1) return SendClientMessage(playerid, 0xF69521AA, "You can't use this command!");//Checking if the player has admin level 1, if not it sends him a message.
    if(sscanf(params,"us[128]",id, reason)) return SendClientMessage(playerid, 0xa10000,"USAGE: /slap [playerid/partofname] [reason]");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xF69521AA,"The specified player is currently not connected!");//Checking if the selected user is connected or not.

    GetPlayerPos(id, PPos[0], PPos[1], PPos[2]);
    SetPlayerPos(id, PPos[0], PPos[1], PPos[2]+4);

    new GetName[MAX_PLAYER_NAME]
    GetPlayerName(playerid, GetName, sizeof(GetName));
    format(string, sizeof(string), "You have successfully slapped %s!", GetName(id));
    SendClientMessage(playerid, -1, string);
    return 1;
}
pawn Код:
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1219) : warning 219: local variable "GetName" shadows a variable at a preceding level
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1220) : error 001: expected token: ";", but found "-identifier-"
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1221) : error 012: invalid function call, not a valid address
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1221) : warning 215: expression has no effect
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1221) : error 001: expected token: ";", but found ")"
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1221) : error 029: invalid expression, assumed zero
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1221) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


5 Errors.
Reply
#2

pawn Код:
new GetName[MAX_PLAYER_NAME];
Reply
#3

Change the variable "GetName" in the above code to "GetNameVar" (error 219 means that the variable is already assigned a value... so you probably have "GetName" somewhere else above).

Then change
pawn Код:
new GetName[MAX_PLAYER_NAME]
to
pawn Код:
new GetNameVar[MAX_PLAYER_NAME];//Again, make sure to change all the "GetName" to "GetNameVar"
Agter that, properly indent your code using brackets (see bellow)... it's not very neat.
pawn Код:
if(Event1)
{
      ResultOutcome1
      return 1;
}
else if (Event2)
{
     ResultOutcome2
     return 1;
}
else
{
     ResultOutcome3
     return 1;
}
Reply
#4

pawn Код:
GetPlayerName(playerid, GetName, sizeof(GetName));
    format(string, sizeof(string), "You have successfully slapped %s!", GetName(id));
Jake, I changed the variable into GetNameSlap and now have the following errors.

pawn Код:
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1220) : error 072: "sizeof" operator is invalid on "function" symbols
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1221) : error 012: invalid function call, not a valid address
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1221) : warning 215: expression has no effect
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1221) : error 001: expected token: ";", but found ")"
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1221) : error 029: invalid expression, assumed zero
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1221) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


5 Errors.
Although I'm not sure what you mean by telling me to properly indent my code with brackets?
Reply
#5

This is what I mean, this should not have any errors in it, but if there are let me know:

pawn Код:
CMD:slap(playerid, params[])
{    
    new id, string[128], Float: PPos[3], reason[128];    
    if(PlayerInfo[playerid][Level] < 1)
    {
        SendClientMessage(playerid, 0xF69521AA, "You can't use this command!");//Checking if the player has admin level 1, if not it sends him a message.
        return 1;
    }
    if(sscanf(params,"us[128]",id, reason))
    {
        SendClientMessage(playerid, 0xa10000,"USAGE: /slap [playerid/partofname] [reason]");
        return 1;      
    }    
    if(!IsPlayerConnected(id))
    {
        SendClientMessage(playerid, 0xF69521AA,"The specified player is currently not connected!");//Checking if the selected user is connected or not.  
        return 1;
    }
    new GetNameVar[MAX_PLAYER_NAME];//Your main error was on this line, you forgot the ";"
    GetPlayerPos(id, PPos[0], PPos[1], PPos[2]);    
    SetPlayerPos(id, PPos[0], PPos[1], PPos[2]+4);        
    GetPlayerName(playerid, GetNameVar, sizeof(GetNameVar));    
    format(string, sizeof(string), "You have successfully slapped %s!", GetNameVar(id));    
    SendClientMessage(playerid, -1, string);    
    return 1;
}
Reply
#6

I received the following errors.

pawn Код:
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1231) : error 012: invalid function call, not a valid address
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1231) : warning 215: expression has no effect
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1231) : error 001: expected token: ";", but found ")"
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1231) : error 029: invalid expression, assumed zero
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1231) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
Line 1231 is the following.

pawn Код:
format(string, sizeof(string), "You have successfully slapped %s!", GetNameVar(id));
Your help is highly appriciated mate.
Reply
#7

pawn Код:
CMD:slap(playerid, params[])
{
    if(PlayerInfo[playerid][Level] < 1) return SendClientMessage(playerid, 0xF69521AA, "You can't use this command!");//Checking if the player has admin level 1, if not it sends him a message.
    new id, reason[100];
    if(sscanf(params,"us[100]",id, reason)) return SendClientMessage(playerid, 0xa10000,"USAGE: /slap [playerid/partofname] [reason]");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xF69521AA,"The specified player is currently not connected!");//Checking if the selected user is connected or not.
   
    new string[128], Float: PPos[3];
    GetPlayerPos(id, PPos[0], PPos[1], PPos[2]);
    SetPlayerPos(id, PPos[0], PPos[1], PPos[2]+4);
   
    GetPlayerName(playerid, string, 21);
    format(string, sizeof(string), "You have successfully slapped %s! Reason: %s", string, reason);
    SendClientMessage(playerid, -1, string);
    return 1;
}
Reply
#8

Try this:

pawn Код:
CMD:slap(playerid, params[])
{    
    new id, string[128], Float: PPos[3], reason[128];    
    if(PlayerInfo[playerid][Level] < 1)
    {
        SendClientMessage(playerid, 0xF69521AA, "You can't use this command!");//Checking if the player has admin level 1, if not it sends him a message.
        return 1;
    }
    if(sscanf(params,"us[128]",id, reason))
    {
        SendClientMessage(playerid, 0xa10000,"USAGE: /slap [playerid/partofname] [reason]");
        return 1;      
    }    
    if(!IsPlayerConnected(id))
    {
        SendClientMessage(playerid, 0xF69521AA,"The specified player is currently not connected!");//Checking if the selected user is connected or not.  
        return 1;
    }
    new GetNameVar[MAX_PLAYER_NAME];//Your main error was on this line, you forgot the ";"
    GetPlayerPos(id, PPos[0], PPos[1], PPos[2]);    
    SetPlayerPos(id, PPos[0], PPos[1], PPos[2]+4);
    GetPlayerName(id, GetNameVar, sizeof(GetNameVar));
    format(string, sizeof(string), "You have successfully slapped %s!", GetNameVar);
    SendClientMessage(playerid, -1, string);
    return 1;
}
Reply
#9

Lmao Konstantinos, you're just bawsing it haha! Thanks mate, it worked. REP +!

Edit: Didn't saw your comment Jake, Konstantinos script worked though. REP + to you too for helping me out.
Reply
#10

There you go,

Код:
CMD:slap(playerid, params[])
{    
    new id, string[128], Float: PPos[3], reason[128];    
    if(PlayerInfo[playerid][Level] < 1) 
    {
        SendClientMessage(playerid, 0xF69521AA, "You can't use this command!");//Checking if the player has admin level 1, if not it sends him a message.
        return 1;
    }
    if(sscanf(params,"us[128]",id, reason))
    {
        SendClientMessage(playerid, 0xa10000,"USAGE: /slap [playerid/partofname] [reason]");
        return 1;       
    }     
    if(!IsPlayerConnected(id)) 
    {
        SendClientMessage(playerid, 0xF69521AA,"The specified player is currently not connected!");//Checking if the selected user is connected or not.   
        return 1;
    }
    new GetNameVar[MAX_PLAYER_NAME];//Your main error was on this line, you forgot the ";"
    GetPlayerPos(id, PPos[0], PPos[1], PPos[2]);    
    SetPlayerPos(id, PPos[0], PPos[1], PPos[2]+4);
             GetPlayerName(id, GetNameVar, sizeof(GetNameVar));
             format(string, sizeof(string), "You have successfully slapped %s!", GetNameVar);
             SendClientMessage(playerid, -1, string);
             return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)