• 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!

Lua Turn sword into Mace

highclick

New Member
Joined
Mar 21, 2011
Messages
80
Reaction score
4
Hi! I'm trying too transform a sword (ID 11395) into a mace (ID 2448). I'm very new at using .lua and im unfamiliar with their functions. If anyone could explain what i should put into the parameters and why that would be great

This is how far I've come with my script:

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 11395 then
        doTransformItem(uid, toitemid[, count/subtype])
 
I kept it simple for you so you could understand how it works :)
Code:
local transformItem = {
    from = 11395, -- sword
    to = 2448 -- studded club
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == transformItem.from then
        doTransformItem(item.uid, transformItem.to)
    end
    return true
end
 
I kept it simple for you so you could understand how it works :)
Code:
local transformItem = {
    from = 11395, -- sword
    to = 2448 -- studded club
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == transformItem.from then
        doTransformItem(item.uid, transformItem.to)
    end
    return true
end

Wow thanks alot, it took some headscratching too fully understand but I got it now!

One more question:

I've added this line into movements.xml :

PHP:
    <movevent event="Equip" itemid="11395" function="onEquipItem" slot="sword" script="swordtomace.lua"/>
    <movevent event="DeEquip" itemid="11395" function="onDeEquipItem" slot="sword" script="swordtomace.lua"/>

And then I've created a .lua file in the scripts folder thats names "swordtomace.lua" where I've used your script.

Why doesn't it work in game?
 
onUse is for actions, you would apply this to actions.xml
Code:
<action itemid="11395" script="swordtomace.lua"/>
 
onUse is for actions, you would apply this to actions.xml
Code:
<action itemid="11395" script="swordtomace.lua"/>

I added that line into actions.xml and i also moved swordtomace.lua from /movements/scripts too /actions/scripts.

It works perfect, thank you very much Breed!
 

I tried too modify the script too loop between sword-mace-axe. So that when its a sword it becomes a mace, if it's a mace it becomes an axe, if it's an axe it becomes a sword and so on.

I added this script:
Code:
local transformItem = {
    sword = 11395, -- sword
    mace = 2448, -- mace
    axe = 2441 -- axe
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == transformItem.sword then
        doTransformItem(item.uid, transformItem.mace)
    elseif item.itemid == transformItem.mace
        doTransformItem(item.uid, transformItem.axe)
    elseif item.itemid == transformItem.axe
        doTransformItem(item.uid, transformItem.sword)
    end
    return true
end

and these lines too action.xml:


Code:
    <action itemid="11395" script="weapons/swordtomace.lua"/>
    <action itemid="2448" script="weapons/swordtomace.lua"/>
    <action itemid="2441" script="weapons/swordtomace.lua"/>


Do you know why it doesnt work?
 
did you get an error?
what happened when you clicked the initial item and did it change at all and upto what point.
 
When using this method, it attempts to use the item, and then the script.
Is there a way to stop the on-use method of the item?
 
Idk try that, love the sig btw :)
Code:
local transformItem = {
    sword = 11395, -- sword
    mace = 2448, -- mace
    axe = 2441 -- axe
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == transformItem.sword then
        doTransformItem(item.uid, transformItem.mace)
        return true
    elseif item.itemid == transformItem.mace then
        doTransformItem(item.uid, transformItem.axe)
        return true
    elseif item.itemid == transformItem.axe then
        doTransformItem(item.uid, transformItem.sword)
        return true
    end
    return true
end
 
Tried just now, didn't work. :confused:
I couldn't tell ya then coz I'm only running tfs 1.x :(

I wonder if we removed the last 3 param's would it make a different, coz if you think about it, there is a thing called function overloading.

It is where there is a several functions with the same name but with different parameters.
If this is the case the server would choose the correct functions to use or what information to pass based on the parameters given.

So instead of this
Code:
onUse(cid, item, fromPosition, itemEx, toPosition)
You could try
Code:
onUse(cid, item)

Because itemEx is effected by item which is why you get the little icon when you right click the item, if I am wrong that is ok too.
 
Last edited:
If you want to remove the usable option of an item, edit tibia.dat and items.otb.
If you want to prevent players from doing something, check for itemids of the item/itemEx.
 
Back
Top