This thread archives tips and tricked used in coding war3 races to help improve efficiency of the code used and thus reduce lag, improve performance and prevent crashes. As no true guide serves for making war3 races this thread serves to place important code snippets in one place on a post by post basis.
---------- Post added at 03:04 PM ---------- Previous post was at 02:56 PM ----------
Get weapon to prevent ability damage stacking, use for all ability's that require hit detection regardless of internal function use for consistency:
OLD
Code:
public PlayerHurtEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
decl String:weapon[64];
GetEventString(event,"weapon",weapon,63);
CORRECT
Code:
public OnWar3EventPostHurt(victim,attacker,dmgamount)
{
decl String:weapon[64];
GetEventString(W3GetVar(SmEvent),"weapon",weapon,63);
Advantages:
Removes the need for a hook event like:
Code:
HookEvent( "player_hurt", PlayerHurtEvent );
Also removes the need for all of the following code:
Code:
new userid=GetEventInt(event,"userid");
new attacker_userid=GetEventInt(event,"attacker");
new victim=GetClientOfUserId(userid);
new attacker=GetClientOfUserId(attacker_userid);
new dmg=GetEventInt(event,"dmg_health");
Lastly as seen it additionally removes the problem of dmg being a Float value and thus the need for RoundToFloor() to be used to convert back to an Integer.