Raised This Month: $ Target: $400
 0% 

Help set_task


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tolpecek
Member
Join Date: Dec 2018
Old 12-26-2018 , 16:54   Help set_task
Reply With Quote #1

Hello
it looks like set_task ignores a delay or idk.. code:
Code:
plugin_init()
{
RegisterHam(Ham_Spawn, "player", "zaciatok_kola", 1 )
}
Code:
public zaciatok_kola(id)
{
	set_task(2,"Task_HPRegenLoop",id,_,_,"b")
	set_task(2,"uzdraveniloop",id,_,_,"b")
}
Code:
public Task_HPRegenLoop(id)
{
	if(g_item_reg[id] && cs_get_user_team(id)== CS_TEAM_CT && is_user_alive(id))
	{
		if((get_user_health(id) >= 500))
		{
			set_user_health(id, 500)
		}
		else
		{ 
			set_user_health(id, get_user_health(id) + 5)
		}
	}
	else 
	{
		set_user_health(id, get_user_health(id))
	}
}
public uzdraveniloop(id)
{
	new float:addhealths = MaxHP[id]*0.05
	if(g_item_sti[id] && cs_get_user_team(id) == CS_TEAM_T && is_user_alive(id))
	{
		if(!(get_user_health(id) >= MaxHP[id]))
			set_user_health(id, get_user_health(id) + floatround(addhealths))
			if(get_user_health(id) > MaxHP[id]) 
				set_user_health(id, floatround(MaxHP[id]))
	}
	else 
	{
		set_user_health(id, get_user_health(id))
	}
}
adding health works ok but that delay thanks

Last edited by tolpecek; 12-26-2018 at 18:45.
tolpecek is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-26-2018 , 17:50   Re: Help set_task
Reply With Quote #2

1. set_task() expects a float for the interval, use 2.0 instead of 2.
2. What is the value of g_item_sti[]?
3. Add an is_user_alive() check before executing the set_task() calls in zaciatok_kola().
4. You can reduce code (which also fixes a player potentially getting over MaxHP[] in the first if-statement if a player has MaxHP[]-1 hp and then it adds [addhealths]):

Replace
PHP Code:
if(!(get_user_health(id) >= MaxHP[id]))
    
set_user_health(idget_user_health(id) + floatround(addhealths))
        
if(
get_user_health(id) > MaxHP[id]) 
    
set_user_health(idfloatround(MaxHP[id])) 
With
PHP Code:
set_user_healthid clampget_user_health(id) + floatround(addhealths) , MaxHP[id] ) ); 
__________________

Last edited by Bugsy; 12-26-2018 at 17:56.
Bugsy is offline
tolpecek
Member
Join Date: Dec 2018
Old 12-26-2018 , 18:08   Re: Help set_task
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
1. set_task() expects a float for the interval, use 2.0 instead of 2.
2. What is the value of g_item_sti[]?
3. Add an is_user_alive() check before executing the set_task() calls in zaciatok_kola().
4. You can reduce code (which also fixes a player potentially getting over MaxHP[] in the first if-statement if a player has MaxHP[]-1 hp and then it adds [addhealths]):

Replace
PHP Code:
if(!(get_user_health(id) >= MaxHP[id]))
    
set_user_health(idget_user_health(id) + floatround(addhealths))
        
if(
get_user_health(id) > MaxHP[id]) 
    
set_user_health(idfloatround(MaxHP[id])) 
With
PHP Code:
set_user_healthid clampget_user_health(id) + floatround(addhealths) , MaxHP[id] ) ); 

g_item_sti[id] is bool, item in game from shop and it checks if it is bought or not
Thanks for reply, gonna test it
tolpecek is offline
tolpecek
Member
Join Date: Dec 2018
Old 12-26-2018 , 18:18   Re: Help set_task
Reply With Quote #4

