ScriptUO
Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: Meatt Wad on October 06, 2011, 12:08:19 PM
-
When I played UO a couple years ago and farther back, I became pretty good at taking scripts and modifying them to suit my needs. However I really have no clue how to script myself. I have read the tutorials here and have decided to take a shot at a fairly simple script and I am struggling to get it to work.
I have used many scripts and have studied how those scripts made things happen, I have a limited understanding for what is going on. I can script for the most part in a straight line. Where i tell it do this then this etc. etc.(uoap or uoa for example). Its the subs and goto type stuff that i find confusing. I have made my script work the way I want in a linear fashion but I dont like it as its not versatile and changeable like the scripts made here.
I have decided to make a simple begging script (halloween and all), to test my understanding. I want it to Find target, use begging, select target, and repeat basically. I also want to have a menu that displays at least current skill and number of gains. I have used many scripts as references and have written my own script.
Can I post this script here to receive advice on how to fix it, tweak it improve it etc. ??
I dont care about publishing it unless I am asked to.
I just need to get script 1 under my belt so I have a toy to learn on.
-
Can I post this script here to receive advice on how to fix it, tweak it improve it etc. ??
Most defiantly ... post it here in this thread with a question and one of us is bound to jump right in
-
Thanks Endless. Well here it is. I use it in my house to train up begging. Its slow with no tricks just a simple beg and repeat.
;==================================
; Script Name: Meatt Wad's Simple Beggar
; Author: Meatt Wad
; Version: .1
; Client Tested with: 7.0.18
; EUO version tested with: 1.5.202
; Shard OSI: OSI
; Revision Date: Oct 6, 2011
; Public Release:
; Purpose: Automate Begging
; Globals: none
;====================================
;
;====================================
; Instructions: Find a heavily populated area of NPC's or better yet . . .
; Go Hire Blue NPC's, fighters, beggar's whatever(15 to 20 should do), has to be the ones you pay to follow you.
; Take them to your house and trap them (I like walking them up to third floor and leaving a hole to 2nd
; Allow them to fall through to 2nd floor with no doors and no teles no stairs so they can't escape.)
; I also like to make this room fairly small like 8x8 or less so they are within begging range.
;====================================
; Special thanks to everyone at SUO for all the help!
;====================================
set %ver 0.1
chooseskill BEGGING
set %skill #skill
set %BEGGING #skill
set %gain 0
set %gains 0
set %status Begging
menu show 290 112
menu hideEUO
gosub menu
REPEAT
gosub find
gosub beg
until #charghost = yes
set %status = Dead
gosub menu
display You are Dead! Script Halted!
halt
;============ find sub =============
sub find
finditem HS_IS G_10
if #FINDKIND = -1
{
ignoreitem reset
gosub find
}
if #FINDID = #CHARID
{
ignoreitem #FINDID
gosub find
}
;============beg sub ===============
sub beg
move #FINDX #FINDY 1 10s
finditem #FINDID
if #FINDDIST > 1
{
ignoreitem #FINDID
return
}
chooseskill BEGGING
set %skill #SKILL
set #LTARGETID #FINDID
set #LTARGETKIND 1
event macro 13 6
target
event macro 22
wait 10s
chooseskill BEGGING
if %skill < #SKILL
{
finditem #FINDID
gosub beg
}
ignoreitem #FINDID
gosub skillgain
return
;=============Skillgain sub============
sub skillgain
chooseskill BEGGING
if #skill = #skillcap
{
display You have reached your skill cap.$
+$Thanx for using Meatt Wad's Simple Begger
+$
+$Please rate the script.
+$
+$
+Script is Halted$
+$
+ ~ Meatt Wad$
halt
}
if #skill > %BEGGING
set %gains %gains + #skill - %BEGGING
set %BEGGING #skill
gosub menu
return
;
;--------- EasyUO Menu Designer Code Begin ---------
sub menu
menu Clear
menu Window Title MeattWads Simple Beggar %ver
menu Window Color Black
menu Window Size 290 112
menu Font Transparent #true
menu Font Align Right
menu Font Name MS Sans Serif
menu Font Size 14
menu Font Style
menu Font Color $9933CC
menu Font Transparent #false
menu Font Align Left
menu Font BGColor Black
menu Text EUOLabel1 10 40 Gains:
menu Text EUOLabel2 10 72 Status:
menu Font Size 8
menu Text EUOLabel3 70 80 %status
str len %gains
str ins %gains #dot #strRes
menu Text EUOLabel4 70 48 #strRes
menu Font Size 14
menu Text EUOLabel5 22 10 Skill:
menu Font Size 8
str len #skill
str ins #skill #dot #strRes
menu Text EUOLabel6 70 18 #strRes
return
;--------- EasyUO Menu Designer Code End ---------
I actually have it working now, so just looking for advice for better coding, better functionality etc.
I use this in my house in a room roughly 8x8 so I comment out the line in the beg sub that moves.
Any and all advice is welcome, Im just wanting to learn to write a better script.
-
in that case heres some feed back .. take what you want from it and most importantly dont get offended.. use as a learning experience
-Firstly I find it usefull to indent my code 2 spaces per grouping this makes it easier to read... see what i did below
-I stripped your comments purely to make it shorter and easier to read here.. leave them in your original version
-ALL SUBS must exit via a RETURN...
- use loop commands like For, Repeat..Until, While instead of GOTO .. makes your code easier to debug
- Moved some subs into the main loop. This a good practice to list the things it does one after another and put that into your main loops vers loop A A calls B b calls C call d d calls E ... thats hard to debug as its hard to follow a loop of ABCDE is easy to see whats happening.
- You dont have to redraw the menu entirely to change one item, lookup the menu set command its faster and elimates and menu flashing from destroying and redrawing.
- Other edits see if they make sense to you
NOTE ALL untested edits...
set %ver 0.1
chooseskill BEGGING ; shouldnt this be only a 4 letter code
set %skill #skill
set %BEGGING #skill
set %gain 0
set %gains 0
set %status Begging
menu show 290 112
menu hideEUO
gosub menu
REPEAT
gosub find
gosub beg
gosub skillgain
gosub UpdateMenu
until #charghost = yes || #Skill = #Skillcap
halt
sub UpdateMenu
str len %gains
str ins %gains #dot #strRes
menu set EUOLabel4 #strRes
str len #skill
str ins #skill #dot #strRes
menu set EUOLabel6 #strRes ; no need to redraw entire menu to set current skill
menu set EUOLabel3 %status
if #Charghost = yes
display You are Dead! Script Halted!
return
sub find
repeat
wait 1 ; Give your machine a chance to catch up on tasks
finditem HS_IS G_10
if #findcnt = 0
ignore reset
if #findid = #charid
ignoreitem #FINDID
until #FINDcnt = 1 && #findid <> #charid ; findcnt = number of items found
RETURN ; must must return from a sub
;============beg sub ===============
sub beg
move #FINDX #FINDY 1 10s
ignoreitem #FINDID ; stops it being found on the next search has no effect on current search results
if #FINDDIST > 1
return
Repeat ; begging loop
chooseskill BEGGING
set %skill #SKILL
set #LTARGETID #FINDID
set #LTARGETKIND 1
event macro 13 6
target
event macro 22
wait 10s
chooseskill BEGGING
until %skill >= #skill ; note sure on objective so not sure if this logic correct... its a correct rendition of your logic but was that right ?
return
;=============Skillgain sub============
sub skillgain
chooseskill BEGGING
if #skill > %BEGGING
set %gains %gains + #skill - %BEGGING
set %BEGGING #skill
if #skill = #skillcap
{
display You have reached your skill cap.$
+$Thanx for using Meatt Wad's Simple Begger
+$
+$Please rate the script.
+$
+$
+Script is Halted$
+$
+ ~ Meatt Wad$
}
return
;
;--------- EasyUO Menu Designer Code Begin ---------
sub menu
menu Clear
menu Window Title MeattWads Simple Beggar %ver
menu Window Color Black
menu Window Size 290 112
menu Font Transparent #true
menu Font Align Right
menu Font Name MS Sans Serif
menu Font Size 14
menu Font Style
menu Font Color $9933CC
menu Font Transparent #false
menu Font Align Left
menu Font BGColor Black
menu Text EUOLabel1 10 40 Gains:
menu Text EUOLabel2 10 72 Status:
menu Font Size 8
menu Text EUOLabel3 70 80 %status
str len %gains
str ins %gains #dot #strRes
menu Text EUOLabel4 70 48 #strRes
menu Font Size 14
menu Text EUOLabel5 22 10 Skill:
menu Font Size 8
str len #skill
str ins #skill #dot #strRes
menu Text EUOLabel6 70 18 #strRes
return
;--------- EasyUO Menu Designer Code End ---------
-
Thank you for such a quick response. Messing around with your suggestions right now
-
Thank you for such a quick response. Messing around with your suggestions right now
your welcome ... I've got to tell you, you are doing pretty dam fantastic for your first script.
-
Gets Stuck looping in your find sub.
sub find
repeat
wait 1 ; Give your machine a chance to catch up on tasks
finditem HS_IS G_10
if #findcnt = 0
ignore reset
if #findid = #charid
ignoreitem #FINDID
until #FINDcnt = 1 && #findid <> #charid ; findcnt = number of items found
RETURN ; must must return from a sub
not sure how this line works as far as moving the script on, could you explain a little more to me, it appears this line is causing the loop when I f7 through the script.
until #FINDcnt = 1 && #findid <> #charid ; findcnt = number of items found
Thanks again for the lessons. Most of it makes sense to me and my script is definitely prettier ;D
PS. #FINDcnt is returning 14 which is the number of npcs in my house not including me
-
Thank you for such a quick response. Messing around with your suggestions right now
your welcome ... I've got to tell you, you are doing pretty dam fantastic for your first script.
Well Thank You, I just pay attention to how you guys do things and try to mimic in an effort to learn how and why.
-
OK I changed this:
until #FINDcnt = 1 && #findid <> #charid ; findcnt = number of items found
to this:
until #FINDcnt > 1 && #findid <> #charid ; findcnt = number of items found
That sound about right?
-
OK. . . through some trial and error I think I got this down now. First I changed the Find sub to read:
sub find
repeat
wait 1
finditem HS_IS G_10
if #findcnt = 0
ignoreitem reset ;fixed this
if #findid = #charid
ignoreitem #FINDID
until #FINDcnt >= 1 && #findid <> #charid ;fixed this i think
RETURN
Took me a bit to figure out the ignoreitem reset, and I think the "until" line is good now with a >= ( I understand what is happening here now.)
-
lol you got it .. >=
-
And now I have this:
;==================================
; Script Name: Meatt Wad's Simple Beggar
; Author: Meatt Wad
; Version: 0.2
; Client Tested with: 7.0.18
; EUO version tested with: 1.5.202
; Shard OSI: OSI
; Revision Date: Oct 6, 2011
; Public Release:
; Purpose: Automate Begging
; Globals: none
;====================================
;
;====================================
; Instructions: Find a heavily populated area of NPC's or better yet . . .
; Go Hire Blue NPC's, fighters, beggar's whatever(15 to 20 should do), has to be the ones you pay to follow you.
; Take them to your house and trap them (I like walking them up to third floor and leaving a hole to 2nd
; Allow them to fall through to 2nd floor with no doors and no teles no stairs so they can't escape.)
; I also like to make this room fairly small like 8x8 or less so they are within begging range.
;====================================
; Thanks to everyone at SUO for all the help!
;====================================
; Special thanks to Endless Night for sharing your knowledge with me and helping to edit this script!
;====================================
set %ver 0.2
chooseskill BEGG
set %skill #skill
set %BEGG #skill
set %gain 0
set %gains 0
set %status Begging
menu show 290 112
menu hideEUO
gosub menu
;======== Main Loop ================
REPEAT
gosub find
gosub beg
gosub skillgain
gosub UpdateMenu
until #charghost = yes || #Skill = #Skillcap
halt
;======== Update Menu Sub ===========
sub UpdateMenu
str len %gains
str ins %gains #dot #strRes
menu set EUOLabel4 #strRes
str len #skill
str ins #skill #dot #strRes
menu set EUOLabel6 #strRes
menu set EUOLabel3 %status
if #Charghost = yes
display You are Dead! Script Halted!
return
;============= Find Sub ==========
sub find
repeat
wait 1
finditem HS_IS G_10
if #findcnt = 0
ignoreitem reset
if #findid = #charid
ignoreitem #FINDID
until #FINDcnt >= 1 && #findid <> #charid
RETURN
;============ Beg Sub ===============
sub beg
move #FINDX #FINDY 1 10s
ignoreitem #FINDID
if #FINDDIST > 1
return
Repeat
chooseskill BEGG
set %skill #SKILL
set #LTARGETID #FINDID
set #LTARGETKIND 1
event macro 13 6
target
event macro 22
wait 10s
return
;=============Skillgain sub============
sub skillgain
chooseskill BEGG
if #skill > %BEGG
set %gains %gains + #skill - %BEGG
set %BEGG #skill
if #skill = #skillcap
{
display You have reached your skill cap.$
+$Thanx for using Meatt Wad's Simple Begger
+$
+$Please rate the script at ScriptUO.com
+$
+$
+Script is Halted$
+$
+ ~ Meatt Wad$
}
return
;=========== EasyUO Menu Designer Code ============
sub menu
menu Clear
menu Window Title MeattWads Simple Beggar %ver
menu Window Color Black
menu Window Size 290 112
menu Font Transparent #true
menu Font Align Right
menu Font Name MS Sans Serif
menu Font Size 14
menu Font Style
menu Font Color $9933CC
menu Font Transparent #false
menu Font Align Left
menu Font BGColor Black
menu Text EUOLabel1 10 40 Gains:
menu Text EUOLabel2 10 72 Status:
menu Font Size 8
menu Text EUOLabel3 70 80 %status
str len %gains
str ins %gains #dot #strRes
menu Text EUOLabel4 70 48 #strRes
menu Font Size 14
menu Text EUOLabel5 22 10 Skill:
menu Font Size 8
str len #skill
str ins #skill #dot #strRes
menu Text EUOLabel6 70 18 #strRes
return
;====================================================
Any more Ideas on improving this. It is definitely prettier and more organized, runs alot smoother. Thank You Endless this is starting to be fun :)
-
In sub beg, you have a starting - never ending "repeat" and few not really req lines.
sub beg
move #FINDX #FINDY 1 10s
ignoreitem #FINDID
if #FINDDIST > 1
return
Repeat < --------------
set #LTARGETID #FINDID
set #LTARGETKIND 1
chooseskill BEGG < ---- you dont need this
set %skill #SKILL < ---- you dont need this
event macro 13 6
target
event macro 22
wait 10s
return
I can show you an example how i would do it .
A change in mainloop.
repeat
gosub Find
gosub Skillgain
gosub UpdateMenu
until #charghost = yes || #Skill = #Skillcap
halt
Then a change in these two subs
Sub Find
ignoreitem #charid
finditem HS_IS G_10
for #findindex 1 #findcnt
gosub beg
return
Sub Beg
if #finddist > 1
move #FINDX #FINDY 1 10s
set #LTARGETID #FINDID
set #LTARGETKIND 1
event macro 13 6
target
event macro 22
wait 10s
return
Keep on trying and reading the manual.
ps; if you dont understand the #findindex loop, below is a bit longer version of the same loop
ignoreitem #charid
finditem HS_IS G_10
while #findcnt > 0
{
ignoreitem #findid
gosub beg
finditem HS_IS G_10
}
ignoreitem reset
-
Thanks Cam. I will play around with that and see if I get it.
-
There's been a while, have you managed to get things working?