Raised This Month: $32 Target: $400
 8% 

set_speak() in Fakemeta


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-08-2008 , 11:45   set_speak() in Fakemeta
Reply With Quote #1

Quote:
Originally Posted by Hawk552 View Post
Before we begin, I'd just like to state that this tutorial is intended for intermediate to expert level scripters.
You should be able to read all the code I've put here and almost immediately understand what should happen.
This tutorial is for an engine-to-fakemeta conversion for the functions set_speak() and get_speak().

First, we'll start off by defining the variables.

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

Now, "What is 'SPEAK_TEAM' ?"
SPEAK_TEAM is a new one that I have thought up myself.
It acts as if alltalk is on, but only for that team.
Example:
I'm dead, and I can still talk to my alive teammates, but not to the other team.

Now, we will need to create a variable so each player can have his/her own flag.
And, we will need to reset the player's flag to SPEAK_NORMAL when he/she enters.

Code:
new g_iSpeakFlags[33]; public client_connect(id) {     g_iSpeakFlags[id] = SPEAK_NORMAL; }

We will need some functions to get and set the player's speak mode.

Code:
#define fm_get_speak(%1) g_iSpeakFlags[%1] #define fm_set_speak(%1, %2) g_iSpeakFlags[%1] = %2
fm_get_speak(index) - returns a player's speak mode
fm_set_speak(index, iSpeakFlag) - sets a player's speak mode


To hook when a player talks, we will need to register the forward FM_Voice_SetClientListening.
Code:
public plugin_init() {     register_forward(FM_Voice_SetClientListening, "fwd_FM_Voice_SetClientListening"); }

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"); } public client_connect(id) {     g_iSpeakFlags[id] = SPEAK_NORMAL; } public fwd_FM_Voice_SetClientListening(receiver, sender, bool:bListen) {     if(!is_user_connected(receiver) || !is_user_connected(sender))     {         return FMRES_IGNORED;     }         if(g_iSpeakFlags[sender] == SPEAK_NORMAL && g_iSpeakFlags[receiver] != SPEAK_LISTENALL)     {         return FMRES_IGNORED;     }         new iSpeakValue = 0;     if(g_iSpeakFlags[sender] == SPEAK_ALL     || g_iSpeakFlags[receiver] == SPEAK_LISTENALL     || g_iSpeakFlags[sender] == SPEAK_TEAM && get_pdata_int(sender, 114) == get_pdata_int(receiver, 114))     {         iSpeakValue = 1;     }         engfunc(EngFunc_SetClientListening, receiver, sender, iSpeakValue);     return FMRES_SUPERCEDE; }

Any mistakes or suggestions, speak up!
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 04-08-2008 at 13:45.
Exolent[jNr] is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-08-2008 , 12:17   Re: set_speak() in Fakemeta
Reply With Quote #2

http://forums.alliedmods.net/showpos...06&postcount=2
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-08-2008 , 12:24   Re: set_speak() in Fakemeta
Reply With Quote #3

Never seen that.

I only posted it as a request anyway.
But that one wasn't in here, and people needed this, so I decided to make one to post.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-08-2008 , 12:35   Re: set_speak() in Fakemeta
Reply With Quote #4

Just posted this link as a complement, haven't look your code ;)
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 04-08-2008 , 18:29   Re: set_speak() in Fakemeta
Reply With Quote #5

This one is better anyhow. X-olent explains everything.
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
Reply



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 09:07.


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