Raised This Month: $12 Target: $400
 3% 

Parsing one word from a string - i.e. 1 word from a sentence


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
[TooL] Faaip De Oiad
Senior Member
Join Date: Apr 2005
Old 04-21-2005 , 22:14   Parsing one word from a string - i.e. 1 word from a sentence
Reply With Quote #1

Is there any way to parse a single word from a string?

In this case, I'd like to be able to set up a script in player_say.cfg that will test the string output of player_say for a word, such as "gravity", and execute a command.

For an example, the script, in it's very basic form, would currently look like this:

if (event_var(text) equalto "Marco") then ma_say "Polo!"

I want to be able to extract Marco from anywhere in anything someone says, so instead of saying:

Marco

to get the result of the console running the command to show 'Polo!', someone would be able to say:

"What does marco do?"

...to get the same result.

Any way this is possible?

Thanks for any help.
__________________
[TooL] Faaip De Oiad is offline
Mattie
Veteran Member
Join Date: Jan 2005
Old 04-21-2005 , 23:08   Re: Parsing one word from a string - i.e. 1 word from a sent
Reply With Quote #2

Quote:
Originally Posted by [TooL
Faaip De Oiad]Is there any way to parse a single word from a string?

In this case, I'd like to be able to set up a script in player_say.cfg that will test the string output of player_say for a word, such as "gravity", and execute a command.

For an example, the script, in it's very basic form, would currently look like this:

if (event_var(text) equalto "Marco") then ma_say "Polo!"

I want to be able to extract Marco from anywhere in anything someone says, so instead of saying:

Marco

to get the result of the console running the command to show 'Polo!', someone would be able to say:

"What does marco do?"

...to get the same result.

Any way this is possible?

Thanks for any help.
The best you'll find is using es_token for this sort of thing at the moment. There's no other way to do this that I know of.

You can search for the string with es_token by slowly incrementing what token you're checking (perhaps maxing-out at 10 tokens), or you could even write an alias loop to handle it. Unfortunately, I don't know of a clean way to handle it better at the moment.

-Mattie
Mattie is offline
[TooL] Faaip De Oiad
Senior Member
Join Date: Apr 2005
Old 04-21-2005 , 23:11  
Reply With Quote #3

I don't know how to use tokens to do this, but I understand what you're saying and I'll learn how to use it to give it a shot.

Thanks for the quick reply - and thanks for the EXTREMELY useful plugin.
__________________
[TooL] Faaip De Oiad is offline
[TooL] Faaip De Oiad
Senior Member
Join Date: Apr 2005
Old 04-21-2005 , 23:43  
Reply With Quote #4

I'm sorry if this is total n00b, but after reviewing the documentation on defining tokens I'm still a bit hazy.

So far I've written this out as a test in player_say.cfg:

setinfo word1 0
setinfo word2 0
setinfo word3 0
es_token word1 "event_var(text)" 1
es_token word2 "event_var(text)" 2
es_token word3 "event_var(text)" 3
if (word1 equalto "marco") then ma_say "Polo"
if (word2 equalto "marco") then ma_say "Polo"
if (word3 equalto "marco") then ma_say "Polo"

Tokens are defined as <variable> <string> <token#>, so I have the variable as word1, the string as the text players type, and the token# is progressing to test each word as you said. I haven't defined a seperator, since obviously it'll be the default of space.

In my mind, this is creating a variable "wordX", defining the variable from the string, then testing that variable to see if it's equal to "marco".

It doesn't work, though, and I've already tried a few variations of this. I just don't have the experience it takes to spit one of these out.

I'm going to keep trying different things, and I'm sure I will eventually figure it out... but do you think you could give me any pointers to speed me along?

Thanks again,
__________________
[TooL] Faaip De Oiad is offline
Dygear
SourceMod Donor
Join Date: Apr 2004
Location: Levittown, NY
Old 04-22-2005 , 00:11   Re: Parsing one word from a string - i.e. 1 word from a sent
Reply With Quote #5

Quote:
Originally Posted by Mattie
The best you'll find is using es_token for this sort of thing at the moment. There's no other way to do this that I know of.

You can search for the string with es_token by slowly incrementing what token you're checking (perhaps maxing-out at 10 tokens), or you could even write an alias loop to handle it. Unfortunately, I don't know of a clean way to handle it better at the moment.

-Mattie
What's the SDK's functions that allows you to "see" what a player is saying?

for example :
Code:
.:KPS:.Dygear : Hey what's up KingPin.
.:XFX:.KingPin : Hey the chat is working, that's good.
.:KPS:.Dygear : Yea it looks like you know what your doing, but it only looks that way. :P.
Would that all be handled by one function? That function would be called one time for each time a client sends chat text. I do hope it's in an array. Any way, could ya tell me what that function is.


On a side note, we need to setup a wiki, eather here on the SourceMod.net, or I could make it on my own website. Going to send a PM to BAILOPAN now about that.
__________________
Dygear is offline
Send a message via AIM to Dygear Send a message via MSN to Dygear Send a message via Skype™ to Dygear
[TooL] Faaip De Oiad
Senior Member
Join Date: Apr 2005
Old 04-22-2005 , 00:34  
Reply With Quote #6

You can get it to spit back exactly what is pulled from event_var(text) by using es_msg, which expands variables. Try this in player_say.cfg:

es_msg event_var(text)
__________________
[TooL] Faaip De Oiad is offline
ajax
Veteran Member
Join Date: Jan 2005
Old 04-22-2005 , 00:59  
Reply With Quote #7

try this...

Quote:
if (server_var(word1) equalto "marco") then ma_say "Polo"
if (server_var(word2) equalto "marco") then ma_say "Polo"
if (server_var(word3) equalto "marco") then ma_say "Polo"
ajax is offline
[TooL] Faaip De Oiad
Senior Member
Join Date: Apr 2005
Old 04-22-2005 , 01:01  
Reply With Quote #8

Quote:
Originally Posted by ajax
try this...

Quote:
if (server_var(word1) equalto "marco") then ma_say "Polo"
if (server_var(word2) equalto "marco") then ma_say "Polo"
if (server_var(word3) equalto "marco") then ma_say "Polo"
HA! I had JUST gotten to this step about 5 minutes ago.

It's perfect for the test I was doing. Now I just need to plug in the actual variables I was going for...

Thank you!
__________________
[TooL] Faaip De Oiad is offline
[TooL] Faaip De Oiad
Senior Member
Join Date: Apr 2005
Old 04-22-2005 , 01:44  
Reply With Quote #9

Excellent. I've got this part of the project working perfectly.

...and now I know how to use tokens as well. ;)

Thanks for your help, guys.
__________________
[TooL] Faaip De Oiad is offline
Mattie
Veteran Member
Join Date: Jan 2005
Old 04-22-2005 , 07:46  
Reply With Quote #10

Quote:
Originally Posted by [TooL
Faaip De Oiad]Excellent. I've got this part of the project working perfectly.

...and now I know how to use tokens as well. ;)

Thanks for your help, guys.
Great news! Exactly the sort of thing I love to see.

Sorry my answer above was so terse, but I was completely exhausted from many late night researching binges on this plugin. I went immediately to bed after posting. (I'm surprised I was coherent enough to help.)

Good job, and sorry again for such a short/sleepy response,
-Mattie
Mattie 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 13:58.


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