• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Action Perfect items upgrade

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil

Ahtor:
bearpaw.png
(Me XP)
Tested in: TFS 0.3.6
Version
: 1.1

Updated to 0.3.6
Hello! Well, some months ago my server Pharenight is closed. In it have MANY scripts and alot of them are VERRY good and many peoples are looking for some like them, so i decided post some scripts of this otserv, all scripts made by me. I see many scripts of upgrade and i see an fail in all, its hard to configure items, you need add 1 to 1 in tables, one line by each weapon or one by armor, and 70% of this scripts dont work. But this is more dinamic, you add ONLY the blocked items, this blockd items dont will be upgraded, the script find if the item is an armor, an weapon or is an shield. ^^

So.. lets install it ^^

Got to data/actions/actions.xml and add this tag:

PHP:
<action itemid="8306" script="upgrade.lua"/>
Now go to scripts and create file called upgrade.lua and add it:

Lua:
--- Perfect refine system by Mock the bear (MTB).
--- Email: [email][email protected][/email]
local gain = {
gainArmor='&p+1',loseArmor='&p-1',
gainShield='&s+#',loseShield='&s-(#+1)',
gainAttack='&a+(2*(#))',loseAttack='&a-(2*(#+1))',
gainDefense='&d+(2*(#))',loseDefense='&d-(2*(#+1))',
chance='100/((#*(1/(@/2)))*(@/2))',  -- Eu fiz essa equação para variar de +0 a +7 o item
--- Essa equação deve retornar em % a chance do item se refinar (0-100) 100 = sempre, 0 = nunca
maxlvl = 7,
blocked_ids = {2488,8881}
}
-- &a = weapon attack
-- &d = weapon defense
-- &s = shield defense
-- &p = armor defense
-- # = nivel do item
-- @ = max level
if not setItemName then
	function setItemName(uid,name)
	 return doItemSetAttribute(uid,'name',name)
	end
	function setItemArmor(uid,name)
	 return doItemSetAttribute(uid,'armor',name)
	end
	function setItemDefense(uid,name)
	 return doItemSetAttribute(uid,'defense',name)
	end
	function setItemAttack(uid,name)
	 return doItemSetAttribute(uid,'attack',name)
	end
	function getItemAttack(uid)
	   return getItemAttribute(uid,'attack')
	end
	function getItemDefense(uid)
	   return getItemAttribute(uid,'defense')
	end
	function getItemArmor(uid)
	   if type(uid) == 'number' then
		  return getItemAttribute(uid,'armor')
	   else
		  return getItemInfo(uid.itemid).armor
	   end
	end
end
function isArmor(uid) -- Function by Mock the bear.
         if (getItemArmor(uid) and getItemArmor(uid) ~= 0 and not getItemInfo(uid.itemid,'attack') and not getItemInfo(uid.itemid,'defense') and getItemWeaponType(uid.uid) == 0) then
            return true
         end
         return false
end
function isWeapon(uid) -- Function by Mock the bear.
         uid = uid or 0
         local f = getItemWeaponType(uid)
         if f == 1 or f == 2 or f == 3 then
             return TRUE
         end
         return FALSE
end
function isShield(uid) -- Function by Mock the bear.
         uid = uid or 0
         if getItemWeaponType(uid) == 4 then
             return TRUE
         end
         return FALSE
end

function getWeaponLevel(uid) -- Function by Mock the bear.
   uid = uid or 0
   local name = getItemName(uid)
   local lvl = string.match(name,'+(%d)')
   return tonumber(lvl) or 0
