Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
|
01-23-2016
, 00:25
Re: Dragon Ball Z Mod 1.4 [Heroes vs Villains] (21 january 2016)
|
#40
|
Quote:
Originally Posted by Perfect Scrash
Before I update the plugin see if it has anything to improve this code.
|
Hi, I wrote too much I think, may be some good stuff, may be some bad ones. So, let us see what do you think about them. You can see here on red highlighted some of my coding style, if you like it. - At 'public fwd_PlayerSpawn(id)' you remove the task 'id+TASK_LOOP' and at 'public give_itens(id)' which is called right after, you removed it again, and right after create it.
- A zero thought: Then, at 'if(!is_user_alive(id)) return;' on 'public dbz_loop(id)' function, remove the task instead of just return.
- At 'remove_task(id+TASK_LOOP)' you wrote '// If they change the value of the cvar energy per second', and right after create the task again, but there no relation on doing that with re-creating a task again. Whatever, that is the task to remove, as we do not need a new one because we can just re-use that one created when the player connect.
- A first thought: At 'public fwd_PlayerSpawn(id)', 'public choose_hero_handler( id, menu, item )', 'public choose_vilain_handler( id, menu, item )', and 'public give_itens(id)', there is not need to remove it again, because: a) if the player dies, it will be removed. b) if the player do not die, there is not need to remove.
- A second thought: However I noticed that you create another task that is executed every 1 second too. That task is created when the player connect and removed when its disconnects. Hence, as task operations are expensive operations, can remove the task you create at 'public give_itens(id)', and call 'public dbz_loop(id)' at the beginning of the task you create when the client connect. But now at 'public ShowHUD(taskid)' we need to check if the client is at bot, right after call 'public dbz_loop(id)'.
- A third thought: To have only one task that is created when the first player is put in to the server, and removed when the last player disconnects. And when someone is put in server/disconnected, add/remove its id to the current players ids array. Then on that task, loop through all players on that list.
- Use a 'switch(cs_get_user_team(id))' at 'public ShowHUD(taskid)', on those ifs 'if(cs_get_user_team(id) == CS_TEAM_T)...' because a switch is faster then ifs and that operation is executed every second, then is good to save some cycles.
- At 'public give_itens(id)' you use 'give_item(id, "weapon_knife"); // Knifes Only', but prefer use the natives instead your own stocks because as the AMXX upgrade, they upgrade also, so you do not need to change your code and as they are written on native c++, they should be faster. If you need to filter some weapons or anything, so just create a interface as 'my_give_item', than apply your filters and then call the native 'give_item' when it is done filtering. The same to 'stock fm_strip_user_weapons(index)', 'stock set_user_health(index, health)'.
- At 'set_task( random_float( 5.0, 20.0 ), "use_power", id, _, _, "b" ) // For Bots use the Powers', what do you think about a higher time range, so they can give also powerful attacks? Maybe new cvars like minimum and maximum time.
- You removed these tasks at client put in server 'remove_task(id), remove_task(id+TASK_LOOP), remove_task(id+TASK_SHOWHUD)', but you also remove then at client disconnect. Since I know, a client cannot connect without disconnect first, then just removed then at client disconnect.
- On 'new name[ 32 ]; get_user_name( id, name, 31 )', 'entity_get_string( pToucher, EV_SZ_classname, szClassName, 31 )', 'new sName[ 32 ]; get_user_name( id, sName, 31 )', 'menu_item_getinfo( menu, item, access, data, 5, iName, 63, callback )', 'static msg[ 191 ]', 'replace_all( msg, 190, "!g", "^4" )', 'replace_all( msg, 190, "!y", "^1" )', 'replace_all( msg, 190, "!t", "^3" )', do not hard code the string size, use charsmax( string_name ).
- At 'if( !is_user_alive( vic ) || cs_get_user_team( id ) == cs_get_user_team( vic ) )', use a pcvar for the mp_friendlyfire to allow team damage when friendlyfire is enabled.
- At 'client_printcolor', register/use a register_colored_dictionary, which loads the LANG constants from the file replacing the '!g', '!y', '!t' with '^4', '^1', '^2' on server load, instead of every time you print a colored text. So, now while coloring inside your plugin use: '^4', '^1', '^2'.
- At 'public plugin_precache()', you let the poor pity sounds and sprites being hardcoded, instead of write their names only once, and latter access them as you do with the models. To write their names only once is good because it avoids/lets you changing/modifying they at one place and forgetting to do/changing it on the others they are used.
- At 'public plugin_init()' you cache 'g_msg_syc = CreateHudSyncObj()', 'g_maxpl = get_maxplayers()', but do not cache 'g_msgsaytext = get_user_msgid( "SayText" )' then you keep executing that 'if( !g_msgsaytext )' on 'stock client_printcolor( const id, const input[], any: ... )'. You can protect it also at 'public plugin_init()', using the same protection as '#if AMXX_VERSION_NUM < 183', which you use at 'stock client_printcolor( const id, const input[], any: ... )' for Amx Mod X 182 compatibility.
- By your 'public event_CurWeapon( id )', see this about CurWeapon Event and what do you think about that.
- At 'public use_power( id )', on 'if( !is_user_connected( id ) || !is_user_alive( id ) )', if the user is alive, it is not connect. The 'is_user_alive' already verify if the user is connected. See the function is_user_connected and is_user_alive implementations.
__________________
Last edited by addons_zz; 01-28-2016 at 22:15.
Reason: spelling fix
|
|