Need help with this Health Hack command please.
#1

Evening.
I'm seeking help for making this /hh command. I'm trying to make it, so if the player's health, OR armour is above 105 (the regular amount is 100) then it'll send a message to the player who did the command, telling them the result. Here's my current code.

pawn Code:
CMD:hh(playerid, params[])
{
    new iTarget;
    if(sscanf(params, "u", iTarget)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /hh [PlayerID] (Spectate before exploding.)");
    {
        if(iTarget == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: That Player is not connected.");
        {
            if(PlayerInfo[playerid][pAdmin] >=3)
            {
                new TStr[256];
                new pStr[256];
                new pname[MAX_PLAYER_NAME];
                GetPlayerName(playerid,pname,sizeof(pname));
                new tname[MAX_PLAYER_NAME];
                GetPlayerName(iTarget, tname,sizeof(tname));
                format(pStr,sizeof(pStr), "You have checked %s for health hacks.",tname);
                format(TStr,sizeof(TStr), "You've been checked for health hacks by Administrator %s.",pname);
                SendClientMessage(iTarget, COLOR_TAN, TStr);
                SendClientMessage(playerid, COLOR_GREEN, pStr);
                new Float:health;
                new Float:armour;
                GetPlayerHealth(iTarget, health);
                GetPlayerArmour(iTarget, armour);
                if (armour > 105)
                {
                    SendClientMessage(playerid, COLOR_TAN, "Player is possibly hacking.");
                }
                else if (health > 105)
                {
                    SendClientMessage(playerid, COLOR_TAN, "Player is possibly hacking.");
                }
                else if(armour < 100.0)
                {
                    SendClientMessage(playerid, COLOR_TAN, "Player is NOT hacking.");
                }
                else if(health < 100.0)
                {
                    SendClientMessage(playerid, COLOR_TAN, "Player is NOT hacking.");
                }
            }
            else SendClientMessage(playerid, COLOR_BRIGHTRED, "You're not authorized to use this command.");
        }
    }
    return 1;
}
I've tried messing with < and > for everything, really. What do I need to do?
Reply
#2

Usage /explode <<<< first mistake in codes

by the way whats the bug?
Reply
#3

the "else if" statements are th reason. firsly, you allow 1 state only, either if the player IS armor hacking, if not (else) hes health hacking etc. it all depends on the fail of the prior check.
never make a check depend on another one, unless its the sam variable - you want to check for both health AND armor cheaters? try this, i only took out one "else", and rearranged the order:
pawn Code:
CMD:hh(playerid, params[])
{
    new iTarget;
    if(sscanf(params, "u", iTarget)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /explode [PlayerID] (Spectate before exploding.)");
    {
        if(iTarget == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: That Player is not connected.");
        {
            if(PlayerInfo[playerid][pAdmin] >=3)
            {
                new TStr[256];
                new pStr[256];
                new pname[MAX_PLAYER_NAME];
                GetPlayerName(playerid,pname,sizeof(pname));
                new tname[MAX_PLAYER_NAME];
                GetPlayerName(iTarget, tname,sizeof(tname));
                format(pStr,sizeof(pStr), "You have checked %s for health hacks.",tname);
                format(TStr,sizeof(TStr), "You've been checked for health hacks by Administrator %s.",pname);
                SendClientMessage(iTarget, COLOR_TAN, TStr);
                SendClientMessage(playerid, COLOR_GREEN, pStr);
                new Float:health;
                new Float:armour;
                GetPlayerHealth(iTarget, health);
                GetPlayerArmour(iTarget, armour);
                if (armour > 105)//first, check if its an armor cheater. if so, warn admin...
                {
                    SendClientMessage(playerid, COLOR_TAN, "Player is possibly hacking.");
                }
                else if(armour < 100.0)//..if not, hes ok. the next check will start regardless this one:
                {
                    SendClientMessage(playerid, COLOR_TAN, "Player is NOT hacking.");
                }
                if (health > 105)//now do the check from above for health aswell...
                {
                    SendClientMessage(playerid, COLOR_TAN, "Player is possibly hacking.");
                }
                else if(health < 100.0)
                {
                    SendClientMessage(playerid, COLOR_TAN, "Player is NOT hacking.");
                }
            }
            else SendClientMessage(playerid, COLOR_BRIGHTRED, "You're not authorized to use this command.");
        }
    }
    return 1;
}
Reply
#4

Quote:
Originally Posted by Babul
View Post
the "else if" statements are th reason. firsly, you allow 1 state only, either if the player IS armor hacking, if not (else) hes health hacking etc. it all depends on the fail of the prior check.
never make a check depend on another one, unless its the sam variable - you want to check for both health AND armor cheaters? try this, i only took out one "else", and rearranged the order:
pawn Code:
CMD:hh(playerid, params[])
{
    new iTarget;
    if(sscanf(params, "u", iTarget)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /explode [PlayerID] (Spectate before exploding.)");
    {
        if(iTarget == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: That Player is not connected.");
        {
            if(PlayerInfo[playerid][pAdmin] >=3)
            {
                new TStr[256];
                new pStr[256];
                new pname[MAX_PLAYER_NAME];
                GetPlayerName(playerid,pname,sizeof(pname));
                new tname[MAX_PLAYER_NAME];
                GetPlayerName(iTarget, tname,sizeof(tname));
                format(pStr,sizeof(pStr), "You have checked %s for health hacks.",tname);
                format(TStr,sizeof(TStr), "You've been checked for health hacks by Administrator %s.",pname);
                SendClientMessage(iTarget, COLOR_TAN, TStr);
                SendClientMessage(playerid, COLOR_GREEN, pStr);
                new Float:health;
                new Float:armour;
                GetPlayerHealth(iTarget, health);
                GetPlayerArmour(iTarget, armour);
                if (armour > 105)//first, check if its an armor cheater. if so, warn admin...
                {
                    SendClientMessage(playerid, COLOR_TAN, "Player is possibly hacking.");
                }
                else if(armour < 100.0)//..if not, hes ok. the next check will start regardless this one:
                {
                    SendClientMessage(playerid, COLOR_TAN, "Player is NOT hacking.");
                }
                if (health > 105)//now do the check from above for health aswell...
                {
                    SendClientMessage(playerid, COLOR_TAN, "Player is possibly hacking.");
                }
                else if(health < 100.0)
                {
                    SendClientMessage(playerid, COLOR_TAN, "Player is NOT hacking.");
                }
            }
            else SendClientMessage(playerid, COLOR_BRIGHTRED, "You're not authorized to use this command.");
        }
    }
    return 1;
}
Thank you, completely understandable. I really do appreciate it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)