end
function doTransform(s,i) -- Function by Mock the bear.
    local c = string.gsub(s,'@',gain.maxlvl)
    local c = string.gsub(c,'&a',getItemAttack(i.uid) or getItemInfo(i.itemid).attack)
    local c = string.gsub(c,'&d',getItemDefense(i.uid) or getItemInfo(i.itemid).defense)
    local c = string.gsub(c,'&s',getItemDefense(i.uid) or getItemInfo(i.itemid).defense)
    local c = string.gsub(c,'&p',getItemArmor(i.uid) or getItemInfo(i.itemid).armor)
    local c = string.gsub(c,'#',getWeaponLevel(i.uid))
    local q,err = loadstring('return '..c)
    assert(q,err)
    return assert(q())
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
         toPosition.stackpos = 255
         if isInArray(gain.blocked_ids, itemEx.itemid) == TRUE
          or getItemWeaponType(itemEx.uid) > 4
           or (getItemWeaponType(itemEx.uid) == 0
            and isArmor(itemEx) == FALSE)
             or itemEx.itemid == 0 then
                doPlayerSendTextMessage(cid, 24,"You cant refine this item.")
                return TRUE
         end
         if isCreature(itemEx.uid) == TRUE then
            return FALSE
         end
        local level = getWeaponLevel(itemEx.uid)
        local chance = doTransform(gain.chance,itemEx)
        if chance >= math.random(0,100) or item.actionid >= 1000 or (item.actionid == 500 and math.random(0,100) <= 25) then
           if level+1 > gain.maxlvl then
              doSendMagicEffect(toPosition, 2)
              return doPlayerSendTextMessage(cid, 24,"Your item is on max level, you can't upgrade it.")
           else
              setItemName(itemEx.uid, getItemNameById(itemEx.itemid)..' +'..(level+1))
              doPlayerSendTextMessage(cid, 24,"Your item has been upgrated to +"..(level+1)..".")
              doSendMagicEffect(toPosition, 12)
              if isArmor(itemEx) == TRUE then
                 local get = doTransform(gain.gainArmor,itemEx)
                 setItemArmor(itemEx.uid,get)
              elseif isWeapon(itemEx.uid) == TRUE then
                  setItemAttack(itemEx.uid, doTransform(gain.gainAttack,itemEx))
                  setItemDefense(itemEx.uid, doTransform(gain.gainDefense,itemEx))
              elseif isShield(itemEx.uid) == TRUE then
                  setItemDefense(itemEx.uid, doTransform(gain.gainShield,itemEx))
              end
           end
        else

           if level == 0 then
               doPlayerSendTextMessage(cid, 24,"No effect.")
               doSendMagicEffect(toPosition, 2)
           elseif level == gain.maxlvl then
                  doSendMagicEffect(toPosition, 2)
                  return doPlayerSendTextMessage(cid, 24,"Your item is on max level, you can't upgrade it.")
           elseif level > 0 then
               if level == 1 then
                   setItemName(itemEx.uid, getItemNameById(itemEx.itemid))
                   doPlayerSendTextMessage(cid, 24,"Your item back to normal.")
               else
                   setItemName(itemEx.uid, getItemNameById(itemEx.itemid)..' +'..(level-1))
                   doPlayerSendTextMessage(cid, 24,"Your item back to +"..(level-1)..".")
               end
              if isArmor(itemEx) == TRUE then
                 setItemArmor(itemEx.uid,doTransform(gain.loseArmor  ,itemEx))
              elseif isWeapon(itemEx.uid) == TRUE then
                  setItemAttack(itemEx.uid, doTransform(gain.loseAttack,itemEx))
                  setItemDefense(itemEx.uid, doTransform(gain.loseDefense,itemEx))
              elseif isShield(itemEx.uid) == TRUE then
                  setItemDefense(itemEx.uid, doTransform(gain.loseShield,itemEx))
              end
           end
           doSendMagicEffect(toPosition, 9)
        end
     doRemoveItem(item.uid,1)
     return TRUE
end
Working on 0.3.4
http://lua.pastey.net/134570

Congratz, now your otserver have an item upgrade! now its just use itemid 8306 in some item (armor shield or weapon non distance) and this item will be upgraded! If you put actionid 1000 in itemid 8306 (pure energy) the fail chance will be = 0, and sucess chance == 100% ^^

Have fun!


fdssfdsfd.png

Sorry by the bad english XP

You like this script? So give-me rep ^^
 
Last edited:
@silentsniper
Lol?
wath the difference in XML servers to SQL server on scripts? ._.
...
You change here
if chance >= math.random(0,100) or item.actionid >= 1000 then
but not exactly actionid 1000
if you put 1000 or higher works too like:
4500, 6000, 9999,1234
 
I'll test it and maybe add on my war ots (good item to sms shop) :)
Thanks!
 
só precisa melhorar o inglês mock.
bá ja e versão 1.3?
no xtibia ta 1.1 -- o.0

reduce some script is very lage.
 
@marcryzius
use only english on forum.

Reduce script? are you crazy?
this script is too short.
anithing in it is verry importante.

And your english it's not better too ^^
 
@marcryzius
use only english on forum.

Reduce script? are you crazy?
this script is too short.
anithing in it is verry importante.

And your english it's not better too ^^

