Problem with TogglePlayerControllable
#1

Hi guys, I have found out TogglePlayerControllable (TGP) does not work properly. I usually use this function for AFK system.

For example:

PHP Code:
new bool:isAFK[MAX_PLAYERS];
dcmd_afk(playeridparams[])
{
#pragma unused params
if(isAFK[playerid] == false)
{
TogglePlayerControllable(playerid0);
isAFK[playerid] = true;
}
else
{
TogglePlayerControllable(playerid1);
isAFK[playerid] = false;
}

TGP works against hit by a weapon or a vehicle, but when I hit a player by fist, then I am able to kill him.

Is it there any solution, how fix that problem? Thanks in advance for a help
Reply
#2

Ahoj, pouћij public "OnPlayerTakeDamage" vice zde: https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage
Jednoduљe zkontroluj jestli je afk a pak mu nastav zpět ћivoty, kterй mб mнt.

Hi, try using public "OnPlayerTakeDamage" more info: https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage
Just check if is player afk and then set back his health bar.
Reply
#3

Quote:
Originally Posted by Hrb
View Post
Ahoj, pouћij public "OnPlayerTakeDamage" vice zde: https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage
Jednoduљe zkontroluj jestli je afk a pak mu nastav zpět ћivoty, kterй mб mнt.

Hi, try using public "OnPlayerTakeDamage" more info: https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage
Just check if is player afk and then set back his health bar.
CZ: Napsal jsem si ten kуd takto a nic.
EN: I have wrote following code, but it does not work anyway.

PHP Code:
public OnPlayerTakeDamage(playeridissueridFloatamountweaponidbodypart)
{
    if(
issuerid != INVALID_PLAYER_ID)
    {
        if(
weaponid == && AFK[playerid] == true)
        {
            new 
Float:iarmour;
            
GetPlayerArmour(playeridiarmour);
            if(
iarmour 0)
            {
                
SetPlayerArmour(playeridamount);
            }
            else
            {
                
SetPlayerHealth(playeridamount);
            }
        }
    }
    return 
1;

Reply
#4

Zkus toto:

Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart) 
{ 
    if(issuerid != INVALID_PLAYER_ID) 
    { 
        if(weaponid == 0 && AFK[playerid]) 
        { 
            new Float:iarmour;
            new Float:ihealth;  
            GetPlayerArmour(playerid, iarmour);
            GetPlayerHealth(playerid, ihealth);
            SetPlayerArmour(playerid, iarmour); 
            SetPlayerHealth(playerid, ihealth); 
        } 
    } 
    return 1; 
}
Reply
#5

Why use the toggle, simply set his health so far up that it doesn't drop. And if it does start going down, just set it back up again.
Reply
#6

Quote:
Originally Posted by Sew_Sumi
View Post
Why use the toggle, simply set his health so far up that it doesn't drop. And if it does start going down, just set it back up again.
Because they can go around with endless health while their afk variable is set on true?
Freezing them is the best option.
Reply
#7

Quote:
Originally Posted by Hrb
View Post
Zkus toto:

Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart) 
{ 
    if(issuerid != INVALID_PLAYER_ID) 
    { 
        if(weaponid == 0 && AFK[playerid]) 
        { 
            new Float:iarmour;
            new Float:ihealth;  
            GetPlayerArmour(playerid, iarmour);
            GetPlayerHealth(playerid, ihealth);
            SetPlayerArmour(playerid, iarmour); 
            SetPlayerHealth(playerid, ihealth); 
        } 
    } 
    return 1; 
}
CZ: Dнky moc
EN: Nice one
Reply
#8

Quote:
Originally Posted by Lucases
View Post
Because they can go around with endless health while their afk variable is set on true?
Freezing them is the best option.
Not if you monitor their positions, and the commands/areas they are entering/leaving.

You could put them in a room, 'afk' so they can simply sit... Even put them in another world.



One problem with your code is you aren't using that callback correctly. If you don't want the damage to affect, then use the appropriate return, in the right callbacks. Isolating the fist, you may want to alert an admin that someone is being a dick (punching), or abusing(walking around with afk on(Even though you should monitor their positions))...

(It's also not a new bug, and has no 'fix' in fixes.inc, yet it almost should for this sort of problem)
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)