Raised This Month: $ Target: $400
 0% 

Help set_task


Post New Thread Reply   
 
Thread Tools Display Modes
tolpecek
Member
Join Date: Dec 2018
Old 12-27-2018 , 10:55   Re: Help set_task
Reply With Quote #11

and how do i remove task?//done

Last edited by tolpecek; 12-27-2018 at 10:58.
tolpecek is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-27-2018 , 11:58   Re: Help set_task
Reply With Quote #12

@LondoN, you are missing the check for g_item_sti[] for terrorists, while also applying the check for g_item_reg[] for both teams while his original code had it for only CT. If this is specific to CT's, terrorists would never get health regen.

I would eliminate the set_task() at spawn. Create the task one time and check all players.
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fun>
#include <hamsandwich>

#define Task_RegenHealth 29812

new g_item_regMAX_PLAYERS ];
new 
g_item_stiMAX_PLAYERS ];
new 
Float:MaxHPMAX_PLAYERS ];

public 
plugin_init() 
{
    
set_task2.0 "Task_HPRegenLoop" Task_RegenHealth , .flags="b" );
}

public 
Task_HPRegenLoop()
{
    new 
iPlayers32 ] , iNum id CsTeams:ctTeam iHealth;
    
    
get_playersiPlayers iNum "ach" );
    
    if ( 
iNum )
    {
        for ( new 
iNum i++ )
        {
            
id iPlayers];
            
            
ctTeam cs_get_user_teamid );
            
iHealth get_user_healthid );
            
            if ( 
g_item_regid ] && ( ctTeam == CS_TEAM_CT ) )
            {
                if ( 
iHealth 500 )
                    
set_user_health(idclampiHealth 500 ) );
            }
            else if ( 
g_item_stiid ] && ( ctTeam == CS_TEAM_T ) )
            {    
                if ( 
iHealth MaxHPid ] )
                    
set_user_healthid clampiHealth floatroundMaxHPid ] * 0.05 ) , floatroundMaxHPid ] ) ) );
            }
        }
    }

__________________
Bugsy is offline
tolpecek
Member
Join Date: Dec 2018
Old 12-27-2018 , 12:36   Re: Help set_task
Reply With Quote #13

I made set_task when the item is bought, now itīs all working, thankīs u all <3
tolpecek is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-27-2018 , 12:40   Re: Help set_task
Reply With Quote #14

You do not want to call set_task() with this setup more than once in a map. I would leave it in plugin_init() to ensure it is only executed one time, or else you will end up with it repeating and you will end up with the health regen getting called multiple times for every player.

Or, you can add this to the buy function:
PHP Code:
if ( !task_existsTask_RegenHealth ) )
     
set_task2.0 "Task_HPRegenLoop" Task_RegenHealth , .flags="b" ); 
__________________

Last edited by Bugsy; 12-27-2018 at 12:41.
Bugsy is offline
tolpecek
Member
Join Date: Dec 2018
Old 12-27-2018 , 13:11   Re: Help set_task
Reply With Quote #15

Thanks a lot
tolpecek is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 05:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode