Yoko

All sides of Injection
It is currently 2024-03-28 11:31:12

All times are UTC+02:00




Post new topic  Reply to topic  [ 1 post ] 
Author Message
 Post subject: Auxiliar Functions
PostPosted: 2013-04-01 16:09:27 
Offline

Joined: 2012-09-10 20:18:54
Posts: 14
1. Repeat 'Guards' until die, or get full health (without being poisoned)
Code:
Sub CallGuards()
var timeout=10
If UO.GetNotoriety('self')<=1 Then
   UO.Msg('Guards')
End If
While (UO.Life<UO.Str Or UO.Poisoned()) And Not Uo.Dead()
   If timeout<=0 Then
      UO.Msg('Guards')
      timeout=10
   End If
   Wait(1000)
   timeout=timeout-1
WEnd
End Sub



2. Wait lag (ping and reponde ms delay)
Code:
Sub Ping()
var aux=0
EraseFromJournal('backpack')
UO.Click('backpack')
Repeat
   Wait(1)
   aux=aux+1
Until UO.InJournal('backpack')
return aux
End Sub



3. Erase the lines of the journal that contains the text
Code:
Sub EraseFromJournal(text)
var aux=UO.InJournal(text)
While aux>0
   UO.SetJournalLine(aux-1,'')
   aux=UO.InJournal(text)
Wend
End Sub