The first function, task_hpregenloop , is doing wierd things, it adds hp twice and then wait for 2 second..
so itīs like
set_user_health(id, get_user_health(id) + 5)
set_user_health(id, get_user_health(id) + 5)
wait(2sec)
set_user_health(id, get_user_health(id) + 5)
set_user_health(id, get_user_health(id) + 5)
wait(2sec) ...

Last edited by tolpecek; 12-26-2018 at 18:22. Reason: s
tolpecek is offline
tolpecek
Member
Join Date: Dec 2018
Old 12-26-2018 , 18:25   Re: Help set_task
Reply With Quote #5

[SOLVED] Just added if(is_user_alive(id) like you said and it works thanks
tolpecek is offline
tolpecek
Member
Join Date: Dec 2018
Old 12-26-2018 , 18:45   Re: [SOLVED]Help set_task
Reply With Quote #6

Sorry for spam, but it doesnt work again, it worked for a while and now again same problem :/
tolpecek is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-26-2018 , 19:05   Re: Help set_task
Reply With Quote #7

Its hard to troubleshoot code without having the full code. Based on what you provided, my suggestions should have fixed the issue.

Another suggestion, use the same function and call set_task() only once.
PHP Code:
public Task_HPRegenLoop(id)
{
    if ( 
is_user_aliveid ) )
    {
        new 
CsTeams:ctTeam cs_get_user_team(id);
        
        new 
iHealth get_user_healthid );
        
        if(
g_item_reg[id] && ctTeam== CS_TEAM_CT )
        {
            
//if((get_user_health(id) >= 500))
            //{
            //    set_user_health(id, 500)
            //}
            //else
            //{ 
            //    set_user_health(id, get_user_health(id) + 5)
            //}
            
            
if ( iHealth 500 )
                
set_user_health(idclampget_user_healthid ) + 500 ) )
        }
        else if( 
g_item_sti[id] && ctTeam == CS_TEAM_T )
        {    
            new 
Float:addhealths MaxHPid ] * 0.05
            
            
//if( !( iHealth >= MaxHP[id] ) )
            //    set_user_health( id , iHealth + floatround( addhealths ) )
            //    if(get_user_health(id) > MaxHP[id]) 
            //        set_user_health(id, floatround(MaxHP[id]))
            
            
if ( iHealth MaxHPid ] )
                
set_user_health(idclampiHealth floatroundaddhealths ) , 1MaxHP[id] ) )
        }
        
        
//This is a complete waste:
        //else 
        //{
        //    set_user_health(id, get_user_health(id))
        //}
    
}
    
    
//This is a complete waste:
    //else 
    //{
    //    set_user_health(id, get_user_health(id))
    //}

__________________

Last edited by Bugsy; 12-26-2018 at 19:05.
Bugsy is offline
tolpecek
Member
Join Date: Dec 2018
Old 12-26-2018 , 19:32   Re: Help set_task
Reply With Quote #8

I think i found a problem, it works only if i am alone on the server, when we are2, it goes twice faster and if 3 then 3 times faster
tolpecek is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-27-2018 , 07:07   Re: Help set_task
Reply With Quote #9

It's because you're not removing the task when the client disconnects, so the same task is assigned to the same client id and is executed multiple times. Another reason can be that you're using 0 as the client index.
__________________

Last edited by OciXCrom; 12-27-2018 at 07:08.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 12-27-2018 , 07:14   Re: Help set_task
Reply With Quote #10

Code:
public Task_HPRegenLoop ( id )
{
	if ( !is_user_alive ( id ) || !g_item_reg [ id ] )
		return;

	new Team = cs_get_user_team ( id );
	new Health = get_user_health ( id );

	switch ( Team )
	{
		case CS_TEAM_CT:	set_user_health ( id, clamp ( get_user_health ( id ) + 5, 1, 500 ) );
		case CS_TEAM_T:		set_user_health ( id, clamp ( get_user_health ( id ) + MaxHP [ id ] * 0.05, 1, MaxHP [ id ] ) )
	}
}
i think thats its very simple.
you can try first to check g_item_reg[id] and user alive then store team and hp then make switch.
__________________
LondoN 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 07:34.


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