ScriptUO
Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: Citrus82 on May 07, 2011, 08:11:55 AM
-
Hi,
I just wrote my first script line for line by myself, and im having trouble with the first sub getting skipped. I'm not sure what the problem is, so i figured i would try to get some help here.
Im sure i did lots of things the hard way and ass backwards, but im still learning.
Btw, this script is meant to farm feathers from chickens, and when you get full drop them off at home.
EDIT: To be more clear the gosub setup book gets skipped when i start the script, it goes straight to gosub setup box.
;================================
;Kills chickens and loots feathers.
;By Slacker.
;================================
;set %box AYBUPMD ;set your drop box id here.
set %kill AG ; monster's id to kill, in this case chicken.
Set %cut HNF ;Item that cuts the corpse like a dagger.
Set %body YFM ; Id of bodies on ground, dont touch this.
set %loot VLK ;Id of items to loot off bodie.
;Set %Rbook WSMIMMD ;set your rune book id here.
;================================
gosub setup book
gosub setup box
gosub stablecheck
goto Main loop
;================================
Main loop:
gosub Find
gosub Kill
gosub Findncut
gosub Open Dead
gosub Loot
gosub Unload
goto Main loop
;================================
Sub Find
finditem %kill G_10
if #findkind = -1
{
Gosub Find
}
Return
Sub Kill
Set #ltargetid #FINDID
event macro 15 17
target 3s
event macro 22 0
wait 3s
return
sub Findncut
finditem %cut C_ , #BACKPACKID
Set #LOBJECTID #FINDID
event macro 17 0
wait 1s
finditem YFM G_10
move #FINDX #FINDY
wait
Set #ltargetid #FINDID
event macro 22
Return
Sub Open Dead
FINDITEM %body G_
set #LobjectID #FINDID
event macro 17 0
set %deadbody #CONTID
Return
Sub Loot
wait 1s
finditem %loot C_
if #findkind <> -1
{
exevent drag #FINDID #FINDSTACK
wait 15
exevent dropc #BACKPACKID
wait 15
ignoreitem #findid
}
finditem %items C_
if #findkind <> -1
{
goto loot
}
ignoreitem %deadbody
Return
Sub Unload
set %weight #MAXWEIGHT - 25
if #WEIGHT > %weight
{
wait 1s
finditem %Rbook C_ , #BACKPACKID
set #LobjectID #findID
event macro 17 0
wait 8
set %xclick #contposx + 135
set %yclick #contposy + 192
click %xclick %yclick
wait 8
set %xclick #contposx + 136
set %yclick #contposy + 144
click %xclick %yclick
wait 4s
Drop:
finditem %loot C_ #BACKPACKID
exevent drag #FINDID #FINDSTACK
wait 15
exevent dropc %box
wait 15
finditem %loot C_ #BACKPACKID
if #findkind <> -1
{
goto Drop
}
wait 2s
finditem %Rbook C_ , #BACKPACKID
set #LobjectID #findID
event macro 17 0
wait 8
set %xclick #contposx + 135
set %yclick #contposy + 192
click %xclick %yclick
wait 8
set %xclick #contposx + 295
set %yclick #contposy + 144
click %xclick %yclick
wait 4s
move 1294 1768
}
Return
Sub setup book
event SysMessage pls Target your rune book fool!!!
event SysMessage pls Target your rune book fool!!!
event SysMessage pls Target your rune book fool!!!
event SysMessage pls Target your rune book fool!!!
set #lTargetID X
set #targCurs 1
wait 2
Bookid:
if #lTargetID = X
{
goto Bookid
}
set %Rbook #LTARGETID
finditem %Rbook C_ , #BACKPACKID
set #LobjectID #findID
event macro 17 0
wait 8
set %xclick #contposx + 135
set %yclick #contposy + 192
click %xclick %yclick
wait 8
set %xclick #contposx + 136
set %yclick #contposy + 144
click %xclick %yclick
wait 1s
set %boxcheck #CHARPOSX
return
Sub setup box
event SysMessage Now target your box hoe!!!
event SysMessage Now target your box hoe!!!
event SysMessage Now target your box hoe!!!
event SysMessage Now target your box hoe!!!
set #lTargetID X
set #targCurs 1
wait 2
boxid:
if #lTargetID = X
{
goto boxid
}
set %box #LTARGETID
return
Sub stablecheck
finditem %Rbook C_ , #BACKPACKID
set #LobjectID #findID
event macro 17 0
wait 8
set %xclick #contposx + 135
set %yclick #contposy + 192
click %xclick %yclick
wait 8
set %xclick #contposx + 295
set %yclick #contposy + 144
click %xclick %yclick
wait 4s
set %stallcheck #CHARPOSX
wait 1s
move 1294 1768
return
-
Kudos to you for working at it on your own!
First thing is that you can't have spaces in your sub names.
Still looking it over but there's a start.
X
-
Still looking through the code as well, but I see a potential problem in your sub Find:
Sub Find
finditem %kill G_10
if #findkind = -1
{
Gosub Find ; This is the line that could be a problem!
}
Return
Specifically, you don't want to call the sub from within itself, as this may eventually lead to a crash. Instead, you may want to either try moving the character a short distance to find a new chicken, or simply wait until a chicken wanders within your search range. Given that you've done all the coding on this yourself, I'll refrain from supplying any code in case you want to research it yourself, but am more than happy to help if you want (although there are many others who can help much more than I, but I still get by!).
-
Thanks, i removed the spaces in the two subs and now it doesn't skip them.
I set the three top subs to set the rune book id, drop container id, and get the x coordinates of both my box and chicken recall spot. So i can compare the values after a recall, to see if i actually recalled. You may have spotted the un-used variables that i haven't used yet.
Anyways, instead of skipping the setup gosubs after it gets into the main loop, it goes through them again.
@Dixie Wrecked, thanks ill have to do some reading on that.
-
you cannot have spaces in any var name tag name goto names sub names just use _ ie main_loop
Another thing your learning but if you can learn to aviod goto's you will be doing your self a big favour. instead of goto try this
set !ExitScript #false
repeat ; main loop
; code
; gosub thissub
; gosub thatsub
; code etx
until !exitscript = #true
halt
As to why it repeated the setup over and over.. thats easy.. When easyuo gets to the last line in the file it goes back to the top in an infinite cirlce .. thats why i recommend a halt command like above... so easyuo didnt reconize your gotos becuase of the spaces thus continued to last line back to first line .. do setup etc.
-
Thanks :)
Its working again, ill have to remember that for my future scripts.
Now if only i cant make/insert my recall check subs, and a world save checker without screwing it up.
-
For world save I simply do this;
In the script setup code I contain this:
gosub TM_AdvJournalSync world 100
Then I call a sub within my main loop, as follows: (Please note that the wait is set to 30 seconds here, as some shards I play on have a rather long world save of 8-10 seconds. This script actually searches for the "about to save" message.)
sub world_save
gosub TM_AdvJournalScan world VALID_ADVANCE The_world_will_
if #result = #true
{
sound
wait 300
if %debug = 2
{
display ok You've sucessfully got TMs sub to work
}
}
return
Then, you must always include TM's subs in your script, those you can find on your own :P
-
That sounds good but i was wondering, instead of having it wait for 30s, could you have it scanning for something like World_save_complete??
-
You could do that, however then your adding more and more subs into the script, so there's a greater potential for it going wrong. Don't forget, your only losing 30 seconds out of every 30 mins to an hour, depending on how often the world saves are.
-