AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Optimizing a plugin.Wich of these options is better? (https://forums.alliedmods.net/showthread.php?t=90172)

_lol_ 04-14-2009 20:58

Optimizing a plugin.Wich of these options is better?
 
well, i only want to know wich is the better and appropriate

joaquimandrade 04-14-2009 21:11

Re: Optimizing a plugin.Wich of these options is better?
 
Quote:

Originally Posted by _lol_ (Post 805647)
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.

_lol_ 04-14-2009 21:18

Re: Optimizing a plugin.Wich of these options is better?
 
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?

joaquimandrade 04-14-2009 21:23

Re: Optimizing a plugin.Wich of these options is better?
 
Quote:

Originally Posted by _lol_ (Post 805657)
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_ (Post 805657)
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.

_lol_ 04-14-2009 21:53

Re: Optimizing a plugin.Wich of these options is better?
 
thanks

joaquimandrade 04-14-2009 22:06

Re: Optimizing a plugin.Wich of these options is better?
 
Quote:

Originally Posted by _lol_ (Post 805670)
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_ (Post 805670)
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.

_lol_ 04-14-2009 22:12

Re: Optimizing a plugin.Wich of these options is better?
 
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

joaquimandrade 04-14-2009 22:22

Re: Optimizing a plugin.Wich of these options is better?
 
Quote:

Originally Posted by _lol_ (Post 805688)
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.

Exolent[jNr] 04-14-2009 22:29

Re: Optimizing a plugin.Wich of these options is better?
 
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().

ConnorMcLeod 04-15-2009 04:10

Re: Optimizing a plugin.Wich of these options is better?
 
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() 



All times are GMT -4. The time now is 02:20.

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