text
stringlengths 0
692
|
---|
Information about the forward: |
Quote: |
FM_Voice_SetClientListening, // bool ) (iReceiver, iSender, bool:bListen) |
Now, we will create our hooked function: |
Code: |
public fwd_FM_Voice_SetClientListening(receiver, sender, bool:bListen) |
{ |
} |
This function is called even when a player isn't talking, so we must filter it out to check if the voice is valid: |
Code: |
public fwd_FM_Voice_SetClientListening(receiver, sender, bool:bListen) |
{ |
if(!is_user_connected(sender) || !is_user_connected(receiver)) |
{ |
return FMRES_IGNORED; |
} |
} |
Also, we will need to check if the voice is a default server voice, and the two players don't have any special voice flags. |
Code: |
public fwd_FM_Voice_SetClientListening(receiver, sender, bool:bListen) |
{ |
if(!is_user_connected(sender) || !is_user_connected(receiver)) |
{ |
return FMRES_IGNORED; |
} |
// the speaker has no special speech |
// and the receiver isn't listening to everyone, so this is a default voice |
if(g_iSpeakFlags[sender] == SPEAK_NORMAL && g_iSpeakFlags[receiver] != SPEAK_LISTENALL) |
{ |
return FMRES_IGNORED; |
} |
} |
Now it's time to set the listening. |
Code: |
public fwd_FM_Voice_SetClientListening(receiver, sender, bool:bListen) |
{ |
if(!is_user_connected(sender) || !is_user_connected(receiver)) |
{ |
return FMRES_IGNORED; |
} |
// the speaker has no special speech |
// and the receiver isn't listening to everyone, so this is a default voice |
if(g_iSpeakFlags[sender] == SPEAK_NORMAL && g_iSpeakFlags[receiver] != SPEAK_LISTENALL) |
{ |
return FMRES_IGNORED; |
} |
new iSpeakValue = 0; |
// this will be the value to determine if the voice should be sent |
// (1 for true, 0 for false) |
// Check if the voice SHOULD be sent |
if(g_iSpeakFlags[sender] == SPEAK_ALL |
// speaker can talk to everyone |
// or |
|| g_iSpeakFlags[receiver] == SPEAK_LISTENALL |
// receiver can hear anyone |
// or |
|| g_iSpeakFlags[sender] == SPEAK_TEAM && get_pdata_int(sender, 114) == get_pdata_int(receiver, 114)) |
// speaker can only talk to team. |
// get_pdata_int(index, 114) is the fakemeta version of cs_get_user_team(index) |
{ |
iSpeakValue = 1; |
} |
// set the voice |
engfunc(EngFunc_SetClientListening, receiver, sender, iSpeakValue); |
return FMRES_SUPERCEDE; |
} |
When you are finished, this should be your full code (without comments): |
Code: |
#include <amxmodx> |
#include <fakemeta> |
#define SPEAK_MUTED 0 |
#define SPEAK_NORMAL 1 |
#define SPEAK_ALL 2 |
#define SPEAK_LISTENALL 4 |
#define SPEAK_TEAM 8 |
new g_iSpeakFlags[33]; |
#define fm_get_speak(%1) g_iSpeakFlags[%1] |
#define fm_set_speak(%1, %2) g_iSpeakFlags[%1] = %2 |
public plugin_init() |
{ |
register_forward(FM_Voice_SetClientListening, "fwd_FM_Voice_SetClientListening"); |
} |