Raised This Month: $ Target: $400
 0% 

View Poll Results: Wich of this options is better at the moment of call a function very often?
simple set_task at 0.1 in the called funcion.. 1 8.33%
infinite set_task (and then remove it out) (id, _, _, "b") 2 16.67%
Client_prethink 4 33.33%
fm_prethink 3 25.00%
ham_prethink 2 16.67%
Voters: 12. You may not vote on this poll

Optimizing a plugin.Wich of these options is better?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
_lol_
Senior Member
Join Date: Apr 2009
Old 04-14-2009 , 20:58   Optimizing a plugin.Wich of these options is better?
Reply With Quote #1

well, i only want to know wich is the better and appropriate
_lol_ is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-14-2009 , 21:11   Re: Optimizing a plugin.Wich of these options is better?
Reply With Quote #2

Quote:
Originally Posted by _lol_ View Post
well, i only want to know which is the better and appropriate
None.

Set a thinking entity with a custom class name, using engine:

PHP Code:
new Float:handlerThinkDelay 2.0

new handlerClassName[] = "someName";

register_think(handlerClassName,"handlerThink");    

new 
handlerEntity create_entity("info_target")  
entity_set_string(sprite,EV_SZ_classname,handlerClassName);
entity_set_float(sprite,EV_FL_nextthinkget_gametime() + handlerThinkDelay);

public 
handlerThink(id)
{
    
entity_set_float(sprite,EV_FL_nextthinkget_gametime() + handlerThinkDelay);

I don't know, and I can't prove it but, i think it's better than using a fakemeta approach but, you can use also FM_Think.

Edit:

Be aware that it depends on each case. Tell the exactly situation since probably it can be found a better way to handle it.
__________________

Last edited by joaquimandrade; 04-14-2009 at 21:15.
joaquimandrade is offline
_lol_
Senior Member
Join Date: Apr 2009
Old 04-14-2009 , 21:18   Re: Optimizing a plugin.Wich of these options is better?
Reply With Quote #3

if i just want to execute a message?like te_delight, te_particleburst, tracers...

or if i just want to check the buttons that a player is pressing?
and if the player pres x button execute something?

Last edited by _lol_; 04-14-2009 at 21:24.
_lol_ is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-14-2009 , 21:23   Re: Optimizing a plugin.Wich of these options is better?
Reply With Quote #4

Quote:
Originally Posted by _lol_ View Post
if i want just to execute a message?like te_delight, te_particleburst, tracers...
You must be more specific. You are just talking about sending a message.

Quote:
Originally Posted by _lol_ View Post
or if i just want to check the buttons that a player is pressing?
and if the player pres x button execute something?
FM_PlayerPreThink or FM_PlayerPostThink. Probably you will have to choose one of them for specific situations.
__________________
joaquimandrade is offline
_lol_
Senior Member
Join Date: Apr 2009
Old 04-14-2009 , 21:53   Re: Optimizing a plugin.Wich of these options is better?
Reply With Quote #5

thanks

Last edited by _lol_; 04-15-2009 at 12:21.
_lol_ is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-14-2009 , 22:06   Re: Optimizing a plugin.Wich of these options is better?
Reply With Quote #6

Quote:
Originally Posted by _lol_ View Post
something like this...
Code:
static Float:originF[3]            
                pev(id, pev_origin, originF)
                // Colored Aura
                engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, originF, 0)
                write_byte(TE_DLIGHT) // TE id
                engfunc(EngFunc_WriteCoord, originF[0]) // x
                engfunc(EngFunc_WriteCoord, originF[1]) // y
                engfunc(EngFunc_WriteCoord, originF[2]) // z
                write_byte(13) // radius asdasdasd
                write_byte(255) // r
                write_byte(0) // g
                write_byte(0)  // b 
                write_byte(2) // life
                write_byte(0) // decay rate
                message_end() 
                
                //Glow
                fm_set_rendering(id, kRenderFxGlowShell, 255, 0, 0, kRenderNormal, 35)
                
                // Particle Burst
                engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, originF, 0)
                write_byte(TE_PARTICLEBURST) // TE id
                engfunc(EngFunc_WriteCoord, originF[0]) // x
                engfunc(EngFunc_WriteCoord, originF[1]) // y
                engfunc(EngFunc_WriteCoord, originF[2]) // z
                write_short(20) // radius
                write_byte(208) // color
                write_byte(3) // duration (will be randomized a bit)
                message_end()
You still haven't said how that is used.

