error when i slap.
#1

when i slap myself for example i get 'you have been slapped by an admin'. also i get the error message at the same time..

pawn Код:
dcmd_slap(playerid,params[])
{
    if(AccInfo[playerid][LoggedIn] == 1)
    {
        if(AccInfo[playerid][Level] >= 2)
        {
            new Index;
            new tmp[256];  tmp  = strtok(params,Index);
            new tmp2[256]; tmp2 = strtok(params,Index);

            if(!strlen(params)) return
            SendClientMessage(playerid, red, "Usage: /slap [PlayerID/PartOfName] [Reason]") &&
            SendClientMessage(playerid, orange, "Function: Will Slap the specified player");
            new player1;
            new string[128];
            new playername[MAX_PLAYER_NAME];
            new adminname [MAX_PLAYER_NAME];
            player1 = strval(tmp);

            if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID)
             {
                GetPlayerName(player1, playername, sizeof(playername));
                GetPlayerName(playerid, adminname, sizeof(adminname));
                SendCommandToAdmins(playerid,"Slap");
                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 an Admin.");
                SendClientMessage(player1,red,string);
              }
                  else
                {
                format(string,sizeof(string),"You Have Been Slapped By an Admin.");
                SendClientMessage(player1,red,string);
                }
    }
            else return SendClientMessage(playerid, red, "ERROR: Player is not connected or is the highest level admin");
  }
   else return ErrorMessages(playerid,1);
    }
    else return SendClientMessage(playerid,red,"ERROR: You must be logged in to use this commands");
 }
Reply
#2

What error message do u get?
Reply
#3

Quote:
Originally Posted by suhrab_mujeeb
Посмотреть сообщение
What error message do u get?
i think its because else return ErrorMessages(playerid,1); there. i put Unknown command for case no: 1 error message
Reply
#4

pawn Код:
dcmd_slap(playerid,params[])
{
    if(AccInfo[playerid][LoggedIn] == 1)
    {
        if(AccInfo[playerid][Level] >= 2)
        {
            new Index;
            new tmp[256];  tmp  = strtok(params,Index);
            new tmp2[256]; tmp2 = strtok(params,Index);

            if(!strlen(params)) return
            SendClientMessage(playerid, red, "Usage: /slap [PlayerID/PartOfName] [Reason]") &&
            SendClientMessage(playerid, orange, "Function: Will Slap the specified player");
            new player1;
            new string[128];
            new playername[MAX_PLAYER_NAME];
            new adminname [MAX_PLAYER_NAME];
            player1 = strval(tmp);

            if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID)
            {
                GetPlayerName(player1, playername, sizeof(playername));
                GetPlayerName(playerid, adminname, sizeof(adminname));
                SendCommandToAdmins(playerid,"Slap");
                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 an Admin.");
                    SendClientMessage(player1,red,string);
                }
                else
                {
                    format(string,sizeof(string),"You Have Been Slapped By an Admin.");
                    SendClientMessage(player1,red,string);
                }
                return 1;
            }
            else return SendClientMessage(playerid, red, "ERROR: Player is not connected or is the highest level admin");
        }
        else return ErrorMessages(playerid,1);
    }
    else return SendClientMessage(playerid,red,"ERROR: You must be logged in to use this commands");
 }
Use this better intended code and tell if it works.
Reply
#5

Код:
         {
           format(string,sizeof(string),"You Have Been Slapped By an Admin.");
                    SendClientMessage(player1,red,string);
                      return 1;
                }
                else
                {
                    format(string,sizeof(string),"You Have Been Slapped By an Admin.");
                    SendClientMessage(player1,red,string);
                      return 1;
                }
Add those returns.
Reply
#6

