AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   If-statement problems... (https://forums.alliedmods.net/showthread.php?t=19632)

Zenith77 10-21-2005 20:18

If-statement problems...
 
Ok this function is called when a player dies,


Code:
public eventDeath(id) {         if( get_cvar_num("amx_sound_events") < 1 ) {                 return PLUGIN_CONTINUE     }         new i         for( i = 1; i < get_maxplayers(); i++ ) {                 if( !is_user_connected(i) ) continue                 if( get_user_team(id) == get_user_team(i) && i != id ) {                         client_cmd(i, "spk ^"events/friend_died.wav^" " )                         if( get_cvar_num("amx_sound_notify") > 0 ) {                                 client_print(i, print_chat, "[AMXX] A friendly player died " )             }         }                 if( get_user_team(id) != get_user_team(i) && i != id ) {                         client_cmd(i, "spk ^"events/enemy_died.wav^" " )                         if( get_cvar_num("amx_sound_notify") > 0 ) {                                 client_print(i, print_chat, "[AMXX] An enemy player died " )             }                                 }             }         return PLUGIN_CONTINUE }


But this if statement is always executed no matter what team ' id ' or ' i ' is on. :/

Code:
if( get_user_team(id) != get_user_team(i) && i != id ) {                         client_cmd(i, "spk ^"events/enemy_died.wav^" " )                         if( get_cvar_num("amx_sound_notify") > 0 ) {                                 client_print(i, print_chat, "[AMXX] An enemy player died " )             }                                 }

I would apperciate any help :)

Thnx
--Zenith77

Brad 10-21-2005 21:18

Would you mind terribly if I just rewrote your entire function?

Charr 10-21-2005 21:23

Try using this for maxplayers:
Code:
new players[32],inum get_players(players,inum) for(new i = 0; i < inum; i++) {     .... }

Zenith77 10-21-2005 21:32

Thats not the problem, and i dont like using get_players(), i dont know why, i just dont.

Charr 10-21-2005 21:36

If its for C-strike you could try using the 'cs_get_user_team'

Zenith77 10-21-2005 21:38

I thought about that, it really woudnt make a difference since they both return the same numbers.

Brad 10-21-2005 21:46

My style of programming is slightly different and some of my variables could probably be named better but...
Code:
public eventDeath(id) {     if( !get_cvar_num("amx_sound_events") ) return PLUGIN_CONTINUE         new iTeamID = get_user_team(id)     new iOtherID, iOtherTeamID     new players[32], iPlayerCnt     get_players(players, iPlayerCnt)         for( new i = 0; i < iPlayerCnt; i++ )     {         iOtherID = get_user_userid(players[i])         iOtherTeamID = get_user_team(iOtherID)                 if (iOtherID != id)         {             if (iTeamID == iOtherTeamID)             {                 client_cmd(i, "spk ^"events/friend_died.wav^" " )                             if( get_cvar_num("amx_sound_notify") )                 {                     client_print(i, print_chat, "[AMXX] A friendly player died " )                 }             }             else             {                 client_cmd(i, "spk ^"events/enemy_died.wav^" " )                                 if( get_cvar_num("amx_sound_notify") > 0 )                 {                     client_print(i, print_chat, "[AMXX] An enemy player died " )                 }             }         }     }     return PLUGIN_CONTINUE }
If you'd like to question anything I've done, please do so.

XxAvalanchexX 10-21-2005 21:47

Look beyond the code... actually, look above it, at the function header:

Code:
public eventDeath(id) {

I'm assuming this function is a hook of DeathMsg. DeathMsg is a global event and is sent to everyone. Use read_data(2) to get the victim, I'm not sure what id actually holds, but I'm fairly confident it's not the id of the player receiving the message (since it is only sent once, to everyone).

Brad 10-21-2005 21:53

Thanks for looking outside the box, Avalanche.

WaZZeR++ 10-22-2005 17:59

Quote:

Originally Posted by Zenith77
Thats not the problem, and i dont like using get_players(), i dont know why, i just dont.

But you must use it, because in some case it will miss a player id...
not really must, but it the easiest way.


All times are GMT -4. The time now is 23:38.

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