[Script] Calculator on Injection

Anything and all.

Moderators: Murderator+, Murderator

Post Reply
bright
Posts: 1
Joined: 2011-12-20 02:10:15

[Script] Calculator on Injection

Post by bright »

First at all, I am brazilian, and I did this script with my friend, who is brazilian too, please comment !


Guuuuuuuuys, I come here to show a calculator to your Ultima Online, using injection.

Tired of doing the whole time you're having to open the trade the sake of their Windows calculator?

Your troubles are over (aeuaoieuaoieuaoieue) now with this script you performs mathematical operations IN-GAME!

What it does?
IN GAME performs mathematical operations, making it very easy trade at the game!

How to use?
Following the instructions at the beginning of the script, you type without spaces you want to do the operation by
Examples of how to do InGame:

Code: Select all

2+2
2*2
2/2
2-2
Image:
Image

Script:

Code: Select all

Sub Calc()
UO.DeleteJournal()
UO.Print('Welcome to the calculator system, by Samsung & DracoX')
UO.Print('Operations : Division \ , Plus + , Subtraction - , Multiplication * ')
Wait(500)
UO.Print('Following the example: 123+123')
var conta=TextoAlguem('self')
var i=0
var numero1=''
While MID(conta,i,1)<>'+' AND MID(conta,i,1)<>'-' AND MID(conta,i,1)<>'*' AND MID(conta,i,1)<>'/' AND Len(conta)>i
If MID(conta,i,1)=='k' then
  numero1=numero1+'000'
Else
  numero1=numero1+MID(conta,i,1)
End If
i=i+1
WEnd
var operador=MID(conta,i,1)
var numero2=''
While MID(conta,i,1)<>' ' AND Len(conta)>i
If MID(conta,i,1)=='k' then
  numero2=numero2+'000'
Else
  numero2=numero2+MID(conta,i,1)
End If
i=i+1
WEnd
If numero1=='' Then
numero1=0
Else
numero1=Str2Int(numero1)
End If
If numero2=='' Then
numero1=0
Else
numero2=Str2Int(numero2)
End If
var resultado=0
If operador=='+' Then
resultado=numero1+numero2
End If
If operador=='-' Then
resultado=numero1-numero2
End If
If operador=='*' Then
resultado=numero1*numero2
End If
If operador=='/' Then
resultado=numero1/numero2
End If
If operador<>'+' AND operador<>'-' AND operador<>'*' AND operador<>'/' Then
UO.Print('Error')
Else
UO.Print(str(numero1)+' '+operador+' '+str(numero2)+' = '+str(resultado))
End If
End Sub
;;;  Converção de Texto em Número Inteiro {
##### ##### Converter Texto em Número Inteiro ##### #####
; Descrição:
; - Converte os caracteres numéricos em seus números correspondentes a ordem em que aparecem e transforma letras e outros em zeros. (Ex.: '12345' -> 12345 | '1ab45' -> 10045 | '12,21' -> 12021)
;
; Parâmetros:
; - texto = o que se quer converter em número inteiro
;
Sub Str2Int(texto)
var valor
var resultado=0
var loop1, loop2
For loop1=0 to Len(texto)-1
If MID(texto,loop1,1)=='1' Then
  valor=1
Else
  If MID(texto,loop1,1)=='2' Then
   valor=2
  Else
   If MID(texto,loop1,1)=='3' Then
        valor=3
   Else
        If MID(texto,loop1,1)=='4' Then
         valor=4
        Else
         If MID(texto,loop1,1)=='5' Then
          valor=5
         Else
          If MID(texto,loop1,1)=='6' Then
           valor=6
          Else
           If MID(texto,loop1,1)=='7' Then
                valor=7
           Else
                If MID(texto,loop1,1)=='8' Then
                 valor=8
                Else
                 If MID(texto,loop1,1)=='9' Then
                  valor=9
                 Else
                  valor=0
                 End If
                End If
           End If
          End If
         End If
        End If
   End If
  End If
End If
If loop1<Len(texto)-1 Then
  For loop2=1 to Len(texto)-loop1-1
   valor=valor*10
  Next
End If
resultado=resultado+valor
Next
return resultado
End Sub
;;;  }
;;;  Texto que Alguém Disse {
##### ##### Texto que Alguém Disse ##### #####
; Descrição:
; - Retorna uma mensagem (fala) ser escrita pela pessoa cujo nome foi informado (A mensagem no journal aparece como 'Nome: Mensagem bla' e esta função retona 'Mensagem bla')
;
; Parâmetros:
; - alguem = o nome da pessoa que se deseja esperar a mensagem (fala)
;
Sub TextoAlguem(alguem)
Repeat
Wait(100)
Until UO.InJournal(UO.GetName(alguem))
var texto=UO.Journal(UO.InJournal(UO.GetName(alguem))-1)
If Len(texto)>Len(UO.GetName(alguem))+2 Then
return MID(texto,Len(UO.GetName(alguem))+2,Len(texto)-Len(UO.GetName(alguem))-2)
Else
return ''
End If
End Sub
;;;  }
DracoX
Posts: 14
Joined: 2012-09-10 20:18:54

