Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Half second timers

Half second timers

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1 2  3  

Posted by David   USA  (49 posts)  Bio
Date Sun 15 Apr 2001 04:00 AM (UTC)
Message
I know I was talking about this before in another forum, but I decided to move it here.

The problem:

The MUD is a timered based MUD, This means everything that is done can be reacted to.

Instead of rolling dice to see if you hit, its based on literal timing. If i punch You you have 1.5 seconds to reacts and parry, or dodge the attack.

I have worked out the trigger code, thanks to you Nick.(I would still be stumbling along otherwise)

You mentioned about making "one shot" timers, I think that is a great idea.

I would love to implement that, i read the other forums regarding addtimer, its far more complex than what i am needing.

first thing:
world.addtimer (??????) what goes here, I did not understand what was being said in the other forums.

Second thing:
I need a timer that A. waits 1.5 seconds before sending something to the world, Or B. the script which does all the thinking, meaning it waits X amount of time before sending to the world my command of "parry High". From what I read it doesn't sound like scripting can do that. I understand you can't Pause the script without stopping everything, someone mentioned something about a wait command. It was a little too complex for me to understand. Perhaps you might simplify what it meant for me.

Thanks for the help again.


My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 15 Apr 2001 07:02 AM (UTC)

Amended on Thu 19 Apr 2001 10:57 PM (UTC) by Nick Gammon

Message
OK, first let's look at the difference between manually entering a timer or trigger, and doing it in a script.

By "manually" doing it, you simply use the MUSHclient configuration screen to type in a trigger, timer, alias or whatever. This is fine if you can plan to do something in advance, like set up a timer that says "inventory" every hour to stop your being disconnected for inactivity.

However you might want to have a script add a timer, for example if you want to do something 2 seconds after a trigger fires.

Addtimer (in a script) looks like this:


World.addtimer "my_timer", 1, 10, 30, "parry high", 5, "my_timer_script"


(This is in VBscript). Breaking it up piece-by-piece ...


"my_timer" - the name of the timer (used if you need to delete or reset it)
1 - the number of hours to wait, plus
10 - the number of minutes to wait, plus
30 - the number of seconds to wait
"parry high" - what to send to the MUD
5 - some flags - in this case enabled=1 plus one-shot=4. So, adding the flags together gives 5.
"my_timer_script" - the name of the script to execute when the timer fires (optional)


The various flags are documented on the page http://www.gammon.com.au/mushclient/functions.htm.

For example, if you add 2 to the flags it becomes a timer that fires at a particular time (in this case 01:10:30).

Now, to solve your problem, basically you want to set up a script that, when you are attacked, sends "parry high" 1.5 seconds later.

The first point is that I haven't allowed for sub-second timers. In my view, because of lag and other considerations, rounding to the nearest second should be good enough. So, let's make it 2 seconds.

You need, then, a trigger that matches on the event that needs the parry. You haven't said what that is, but let's assume it is something like:


The Gorgon attacks you!


Thus, you set up a trigger like this:


Trigger: * attacks you!
Label: attack_trigger
Script: OnAttack


Then you need a script routine (OnAttack) that sets up the timer to fire 2 seconds later and do the parry. Thus you add to the script file:


sub OnAttack (TriggerName, TriggerLine, Wildcards)
World.addtimer "my_timer", 0, 0, 2, "parry high", 5, ""
end sub


This trigger adds a one-shot timer that fires in 2 seconds. When it fires it sends "parry high" and then deletes itself.

This is simple enough. You can modify this general idea for all sorts of things.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by David   USA  (49 posts)  Bio
Date Reply #2 on Sun 15 Apr 2001 07:56 AM (UTC)
Message
Ok, So basically There is no possible way to make a 1.5 second timer.

I was browsing the forums, and I came across something interesting.

I see:
* <insert name> Retracts his right arm...

Now I saw you make a post about regular expressions in a trigger, making asterisks asterisks not wildcards

My question is:

Can you make a regular expresion with a wildcard in it?

As a side thought:

Also, currently i am using the copy wildcard to clipboard in most of my aliases

E.g
* Apoc retracts his right arm...

My trigger is:

* * retracts his right arm...

I copy the second wildcard to the clipboard

My alias:

Match on: pr
sends to world: punch right %c

My original though was to use variables.

i wanted my trigger to set a variable as an attacker( I got the same problem as someone else did, it will work from the command box, but not as a trigger)

E.g.

* Apoc retracts his right arm...

I now know how to use a trigger in scripting, I do not know how to translate my wildcards from the client to the script

I want to beable to use scripting in my aliases instead
of %c

If I go and look at my variables I see:

Name: Attacker
Content: Apoc

