AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   displaying who did the damage!? [SOLVED] (https://forums.alliedmods.net/showthread.php?t=51600)

gzus 02-20-2007 19:17

displaying who did the damage!? [SOLVED]
 
PHP Code:

public MHO_Damage(id)
 {
 new 
damage read_data(2)
 
//new attacker = read_data(1)
 
new szName[32]     get_user_name(idszName31)
 new 
P_A_Name get_user_attacker(id)
 
//get_user_name(idInflictor, P_A_Name[idInflictor], 31)
 
server_print("--MHO MOD-- [DAMAGE] %s took: %i from: %s"szNamedamageP_A_Name)     //PlayerXP[idInflictor] += damage     //ShowHUD(attacker)
 


using this, in the console i get the name of my server as the attacker, any idea what i did wrong?

XxAvalanchexX 02-20-2007 19:41

Re: displaying who did the damage!?
 
It means that "id" is 0.

gzus 02-20-2007 20:34

Re: displaying who did the damage!?
 
ok i get it now, i got a lil post happy and jumpped the gun.. i ended up havin to do a bunch of error handling for it..

i ended up with this:
Code:
public MHO_Damage(id)     {     new damage = read_data(2)     //new attacker = read_data(1)     new szName[32], szAtt[32]     get_user_name(id, szName, 31)     new P_A = get_user_attacker(id)     get_user_name(P_A, szAtt, 31)     //get_user_name(idInflictor, P_A_Name[idInflictor], 31)     //server_print("--MHO MOD-- [DAMAGE] - %s took: %i from: %s", szName, damage, szAtt)     if (P_A >= 32){     server_print("--MHO MOD-- [DAMAGE] - NONE Player Attacker")     } else {         if (P_A == 0){             server_print("--MHO MOD-- [DAMAGE] - NONE Player Attacker")         } else {             PlayerXP[P_A] += damage             server_print("--MHO MOD-- [DAMAGE] - Player Attacker: %s", szAtt)             if(is_user_bot(id) == 1){             } else {                 if(is_user_alive(id)){                     ShowHUD(P_A)                 }             }         }     }     //ShowHUD(attacker) }


its still throwin me a few index out of bounds in the showhud here n there, but im workin the bugs out, well trying to.

any advice on the out of bounds debugging? all was fine and dandy till i added this in there, now its spittin those index errors at me. i understand that usually it means that im tryin to display a hud to an index of something above 32 or 33, but it doesnt seem like any thing higher than 32 will get passed me here.. atleast id think i handled it all.


//------------------------------------------
edited:

i never hand error handling in the ShowHUD, i needed checks for if user is alive, and all that, with that in there, it solved the index out of bounds issues.


All times are GMT -4. The time now is 00:37.

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