ScriptUO
Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Toptwo on June 11, 2009, 06:59:27 AM
-
OK, OK...I am attempting to actually write/modify a script. What I want to make is a server line healer script. I know there is a lot of healing scripts out there but they all seem to require damaging your char, and I would like to try making one that utilizes a server line to do this.
So far, I have managed to write the first part..I can make my char walk 4 steps, turn around, and walk 4 steps back. WOOHOO!!!!!!
How would I go about writing in a pause after the 4 steps though, I am confused if I would actually need to make him pause, or just the act of using a bandage would make him pause (I dont think using the bandage will do it, I think I need a real pause)...right??
Here is what I have so far:
set %X #CHARPOSX
set %XX #CHARPOSX + 4
set %Y #CHARPOSY
menu text scriptstatus
HealTrainingLoop:
{
move %X %Y 0 4s
move %XX %Y 0 4s
}
Goto HealTrainingLoop
Return
hehe pretty simple for you guys, but it took me over a hour to do it LOL!!
Thanks
-
After your second move, you could just apply the bandage and then add a "wait". If you are bandaging yourself, the wait time is based off your healing/anatomy. There's a formula on stratics that tells of this wait time, but is like 6 seconds or so. So perhaps "wait 6s". Dunno if that's what you had in mind.
-
Thanks TM, I actually managed to figure that out since I posted...now I am dealing with another problem (well, for me problem) LOL This is what I have
set %X #CHARPOSX
set %XX #CHARPOSX + 6
set %Y #CHARPOSY
menu text scriptstatus
HealTrainingLoop:
{
move %X %Y 0 6s
wait 200
I actually used a wait 200. I think that is 10 seconds...which would be what it takes to heal at only 20 skill...
move %XX %Y 0 6s
}
now, running this makes him move East and West
How do I change that to make him walk North and South??
Thanks!!!
-
You just need to set another variable using #CHARPOSY + 6 just like you did for #CHARPOSX. If you do it with a sub instead, it'll make it easier:
HealTrainingLoop:
gosub MoveYourself 6 0
wait 200
gosub MoveYourself -6 0
wait 200
gosub MoveYourself 0 6
wait 200
gosub MoveYourself 0 -6
goto HealTrainingLoop
;---------------------------------
sub MoveYourself
set %X #CHARPOSX + %1
set %Y #CHARPOSY + %2
move %X %Y 0 6s
return
-
HOLY CRAP!!!!!!!!!!!!!
I (with your help, and cerv's tutorial) JUST WROTE MY FIRST SCRIPT!!!
and IT WORKS!!!!!!!!!!
I have it set up at a server line...wearing everything I can find to add HP (crimson etc...) When I cross server line and my HP goes down, the script throws a bandage on me...I heal...walk back across server line..and heal again..over and over...WOOOTTTTTTTTT!!!!!!!!!!
-
Now theres no stopping you!
Congrats!!
-
Thanks Cerv!!
Here is what the whole thing looks like...dont know if it could be made more efficient or not...but I know it is working.
------------------------------------------------------------------------
gosub MoveYourself 0 6
wait 160
gosub MoveYourself 0 -6
goto HealTrainingLoop:
sub MoveYourself
set %X #CHARPOSX + %1
set %Y #CHARPOSY + %2
move %X %Y 0 6s
FindItem ZLF C_ , #BackpackID
if #findkind = -1
{
Display ok You have run out of bandages.$
+ Please get more and restart the script.$
+$
+Script is Halting$
Halt
}
Set #LObjectID #FindID
menu text scriptstatus 110 268 Using Bandage
Event Macro 17 0 ; Use Last Object (Bandages)
Target
Event Macro 23 0 ; Target Self
wait 200
Goto HealTrainingLoop
Return
-
Careful with what you are doing, you are jumping out of your subroutine. That's bad mojo. Follow the script flow a bit to make sure it's doing what you think it should be doing...
Just get rid of the "goto HealTrainingLoop:" I don't think you have the tag, so it won't actually do anything, but it's good to understand that.
Also, you are relying on the script to start over again. You might want to fix it so the loop happens under your control perhaps something like this:
repeat
gosub MoveYourself 0 6
wait 160
gosub MoveYourself 0 -6
until #FALSE
sub MoveYourself
set %X #CHARPOSX + %1
set %Y #CHARPOSY + %2
move %X %Y 0 6s
FindItem ZLF C_ , #BackpackID
if #findkind = -1
{
Display ok You have run out of bandages.$
+ Please get more and restart the script.$
+$
+Script is Halting$
Halt
}
Set #LObjectID #FindID
menu text scriptstatus 110 268 Using Bandage
Event Macro 17 0 ; Use Last Object (Bandages)
Target
Event Macro 23 0 ; Target Self
wait 200
Return
-
Congrats M8!! :)
Just want to mention that it is good practice to avoid using GOTO statements to jump in and out of subroutines. In your example you may want to simply remove the "GOTO HealTrainingLoop" at the end of your MoveYourself sub.
If you wanted to, you could also break into an "ApplyBandage" sub and seperate that logic a litle bit from the move sub. Maybe something like:
Loop:
Gosub moveyourself 0 6
Gosub healyourself
Gosub moveyourself 0 -6
Gosub healyourself
GoTo Loop
Just some "good practice" stuff for ya but either way keep it up!!
XII
<edit> doh TM beat me to the Reply button!! :P
-
Thanks Guys!
Yep, and with all you guys have said here I still managed a stinking goto :( live and learn!!!
TM..I think I understand...by putting return in there and the #FALSE, you are telling the script to run until stopped or until out of bandages...is that correct??
Thanks Guys!!
I might even get faster someday....that little timy bit o script took me 6 hours to accomplish LOLOL!!!
-
You can most certainly use GoTo's - that's why the command exists; however, there is a time and a place. TM's example though is a good way to run your main loop without one, the "Repeat" tells the loop to run and the "Until" criteria is never met thus it loops indefinitely unless you have logic builtin elsewhere else to tell it to stop (like when you are out of bandages).
Most importantly, if you DO use a GoTo, NEVER (repeat - NEVER) use GoTo to hop between subs.
Also, I don't see a menu anywhere in there so I think you can get rid of your 'menu text' line.
XII
-
Well the idea behind:
repeat
...
until #FALSE
This is really the same as:
loop:
...
goto loop
repeat/until #FALSE is an infinite loop since there's NOT a way for the until to be #TRUE. ;)
-
Didn't I say that?
:)
-
#TRUE is always true, unless it's false.
*TM made a mainloop without a goto :o... sorry... got a little teary there.... :'(
It's the greatest day of my life!
-
roflmao!!
-
*TM made a mainloop without a goto :o... sorry... got a little teary there.... :'(
Cerveza hasn't been keeping up on world events or checking my code. GOTOs have use whether he likes it or not. Especially in EUO just because of the strange way the parser works. I'd rather code something in 5 minutes, than work for 2 hours trying to figure out a "clever" way to eliminate all gotos. I'd rather write clever scripts. :)
-
You can most certainly use GoTo's - that's why the command exists; however, there is a time and a place. TM's example though is a good way to run your main loop without one, the "Repeat" tells the loop to run and the "Until" criteria is never met thus it loops indefinitely
Most importantly, if you DO use a GoTo, NEVER (repeat - NEVER) use GoTo to hop between subs.
I have 2 cents (4 actually)
I use goto consistently, but as stated I never use it to jump outside a sub. Most of my scripts have each sub with a exit_SubName, most of this is learned behaviour, but I do it to ensure that the correct clean up always takes place and to me a single point of exit form a procedure is more sacred that not using gotos.
When choosing between repeat .. unitil and While, there is an important distinction. The while is top tested so you can check to see whether or not you quailfy to run the loop before the first attempt, the repeat .. until is bottom tested so you're already committed to one cycle before doing any checks. Both are valid just make sure to remember this.
The repeat .. until used to be my favorite because I used to create boolean vars like TheCowsComeHome or HellFreezesOver and the code looked like
Repeat
Do something
Until TheCowsComeHome
That still makes me chuckle. But I use the while more often so that I can test before executing the first cycle.
Ack! btw, Great job on a first script always a nice feeling
-
Don't get Cerveza started, he's the Unibomber of anti-GOTO use. lol
-
Don't get Cerveza started, he's the Unibomber of anti-GOTO use. lol
He don't scare me I have a boat and know how to use it.
--Gone Fishin' --
-
Oh Jeez! Now combining two of my hates in the same post....
if %fishing = #TRUE
goto DeleteUOandKillMyself
-
Ok, now I really am laughing out loud, right here in my kitchen.
:-)