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.
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.
(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)
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:
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
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.
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.
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.
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.
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.
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.
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, ""
I'm not sure what you mean here. A timer goes off after so many seconds, you don't put a wildcard in it. However if you mean the wildcard from the trigger, here is an example. Say you have a trigger that matches on a monster name, eg.
* attacks you!
Then in this case the monster name is wildcard #1. So, to make a timer that says "kick dragon" after 2 seconds (assuming that the monster is a dragon) you would do this:
sub OnAttack (TriggerName, TriggerLine, Wildcards)
World.addtimer "my_timer", 0, 0, 2, "kick " + Wildcards (1), 5, ""
end sub
By using "+" you concatenate together two strings, in this case "kick" and the contents of wildcard 1.
Wildcards in aliases
Quote:
Same goes for an alias I need to make
Alias:
^(.*)= (.*) (.*)$
Punch right=rp @attacker
You would do a similar thing there ...
sub OnAliasCreation (TriggerName, Triggerline, arrWildCards)
world.AddAlias ("alias_" + cstr (world.getuniquenumber), arrWildCards (1), arrWildCards (2) + arrWildCards (3), 1 + 1024, "");
end sub
What the above is doing is:
Alias name: alias_22 (just a unique name for it)
Match on: Wildcard 1
Send: Wildcard 2 + Wildcard 3
Flags: Enabled + Replace any existing one of the same name
Script: None
Required. String expression containing substrings and delimiters. If expression is a zero-length string, Split returns an empty array, that is, an array with no elements and no data.
delimiter
Optional. String character used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned.
count
Optional. Number of substrings to be returned; -1 indicates that all substrings are returned.
compare
Optional. Numeric value indicating the kind of comparison to use when evaluating substrings, as follows:
0 Perform a binary comparison.
1 Perform a textual comparison.
Remarks
The following example uses the Split function to return an array from a string. The function performs a textual comparison of the delimiter, and returns all of the substrings.
In your case you want to use "split" on a space delimiter (which is the default anyway), so (without testing it) I would guess you would want something like this:
Dim MyArray
MyArray = Split (wildcards (1))
Now you can "walk" (there's that word again!) each of the elements in the array, as in this example:
Dim i
for i = lbound (MyArray ) to ubound (MyArray )
world.note MyArray (i)
next
Match on: ^Combonation \( (rp|lp|s|r) * \)^
send to world: Blank
flags:enabled, and regular expression clicked on, all else off
Name:AutoCombo(for lack of a Better name)
script: OnAutoCombo
Now for the doozy:
sub OnAutoCombo (TriggerName, Triggerline, arrWildCards)
Dim AutoCombo
Autocombo= split (arrWildCards (1))
Dim i
for i=lbound (AutoCombo ) to ubound (AutoCombo )
world.send AutoCombo (i)
next
end sub
Ok Now about the trigger
^Combonation \( (rp|lp|s|r) * \)^
Is the (rp|lp|s|r) a wildcard?
I don't think it is
so what i think I can do is this
^Combonation \( (.*) \)^
That should work.
I am off to try to imp this, Get back to you soon with sucess, I hope.
'
' loop through each possible response
'
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
' ----> and so on for each different one
case "s" attack = "blah"
case "r" attack = "blah
case else attack = "" ' unknown attack type
End Select
' send our response if we found one
if attack <> "" then
world.send attack + " " + world.GetVariable ("attacker")
end if
next
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 attack <> "" then
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Wasn't 100% sure how to add the code you gave me.
I guessed in the implementaion,
I got an error:
-2146828275
Execution of line 77 column 1
AutoCombo split (arrWildCards (1))<--- Line 77
Type mismatch: 'AutoCombo'
Function/Sub: OnAutoCombo called by trigger
Reason: processing trigger "AutoCombo"
Unable to invoke script subroutine 'OnAutoCombo' While Processing trigger 'AutoCombo'
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
Works perfect for characters or mobs that have a single name. I.E. Saibaman, Or any PC name.
It does not work on multi-named mobs.
My question is, Using the split command how wuld I use it to set variables using the second array
sub UnNamed (TriggerName, Triggerline, arrWildCards)
Dim UnNamed
UnNamed= split (arrWildCards (1))
Dim i
for i=lbound (UnNamed ) to ubound (UnNamed )
world.SetVariable "UnNamed" + UnNamed (i)
next
end sub
I think this how I might do it.
This will give me the result I think I want, but it will be kinda sloppy in My opinion.
reason being, it will be continuesly setting multiple variables, potentially hogging CPU speed(although it will prolly be next to nothing)
I would like to tighten it up. so that it will only set the ubound (UnNamed ) as the variable, and ignores the ibound (UnNamed )
I thought about uusing the if, command
if i= ubound (UnNamed ) then
world.setvariable "UnNamed" + UnNamed (i)
end if
next
end sub
I don't think thats right, could you please correct me if I am wrong
Also, looking back through the messages in this section it isn't obvious how the monster name gets into the variable in the first place. How do you put it there? Through an alias?
Hrm... I tried using the "" or the '' but this is a completely custom mud, it is not based on ANY MUD that I know of. it did not work
Its not ROM its not SMAUG, its not CIRCLE, its coded from scratch
I don't think there is the "" '' in it.
I got the code to do what i want, It splits the names into array's and uses the last one as the variable
What I want to do is make it a little tighter, instead of setting a varible for the first name "King", then "walking" to the next Array "Cold" and setting that variable as well.
I would prefere it to ignore all but the last array
and use that as the variable.
The split works, I just want to make it less cpu intensive... setting one varible instead of cycling through the names in the array's and setting multiple variables
This is what I am currently using to change my varible "attacker" to something that works
sub OnAttacker (Triggername, triggerline, arrWildCards)
Dim Sense
Sense = split (arrWildCards (1))
Dim i
for i=lbound (Sense ) to ubound (sense )
world.SetVariable "Attacker", sense (i)
next
End Sub
What I want to do is change this into seomthing like what we did with throw as the last command in the combo
Instead of setting 2 variables
the first being Android
and the second Being 17
It is simpler than what you are doing. You don't need a loop just to get the last word in the list. Do this:
sub OnAttacker (Triggername, triggerline, arrWildCards)
Dim Sense
Sense = split (arrWildCards (1))
world.SetVariable "Attacker", sense (ubound (sense))
End Sub
The split will give you one or more words.
"Ubound (sense)" gives you the offset of the last word.
"sense (ubound (sense))" gives you the last word itself.
What if i wanted to access something in the middle?
Is that possible to do?
How would you do so?
Also. another side thought.
I have this Trigger. I want it to run a script... Lets jsut say Autocombo for instance. However once it runs through the combo i get another Combination! ( * ) trigger, but the second Combination! ( * ) that I get, I want the script to act differently.
Is there a way to make the script create a new trigger, and timer to re-enable the old trigger, then run a different subroutine, from within the scrpt, to do something else, then go back to the original script?
____________________________________________________________
Ok this is a better way to put it I think. Its a map of what this thing is suposed to do
____________________________________________________________
Ok the first trigger is activated it-> runs a script to make a new trigger, and timer->Runs a "sub subroutine"(I.E. AutoCombo)-> The second Trigger comes-> Runs a differnet subroutine(IE autocombo)-> third trigger comes, Runs the same as the second-> the timer expires and changes the 2nd, and 3rd trigger, back to the first trigger, and completes the rest of the first script.
This is kinda confusing I am sure, but I think if you look at it, it does make sense in a wierd way
Ok the first trigger is activated it-> runs a script to make a new trigger, and timer->Runs a "sub subroutine"(I.E. AutoCombo)-> The second Trigger comes-> Runs a differnet subroutine(IE autocombo)-> third trigger comes, Runs the same as the second
You confuse me a bit by talking about two subroutines both called Autocombo (as VB is not case-sensitive) however, you can probably achieve what you are doing by having a flag which you test in the trigger.
Something like this:
sub OnTrigger (Triggername, triggerline, arrWildCards)
dim flag
flag = world.getvariable ("flag")
if flag = "b" then
' ..... do something here (action B) .....
else
' ..... do something different here (action A) .....
world.setvariable "flag", "b"
world.AddTimer ("blahblah", 0, 0, 5, "", 1029, "On_Fix_Trigger");
end if
end sub
sub On_Fix_Trigger (strTimerName)
world.setvariable "flag", "a"
end sub
What you have here is a single trigger that does action A or action B depending on the flag. Initially the flag will be "a" (or empty) so action A is done. In this case we set the flag to "b" so the action B is done next time around, and set up a 5-second timer to change the flag back at the end of the 5 seconds.
The other sub is called by the timer to switch the flag back.
When your creating a new character, I want to set a varible for the race that you select
Let me show you the code that I am trying to do, maybe you will know what I am doing wrong
sub OnRace (Triggername, triggerline, arrWildCards)
world.setvariable "Race", arrWildCards (1)
dim flag
flag = world.getvariable ("Race")
if flag = "saiyan|human|namek|android" then
world.setvariable "Race", arrWildCards (1)
world.send arrWildCards (1)
else
world.note "That is an invalid Race selection, Please check spelling and capitalization (hint, Don't capitilize your race)"
end if
end sub
I guess the question is I need the race to be case sensitive The only way I can see how to do this is at character creation
How do I create an "or" statement in the script.
if flag = "any of these possibilities" then
do this
else
world.note "Try again type this"
end if
Ok, again, I wasted time with posting, I ended up using elseif statement
It works, but I can not seem to get an alias added from within the script
This is what I am doing, it is giving me an errorsub OnRace (Triggername, triggerline, arrWildCards)
world.SetVariable "Race", arrWildCards (1)
dim flag
flag = world.getvariable ("Race")
if flag = "saiyan" then
world.setvariable "Race", arrWildCards (1)
world.send arrWildCards (1)
world.note "Your have selected: " + world.getvariable ("Race")
world.deletealias "RaceSelection"
world.setVariable "Kaioken", "off"
World.addalias "Kaioken", "kk", "", "", 1+32, "OnKaioken"
elseif flag= "human" then
elseif flag= "namek" then
elseif flag= "android" then
else
world.note "That is an invalid Race selection, Please check spelling and capitalization (hint, Don't capitilize your race)"
end if
end sub