Raised This Month: $ Target: $400
 0% 

If-statement problems...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-21-2005 , 20:18   If-statement problems...
Reply With Quote #1

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
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 10-21-2005 , 21:18  
Reply With Quote #2

Would you mind terribly if I just rewrote your entire function?
Brad is offline
Charr
Senior Member
Join Date: Jul 2005
Location: Long Island, New York, U
Old 10-21-2005 , 21:23  
Reply With Quote #3

Try using this for maxplayers:
Code:
new players[32],inum get_players(players,inum) for(new i = 0; i < inum; i++) {     .... }
Charr is offline
Send a message via AIM to Charr Send a message via MSN to Charr
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-21-2005 , 21:32  
Reply With Quote #4

Thats not the problem, and i dont like using get_players(), i dont know why, i just dont.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Charr
Senior Member
Join Date: Jul 2005
Location: Long Island, New York, U
Old 10-21-2005 , 21:36  
Reply With Quote #5

If its for C-strike you could try using the 'cs_get_user_team'
Charr is offline
Send a message via AIM to Charr Send a message via MSN to Charr
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-21-2005 , 21:38  
Reply With Quote #6

I thought about that, it really woudnt make a difference since they both return the same numbers.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 10-21-2005 , 21:46  
Reply With Quote #7

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.
Brad is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 10-21-2005 , 21:47  
Reply With Quote #8

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).
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 10-21-2005 , 21:53  
Reply With Quote #9

Thanks for looking outside the box, Avalanche.
Brad is offline
WaZZeR++
Veteran Member
Join Date: Mar 2005
Location: Sweden
Old 10-22-2005 , 17:59  
Reply With Quote #10

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.
WaZZeR++ is offline
Send a message via MSN to WaZZeR++
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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