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

Optimization help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 04-22-2011 , 10:49   Optimization help
Reply With Quote #1

I'm pretty much trying to mimic the build process in Natural Selection.
I'm having a hard to trying to optimize this piece of code.
What it main does it 'build' a custom ent. The custom ent has its own index, build percentage (and most likely other small things I'll add).
The ent can be built by multiple players at the same time (untested as I only test with bots). When building the ent the user should have no v_ models showing and the nextattack time is delayed.

Thanks!

PHP Code:
public Forward_CmdStart(iduc_handleseed)
{
    if(!
is_user_alive(id))
        return;

    static 
iButtoniButton get_ucuc_handleUC_Buttons );
    static 
oldButton oldButton pev(idpev_oldbuttons);
    static 
FloatflTime flTime get_gametime();
    static 
aimbodyszAimingEnt[32];
    
get_user_aiming(idaimbody60);
    
entity_get_string(aimEV_SZ_classnameszAimingEntcharsmax(szAimingEnt));
    
    if ((
iButton IN_USE) && (oldButton IN_USE))
    {
        if (
flTime 1.0 g_BuildTime[id])
        {
            for(new 
0g_EntCounti++)
            {
                if(
is_valid_ent(g_EntIndex[i]))
                {
                    if( (
get_entity_distance(idg_EntIndex[i]) < 75) && (equal(szAimingEntg_EntClassName)) )
                    {
                        if(!
g_EntActive[i])
                        {
                            
CacheWeaponInfo (id);
                            static 
FloatEntPercent pev(g_EntIndex[i], pev_fuser1EntPercent);
                            if(
EntPercent >= g_MaxPercent)
                            {
                                
client_print(idprint_center"Beacon Complete");
                                
emit_sound(g_EntIndex[i], CHAN_VOICEg_SoundComplete[random(sizeof g_SoundComplete)], VOL_NORMATTN_NORM0PITCH_NORM);
                                
g_EntActive[i] = true;
                                
entity_set_int(g_EntIndex[i], EV_INT_effectsEF_BRIGHTLIGHT);

                                
ExecuteHamBHam_Item_Deployg_WeaponIndex[id], );
                                
g_Building[id] = false;
                                
//Check all  ents here
                                
if(Is_Ents_Built())
                                {
                                    
client_print(idprint_chat"ALL ENTS BUILT!!");
                                    
set_task(5.0"BOOM"TASKID_BEACON);
                                }
                                return;
                            }

                            
client_print(idprint_center"%d%"floatround((pev(g_EntIndex[i], pev_fuser1) / g_MaxPercent) * 100.0));            
                            
set_pev(g_EntIndex[i], pev_fuser1EntPercent 1.0);
                            
                            static 
FloatEntMin[3], FloatEntMax[3];
                            
entity_get_vector(g_EntIndex[i], EV_VEC_absminEntMin);
                            
entity_get_vector(g_EntIndex[i], EV_VEC_absmaxEntMax);

                            for(new 
j++)
                            {
                                
message_begin(MSG_BROADCASTSVC_TEMPENTITY);
                                
write_byte(TE_SPARKS);
                                
write_coord_f(random_float(EntMin[0], EntMax[0]));
                                
write_coord_f(random_float(EntMin[1], EntMax[1]));
                                
write_coord_f(random_float(EntMin[2], EntMax[2]));
                                
message_end();
                            }
                            
emit_sound(g_EntIndex[i], CHAN_AUTOg_SoundBuild[random(sizeof g_SoundBuild)], VOL_NORMATTN_NORM0PITCH_NORM);
                            
                            
                            
UTIL_SetNextAttack g_WeaponIndex[id], 1.25 );
                            
UTIL_SetModel(id0);
                            
// client_print(id, print_chat, "Build - INDEX: %d", g_EntIndex[i]);

                            
g_BuildTime[id] = flTime;    
                            
g_Building[id] = true;
                            break;
                        }
                    }
                    else
                    {
                        if(
g_Building[id])
                        {
                            
ExecuteHamBHam_Item_Deployg_WeaponIndex[id], );
                            
g_Building[id] = false;
                        }    
                    }
                }
                else
                    
log_amx("Error: Failed to use. Index number: %d. Create a new config file."i);
            }
        }
    }
    else if( !(
iButton IN_USE) && (oldButton IN_USE))
    {
        if(
g_Building[id])
        {
            
ExecuteHamBHam_Item_Deployg_WeaponIndex[id], );
            
g_Building[id] = false;
        }
    }


__________________
It's a mystery.

Last edited by Mini_Midget; 04-22-2011 at 10:52.
Mini_Midget is offline
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 06-05-2011 , 05:32   Re: Optimization help
Reply With Quote #2

Bump!
__________________
It's a mystery.
Mini_Midget 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 03:02.


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