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(id, uc_handle, seed)
{
if(!is_user_alive(id))
return;
static iButton; iButton = get_uc( uc_handle, UC_Buttons );
static oldButton ; oldButton = pev(id, pev_oldbuttons);
static Float: flTime ; flTime = get_gametime();
static aim, body, szAimingEnt[32];
get_user_aiming(id, aim, body, 60);
entity_get_string(aim, EV_SZ_classname, szAimingEnt, charsmax(szAimingEnt));
if ((iButton & IN_USE) && (oldButton & IN_USE))
{
if (flTime - 1.0 > g_BuildTime[id])
{
for(new i = 0; i < g_EntCount; i++)
{
if(is_valid_ent(g_EntIndex[i]))
{
if( (get_entity_distance(id, g_EntIndex[i]) < 75) && (equal(szAimingEnt, g_EntClassName)) )
{
if(!g_EntActive[i])
{
CacheWeaponInfo (id);
static Float: EntPercent ; pev(g_EntIndex[i], pev_fuser1, EntPercent);
if(EntPercent >= g_MaxPercent)
{
client_print(id, print_center, "Beacon Complete");
emit_sound(g_EntIndex[i], CHAN_VOICE, g_SoundComplete[random(sizeof g_SoundComplete)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
g_EntActive[i] = true;
entity_set_int(g_EntIndex[i], EV_INT_effects, EF_BRIGHTLIGHT);
ExecuteHamB( Ham_Item_Deploy, g_WeaponIndex[id], 1 );
g_Building[id] = false;
//Check all ents here
if(Is_Ents_Built())
{
client_print(id, print_chat, "ALL ENTS BUILT!!");
set_task(5.0, "BOOM", TASKID_BEACON);
}
return;
}
client_print(id, print_center, "%d%", floatround((pev(g_EntIndex[i], pev_fuser1) / g_MaxPercent) * 100.0));
set_pev(g_EntIndex[i], pev_fuser1, EntPercent + 1.0);
static Float: EntMin[3], Float: EntMax[3];
entity_get_vector(g_EntIndex[i], EV_VEC_absmin, EntMin);
entity_get_vector(g_EntIndex[i], EV_VEC_absmax, EntMax);
for(new j = 0 ; j < 5 ; j++)
{
message_begin(MSG_BROADCAST, SVC_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_AUTO, g_SoundBuild[random(sizeof g_SoundBuild)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
UTIL_SetNextAttack ( g_WeaponIndex[id], 1.25 );
UTIL_SetModel(id, 0);
// 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])
{
ExecuteHamB( Ham_Item_Deploy, g_WeaponIndex[id], 1 );
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])
{
ExecuteHamB( Ham_Item_Deploy, g_WeaponIndex[id], 1 );
g_Building[id] = false;
}
}
}
__________________