• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Get Element atk TFS 1.2

lazarus321

Member
Joined
May 8, 2017
Messages
222
Reaction score
23
Hi all,

Well im try add more damage element with weapons and no work see in bold; (TFS 1.2)

i have this action script,

function getItemDescriptionsById(id)
local it = ItemType(id)
return {attack = it.getAttack(), defense = it.getDefense(), armor = it.getArmor(), element = it.getElementDamage()}
end


function onUse(cid, item, fromPosition, itemEx, toPosition)
local player = Player(cid)


local atk = ItemType(itemEx.itemid):getAttack() or nil
local def = ItemType(itemEx.itemid):getDefense() or nil
local arm = ItemType(itemEx.itemid):getArmor() or nil
local tipoele = ItemType(itemEx.itemid):getElementType() or nil
local atkele = ItemType(itemEx.itemid):getElementDamage() or nil


if atkele > 0 then
for _, upgrade in pairs(controle) do
local chance = math.random(1, 100)
local item = Item(itemEx.uid)
if item:getLevel() == upgrade.level then
if player:removeItem(26180, upgrade.quantOre) then
item:getPosition():sendMagicEffect(CONST_ME_FERREIRO)
if chance <= upgrade.chance then
if upgrade.level >= 9 then
item:setAttribute("description", "Esse item foi refinado por " ..player:getName())
Game.broadcastMessage("Parabens " ..player:getName().. "!. Seu item "..ItemType(itemEx.itemid):getName().. " foi refinado para +10 com sucesso!", MESSAGE_STATUS_WARNING)
end
item:addLevel(1)
item:setAttribute("name", ItemType(itemEx.itemid):getName().. " + " ..item:getLevel())
player:sendTextMessage(MESSAGE_INFO_DESCR, "Voce refinou com sucesso! "..ItemType(itemEx.itemid):getName().." level " ..item:getLevel())
player:say(""..tipoele.."", TALKTYPE_MONSTER_SAY)
if atkele > 0 then
item:setAttribute("element", atkele+(2*item:getLevel()))
return true

elseif arm > 0 then
item:setAttribute("armor", arm+(2*item:getLevel()))
return true
elseif def > 0 and atk <= 0 then
item:setAttribute("defense", def+(2*item:getLevel()))
return true
end
end

player:sendTextMessage(MESSAGE_INFO_DESCR, "Falha, o material foi perdido no processo!")

else
player:sendTextMessage(MESSAGE_INFO_DESCR,"Voce nao tem Esfera Mistica suficiente. Voce precisa de "..upgrade.quantOre.." Esferas Misticas para refinar sua arma.")
end


end

end

else
player:sendTextMessage(MESSAGE_INFO_DESCR, "Esse item nao pode ser refinado.")
end
return true
end


For physical damage, arm e def its ok but for element dont work why?
 
Last edited:
Ok so I took a look at this script and re-wrote some of it but the problem is you have an unknown table "controle" that isn't defined anywhere in the script so it makes it hard to determine how to proceed.

We can re-write this function
LUA:
function getItemDescriptionsById(id)
    local it = ItemType(id)
    return {attack = it.getAttack(), defense = it.getDefense(), armor = it.getArmor(), element = it.getElementDamage()}
end
As
LUA:
function getItemDescriptionsById(itemid)
    local item = ItemType(itemid)
    return item and {
        attack = item:getAttack() or 0,
        defense = item:getDefense() or 0,
        armor = item:getArmor() or 0,
        eType = item:getElementType() or 0,
        eDamage = item:getElementDamage() or 0
    } or nil
end
Which eliminates all this code
LUA:
local atk = ItemType(itemEx.itemid):getAttack() or nil
local def = ItemType(itemEx.itemid):getDefense() or nil
local arm = ItemType(itemEx.itemid):getArmor() or nil
local tipoele = ItemType(itemEx.itemid):getElementType() or nil
local atkele = ItemType(itemEx.itemid):getElementDamage() or nil
Instead you can write it like this
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)
    local it = getItemDescriptionsById(itemEx.itemid)

    if it and it.eDamage > 0 then
Soon after that we come to this
LUA:
for _, upgrade in pairs(controle) do
Since we don't know the value of controle the script can't be defined further.
 
Last edited:
Hi Steve,


I re-write the function and get this error,

Lua Script Error: [Action Interface]
data/actions/scripts/uparmaselemental.lua:eek:nUse
data/actions/scripts/uparmaselemental.lua:53: attempt to compare number with nil
stack traceback:
[C]: in function '__lt'
data/actions/scripts/uparmaselemental.lua:53: in function <data/actions/scripts/uparmaselemental.lua:47>

The full script hastebin (https://hastebin.com/lizosawuvo.rb)
 
Back
Top