ScriptUO
Official ScriptUO EasyUO Scripts => Script Snippets => Topic started by: Cerveza on April 14, 2009, 10:54:16 AM
-
Sub routine to handle all pack beetle commands... hopefully.
Written entirely at work mostly using other people's code. TM's beetle subs are included.
None of this has been tested ???
If you run SETUP first it will set two variables for you - %beetleID and %beetlePack Anytime this sub is called, those variables will be used by default so you don't have to put them in as arguments to the sub. I can't see why you would want to have them enabled as arguments, but it wouldn't be hard to setup. Give me a good enough reason and I could set it up.
Contains the sub routines sub DragItem and sub GumpWait. If you already have these in your script you can remove them from this package.
usage:
gosub SUO_Beetle_sub {command} {container} {item} {x} {y}
command = setup, mount, dismount, feed, openpack, load, unload
--- setup = returns two variables, %beetleID and %beetlePack
--- mount = searches for beetle and mounts it if found
--- dismount = gets off the beetle
--- feed = will feed beetle, raw ribs required in main backpack
--- openpack = opens the beetles pack
--- load = loads the beetles pack from some container
--- unload = unloads the beetles pack to some container
container = container ID to get or deposit items
item = the item type to move from/to the container
x,y = the x and y location to open the beetles pack (if used)
example:
gosub SUO_Beetle_sub setup ; returns %beetleID and %beetlePack.
gosub SUO_Beetle_sub mount ; searches for beetle, gets close enough and gets on.
gosub SUO_Beetle_sub dismount ; gets off the beetle
gosub SUO_Beetle_sub feed ; drags 1 rib from backpack to beetle, you MUST already be dismounted.
gosub SUO_Beetle_sub openpack 10 -40 ; opens beetles pack at location 10, -40.
gosub SUO_Beetle_sub unload %containerID %itemID ; moves ALL item type %itemID to %containerID
Be very carefull with the following!
gosub SUO_Beetle_sub load %containerID %itemID ; moves %itemID to %containerID
There currently isn't a check to ensure the beetle isn't overloaded.
ToDo List:
gosub SUO_Beetle_sub load %containerID %itemID 600 ; 600 represents how many to move.
gosub SUO_Beetle_sub weight ; return the current weight stored on the beetle.
gosub SUO_Beetle_sub ?????? ; any thoughts?
;---------------------------------------------------------------------
; gosub SUO_Beetle_sub {command} {beetleID} {container} {item} {x} {y}
;
; %1 - command: setup, mount, dismount, feed, openpack, load, unload
; - beetleID is defaulted to %beetleID
; - container to get/deposit items
; - item type to get/deposit
; - x position to open beetle pack
; - y position to open beetle pack
sub SUO_Beetle_sub
namespace push
namespace local BS
set !old_LOBJECTID #LOBJECTID
set !old_LTARGETID #LTARGETID
;-------------------------------------------------------------------
; setup
; returns %beetleID and %beetlePack
if %1 = setup
{
finditem ZGB G_2
if #FINDKIND <> -1
set %beetleID #FINDID
else
{
display ok Cannot locate beetle
set #LOBJECTID !old_LOBJECTID
set #LTARGETID !old_LTARGETID
namespace pop
return #FALSE
}
exevent popup %beetleID
gosub GumpWait normal_gump normal_gump
set !temp_clickx #CONTPOSX + 29
set !temp_clicky #CONTPOSY + 183
click !temp_clickx !temp_clicky f
gosub GumpWait container_gump -1
set %beetlePack #CONTID
set #LOBJECTID !old_LOBJECTID
set #LTARGETID !old_LTARGETID
namespace pop
return #TRUE
}
;-------------------------------------------------------------------
; mount
if %1 = mount
{
set !wrangle_cnt 0
set !beetle_running #FALSE
WrangleBeetle_loop1:
finditem %beetleID C_ , #CHARID
if #FINDKIND <> -1
goto WrangleAndMountBeetle_skip1 ; already riding one.
finditem %beetleID G_6
if #FINDDIST > 2
{
msg all follow me$
set !beetle_running #TRUE
wait 20
set !wrangle_cnt !wrangle_cnt + 1
if !wrangle_cnt < 5
goto WrangleBeetle_loop1
}
else
{
if #FINDKIND = -1
goto WrangleAndMountBeetle_skip1
set #LOBJECTID %beetleID
event macro 17 0
wait 20
goto WrangleBeetle_loop1
}
finditem %beetleID G
if #FINDKIND <> -1
{
event pathfind #FINDX #FINDY #FINDZ ; try to move to beetle.
wait 20
set !wrangle_cnt 4
goto WrangleBeetle_loop1
}
WrangleAndMountBeetle_skip1:
set #LOBJECTID %old_LOBJECTID
set #LTARGETID %old_LTARGETID
namespace pop
return
}
;-------------------------------------------------------------------
; dismount
if %1 = dismount
{
set #LObjectID #CharID
wait 5
event macro 17 0
wait 20
msg all follow me$
wait 5
set #LOBJECTID !old_LOBJECTID
set #LTARGETID !old_LTARGETID
namespace pop
return
}
;-------------------------------------------------------------------
; feed
if %1 = feed
{
finditem VRD c_ , #BACKPACKID
if #FINDKIND <> -1
{
wait 20
set #LOBJECTID #CHARID
event macro 17 0
wait 20
gosub DragItem #findid 1 C %beetleID
set #LOBJECTID %beetleID
event macro 17 0
wait 10
}
else
{
event ExMsg %beetleID 4 1 I'm Hungry, get some food!
}
set #LOBJECTID !old_LOBJECTID
set #LTARGETID !old_LTARGETID
namespace pop
return
}
;-------------------------------------------------------------------
; openpack
if %1 = openpack
{
set !temp_posX %2
set !temp_posY %3
set #LObjecID %beetlePack
wait 5
if !temp_posX > 0
{
set #nextcposx !temp_posX
set #nextcposy !temp_posY
}
event macro 17 0
wait 5
set #LOBJECTID !old_LOBJECTID
set #LTARGETID !old_LTARGETID
namespace pop
return
}
;-------------------------------------------------------------------
; load
if %1 = load
{
set !temp_container %2
set !temp_items %3
set #LOBJECTID !temp_container
event macro 17 0
wait 20
LoadBeetle_loop:
findItem !temp_items C_ , !temp_container
if #FINDKIND <> -1
{
gosub DragItem #FINDID #FINDSTACK C %beetlePack
goto LoadBeetle_loop
}
wait 30
set #LOBJECTID !old_LOBJECTID
set #LTARGETID !old_LTARGETID
namespace pop
return
}
;-------------------------------------------------------------------
; unload
if %1 = unload
{
set !temp_container %2
set !temp_items %3
set #LOBJECTID %beetlePack
event macro 17 0
wait 20
UnloadBeetle_loop:
finditem !temp_items C_ , %beetlePack
if #FINDKIND <> -1
{
gosub DragItem #FINDID #FINDSTACK C !temp_container
goto UnloadBeetle_loop
}
wait 30
set #LOBJECTID !old_LOBJECTID
set #LTARGETID !old_LTARGETID
namespace pop
return
}
;-------------------------------------------------------------------
; fail
event ExMsg #CHARID 4 1 Incorrect command sent to beetle sub!
set #LOBJECTID !old_LOBJECTID
set #LTARGETID !old_LTARGETID
namespace pop
return
;-----------------------------------
; %1 - #FINDID
; %2 - Stack size
; %3 - destination G=ground, C=container
; %4 - destination ID
; %5 - drop x
; %6 - drop y
; %7 - drop z
sub DragItem
namespace push
namespace local DI
set !old_LOBJECTID #LOBJECTID
set !old_LTARGETID #LTARGETID
set !drag_item %1
set !drag_stack %2
set !drag_dest_op %3
set !drag_dest_id %4
set !drag_x %5
set !drag_y %6
set !dray_z %7
set !drag_time #SCNT
set !drag_lpc #LPC
set #LPC 200
DragItem_loop1:
if #SCNT > ( !drag_time + 8 )
{
set #LPC !drag_lpc
namespace pop
return #FALSE
}
exevent drag !drag_item !drag_stack
wait %exevent_drag_wait
if C in !drag_dest_op
{
exevent dropc !drag_dest_id
wait %exevent_drop_wait
if !drag_stack = 1 && !drag_dest_id <> %beetle
{
set #LOBJECTID !drag_dest_id
event macro 17 0
wait 20
finditem !drag_item C_ , !drag_dest_id
if #FINDKIND = -1
goto DragItem_loop1
}
}
else
{
exevent dropg !drag_x !drag_y !dray_z
wait %exevent_drop_wait
finditem !drag_item G_2
if #FINDKIND = -1
{
exevent dropc #BACKPACKID
}
}
set #LPC !drag_lpc
set #LOBJECTID !old_LOBJECTID
set #LTARGETID !old_LTARGETID
namespace pop
return #TRUE
;-------------------------------------------------------------------------------
; %1 = Gumpname 1
; %2 = Gumpname 2
; #TRUE gump occured before timeout
sub GumpWait
namespace push
namespace local GW
wait 10
set !timedelay #SCNT
while #SCNT <= !timedelay + 7
{
if #CONTNAME = %1 || #CONTNAME = %2
{
namespace pop
return #TRUE
}
}
namespace pop
return #FALSE
-
This is great.. is there going to be some internal SUO Subs that we can use in code?
ex.. Preload SUO_Pack_Beetle_Sub into SUO
then instead of adding the sub in the script its now Client Loaded, so you can call it internally?
Gosub Setup
HALT
Sub Setup
GoSUO BeetleSetup openbackpack
Return
-
Nothing like that planned. It's just a "do all" beetle sub.
I tested a few parts earlier tonight and fixed a typo. So far it's all working. I have some updates planned....
1 - a toggle to identify if your dismounted or not
2 - the weight checking sub for items on and off the beetle
Right now, it's a sub that you can use to control actions on your beetle. With a little work on your part, you can set it up to do about any hauling you need.
-
ya, sounds like a keeper indeed. might make me write something
-
I ran this to test, all worked well.
gosub SUO_Beetle_sub badcommand
gosub SUO_Beetle_sub setup
gosub SUO_Beetle_sub mount
gosub SUO_Beetle_sub dismount
gosub SUO_Beetle_sub feed
gosub SUO_Beetle_sub openpack
gosub SUO_Beetle_sub load %bagID *
gosub SUO_Beetle_sub unload %bagID *
halt
Start DISMOUNTED. The script will give you the bad command message, then go through each beetle function. I had a bag with 50 boards in it and they were moved to the beetle, then back.
I was having ghosted images, but thats more a sub MoveItem problem...
Overall, I'm happy with the way it worked. I have some things I want to do yet, but a good start and a usable tool as it is now.