pawn Код:
dcmd_slap(playerid,params[])
{
    if(AccInfo[playerid][LoggedIn] == 1) return SendClientMessage(playerid,red,"ERROR: You must be logged in to use this commands");
    if(AccInfo[playerid][Level] < 2) return ErrorMessages(playerid,1);
    new Index;
    new tmp[256];  tmp  = strtok(params,Index);
    new tmp2[256]; tmp2 = strtok(params,Index);
    if(!strlen(params))
    {
        SendClientMessage(playerid, red, "Usage: /slap [PlayerID/PartOfName] [Reason]");
        SendClientMessage(playerid, orange, "Function: Will Slap the specified player");
        return 1;
    }
    new player1;
    new string[128];
    new playername[MAX_PLAYER_NAME];
    new adminname [MAX_PLAYER_NAME];
    player1 = strval(tmp);
    if(!IsPlayerConnected(player1) || player1 == INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "ERROR: Player is not connected or is the highest level admin");
    GetPlayerName(player1, playername, sizeof(playername));
    GetPlayerName(playerid, adminname, sizeof(adminname));
    SendCommandToAdmins(playerid,"Slap");
    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 an Admin."); //same as one under
    else format(string,sizeof(string),"You Have Been Slapped By an Admin."); //same as one above. Change that
    SendClientMessage(player1,red,string);
    return 1;
}
Note: Untested. Check comment in code
Reply
#7

pawn Код:
dcmd_slap(playerid,params[])
{
    if(AccInfo[playerid][LoggedIn] == 1)
    {
        if(AccInfo[playerid][Level] >= 2)
        {
            new Index;
            new tmp[256];  tmp  = strtok(params,Index);
            new tmp2[256]; tmp2 = strtok(params,Index);

            if(!strlen(params)) return
            SendClientMessage(playerid, red, "Usage: /slap [PlayerID/PartOfName] [Reason]") &&
            SendClientMessage(playerid, orange, "Function: Will Slap the specified player");
            new player1;
            new string[128];
            new playername[MAX_PLAYER_NAME];
            new adminname [MAX_PLAYER_NAME];
            player1 = strval(tmp);

            if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID)
            {
                GetPlayerName(player1, playername, sizeof(playername));
                GetPlayerName(playerid, adminname, sizeof(adminname));
                SendCommandToAdmins(playerid,"Slap");
                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 an Admin.");
                    SendClientMessage(player1,red,string);
                }
                else
                {
                    format(string,sizeof(string),"You Have Been Slapped By an Admin.");
                    SendClientMessage(player1,red,string);
                }
                return 1;
            }
            else SendClientMessage(playerid, red, "ERROR: Player is not connected or is the highest level admin"); //no need to use return
        }
        else ErrorMessages(playerid,1); //no need to use return
    }
    else SendClientMessage(playerid,red,"ERROR: You must be logged in to use this commands"); //no need to use return
 }
No need to use "else return" -> just "else" is enough!
Reply
#8

Quote:
Originally Posted by [MG]Dimi
Посмотреть сообщение
pawn Код:
dcmd_slap(playerid,params[])
{
    if(AccInfo[playerid][LoggedIn] == 1) return SendClientMessage(playerid,red,"ERROR: You must be logged in to use this commands");
    if(AccInfo[playerid][Level] < 2) return ErrorMessages(playerid,1);
    new Index;
    new tmp[256];  tmp  = strtok(params,Index);
    new tmp2[256]; tmp2 = strtok(params,Index);
    if(!strlen(params))
    {
        SendClientMessage(playerid, red, "Usage: /slap [PlayerID/PartOfName] [Reason]");
        SendClientMessage(playerid, orange, "Function: Will Slap the specified player");
        return 1;
    }
    new player1;
    new string[128];
    new playername[MAX_PLAYER_NAME];
    new adminname [MAX_PLAYER_NAME];
    player1 = strval(tmp);
    if(!IsPlayerConnected(player1) || player1 == INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "ERROR: Player is not connected or is the highest level admin");
    GetPlayerName(player1, playername, sizeof(playername));
    GetPlayerName(playerid, adminname, sizeof(adminname));
    SendCommandToAdmins(playerid,"Slap");
    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 an Admin."); //same as one under
    else format(string,sizeof(string),"You Have Been Slapped By an Admin."); //same as one above. Change that
    SendClientMessage(player1,red,string);
    return 1;
}
Note: Untested. Check comment in code
this helped. exept i had to delete the
pawn Код:
return SendClientMessage(playerid,red,"ERROR: You must be logged in to use this commands");
i was getting the error after i logged in too. +rep to all who tried to help.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)