As far as read_data is concerned, this may help you out somewhat:
http://www.amxmodx.org/funcwiki.php?go=func&id=132
Basically it lets you read the arguments from messages.
For example, let’s say you wanted to send a fake death message in Counter-Strike. To do that you would do this:
Code:
message_begin(MSG_ALL,get_user_msgid("DeathMsg"),{0,0,0},0)
write_byte(1) // Killer user id
write_byte(2) // Victim user id
write_byte(0) // Headshot? 1 if yes, 0 if no
write_string("deagle") // Weapon name
message_end()
Now I know this may look like I'm not answering your question, but bear with me. So now the fake death message will say that the player with userid 1 killed the player with userid 3 without a headshot using the deagle. If you're with me so far, good...
So let's put this in context of read_data. As I said it reads the arguments of a message. In our case that message is DeathMsg. And the arguments of that message are the values we filled in using write_byte, write_string, etc.
So in summary, all the arguments of DeathMsg are as follows:
Arg 1: The killer's user ID
Arg 2: The victim's user ID
Arg 3: 1 if it was headshot, 0 if it was not a headshot
Arg 4: The name of the weapon that was used
You use read_data in conjunction with register_event. So let's use register_event for the DeathMsg.
To do that, first you must use register_event in plugin_init like so:
Code:
public plugin_init() {
register_event("DeathMsg", "event_DeathMsg", "a")
}
You're still probably wondering about the "a" and the other arguments of register_event, but I will get that soon enough. Anyways, now you see that we need to create an event_DeathMsg function.
Code:
public event_DeathMsg() {
}
Now as you probably know the DeathMsg is sent whenever someone is killed. So what if we want to find out the details of this killing? Well we can certainly do this using read_data.
Code:
public event_DeathMsg() {
new killer = read_data(1) // Get the killers user id
new victim = read_data(2) // Get the victims user id
new headshot = read_data(3) // Is this death due to a headshot?
// Get the weapon name
new weapon_name[32]
read_data(4, weapon_name, 31)
}
So basically, the first the argument of read_data will always be the number of the argument you want to retrieve from the message (DeathMsg in this case). Now if want to get the argument as an integer, all you need is that one argument. You see how we got the killer?
However, if you wish to get an argument as a string, you need a variable to put that string into as well as the length of the string you want to get.
Now the last thing that the amxmodx.inc file mentions is retrieving an argument as a float. As you see I didn't do that in my code as it wasn't needed. But in order to do that all you need is the argument number and float variable to put it in. Much of this is shown in the link I gave you at the top of my reply.
I hope this clears up some things about read_data for you.
Now on to explain register_event in more detail. This link may help:
http://www.amxmodx.org/funcwiki.php?go=func&id=26
As you probably know the first argument of register_event is the message you want to check for. Before I used "DeathMsg" and what you posted was "TextMsg". These are the messages sent to players when things in the game happen. The second argument is the function that you want to be called when the message occurs.
The third argument is the flags which can determine if your function should be called.
"a" obviously means the event/message is global, meaning it is sent to all players. In our case, DeathMsg is global because everyone can see it. So when we want to register DeathMsg, we should set this flag as I did in the code above.
"b" means if the event/message was sent to only one player.
"c" means that your function will only be called one time if the message/event happens to be repeated to other players. That basically means if a message was sent to a single player and it is repeated to other players on an individual basis, your function will still only be called one time.
"d" means that your function will only be called if the message was sent to a player that is dead
"e" means that your function will only be called if the message was sent to a player that is alive
So if you wanted your function to be called when a message was sent to one player and the player must also be dead, you would do something like this:
Code:
public plugin_init() {
register_event("TextMsg", "event_TextMsg", "bd")
}
Now for the fourth argument of register_event. As the link I gave you mentions, it lets you use a set of conditions on when your function will be called.
Let's use the code you posted to try to figure this out for you:
Code:
register_event("TextMsg","setSpecMode","bd","2&ec_Mod")
The fourth argument here is "2&ec_Mod". The number represents which message argument you want to check. So in this case you want to check argument 2 of the TextMsg message. The & specifies that you want to see if the argument contains a certain substring. In this case the substring we are looking for is "ec_Mod". So in summary we are checking to see if the second argument of TextMsg contains the "ec_Mod" substring. If that is true, then your function will be called.
Also there are other ways to check arguments. If you used "2!ec_Mod", that means that argument 2 must not contain the substring "ec_Mod". Also you could use an equals sign to see if an argument exactly matches something. You may also use greater than and less than signs to compare numbers as well.
You aren't limited to four arguments however. You can check more than one argument if you wish. You can even check if an arguments contains one thing or the other. For example in StatsX you will see this:
Code:
register_event( "TextMsg", "eventStartGame", "a", "2=#Game_Commencing", "2=#Game_will_restart_in" )
You see, there are 5 arguments here. But that's because we're checking to see if argument 2 equals "#Game_Commencing" or "#Game_will_restart_in". So if either one of those things is true, then your function will be called.
Also to explain exactly what this code does:
Code:
register_event("TextMsg","setSpecMode","bd","2&ec_Mod")
It basically detects when a players goes into spectator mode. So when a TextMsg message is sent to individual dead player and when the second argument of this message contains the substring "ec_Mod", then the function named "setSpecMode" will be called.
I think I answered everything you asked. I hope this information helps you in some way. And if you have any more questions about this, I'll try to answer them as best I can.
Anyone else that sees this, feel free to correct anything I said or add on to it, as I tend to be pretty horrible at explaining things.