The 2 things I need to know about this part is:
A. How do I copy my wildcard to my variable list?
Would it Look something like this?

sub Attacker (PunchRight, trig_line, arrWildCards)
world.setvariable "Attacker", arrWildCards (2)
End Sub

B. How do I then setup my aliases to use that information?

(If I recall correctly, thought I don't know how to do it, When you set a variable, and then reset a variable with different information as long as its the same name the old one will be replaced.)

I feel that scripting this over using the %c will be more effecient, and allws me to use that for other things


My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #3 on Sun 15 Apr 2001 10:07 PM (UTC)

Amended on Thu 19 Apr 2001 10:59 PM (UTC) by Nick Gammon

Message
Yes, you can make regular expressions match on wildcards. In fact, in this version of MUSHclient, internally all triggers are translated into the matching regular expression, so it uses a single regular-expression matching routine on incoming text. In your example:


* * retracts his right arm...


The regular expression you want (assuming that the first asterisk is a literal asterisk) is:


^\* (.*) retracts his right arm...$


The "^" says "match on start of line".
The "$" says "match on end of line".
The "\*" is a literal asterisk.
The "(.*)" is a match on one or more characters of any type.

The brackets also mean "save this in the wildcard array". In other words, this then becomes wildcard %1 in the trigger. (You used wildcard 2 because you had two lots of asterisks).

Quote:

Would it Look something like this?

sub Attacker (PunchRight, trig_line, arrWildCards)
world.setvariable "Attacker", arrWildCards (2)
End Sub


Yes, that is exactly right, although in the example I gave the (2) becomes a (1).

To use this variable in an alias, check "Expand variables", and then put an "@" in front of the variable name in the alias expansion, like this:

Send: kick @Attacker

I think variables are more powerful than the clipboard, which was really retained for historical reasons. If you keep using the clipboard, and then while all your aliases and triggers are working away, want to copy and paste something in the command area, you will find that halfway through, your clipboard has changed.

And yes, you are correct that setting a variable replaces the previous contents, if any.






- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by David   USA  (49 posts)  Bio
Date Reply #4 on Mon 16 Apr 2001 12:25 AM (UTC)
Message
I tried putting that into my script. It did not do as advertised. Also, when I code that particular part:

sub OnAttacker (>>PunchRight<<, triggerline, arrWildCards)
world.setvariable "Attacker", arrWildCards (1)
End Sub

Does the name HAVE to be that? >>PunchRight<<

I need all the attackes to run this subroutine.

Will any name work?

I didn't get any error's It just didn't work
. What did i do Wrong?

Trigger looks like this:
Match on: ^\* (.) retracts his right arm...$
Send: Blank
CopyWildcard to clipboard none
Name: PunchRight
Script OnAttacker

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by David   USA  (49 posts)  Bio
Date Reply #5 on Mon 16 Apr 2001 01:01 AM (UTC)
Message
Oh yeah I got the script to work, but not the exact expression part of it.

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by David   USA  (49 posts)  Bio
Date Reply #6 on Mon 16 Apr 2001 01:38 AM (UTC)
Message
Ok, Question:

Can a script do time functions?

I.E, it waits a certain amount of timer before sending information to the MU*?

If so, how would i do that(if possible)?

Sencondly, If the script can "wait" a number of seconds, then can you therefore, by using divion function, create a half second, then have the script send that to the mud, hence starting a 1 second "one shot" timer, after the scrip has already waited .5 seconds internally?


This is the only way I can see possible to do sub-second timers.

Thanks David

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by David   USA  (49 posts)  Bio
Date Reply #7 on Mon 16 Apr 2001 10:34 AM (UTC)
Message
Ok Played with Regular expressions for 5 hours(I had been up for 20+ hours on 2 hours sleep do to work) I figured out how they work, your example you gave me for the trigger was 99% correct

^\* (.) retracts his right arm... $

The problem was the $tring sign was in the incorrect place.

I hate to have 50 milliong questions.

My next little project is what I call "AutoCombo"

Some times when you "parry" an attack, it will give you a combonation of attacks you may do:

Combination! ( lp rp s lp s )

lp=Left punch
rp=Right punch
s=sweep
r=RoundHouse
(note there is no r in this combo)

My question is How would you script this?

My first thought was once again to use variables
However, you do not always get 5 attacks in a combo
Sometimes you get 2
Combination! ( lp rp )
Combination! ( lp rp s )
Combination! ( lp rp s lp )
Combination! ( lp rp s lp s )
In any order possible of the 4 attacks
And on Occasion you will get a second combonation screen or 3rd or 4th, it all depends on how fast you are. and there is a percentage tossed in there as well

Then I realized that variables might not be the answer to this question, so there must be something I gotta do to do this.

Thank you.

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by David   USA  (49 posts)  Bio
Date Reply #8 on Mon 16 Apr 2001 10:48 AM (UTC)
Message
I was thinking about this Just after I saved my post, I could do something like this:


Triggers match on: ^Combination! ( (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) )$
____________________________________________________________
^Combination! ( (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) )$
____________________________________________________________
^Combination! ( (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) )$
____________________________________________________________
^Combination! ( (lp|rp|s|r) (lp|rp|s|r) )$

Now.. I got the trigger worked out. its a bit harsh on the eyes. but I think this will work as regular expression

Here is where I am get confused. I think I got a solid Idea here. But I don't know where to go with it from here.

Will you give me some suggestions, am I on the right track?
Or have I gone a completely different route than I should?

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #9 on Mon 16 Apr 2001 11:10 AM (UTC)
Message
Quote:

sub OnAttacker (>>PunchRight<<, triggerline, arrWildCards)
world.setvariable "Attacker", arrWildCards (1)
End Sub


No, the name is supplied to you, which is the label of the trigger. Just do this:


sub OnAttacker (Triggername, triggerline, arrWildCards) 
world.setvariable "Attacker", arrWildCards (1) 
End Sub 



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #10 on Mon 16 Apr 2001 11:13 AM (UTC)

Amended on Mon 16 Apr 2001 11:14 AM (UTC) by Nick Gammon

Message
Quote:

Triggers match on: ^Combination! ( (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) )$
____________________________________________________________
^Combination! ( (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) )$
____________________________________________________________
^Combination! ( (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) )$
____________________________________________________________
^Combination! ( (lp|rp|s|r) (lp|rp|s|r) )$


You can do it a bit simpler than that. A regular expression can match on one or more of something, and that something can be "this" or "that".

So, I would do it like this:


Match on: ^Combination! \( (lp|rp|s|r)* \)$


This matches on one or more of: lp, rp, s or r

The "\(" matches a bracket, literally.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #11 on Mon 16 Apr 2001 11:38 AM (UTC)
Message
Quote:

Can a script do time functions?

I.E, it waits a certain amount of timer before sending information to the MU*?


No, and I wouldn't get too worried about trying to time 0.5 seconds. Network lag, and normal human reaction time, are likely to eat into 1/2 second pretty well.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by David   USA  (49 posts)  Bio
Date Reply #12 on Mon 16 Apr 2001 12:33 PM (UTC)
Message
Ok Well, the problem is there is going to have to be commands entered by the computer.

When The combonation comes up:
Combonation! ( lp lp rp s r ) <or whatever the string of attacks are at the time>

I want MUSHClient to do what the Combonation is for me.
I can do it fast enough typing, but i am too lazy while playing :)

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #13 on Mon 16 Apr 2001 11:20 PM (UTC)
Message
If you use the regular expression I suggested a few posts back, the string in question will be in the first wildcard. Then just write a script to "walk" the wildcard value (stopping at spaces) and send the appropriate command to the MUD.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by David   USA  (49 posts)  Bio
Date Reply #14 on Tue 17 Apr 2001 09:00 AM (UTC)
Message
When you set a regular expression trigger, does the trigger start at the beginning of the liine?

