AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Another problem with emit_sound (https://forums.alliedmods.net/showthread.php?t=56055)

Pro Patria Finland 06-05-2007 14:47

Another problem with emit_sound
 
I am using two different "knife" models in Freemanmod. Crowbar for the Gordons and the pipewrench for the Shephards. So obviously I need two different sounds too. So this is how I am doing it:

Code:
public fw_emitsound(id,channel,sample[],Float:volume,Float:attenuation,fFlags,pitch) {     if (cs_get_user_team(id) == CS_TEAM_T) {                 if(equal(sample,"weapons/knife_slash1.wav")) {                 emit_sound(id,channel,"cbar_miss1.wav",volume,attenuation,fFlags,pitch);         return FMRES_SUPERCEDE;         } }     else if (cs_get_user_team(id)== CS_TEAM_CT) {                         if(equal(sample,"weapons/knife_slash1.wav")) {                 emit_sound(id,channel,"pwrench_miss2.wav",volume,attenuation,fFlags,pitch);         return FMRES_SUPERCEDE;         } }             return FMRES_IGNORED;   }

So anyhows the plugin for this part works exactly how I want it to work (I tested it with Potti). When the Gordon hits a wall with his crowbar, I hear the crowbar sound and when the Shephard hits the wall with his pipewrench, I hear the pipewrench sound. Still, my console gets filled with "native error" on the line with "cs_get_user_team" and it also says "player out of range."

Any suggestions how to fix this / do it differently?

Pro Patria Finland 06-05-2007 15:26

Re: Another problem with emit_sound
 
I didn't believe it was gonna, but changing to get_user_team(id) actually worked. (I also tried the first option, but it returned with the same errors).

Thanks alot!

Zenith77 06-06-2007 10:07

Re: Another problem with emit_sound
 
The reason why you were getting errors is because you never added any check to the forward to make sure it's a player. The forward could have been called when some other entity made a sound. To fix this:

Code:
public fw_emitsound(id,channel,sample[],Float:volume,Float:attenuation,fFlags,pitch) {      if (!is_user_alive(id)) // you can do is_user_connected() to if you wish           return FMRES_IGNORED;      // other code here }

And get_user_team() stopped throwing errors because it doesn't throw any in the first place:

Code:
    if (index < 1 || index > gpGlobals->maxClients)         return -1;


All times are GMT -4. The time now is 10:30.

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