Quote:
Originally Posted by _lol_ View Post
what will you choose for this?
Code:
new button = pev(id, pev_button)
    
    if(!is_user_alive(id))
        return ;
        
    if(!zp_get_user_zombie(id) || zp_get_user_nemesis(id))
        return ;
    
    if(zp_get_user_zombie_class(id) != g_invisible)
        return;
      
    if ((button & IN_DUCK))
    {
        if (zp_get_user_frozen(id))
        {
            message_begin ( MSG_ONE_UNRELIABLE, g_MsgShadow, _, id );
            write_long (0);
            message_end ();
            
            set_pev(id, pev_renderfx, kRenderFxNone);
            set_pev(id, pev_rendercolor, Float:{0.0, 0.0, 0.0});
            set_pev(id, pev_rendermode, kRenderTransColor);
            set_pev(id, pev_renderamt, 0.0);
            
            //glow :D
            fm_set_rendering(id, kRenderFxGlowShell, 0, 100, 200, kRenderNormal, 35)
        }
        else
    {
        message_begin ( MSG_ONE_UNRELIABLE, g_MsgShadow, _, id );
        write_long (0);
        message_end ();
            
        set_pev(id, pev_renderfx, kRenderFxNone);
        set_pev(id, pev_rendercolor, Float:{0.0, 0.0, 0.0});
        set_pev(id, pev_rendermode, kRenderTransColor);
        set_pev(id, pev_renderamt, 0.0);
    }
        set_pev(id, pev_viewmodel2, 0)
        set_pev(id, pev_weaponmodel2, "")
    }
    if (!(button & IN_DUCK))
    {
        if (zp_get_user_frozen(id))
        {
            set_pev(id, pev_renderfx, kRenderFxNone)
            set_pev(id, pev_rendercolor, 255,255,255)
            set_pev(id, pev_rendermode, kRenderNormal)
            set_pev(id, pev_renderamt, 0.0)
            
            //glow :D
            fm_set_rendering(id, kRenderFxGlowShell, 0, 100, 200, kRenderNormal, 35)
        }
        else
    {
        set_pev(id, pev_renderfx, kRenderFxNone)
        set_pev(id, pev_rendercolor, 255,255,255)
        set_pev(id, pev_rendermode, kRenderNormal)
        set_pev(id, pev_renderamt, 0.0)
    }
        set_pev(id, pev_viewmodel2, cuchi)
        set_pev(id, pev_weaponmodel2, "")
    }
It should be the same thing.
__________________
joaquimandrade is offline
_lol_
Senior Member
Join Date: Apr 2009
Old 04-14-2009 , 22:12   Re: Optimizing a plugin.Wich of these options is better?
Reply With Quote #7

1-that is just called on a player id...all the time...

2- ok.

PD:please dont quote my codes, because i will delete my posts when this thread be solved, i dont want to show my codes to every one...or only for a time?lol! xd
_lol_ is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-14-2009 , 22:22   Re: Optimizing a plugin.Wich of these options is better?
Reply With Quote #8

Quote:
Originally Posted by _lol_ View Post
1-that is just called on a player id...all the time...

2- ok.

PD:please dont quote my codes, because i will delete my posts when this thread be solved, i dont want to show my codes to every one...or only for a time?lol! xd
Its stupid to delete your posts because people lose time helping you and that help can be useful to others.
__________________
joaquimandrade is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-14-2009 , 22:29   Re: Optimizing a plugin.Wich of these options is better?
Reply With Quote #9

One method is not the best solution to all situations.

To find player's buttons, use FM_CmdStart.
To do something every frame and have it for a specific player, use client_PreThink().
To do something every frame for the whole server, use server_frame().
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-15-2009 , 04:10   Re: Optimizing a plugin.Wich of these options is better?
Reply With Quote #10

To execute something every 0.1 seconds, joaquim's way is really fine, you should consider it (you can also read Hawk552 tuts about tasks)

For your message code, this would be better :

-Don't use floats in you don't really need some
-> so use get_user_origin -> faster
-> message_begin -> faster
-> write_coord -> faster

- set_user_rendering vs fm_set_rendering should be ~ 7 times faster

PHP Code:
    static origin[3]            
    
get_user_origin(idorigin)

    
// Colored Aura
    
message_begin(MSG_PVSSVC_TEMPENTITYorigin)
    
write_byte(TE_DLIGHT// TE id
    
write_coord(origin[0]) // x
    
write_coord(origin[1]) // y
    
write_coord(origin[2]) // z
    
write_byte(13// radius asdasdasd
    
write_byte(255// r
    
write_byte(0// g
    
write_byte(0)  // b 
    
write_byte(2// life
    
write_byte(0// decay rate
    
message_end() 
                
    
//Glow
    
set_user_rendering(idkRenderFxGlowShell25500kRenderNormal35)

    
// Particle Burst
    
message_begin(MSG_PVSSVC_TEMPENTITYorigin)
    
write_byte(TE_PARTICLEBURST// TE id
    
write_coord(origin[0]) // x
    
write_coord(origin[1]) // y
    
write_coord(origin[2]) // z
    
write_short(20// radius
    
write_byte(208// color
    
write_byte(3// duration (will be randomized a bit)
    
message_end() 
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 02:21.


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