Unreachable Code Problem
#1

I tried adding a new admin cmd in ladmin

pawn Код:
dcmd_bslap(playerid,params[]) {
    if(PlayerInfo[playerid][Level] >= 3) {
        if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: /bslap [playerid]");
        new player1 = strval(params), string[128];
        if(PlayerInfo[player1][Level] == ServerInfo[MaxAdminLevel] && PlayerInfo[playerid][Level] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,red,"ERROR: You cannot use this command on this admin");
        if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID) {
            CMDMessageToAdmins(playerid,"BSLAP");
            format(string, sizeof(string), "You have bslapped \"%s's\"", pName(player1)); SendClientMessage(playerid,blue,string);
            if(player1 != playerid) { format(string,sizeof(string),"Administrator \"%s\" has bslapped you", pName(playerid)); SendClientMessage(player1,blue,string); }
            return
                              SetPlayerPos(player1,0.0,0.0,2500.0);
//→This is line 1468          SetPlayerHealth(player1,0.01);
        } else return SendClientMessage(playerid,red,"ERROR: Player is not connected");
    } else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
    return 1;
}
But it gives me that warning
pawn Код:
blabla(1468) : warning 225: unreachable code
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Warning.
Any idea?
Greez

-XoX
Reply
#2

pawn Код:
return SetPlayerPos(player1,0.0,0.0,2500.0), SetPlayerHealth(player1,0.01);
I'm unsure if it would work.
Reply
#3

nop still the same error
Reply
#4

Why 0.01. Make it 1 instead of using decimals.
Reply
#5

pawn Код:
dcmd_bslap(playerid,params[])
{
    if(PlayerInfo[playerid][Level] >= 3)
    {
        if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: /bslap [playerid]");
        new player1 = strval(params), string[128];
        if(PlayerInfo[player1][Level] == ServerInfo[MaxAdminLevel] && PlayerInfo[playerid][Level] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,red,"ERROR: You cannot use this command on this admin");
        if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID)
        {
            CMDMessageToAdmins(playerid,"BSLAP");
            format(string, sizeof(string), "You have bslapped \"%s's\"", pName(player1));
            SendClientMessage(playerid,blue,string);
            if(player1 != playerid)
            {
                format(string,sizeof(string),"Administrator \"%s\" has bslapped you", pName(playerid));
                SendClientMessage(player1,blue,string);
            }
            SetPlayerPos(player1,0.0,0.0,2500.0);
            SetPlayerHealth(player1,0.01);
            return 1;
        }
        else return SendClientMessage(playerid,red,"ERROR: Player is not connected");
    }
    else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
}
Reply
#6

I did this just for not abusing the /kill command there
pawn Код:
dcmd_kill(playerid,params[])
    #pragma unused params
   
{
    new Float:health;
    GetPlayerHealth(playerid,health);
    if (health > 0.1)
    SetPlayerHealth(playerid, 0.0);


    return 1;
}
Everything works fine don't worry



Edit:

OMG Thanks dude. The Syntax wasn't right, was it?
Reply
#7

Cleaner indention always helps. This method will work and is the most efficient way of handling it:


pawn Код:
dcmd_bslap(playerid,params[])
{
    if(PlayerInfo[playerid][Level] < 3)
    {
        SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
        return 1;
    }

    if(!strlen(params))
    {
        SendClientMessage(playerid, red, "USAGE: /bslap [playerid]");
        return 1;
    }

    new player1 = strval(params);

    if(!IsPlayerConnected(player1))
    {
        SendClientMessage(playerid,red,"ERROR: Player is not connected");
        return 1;
    }


    if(PlayerInfo[player1][Level] == ServerInfo[MaxAdminLevel] && PlayerInfo[playerid][Level] != ServerInfo[MaxAdminLevel])
    {
        SendClientMessage(playerid,red,"ERROR: You cannot use this command on this admin");
        return 1;
    }



    CMDMessageToAdmins(playerid,"BSLAP");

    new string[128];
    format(string, sizeof(string), "You have bslapped \"%s's\"", pName(player1));
    SendClientMessage(playerid,blue,string);

    SetPlayerPos(player1,0.0,0.0,2500.0);
    SetPlayerHealth(player1,0.01);

    if(player1 != playerid)
    {
        format(string,sizeof(string),"Administrator \"%s\" has bslapped you", pName(playerid));
        SendClientMessage(player1,blue,string);
    }
    return 1;
}
Reply
#8

Im confused the command isn't working
what i did wrong?
Reply
#9

Right here:

pawn Код:
if(player1 != playerid) { format(string,sizeof(string),"Administrator \"%s\" has bslapped you", pName(playerid)); SendClientMessage(player1,blue,string); }
//→ Error cause uve returned but still continue scripting under..
          return
                              SetPlayerPos(player1,0.0,0.0,2500.0);
//→This is line 1468          SetPlayerHealth(player1,0.01);
Reply
#10

i still don't get why it's not working.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)