this script is too short. :(

I thought you were smarter.
I was wrong.
 
The script is great. If you can't do it better way, don't flame Mock. You all think all scripts should have 5-6 lines? :s
 
You're so full of yourself... But well, it's a great script. I'll surely use it, thanks.
 
Okay i think you are more smarter than me, so reduce this script, and do it 2x better.

é só você querer que você pode reduzir muito esse script.

veja isso que incrivel você sabe criar funções nosssssssa!
sim fica legal criar funções mas como é pra reduzir o script você pode eliminar essas funções e assim economizar muitas linhas.
até porque criar funções como essa por causa de besteirinhas e gastar linhas desnecessarias.
function isArmor(uid) -- Function by Mock the bear.
uid = uid or 0
if getItemArmor(uid) > 0 and getItemAttack(uid) == 0 and getItemDefense(uid) == 0 and getItemWeaponType(uid) == 0 then
return TRUE
end
return FALSE
end
function isWeapon(uid) -- Function by Mock the bear.
uid = uid or 0
local f = getItemWeaponType(uid)
if f == 1 or f == 2 or f == 3 then
return TRUE
end
return FALSE
end
function isShield(uid) -- Function by Mock the bear.
uid = uid or 0
if getItemWeaponType(uid) == 4 then
return TRUE
end
return FALSE
end

a unica coisa que eu admirei foi a função do weapon level que realmente é necessaria nesse script.

sem contar que isso é uma piada isso não é uma função é uma piada.
o que é que você quer provar com isso?
que você sabe mecher com strings? ¬¬
function doTransform(s,uid) -- Function by Mock the bear.
local c = string.gsub(s,'@',gain.maxlvl)
local c = string.gsub(c,'&a',getItemAttack(uid))
local c = string.gsub(c,'&d',getItemDefense(uid))
local c = string.gsub(c,'&s',getItemDefense(uid))
local c = string.gsub(c,'&p',getItemArmor(uid))
local c = string.gsub(c,'#',getWeaponLevel(uid))
local q,err = loadstring('return '..c)
assert(q,err)
return assert(q())
end
mas pra tal script mock isso é frescura.

testei o script e fiquei admirado ao passar uma sov do atack 48 para o 49 e depois pro atack 50 até ae tudo bem só que ao dar outro use ele foi pro atack 57 e no proximo 62 nusssssa
é assim mesmo?

o script em si não é de grandes dimensões mas quando eu citei diminuir é retirar o desnecessario.
então será que da pra diminuir o script ou ainda estou enganado?
 
Nice one.

But I have to confest @up is right. Sure I don't get that language hehe but it could be shortened a lot and remove unnecessary code, such as those gsub stuff... Nobody will write something else than numbers, all you need is "gainArmor = 1", "loseArmor = 1"... Nothing else needed ;)
 
@marcryzius
Tudo bem vou falar em portugues com você.
Seginte eu criei essas funções pois algumas o proprio distro nao possue elas e alguns essa função nao funciona perfeitamente, exemplo do TFS 0.3.5
o script nao funciona apenas para armas, ele funciona para shield armros e armas, sem ter que criar 500000 linhas 1 pra cada item.

A outra função é uma piada? okay. tem noob que nao sabe nem mexer nas formulas do script criei isso pra facilitar o uso pois esses noobs sabem sim editar pelomenos uma tabela.
Tanto que como na otnet me pediram p mostrar como faz pra mudar o ganho de ATK e DEF dos item pra 10% eu ensinei que era so fazer o calculo lá, simples no que eu disse é no caso de configurar.
testei o script e fiquei admirado ao passar uma sov do atack 48 para o 49 e depois pro atack 50 até ae tudo bem só que ao dar outro use ele foi pro atack 57 e no proximo 62 nusssssa
é assim mesmo?
Veja a formula comp é feita, Atk total + nivel + 1.

Mais como eu disse, se vocÊ se acha o sabe-tudo e nao gostou do meu swcript nao me sentirei ofendido se você refizer ele menor e melhor e mais facil de configurar.

o script em si não é de grandes dimensões mas quando eu citei diminuir é retirar o desnecessario.
então será que da pra diminuir o script ou ainda estou enganado?
E tenho certeza de que apesar de o script ficar menor e tirar as funçoes eu nao colocaria minha confiança em uma função do TFS que fala que wooden chair é uma weapon.
E tenho certeza que 8 linhas amais nao vai fazer seu servidor travar de tanto lag ao nao ser que sejem um loop.
Sim da para tirar algumas coisas, como funçoes que ja vem no server so que como a isWeapon(uid) e a isArmor(uid) ja existem elas em si não funcionam perfeitamente entao pra garantir que vá funcionar eu dexei elas lá.

ps: alem disso a is weapon retorna spears, bows, flechas como armas e eu não quero isso no script
@Colandus
I decided to make something more dinamic, i can just do it:
gainArmor = '&a+1'
or...
gainArmor = '&a+(((&a-10)/&a)*100)'
^^
I think it's better do like this.
And 8~9 lines more dont will your server freeze, and in TFS 0.3.5 the function isWeapon(uid) dont work better, it return true to wooden chairs ._.' because of this i decided do it by myself.
 
Last edited:
Well I mean you could simply do it this way:
Lua:
function isShield(uid) -- Function by Mock the bear.
    return getItemWeaponType(uid) == 4
end
 
Well I mean you could simply do it this way:
Lua:
function isShield(uid) -- Function by Mock the bear.
    return getItemWeaponType(uid) == 4
end

yes but i made this script in 1:10~1:30 hours XP
and i dont remenber the possibility to use it.
 
Back
Top