Re: [Script] Calculator on Injection

Post by DracoX »

This Calculator has been recently updated to accept more functionalities:

now accepting a full expression with k as 000 and M as 000.

You'll be able to solve expressions like this: '(1M250+1kk25k)*2'

This code needs some os my own support functions

(and for the record I'm the one that created this calculator with brighT or Samsung)

I'll be opening a new topic with my support functions! I'm currently on my autoload project for 2012, but it's mostly usable in Dimension Shard (Brazilian Free Shard).

Main Code:

Code: Select all

Sub Calculator()
var i
corCharPrintFalha='0x0000'
dim elementos[100]
elementos[0]='('
For i=1 to 99
	elementos[i]=''
Next
var loop=0
var opar=1, apar, fpar, erro=false
var n1, n2, n
UO.DeleteJournal()
UO.Print('Welcome to DracoX & Samsung's IN-GAME calculator!')
Wait(500)
UO.Print('Say your expressino using the elements:')
UO.Print('+ - * / ^ ( ) k M')
Wait(500)
UO.Print('Ex.: (1M250+1kk25k)*2')
var exp=EsperaResposta('self',600)
UO.Print('Calculando o valor de: '+exp)
i=1
While loop<Len(exp) And i<99
	If exp[loop]=='+' Or exp[loop]=='-' Or exp[loop]=='*' Or exp[loop]=='/' Or exp[loop]=='^' Or exp[loop]=='(' Or exp[loop]==')' Then
		elementos[i]=exp[loop]
		loop=loop+1
	Else
		n=''
		n1=0
		While loop<Len(exp) And exp[loop]<>'+' And exp[loop]<>'-' And exp[loop]<>'*' And exp[loop]<>'/' and exp[loop]<>'^' And exp[loop]<>'(' And exp[loop]<>')'
			If exp[loop]=='k' Then
				n=n+'000'
				If exp[loop+1]<>'k' then
					n1=n1+val(n)
					n=''
				End If
			Else
				If exp[loop]=='M' Then
					n=n+'000000'
					n1=n1+val(n)
					n=''
				Else
					n=n+exp[loop]
				End If
			End If
			loop=loop+1
		WEnd
		elementos[i]=str(n1+val(n))
	End If
	i=i+1
WEnd
elementos[i]=')'
i=1
While i<100
	If elementos[i]=='-' And (elementos[i-1]=='+' Or elementos[i-1]=='-' Or elementos[i-1]=='*' Or elementos[i-1]=='/' Or elementos[i-1]=='^' Or elementos[i-1]=='(') Then
		elementos[i]=elementos[i]+elementos[i+1]
		i=i+1
		For loop=i to 98
			elementos[loop]=elementos[loop+1]
		Next
		elementos[99]=''
	End If
	i=i+1
WEnd
While opar==1 And erro==false
	opar=0
	apar=0
	fpar=0
	i=0
	While i<100
		If elementos[i]=='(' Then
			opar=1
			While elementos[i]<>')' And i<100
				i=i+1
			WEnd
			If i>=100 Then
				UO.CharPrint(corCharPrintFalha,'Calculator - Error!')
				UO.CharPrint(corCharPrintFalha,'More ( than ) !')
				erro=true
			Else
				fpar=i
				While elementos[i]<>'(' And i>=0
					i=i-1
				WEnd
				If i<0 Then
					UO.CharPrint(corCharPrintFalha,'Calculator - Error!')
					UO.CharPrint(corCharPrintFalha,'More ) than ( !')
					erro=true
				Else
					apar=i
					If fpar<=apar+1 Then
						elementos[apar]='0'
						For loop=apar+1 to 98
							elementos[loop]=elementos[loop+1]
						Next
						elementos[99]=''
					Else
						i=apar+1
						While i<fpar-1
							If elementos[i]=='^' Then
								n1=val(elementos[i-1])
								n2=val(elementos[i+1])
								elementos[i-1]=str(Potencia(n1,n2))
								For loop=i to 97
									elementos[loop]=elementos[loop+2]
								Next
								elementos[98]=''
								elementos[99]=''
								fpar=fpar-2
							Else
								i=i+1
							End If
						WEnd
						i=apar+1
						While i<fpar-1
							If elementos[i]=='*' OR elementos[i]=='/' Then
								n1=val(elementos[i-1])
								n2=val(elementos[i+1])
								If elementos[i]=='*' Then
									elementos[i-1]=str(n1*n2)
								Else
									If n2==0 Then
										UO.CharPrint(corCharPrintFalha,'Calculator - Error!')
										UO.CharPrint(corCharPrintFalha,'Division by zero!')
										erro=true
									Else
										elementos[i-1]=str(n1/n2)
									End If
								End If
								For loop=i to 97
									elementos[loop]=elementos[loop+2]
								Next
								elementos[98]=''
								elementos[99]=''
								fpar=fpar-2
							Else
								i=i+1
							End If
						WEnd
						i=apar+1
						While i<fpar-1
							If elementos[i]=='-' OR elementos[i]=='+' Then
								n1=val(elementos[i-1])
								n2=val(elementos[i+1])
								If elementos[i]=='+' Then
									elementos[i-1]=str(n1+n2)
								Else
									elementos[i-1]=str(n1-n2)
								End If
								For loop=i to 97
									elementos[loop]=elementos[loop+2]
								Next
								elementos[98]=''
								elementos[99]=''
								fpar=fpar-2
							Else
								i=i+1
							End If
						WEnd
						elementos[apar]=elementos[apar+1]
						For loop=apar+1 to 97
							elementos[loop]=elementos[loop+2]
						Next
						elementos[98]=''
						elementos[99]=''
					End If
				End If
			End If
		End If
		i=i+1
	WEnd
WEnd
If elementos[1]<>'' Then
	UO.CharPrint(corCharPrintFalha,'Calculator - Error!')
	UO.CharPrint(corCharPrintFalha,'Expression was not fully solved!')	
End If
n1=val(elementos[0])
n=''
If int(n1/1000000)>=1 Then
	n=n+str(int(n1/1000000))+'kk'
	n1=n1-int(n1/1000000)*1000000
End If
If int(n1/1000)>=1 Then
	n=n+str(int(n1/1000))+'k'
	n1=n1-int(n1/1000)*1000
End If
If n1<>0 Then
	n=n+str(n1)
End If
If n=='' then
	n='0'
End If
UO.Print(exp+' = '+n)
End Sub
Auxiliar/Support Functions:

Code: Select all

Sub EsperaResposta(alvo,tempomax)
tempomax=tempomax*1000
ApagaDoJournal(UO.GetName(alvo))
Repeat
	Repeat
		Wait(100)
		tempomax=tempomax-100
	Until UO.InJournal(UO.GetName(alvo)) Or tempomax<=0
	If UO.InJournal(UO.GetName(alvo)) And Not UO.JournalSerial(UO.InJournal(UO.GetName(alvo))-1)==UO.GetSerial(alvo) Then
		UO.SetJournalLine(UO.InJournal(UO.GetName(alvo))-1,'')
	End If
Until UO.JournalSerial(UO.InJournal(UO.GetName(alvo))-1)==UO.GetSerial(alvo) Or tempomax<=0
If tempomax>0 Or UO.JournalSerial(UO.InJournal(UO.GetName(alvo))-1)==UO.GetSerial(alvo) Then
	If Len(UO.Journal(UO.InJournal(UO.GetName(alvo))-1))>=Len(UO.GetName(alvo))+2 Then
		return Right(UO.Journal(UO.InJournal(UO.GetName(alvo))-1),Len(UO.Journal(UO.InJournal(UO.GetName(alvo))-1))-Len(UO.GetName(alvo))-2)
	End If
End If
return ''
End Sub

Sub Potencia(nbase,bexp)
var inv=0
var resp=nbase
If bexp==0 Then
	return 1
End If
If bexp==1 Then
	return nbase
End If
If bexp<0 Then
	inv=1
	bexp=-bexp
End If
While bexp>1
	resp=resp*nbase
	bexp=bexp-1
WEnd
If inv==1 Then
	If resp<>0 Then
		return 1/resp
	Else
		return 0
	End If
End If
return resp
End Sub
Post Reply