Senior Member
|
![Old](images/statusicon/post_old.svg)
11-21-2009
, 15:28
Re: ZombieHell 1.2b - Bugfix for 1.2 launched, update!
|
#47
|
Quote:
Originally Posted by fysiks
I think you need to use a switch statement. Too many if statements checking the same thing. This code below will reduce the number of native calls and the number of conditionals needing check.
PHP Code:
if( tsnum == 1 ) { switch( get_pcvar_num(zombie_level) ) { case 1: { new tname[32] get_user_name(ts[0], tname, 31) set_hudmessage(255, 0, 0, -1.0, 0.20, 0, 6.0, 999.0, 0.1, 0.2, 4) show_hudmessage(0, "%s is the Normal Boss! Beware!^n[5000 HP - 320 Velocity]", tname) client_cmd(0, "spk zombiehell/boss_normal.wav") set_user_health(ts[0], 5000) set_user_maxspeed(ts[0], 320.0) server_cmd("zombie_level 2") server_cmd("zombie_respawns 5") } case 2: { new tname[32] get_user_name(ts[0], tname, 31) set_hudmessage(255, 0, 0, -1.0, 0.20, 0, 6.0, 999.0, 0.1, 0.2, 4) show_hudmessage(0, "%s is the Nightmare Boss! Beware!^n[8000 HP - 360 Velocity]", tname) client_cmd(0, "spk zombiehell/boss_nightmare.wav") set_user_health(ts[0], 8000) set_user_maxspeed(ts[0], 360.0) server_cmd("zombie_level 3") server_cmd("zombie_respawns 8") } case 3: { new tname[32] get_user_name(ts[0], tname, 31) set_hudmessage(255, 0, 0, -1.0, 0.20, 0, 6.0, 999.0, 0.1, 0.2, 4) show_hudmessage(0, "%s is the Hell Boss! Beware!^n[10000 HP - 385 Velocity]", tname) client_cmd(0, "spk zombiehell/boss_hell.wav") set_user_health(ts[0], 10000) set_user_maxspeed(ts[0], 385.0) server_cmd("zombie_level 1") server_cmd("zombie_respawns 2") } } }
This one should be done without a switch if you are allowing multiple effects with a single cvar (bitwise addition)
PHP Code:
if( cs_get_user_team(victim) == CS_TEAM_T ) { switch( get_pcvar_num(zombie_effect) ) { case 1: { new Float:FOrigin2[3] pev(victim, pev_origin, FOrigin2) engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, FOrigin2, 0) write_byte(TE_PARTICLEBURST) engfunc(EngFunc_WriteCoord, FOrigin2[0]) engfunc(EngFunc_WriteCoord, FOrigin2[1]) engfunc(EngFunc_WriteCoord, FOrigin2[2]) write_short(50) write_byte(72) write_byte(6) message_end() } case 2: { new Float:FOrigin3[3] pev(victim, pev_origin, FOrigin3) engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, FOrigin3, 0) write_byte(TE_IMPLOSION) engfunc(EngFunc_WriteCoord, FOrigin3[0]) engfunc(EngFunc_WriteCoord, FOrigin3[1]) engfunc(EngFunc_WriteCoord, FOrigin3[2]) write_byte(200) write_byte(100) write_byte(5) message_end() } } }
You could also move all comman lines of code in the switches to before the switch unless there is a specific reason for doing otherwise.
|
Thank you, in the next version it will be modified. Note that there's alot of places which must be modified using this method to optimize the code, your suggestion would be usefull alot.
__________________
Last edited by hectorz0r; 11-21-2009 at 15:31.
|
|