SA-MP Forums Archive
Unreachable Code Problem - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Unreachable Code Problem (/showthread.php?tid=174028)



Unreachable Code Problem - XoX - 04.09.2010

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


Re: Unreachable Code Problem - woot - 04.09.2010

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


Re: Unreachable Code Problem - XoX - 04.09.2010

nop still the same error


Re: Unreachable Code Problem - Retardedwolf - 04.09.2010

Why 0.01. Make it 1 instead of using decimals.


Re: Unreachable Code Problem - woot - 04.09.2010

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");
}



Re: Unreachable Code Problem - XoX - 04.09.2010

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?


Re: Unreachable Code Problem - Jay_ - 04.09.2010

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;
}



Re: Unreachable Code Problem - XoX - 04.09.2010

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


Re: Unreachable Code Problem - Cameltoe - 04.09.2010

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);



Re: Unreachable Code Problem - XoX - 04.09.2010

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