As a part of my work as a GM I created a bunch of subs which could be useful, not only for GM, use any and all as you wish.
PS: if I made a dupe function to any already implemented in YI, please, tell me :)
Code: # Waiting and script pauses ;================= sub setpause(b) ;sets pause flag 0/1 uo.setglobal("pause",str(b)) end sub
sub getpause() ;gets current pause status return val(uo.getglobal("pause")) end sub
sub hitpause() ;switches pause status, suitable for hotkey (i.e. PAUSE :) setpause(getpause()==0) end sub
sub pause(total) ;pauses script for 'total' time on until unpaused ;total <=0 means infinite waiting var a=0,t=UO.timer() setpause(1) repeat wait(20) if (total>0) and ((UO.timer()-t)*10>total) then setpause(0) return end if until getpause()==0 end sub
sub halt() ;emergency exit from any script UO.Print("All scripts terminated.") UO.deletejournal() UO.moveon() UO.Exec("terminate all"); end sub
sub lag_test(time) ;checks if server managed to answer all your previous requests and can wait some extra 'time' var i=0 wait(time) while UO.injournal(UO.getname("self")) UO.setjournalline(UO.injournal(UO.getname("self"))-1,"###") wend Uo.click("self") repeat i=i+1 wait(20) if i>250 then i=0 Uo.click("self") ;restore if blocked somehow Uo.click("self") end if until UO.injournal(UO.getname("self")) end sub
# Misc container functions ;================= sub lock_test() ;quick check for locked conatainer by message var i=UO.injournal("This item is locked") if i then while i UO.setjournalline(i-1,"###") i=UO.injournal("This item is locked") wend return 1 end if return 0 end sub
sub box_test(item) ;quick check for container by message while UO.injournal("items)") UO.setjournalline(UO.injournal("items)")-1,"###") wend Uo.click(item) lag_test(0) if UO.injournal("items)") then return 1 end if return 0 end sub
sub unlock() ;unlocks container by TYPE=1 if UO.getglobal("lastunlocked") <> "0" then UO.print("Restoring previous lock") set(uo.getglobal("lastunlocked"),"type","2") end if if NOT lock_test() then UO.print("Lastobject ain't locked!") end if set("lastobject","type","1") Uo.useobject("lastobject") UO.setglobal("lastunlocked",UO.getserial("lastobject")) end sub
sub lock() ;locks container by TYPE=2 if UO.getglobal("lastunlocked") <> "0" then set(UO.getglobal("lastunlocked"),"type","2") end if end sub
# String operations and formatting ;=================
sub Rtrim(n,text) ;cuts off 'n' chars from the right side of 'text' var i,ret="" for i=0 to len(text)-n-1 ret=ret+text[i] next return ret end sub
sub Ltrim(n,text) ;cuts off 'n' chars from the left side of 'text' var i,ret="" for i=n to len(text)-1 ret=ret+text[i] next return ret end sub
sub REtrim(n,text) ;cuts or extends 'text' to 'n' charaters at the right side var i=0,ret="" while (i<len(text)) and (i<n) ret=ret+text[i] i=i+1 wend while (i<n) ret=ret+" " i=i+1 wend return ret end sub
sub LEtrim(n,text) ;cuts or extends 'text' to 'n' charaters at the left side var j=0,i=n-len(text),ret="" if i>0 then for j=1 to i ret=ret+" " next ret=ret+text else i=len(text) for j=1 to n ret=text[i-j]+ret next endif return ret end sub
sub strinstr(what,where) ;kind of strmatch returns position of occurence of 'what' in 'where' var i=0,j=0,found=0,end=0 while i<len(where)-len(what) AND NOT found j=0 end=0 while what[j]==where[i+j] and NOT end if j==len(what)-1 then found=i end=1 else if (j+1<len(what)) and (1+i+j<len(where)) then j=j+1 else end=1 end if end if wend i=i+1 wend return found end sub
sub err(urg,msg) ;"colored&sounded" UO.print, urg sets mode of displaying message ; sounds are "stolen" from Teamspeak and color 0x3c1 is ment to be shadow-like default one if urg==4 then UO.concolor(0x823) Uo.playwav("C:\Progra~1\Teamspeak2_RC2\sounds\49.error.wav") wait(500) end if if urg==3 then UO.concolor(0x823) end if if urg==2 then UO.concolor(0x825) Uo.playwav("C:\Progra~1\Teamspeak2_RC2\sounds\48.warning.wav") wait(500) end if if urg==1 then UO.concolor(0x825) end if if urg==0 then UO.concolor(0xbb5) end if UO.print(msg) UO.concolor(0x3c1) end sub
# Server commands ;=================
sub set(item,variable,value) ;just .set if UO.hex2int(UO.getserial(item)) then var itm=ltrim(2,UO.getserial(item)) UO.serverprint(".uid.0"+itm+"."+variable+"="+value) ;UO.print("UID "+itm+" SET "+variable+"="+value) end if end sub
sub info(item,variable) ;variable info via .xshow var text="",ret="",i=0,j=0 while UO.injournal("Not a valid command or format") UO.setjournalline(UO.injournal("Not a valid command or format")-1,"###") wend while UO.injournal(" for ") UO.setjournalline(UO.injournal(" for ")-1,"###") wend repeat lag_test(0) UO.serverprint(".uid.0"+ltrim(2,UO.getserial(item))+".show "+variable) i=0 repeat if UO.injournal("Not a valid command or format") then err(4,"Unrecoverable error in .info via .show ! HALTED") halt() end if i=i+1 wait(5) until (i > 500) or UO.injournal(" for ") until UO.injournal(" for ") text=UO.journal(UO.injournal(" for ")-1) i=strinstr(" is ",text) if i then for j=i+5 to len(text)-3 ret=ret+text[j] next else err(2,variable+" for UID:"+ltrim(2,UO.getserial(item))+" cannot be resolved! PAUSED") pause(-1) ret=info(item,variable) end if return ret end sub
Applications are currently being purified, I use them in "it just works" messy state :)
|