Raised This Month: $ Target: $400
 0% 

Which method is more efficient ? Task vs Each time check


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Hamartia
Member
Join Date: Oct 2015
Old 05-25-2016 , 03:38   Which method is more efficient ? Task vs Each time check
Reply With Quote #1

I want to understand how costly using set_task is ? Hence wanted to know the difference.

Why I ask this question is because this hook is going to be called numerous times on using grenade and wanted to know whether the calculation is worth of prevent a set_task.

This uses task to enable grenade.

Code:
public EventRoundStart()
{
    g_canNade = false;
    remove_task(TASK_ENABLE_NADE);
    set_task(get_pcvar_float(g_CvarTime),"EnableGrenade", TASK_ENABLE_NADE,"",0);
    arrayset(g_showBlockMsg, true, 32);   
}

public EnableGrenade(){
	g_canNade = true;
}

public OnCHEGrenade_PrimaryAttack( pEntity ) 
{ 
    if(get_pcvar_num(g_CvarEnable)){
    	
	new id = get_pdata_cbase( pEntity , m_pPlayer , XO_CBASEPLAYERITEM ); 
	
	// Prevent nade in round start
	if(!g_canNade){
		if(g_showBlockMsg[id]){
			client_print(id, print_center, "** You cant nade for first %d seconds **", floatround(get_pcvar_float(g_CvarTime)));
			g_showBlockMsg[id] = false;
		}
		return HAM_SUPERCEDE; 
	}
}
This checks each time when someone tries to use a grenade

Code:
public EventRoundStart()
{
    g_canNade = false;
    g_roundStartTime = get_gametime();
    arrayset(g_showBlockMsg, true, 32);
}

public OnCHEGrenade_PrimaryAttack( pEntity ) 
{ 
    if(get_pcvar_num(g_CvarEnable)){
    	
	new id = get_pdata_cbase( pEntity , m_pPlayer , XO_CBASEPLAYERITEM ); 
	new Float:gameTime = get_gametime();
	
	// Prevent nade in round start
	if(!g_canNade){		
		if(gameTime - g_roundStartTime > get_pcvar_float(g_CvarTime)){
			g_canNade = true;
		}else{
		
			if(g_showBlockMsg[id]){
				client_print(id, print_center, "** You cant nade for first %d seconds **", floatround(get_pcvar_float(g_CvarTime)));
				g_showBlockMsg[id] = false;
			}
			return HAM_SUPERCEDE; 
		}
	}
}
__________________

Last edited by Hamartia; 05-25-2016 at 09:45.
Hamartia is offline
 


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

Forum Jump


All times are GMT -4. The time now is 18:39.


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