For instance:

^\* (.*) retracts his (right|left) arm...$
Thats my trigger

Now what I want to know is will the trigger still fire if I see something like this on the screen"

<1234643/2355466pl> * Apoc retracts his right arm...

Does the ^ signify where the trigger starts looking for something? and the $ is when it stops.
Instead of looking at the entire line, it only searches for thet string of characters, regarless of whats infront or behing the trigger?


I know how to use addtimer, but what if i wanted to put a wildcard into it

world.addtimer "blah", 0, 0, 2, "(need to punt wildcard here)", 5, ""

Same goes for an alias I need to make

Alias:
^(.*)= (.*) (.*)$


Punch right=rp @attacker

I got the Alias part Ok
When I do a world.addalias though. I don't know how to put wildcards into it.

world.AddAlias name, match_text, response_text, parameter, flags, scriptname

world.addalias "(wildcard)", "(wildcard)", "(not sure what parametr is)", eEnabled, ""

I am thinking now that to put wildcards i will have to do something like this:

sub OnAliasCreation (CreateAlias, Triggerline, arrWildCards)
world.addalias arrwildcard (2), arrWildCard (2), arrWildCard (1) arrWildCard (3), "", eEnabled, ""
end sub

Is this correct?
If not, please how do I put wildcards into aliases?



My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


105,394 views.

This is page 1, subject is 3 pages long: 1 2  3  [Next page]

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.