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;
}
}
}
__________________