Raised This Month: $ Target: $400
 0% 

[Solved] questions about read_data


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
breaddawson
Senior Member
Join Date: Jul 2004
Location: Beijing,China
Old 10-18-2004 , 00:51   [Solved] questions about read_data
Reply With Quote #1

i found this script in Statsx.sma
and i can't understand it

Code:
public eventSpecMode( id ) {   new sData[12]   read_data( 2, sData, 11 )   g_izSpecMode[id] = ( sData[10] == '2' )   return PLUGIN_CONTINUE }

and i found the explain of "read_data" in the amxmodx.inc
but it's too brief for me to understand it
Code:
/* Gets value from client messages.
* When you are asking for string the array and length is needed (read_data(2,name,len)).
* Integer is returned by function (new me = read_data(3)).
* Float is set in second parameter (read_data(3,value)). */
native read_data(value, {Float,Sql,Result,Regex,_}:... );
another question is about "register_event"
i also find its explain

Code:
/* Registers event on which a given function will be called
* Flags:
* "a" - global event.
* "b" - specified.
* "c" - send only once when repeated to other players.
* "d" - call if is send to dead player.
* "e" - to alive.
* Examples for conditions:
* "2=c4" - 2nd parameter of message must be sting "c4".
* "3>10" - 3rd parameter must be greater then 10.
* "3!4" - 3rd must be different from 4.
* "2&Buy" - 2nd parameter of message must contain "Buy" substring.
* "2!Buy" - 2nd parameter of message can't contain "Buy" substring. */
native register_event(const event[],const function[],const flags[],cond[]="", ... );
i can understand this
but the one i'm puzzled is that if i do this
for example ,i write this line
Code:
register_event("TextMsg","setSpecMode","bd","2&ec_Mod")
then,what will happen?

is there anyone kindly explain these to me~~
thank u very much~~
__________________
i'm bread dawson ,a chinese boy
wish u be happy~
breaddawson is offline
Send a message via ICQ to breaddawson Send a message via MSN to breaddawson
DS
SourceMod Developer
Join Date: Sep 2004
Location: WI, USA
Old 10-18-2004 , 03:31  
Reply With Quote #2

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.
DS is offline
Votorx
Senior Member
Join Date: Jun 2004
Old 10-18-2004 , 07:25  
Reply With Quote #3

Nice try, but that's a bit lengthy. There are many events that can be used with amxmodx. There's a few topics on here that give you many examples of events that can be used and the info they pass through, use the search engine. Anyways, like modules with amxmodx (which send over parameters), events do the same exact thing. They send over info that can be hooked through the read_data function. How to get this info is just as the description suggests.

When you are asking for string the array and length is needed (read_data(2,name,len)).

When you use the event and you know the second "parameter" is a string then the function you would use is read_data(2,String,lengthofstring). As well lets say you know its an integer then you wuold use something such as new int = read_data(2). if it's the third parameter that your looking for you would use read_data(3,...) It actually acts exactly like read_argv() only there's a certain # of parameters that can be found easily through the search enginge or sdk
__________________
Currently Looking for a mod team.
Votorx is offline
Send a message via AIM to Votorx Send a message via MSN to Votorx Send a message via Yahoo to Votorx
breaddawson
Senior Member
Join Date: Jul 2004
Location: Beijing,China
Old 10-18-2004 , 12:08  
Reply With Quote #4

,Damaged Soul,thank u very much for ur explain to me
it's very expert and really help me a lot
and so does Votorx's reply
i'm not very good at scripting
and actually used the Search button before i posted this topic
but as u know,the engine found too many results
i use a moderm,so i can't check out all the results
so,sorry for my bothering

Code:
register_event("TextMsg","setSpecMode","bd","2&ec_Mod")

now i know how to use read_data
but another question comes out
i don't know how to use "TextMsg"or "DeathMessage"
are they const variables?
or are they scripted in the sdk?
and i also don't know about the "#Game_Commencing"or"#Game_will_restart_i n"

how can i know the TextMsg,for example,contains what strings?


thank u for ur reply again
and sorry for my poor english
__________________
i'm bread dawson ,a chinese boy
wish u be happy~
breaddawson is offline
Send a message via ICQ to breaddawson Send a message via MSN to breaddawson
breaddawson
Senior Member
Join Date: Jul 2004
Location: Beijing,China
Old 10-18-2004 , 23:37  
Reply With Quote #5

Damaged Soul,where r u??
__________________
i'm bread dawson ,a chinese boy
wish u be happy~
breaddawson is offline
Send a message via ICQ to breaddawson Send a message via MSN to breaddawson
DS
SourceMod Developer
Join Date: Sep 2004
Location: WI, USA
Old 10-19-2004 , 07:48  
Reply With Quote #6

Sorry about the delay. Been having a few internet issues. And you inspired me to write a plugin that should be able to help you out with this a great deal. Unfortunately, in order to finish it, I need a function that AMXX currently does not provide. However, I have suggested it to be added.

But in the mean time this plugin might be able to help you: http://forums.alliedmods.net/showthread.php?p=58288

First of all, each mod (such as Counter-Strike, TFC, Natural Selection, etc) has its own set of messages like TextMsg, DeathMsg, etc. A lot of mods usually share the same message names for some things (like DeathMsg), but also have quite a few unique ones as well.

If you type "meta game" in your console while you have Metamod loaded, you will get a list of all the named messages that the particular mod supports.

The difficult part, as you already have found out, is knowing what arguments each of these messages have. That's where that plugin I linked you to comes in.

If you want to find out what arguments and text that the TextMsg might contain. Use that plugin I mentioned. And when you are in the game, set the "msg_name" CVAR to "TextMsg". You may need to change the level to get this to work, however. That's one of the problems with that plugin that I hope to fix in the new plugin that I'm working on.

Anyways, whenever the TextMsg message is used, each argument for it will be displayed to you in the chat area. That is where you can see what strings it uses. I can try to explain this to you in more detail if you need me too..

Now the #Game_Commencing and #Game_will_restart_in come from a file called titles.txt in your MOD directory. However, with Steam, you won't see this file in your MOD directory because it is stored in the GCF file of your MOD. You can extract it from the GCF file using a program called GCFScape, which you can get here: http://countermap.counter-strike.net...index.php?p=26

The "#" just designates that the string comes from titles.txt. I have attached the titles.txt file from Counter-Strike. And if you look through it, you will find "Game_Commencing" and "Game_will_restart_in". There are many other entries in there as well that you may see used in other people's plugins. They are just different text messages that the game will use. For instance #Game_Commencing is the message that says "Game Commencing" in the center of the screen when the game begins. You will see this message in whatever language you are using, but #Game_Commencing is how you can access this text message.
DS is offline
breaddawson
Senior Member
Join Date: Jul 2004
Location: Beijing,China
Old 04-20-2005 , 01:51  
Reply With Quote #7

omg....i have not seen ds's reply till today...

u r really a kind man~
thanks a lot 4 ur help~~
__________________
i'm bread dawson ,a chinese boy
wish u be happy~
breaddawson is offline
Send a message via ICQ to breaddawson Send a message via MSN to breaddawson
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 17:22.


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