SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 27/02/2018, 10:19 AM   #1
ForestCZE
Little Clucker
 
Join Date: Feb 2018
Posts: 8
Reputation: 0
Default Problem with TogglePlayerControllable

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
ForestCZE is offline   Reply With Quote
Old 27/02/2018, 11:42 AM   #2
Hrb
Little Clucker
 
Hrb's Avatar
 
Join Date: Mar 2012
Posts: 26
Reputation: 5
Default Re: Problem with TogglePlayerControllable

Ahoj, použij public "OnPlayerTakeDamage" vice zde: http://wiki.sa-mp.com/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: http://wiki.sa-mp.com/wiki/OnPlayerTakeDamage
Just check if is player afk and then set back his health bar.
Hrb is offline   Reply With Quote
Old 27/02/2018, 01:18 PM   #3
ForestCZE
Little Clucker
 
Join Date: Feb 2018
Posts: 8
Reputation: 0
Default Re: Problem with TogglePlayerControllable

Quote:
Originally Posted by Hrb View Post
Ahoj, použij public "OnPlayerTakeDamage" vice zde: http://wiki.sa-mp.com/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: http://wiki.sa-mp.com/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;

ForestCZE is offline   Reply With Quote
Old 27/02/2018, 02:10 PM   #4
Hrb
Little Clucker
 
Hrb's Avatar
 
Join Date: Mar 2012
Posts: 26
Reputation: 5
Default Re: Problem with TogglePlayerControllable

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; 
}
Hrb is offline   Reply With Quote
Old 27/02/2018, 02:52 PM   #5
Sew_Sumi
Godfather
 
Join Date: Jun 2008
Location: Azerbaijan
Posts: 6,281
Reputation: 517
Default Re: Problem with TogglePlayerControllable

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.
Sew_Sumi is offline   Reply With Quote
Old 27/02/2018, 09:02 PM   #6
Lucases
Huge Clucker
 
Join Date: Jul 2017
Posts: 227
Reputation: 11
Exclamation Re: Problem with TogglePlayerControllable

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.
Lucases is offline   Reply With Quote
Old 27/02/2018, 09:07 PM   #7
ForestCZE
Little Clucker
 
Join Date: Feb 2018
Posts: 8
Reputation: 0
Default Re: Problem with TogglePlayerControllable

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
ForestCZE is offline   Reply With Quote
Old 27/02/2018, 09:40 PM   #8
Sew_Sumi
Godfather
 
Join Date: Jun 2008
Location: Azerbaijan
Posts: 6,281
Reputation: 517
Default Re: Problem with TogglePlayerControllable

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)
Sew_Sumi is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TogglePlayerControllable omer5198 Scripting Help 2 30/09/2011 10:36 AM
Problem with TogglePlayerControllable misticini Help Archive 5 10/08/2011 01:59 AM
TogglePlayerControllable BlackWolf120 Help Archive 4 15/12/2010 06:11 PM
TogglePlayerControllable GooMan Help Archive 4 10/12/2010 12:28 PM
Problem with TogglePlayerControllable... OldDirtyBastard Help Archive 12 10/11/2010 06:32 PM


All times are GMT. The time now is 05:36 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.