4. Check journal searching only for my messages (my char's serial) or the system (0xffffffff) messages
Code:
Sub CheckMyJournal(text)
var aux=UO.InJournal(text)
While aux>0
   If UO.JournalSerial(aux-1)==UO.GetSerial('self') Or UO.JournalSerial(aux-1)=='0xFFFFFFFF' Then
      return aux
   Else
      UO.SetJournalLine(aux-1,'')
   End If
   aux=UO.InJournal(text)
WEnd
return 0
End Sub



5. Get the serial from some message in the journal (not sure where the searh in journal beggins,
Code:
bottom or top.
Sub WhoJournal(text)
If UO.InJournal(text) Then
   return UO.JournalSerial(UO.InJournal(text)-1)
End If
return '0x00000000'
End Sub



6. Wait (or timeout) for a message to be said by someone, checking their name and serial. Usefull in questions, like: "how are you?" (then waits for an answer)
Code:
Sub WaitOwnedText(target,timeout)
EraseFromJournal(UO.GetName(target))
Repeat
   Repeat
      Wait(100)
      timeout=timeout-0.1
   Until UO.InJournal(UO.GetName(target)) Or timeout<=0
   If UO.InJournal(UO.GetName(target)) And Not UO.JournalSerial(UO.InJournal(UO.GetName(target))-1)==UO.GetSerial(target) Then
      UO.SetJournalLine(UO.InJournal(UO.GetName(target))-1,'')
   End If
Until UO.JournalSerial(UO.InJournal(UO.GetName(target))-1)==UO.GetSerial(target) Or timeout<=0
If timeout>0 Or UO.JournalSerial(UO.InJournal(UO.GetName(target))-1)==UO.GetSerial(target) Then
   If Len(UO.Journal(UO.InJournal(UO.GetName(target))-1))>=Len(UO.GetName(target))+2 Then
      return Right(UO.Journal(UO.InJournal(UO.GetName(target))-1),Len(UO.Journal(UO.InJournal(UO.GetName(target))-1))-Len(UO.GetName(target))-2)
   End If
End If
return ''
End Sub



7. Easily gets the serial/graphic/color from the selected target (waiting for the player to choose the target)
Code:
Sub TargetSerial()
UO.AddObject('temp')
While UO.Targeting()
   Wait(100)
WEnd
return UO.GetSerial('temp')
End Sub

Sub TargetGraphic()
UO.AddObject('temp')
While UO.Targeting()
   Wait(100)
WEnd
return UO.GetGraphic('temp')
End Sub

Sub TargetColor()
UO.AddObject('temp')
While UO.Targeting()
   Wait(100)
WEnd
return UO.GetColor('temp')
End Sub



8. Generates a screen shot image in '.bmp' format with the name pattern (shardname)_(playername)_(date)_(time).bmp
Code:
Sub ScreenShot()
var path=UO.GetInfo('shard')+'_'+UO.GetInfo('character')+'_'+str(UO.Date())+'_'+str(UO.Time())+'.bmp'
UO.Snap('bmp',path)
return path
End Sub



9. Opens bank using 'guards' in the message in case notoriety is 'innocent' (blue/apk), or calls only bank
Code:
Sub BankNotoriety()
If UO.GetNotoriety('self')<=1 Then
   UO.Msg('Bank Guards')
Else
   UO.Msg('Bank')
End If
End Sub



10. Force peace mode and cancel actions. If on peace mode will turn war mode and then peace mode.
Code:
Sub CancelAction()
var aux=0
If UO.WarMode()==0 Then
   UO.WarMode(1)
   EraseFromJournal('backpack')
   UO.Click('backpack')
   Repeat
      Wait(1)
      aux=aux+1
   Until UO.WarMode()==1 Or UO.InJournal('backpack')
   UO.WarMode(0)
   Repeat
      Wait(1)
      aux=aux+1
   Until UO.WarMode()==0
   aux=int(aux/2)
Else
   UO.WarMode(0)
   Repeat
      Wait(1)
      aux=aux+1
   Until UO.WarMode()==0
End If
return aux
End Sub



11. Fully Count itens in a container, checking all stacks, like UO.Count but for any container and ground (with 2 tiles distance check)
Code:
Sub CountQuantity(type,color,container)
var count=0
UO.IgnoreReset()
If container=='ground' Then
   UO.Set('finddistance',2)
End If
UO.FindType(type,color,container)
While UO.Findcount()>0
   If UO.GetQuantity('finditem')<=1 Then
      count=count+1
   Else
      count=count+UO.GetQuantity('finditem')
   End If
   UO.Ignore('finditem')
   UO.FindType(type,color,container)
WEnd
UO.IgnoreReset()
return count
End Sub



12. Moves Items from one container/ground to another using 3 diferent ways: 'get' will use quantity as target quantity in the container that will recive items ; 'left' will leave items in the quantity asked (to store all but some portion items) ; anything else in 'quantitytype' will make the quantity value as absolute to move.
Code:
Sub MoveQuantity(type,color,fromcontainer,tocontainer,quantitytype,quantity)
var fromCount=CountQuantity(type,color,fromcontainer)
var toCount=CountQuantity(type,color,tocontainer)
var fromMoved=0
var toMoved=0
var fromBefore=fromCount
var toBefore=toCount
var move=0
var itemWeight=10
If quantitytype=='get' Then
   quantity=quantity-toCount
Else
   If quantitytype=='left' Then
      quantity=fromCount-quantity
   End If
End If
If quantity>fromCount Then
   quantity=fromCount
End If
var trys=quantity*2
While fromMoved<quantity And toMoved<quantity And trys>0 And UO.GetSerial(fromcontainer)<>UO.GetSerial(tocontainer) And (UO.GetSerial(tocontainer)<>UO.GetSerial('backpack') Or UO.Weight<40+(UO.Str*3.5)-itemWeight) And UO.GetSerial(tocontainer)<>'0x00000000'
   UO.Findtype(type,color,fromcontainer)
   If UO.FindCount()>0 Then
      itemWeight=UO.Weight
      If fromMoved<=toMoved Then
         move=quantity-toMoved
      Else
         move=quantity-fromMoved
      End If
      If tocontainer=='ground' Then
         UO.Drop(move,UO.GetX()-2+UO.Random(5),UO.GetY()-1-UO.Random(2)+UO.Random(4),UO.GetZ(),'finditem')
      Else
         UO.MoveItem('finditem',move,tocontainer)
      End If
      Wait(1500)
      Ping()
      itemWeight=(UO.Weight-itemWeight)/move
   End If
   fromCount=CountQuantity(type,color,fromcontainer)
   toCount=CountQuantity(type,color,tocontainer)
   fromMoved=fromMoved+fromBefore-fromCount
   toMoved=toMoved+toCount-toBefore
   fromBefore=fromCount
   toBefore=toCount
   trys=trys-1
WEnd
End Sub



13. Walks to the position X,Y until is close enough (proximity/distance) or until it trys to much to unstuck character (limit)
Code:
Sub Walk(x,y,proximity,limit)
var stuck=0
var stucked=0
var characterX=UO.GetX()
var characterY=UO.GetY()
var walkDirection=0
var loop
dim DirWalk[8]   ;     Dir Press ;
DirWalk[0]=33   ; N  - 0 -  33  ;
DirWalk[1]=39   ; NE - 1 -  39  ;
DirWalk[2]=34   ; E  - 2 -  34  ;
DirWalk[3]=40   ; SE - 3 -  40  ;
DirWalk[4]=35   ; S  - 4 -  35  ;
DirWalk[5]=37   ; SW - 5 -  37  ;
DirWalk[6]=36   ; W  - 6 -  36  ;
DirWalk[7]=38   ; NW - 7 -  38  ;
While (characterX>x+proximity Or characterX<x-proximity Or characterY>y+proximity Or characterY<y-proximity) And stucked<limit
   If characterX==x And characterY>y Then
      walkDirection=0
   End If
   If characterX<x And characterY>y Then
      walkDirection=1
   End If
   If characterX<x And characterY==y Then
      walkDirection=2
   End If
   If characterX<x And characterY<y Then
      walkDirection=3
   End If
   If characterX==x And characterY<y Then
      walkDirection=4
   End If
   If characterX>x And characterY<y Then
      walkDirection=5
   End If
   If characterX>x And characterY==y Then
      walkDirection=6
   End If
   If characterX>x And characterY>y Then
      walkDirection=7
   End If
   If stuck<=5 Then
      If UO.GetDir()<>walkDirection Then
         UO.Press(DirWalk[walkDirection])
         Wait(100)
      End If
      UO.Press(DirWalk[walkDirection])
      Wait(100)
   Else
      walkDirection=UO.Random(8)
      For loop=0 to UO.Random(4)+2
         UO.Press(DirWalk[walkDirection])
         Wait(100)
      Next
      stucked=stucked+1
   End If
   If UO.GetX()==characterX And UO.GetY()==characterY Then
      stuck=stuck+1
   Else
      stuck=0
   End If
   characterX=UO.GetX()
   characterY=UO.GetY()
WEnd
End Sub



14. Format text turning all characters to upper case ('upper'), just the first characters of a word in upper case ('uinit') or all characters lower case (default)
Code:
Sub FormatText(text,format)
dim uppercase[49]
uppercase[0]='A'
uppercase[1]='B'
uppercase[2]='C'
uppercase[3]='D'
uppercase[4]='E'
uppercase[5]='F'
uppercase[6]='G'
uppercase[7]='H'
uppercase[8]='I'
uppercase[9]='J'
uppercase[10]='K'
uppercase[11]='L'
uppercase[12]='M'
uppercase[13]='N'
uppercase[14]='O'
uppercase[15]='P'
uppercase[16]='Q'
uppercase[17]='R'
uppercase[18]='S'
uppercase[19]='T'
uppercase[20]='U'
uppercase[21]='V'
uppercase[22]='W'
uppercase[23]='X'
uppercase[24]='Y'
uppercase[25]='Z'
uppercase[26]='Á'
uppercase[27]='É'
uppercase[28]='Í'
uppercase[29]='Ó'
uppercase[30]='Ú'
uppercase[31]='Â'
uppercase[32]='Ê'
uppercase[33]='Î'
uppercase[34]='Ô'
uppercase[35]='Û'
uppercase[36]='À'
uppercase[37]='È'
uppercase[38]='Ì'
uppercase[39]='Ò'
uppercase[40]='Ù'
uppercase[41]='Ä'
uppercase[42]='Ë'
uppercase[43]='Ï'
uppercase[44]='Ö'
uppercase[45]='Ü'
uppercase[46]='Ã'
uppercase[47]='Õ'
uppercase[48]='Ç'
dim lowercase[49]
lowercase[0] ='a'
lowercase[1] ='b'
lowercase[2] ='c'
lowercase[3] ='d'
lowercase[4] ='e'
lowercase[5] ='f'
lowercase[6] ='g'
lowercase[7] ='h'
lowercase[8] ='i'
lowercase[9] ='j'
lowercase[10]='k'
lowercase[11]='l'
lowercase[12]='m'
lowercase[13]='n'
lowercase[14]='o'
lowercase[15]='p'
lowercase[16]='q'
lowercase[17]='r'
lowercase[18]='s'
lowercase[19]='t'
lowercase[20]='u'
lowercase[21]='v'
lowercase[22]='w'
lowercase[23]='x'
lowercase[24]='y'
lowercase[25]='z'
lowercase[26]='á'
lowercase[27]='é'
lowercase[28]='í'
lowercase[29]='ó'
lowercase[30]='ú'
lowercase[31]='â'
lowercase[32]='ê'
lowercase[33]='î'
lowercase[34]='ô'
lowercase[35]='û'
lowercase[36]='à'
lowercase[37]='è'
lowercase[38]='ì'
lowercase[39]='ò'
lowercase[40]='ù'
lowercase[41]='ä'
lowercase[42]='ë'
lowercase[43]='ï'
lowercase[44]='ö'
lowercase[45]='ü'
lowercase[46]='ã'
lowercase[47]='õ'
lowercase[48]='ç'
var result=''
var aux
var position
var index
If Len(text)>0 Then
   For position=0 to Len(text)-1
      If format=='upper' Then
         aux='upper'
      Else
         aux='lower'
      End If
      If format=='uinit' Then
         If position==0 Then
            aux='upper'
         Else
            If Mid(text,position-1,1)==' ' Then
               aux='upper'
            Else
               aux='lower'
            End If
         End If
      End If
      For index=0 to 48
         If aux=='upper' Then
            If Mid(text,position,1)==lowercase[index] Then
               result=result+uppercase[index]
               aux=''
               index=48
            End If
         Else
            If Mid(text,position,1)==uppercase[index] Then
               result=result+lowercase[index]
               aux=''
               index=48
            End If
         End If
      Next
      If aux<>'' Then
         result=result+Mid(text,position,1)
      End If
   Next
End If
return result
End Sub



15. InText functino works like injournal but checkes is the first text is inside the second (reading from end to start, checks if the second text contains the first)
Code:
Sub InText(text,intext)
var result=0
var position
If Len(text)<Len(intext) Then
   For position=0 to Len(intext)-Len(text)
      If Mid(intext,position,Len(text))==text Then
         result=result+1
      End If
   Next
End If
return result
End Sub



16. This functions work like Mid, but using text also, not only positions (they dont use lenght)
Code:
Sub SubstringPositionText(text,fromposition,totext)
var position=fromposition
While Len(text)>=position+Len(totext)
   If Mid(text,position,Len(totext))==totext Then
      return Mid(text,fromposition,position-fromposition)
   Else
      If Len(text)==position+Len(totext) And Len(totext)>0 Then
         totext=Left(totext,Len(totext)-1)
      End If
   End If
   position=position+1
WEnd
return ''
End Sub

Sub SubstringTextText(text,fromtext,totext)
var fromposition=0
var position=0
While Len(text)>=position+Len(fromtext) And fromposition==0
   If Mid(text,position,Len(fromtext))==fromtext Then
      fromposition=position+Len(fromtext)
   Else
      If Len(text)==position+Len(fromtext) And Len(fromtext)>0 Then
         fromtext=Left(fromtext,Len(fromtext)-1)
      End If
   End If
   position=position+1
WEnd
position=fromposition
While Len(text)>=position+Len(totext)
   If Mid(text,position,Len(totext))==totext Then
      return Mid(text,fromposition,position-fromposition)
   Else
      If Len(text)==position+Len(totext) And Len(totext)>0 Then
         totext=Left(totext,Len(totext)-1)
      End If
   End If
   position=position+1
WEnd
return ''
End Sub

Sub SubstringTextPosition(text,fromtext,toposition)
var position=0
While Len(text)>=position+Len(fromtext)
   If Mid(text,position,Len(fromtext))==fromtext Then
      position=position+Len(fromtext)
      If toposition>position Then
         return Mid(text,position,toposition-position)
      Else
         return Mid(text,position,Len(text)-position)
      End If
   Else
      If Len(text)==position+Len(fromtext) And Len(fromtext)>0 Then
         fromtext=Left(fromtext,Len(fromtext)-1)
      End If
   End If
   position=position+1
WEnd
return ''
End Sub



17. Chages substring to another (substitute)
Code:
Sub StringSubstitution(text,oldtext,newtext)
var result=''
var position
If Len(oldtext)<Len(text) Then
   For position=0 to Len(text)-Len(oldtext)
      If Mid(text,position,Len(oldtext))==oldtext Then
         result=result+newtext
         position=position+Len(oldtext)-1
      Else
         result=result+Mid(text,position,1)
      End If
   Next
   result=result+Right(text,Len(oldtext))
End If
return result
End Sub



18. Gets the word from a word count, like in 'I will have this word' text we have 0 for 'I', 1 for 'will', 2 for 'have' and so on.
Code:
Sub GetWord(text,wordcount)
var position=0
var count=0
var result=''
While count<wordcount-1 and position<Len(text)
   If Mid(text,position,1)==' ' Then
      count=count+1
   End If
   position=position+1
WEnd
If position<Len(text) And count==wordcount-1 Then
   While Mid(text,position,1)<>' ' And position<Len(text)
      result=result+Mid(text,position,1)
      position=position+1
   WEnd
End If
return result
End Sub



19. Pow function (math - power)
Code:
Sub Pow(number,expnumber)
var result=number
var expnegativa=0
If expnumber<0 then
   expnegativa=1
   expnumber=-expnumber
End If
If expnumber==0 Then
   result=1
End If
While expnumber>1
   result=result*number
   expnumber=expnumber-1
WEnd
If expnegativa==1 And result<>0 Then
   return 1/result
End If
return result
End Sub



20. Unit converter (reads 'k' / 'K' as thousand [x10³], 'm' / 'M' as million [x10³x10³] or 'b' / 'B' as billion [x10³x10³x10³] , and can be used like '1kk 30k' that will be converted in 1030000)
Code:
Sub Unit(text)
var result=0
var temp=''
var loop
var flag=0
For loop=0 to Len(text)-1
   If Mid(text,loop,1)=='k' Or Mid(text,loop,1)=='K' Then
      flag=1
      temp=temp+'000'
   Else
      If Mid(text,loop,1)=='m' Or Mid(text,loop,1)=='M' Then
         flag=1
         temp=temp+'000000'
      Else
         If Mid(text,loop,1)=='b' Or Mid(text,loop,1)=='B' Then
            flag=1
            temp=temp+'000000000'
         Else
            If flag==1 Then
               result=result+val(temp)
               temp=''
               flag=0
            End If
            temp=temp+Mid(text,loop,1)
         End If
      End If
   End If
Next
return result+val(temp)
End Sub


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 1 post ] 

All times are UTC+02:00


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited