Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
atraeyu
Novice


Joined: 29 Dec 2006
Posts: 41
Location: Chester, VT

PostPosted: Sun Dec 31, 2006 4:33 pm   

Parsing HP & SP (Setting Variables)
 
The mud passes me my hp (every few ticks) in the following format:
Quote:
** HP: 154/186 SP: 170/186


Now, I'm completely new to cMUD/zMUD.

What I would like to do is parse the hp and sp into variables that I can use in other scripts. Is that possible?

---

On a similar note, I'd also like to setup a "targeting" system if possible.
I type t CREATURE_NAME and cMUD sets a variable with the name of the creature that I can use in other scripts.

After doing t CREATURE_NAME I would then like to be able to type: a and it would output: attack CREATURE_NAME.

Any suggestions? Thanks.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sun Dec 31, 2006 5:07 pm   
 
The #Trigger command is what you need. It looks for text coming from the mud (and has its own wildcard format, as well as supporting Perl Regular Expressions) and runs a script when it finds a match. Look it up in the zMUD help files.

#trig {~*~* HP: (%d)/(%d) SP: (%d)/(%d)} {#var CurrentHP %1;#var MaxHP %2;#var CurrentSP %3;#var MaxSP %4}

Then when you want to refer to them in other scripts, you use @Varname:

#echo @CurrentHP

for example.

--

The other command you want is #ALIAS. An alias is a command that you enter like any other, but which CMUD picks up and changes into another command or series of commands. for example:

#alias t {#var Target %1}

There's much more detailed descriptions of aliases and triggers in the help files.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
atraeyu
Novice


Joined: 29 Dec 2006
Posts: 41
Location: Chester, VT

PostPosted: Sun Dec 31, 2006 5:42 pm   
 
Woo, thanks. That's awesome & it works!
Reply with quote
atraeyu
Novice


Joined: 29 Dec 2006
Posts: 41
Location: Chester, VT

PostPosted: Sun Dec 31, 2006 7:47 pm   
 
Everything is working ... now to extend it a little further.

On certain intervals, I'd like to evaluate my @CurrentSP and perform commands if conditions are met.
I could set this up as another trigger, I think ... and have it fire everytime the mud sends me back my hp & sp, but that's not a great way to do it.
Is there a way to have a series of commands fire based on a timer in cMUD? Does that make sense? Every 60 seconds, do something.

This involves conditional branching, which I've no idea how to do. I tried to set up a trigger that fired based on certain events that looked like this:
#TRIGGER ~*~* { #IF (@CurrentSP > 150) say Lots of SP!; }
But that didn't work. It ALWAYS performed the action.

So basically, I'd like to do this:

Every 60 Seconds, if my @CurrentSP is greater than 150
say "Lots of SP!"

Is this possible?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sun Dec 31, 2006 7:51 pm   
 
#if (expression) {true command} {false command} - the braces are important. And you don't need a semicolon at the end.

Also, take a look at #alarm.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net