Raised This Month: $51 Target: $400
 12% 

Efficiency Questions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-03-2016 , 12:55   Efficiency Questions
Reply With Quote #1

So i am wondering about couple things regarding efficiency
Any idea which method listed in each case would be more efficient?

Case 1
PHP Code:
//Called once for 32 players at spawn
public HamSpawn(id)
{
    if(!
task_exists(id))
    {
        
set_task(0.1"handle_function"id)
    }
}

// Not being called often
public HamKilled(id)
{
    if(!
task_exists(id))
    {
        
set_task(0.1"handle_function"id)
    }
}

// Called alot for 32 players
public HamDamage(id)
{
    if(!
task_exists(id))
    {
        
set_task(0.1"handle_function"id)
    }
}

public 
handle_function(id)
{
    
cs_set_user_money(id15001)

VS
PHP Code:
public plugin_cfg()
{
    
set_task(0.1"handle_function"TASKID__"b")
}

// Called once every 0.1 seconds
public handle_function(TASKID)
{
    new 
iPlayers[32] , iNum Player;
    
get_playersiPlayers iNum "h" );
    
    for ( new 
iNum i++ )
    {    
        
Player iPlayers[i];
        
        
cs_set_user_money(Player15001)
    }

Case 2

PHP Code:
// 32 Tasks on full server
public client_putinserver(id)
{
    
set_task(0.1"handle_function"id_,_"b")
}

// Called 32 times every 0,1 seconds
public handle_function(id)
{
    function(
id)

VS

PHP Code:
// 1 Task at any time
public plugin_cfg()
{
    
set_task(0.1"handle_function"TASKID_,_"b")
}

// Called once every 0,1 seconds
public handle_function(TASKID)
{
    new 
iPlayers[32] , iNum Player;
    
get_playersiPlayers iNum "h" );
    
    for ( new 
iNum i++ )
    {    
        
Player iPlayers[i];
        
        
// Called 32 times
        
function(Player)
    }

__________________

Last edited by Depresie; 09-03-2016 at 12:56.
Depresie is offline
Bos93
Veteran Member
Join Date: Jul 2010
Old 09-03-2016 , 13:05   Re: Efficiency Questions
Reply With Quote #2

if you want always 1500 money, more efficient set in AddAccount
__________________

Last edited by Bos93; 09-03-2016 at 13:05.
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-03-2016 , 14:07   Re: Efficiency Questions
Reply With Quote #3

I do not want to set always 1500 money, it was just an example
__________________
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-03-2016 , 15:12   Re: Efficiency Questions
Reply With Quote #4

You need to define "a lot". Anything that is not called per frame is not a lot. 0.1 task is purely overkill. Also a task in which you loop all players is better than 32 tasks.

But this is general information, you better tell us what you exactly want to do.
__________________

Last edited by HamletEagle; 09-03-2016 at 15:13.
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-03-2016 , 15:18   Re: Efficiency Questions
Reply With Quote #5

Ahm, kind of complicated to explain..

I need to update the cs money with values stored in an array ( g_Money[33] )

I need to update it often since players recieves money everytime they damage or kill other players

I also need to do it with a little delay to avoid some inconviniences

I will try to write below the full story in the following minutes
__________________

Last edited by Depresie; 09-03-2016 at 15:20.
Depresie is offline
Bos93
Veteran Member
Join Date: Jul 2010
Old 09-03-2016 , 15:21   Re: Efficiency Questions
Reply With Quote #6

Update in Ham_TakeDamage, Ham_Killed, Round_Start
__________________
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-03-2016 , 15:31   Re: Efficiency Questions
Reply With Quote #7

I don't know how to explain it with words in order for you guys to understand, but this may give you an idea



PHP Code:
new g_Money[33]

new 
g_MsgMoney

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("Money""event_money""b")
    
g_MsgMoney get_user_msgid("Money")
}

public 
handle_money_event(id)
{
    
// This will block any engine money rewards
    
set_msg_block(g_MsgMoneyBLOCK_SET)
}

// We update the money hud with a little delay to avoid having written in the money flash hud incorrect values
public client_putinserver(id)
{
    
g_Money[id] = get_cvar_num("mp_startmoney")
    
set_task(0.1"UpdateMoney"id)
}

public 
OnDamage(victimattackeretc)
{
    
g_Money[attacker] += damage
    set_task
(0.1"UpdateMoney"id)

}

public 
OnKill(victimattackeretc)
{
    
g_Money[attacker] += 500
    set_task
(0.1"UpdateMoney"id)
    
}

public 
OnSpawn(id)
{
    
// This will manually update the money hud at spawn, since the automatic update is blocked above in the money event
    
set_task(0.1"UpdateMoney"id)
}

public 
UpdateMoney(id)
{
    
cs_set_user_money(idg_Money[id], 1)

I am wondering if it wouldn't be better to do it with a global task and player loop since to avoid the big number of frequent tasks and checks from the take damage event

PHP Code:

new g_Money[33]

new 
g_MsgMoney

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("Money""event_money""b")
    
g_MsgMoney get_user_msgid("Money")
}

public 
plugin_cfg()
{
    
set_task(0.1"UpdateMoney"id_,_"b")
}

public 
handle_money_event(id)
{
    
set_msg_block(g_MsgMoneyBLOCK_SET)
}

public 
client_putinserver(id)
{
    
g_Money[id] = get_cvar_num("mp_startmoney")
}

public 
OnDamage(victimattackeretc)
{
    
g_Money[attacker] += damage
}

public 
OnKill(victimattackeretc)
{
    
g_Money[attacker] += 500
}


public 
UpdateMoney()
{
    new 
iPlayers[32] , iNum Player;
    
get_playersiPlayers iNum "h" );
    
    for ( new 
iNum i++ )
    {    
        
Player iPlayers[i];
       
cs_set_user_money(Playerg_Money[Player], 1)
    }
    

__________________

Last edited by Depresie; 09-03-2016 at 15:38.
Depresie is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-03-2016 , 16:18   Re: Efficiency Questions
Reply With Quote #8

Why don't you just hook Money message and alter it to display your preferred value and then set money in there?
klippy is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-03-2016 , 16:30   Re: Efficiency Questions
Reply With Quote #9

Because i need to set rewards for damage and kill using cs_set_user_money and it doesn't trigger the money event or message, i have tried

Also above i went with the looping every 0.25 seconds, it's cleaner, and i think its better than 32 tasks and checks for task existence in take damage

I know it's an overkill to call a task so often, but i want to keep the money hud flash effect in sync
__________________

Last edited by Depresie; 09-03-2016 at 16:33.
Depresie 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 19:38.


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