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

Item that repairs boots

jeffaklumpen

Member
Joined
Jan 20, 2022
Messages
76
Solutions
2
Reaction score
15
GitHub
jeffaklumpen
I'm trying to create an item that when used repairs soft boots. I have this code:

actions/scripts/repairshoes.lua
Lua:
local boots = {
    [12671] = {id = 6132}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if boots[item.itemid] then
        doTransformItem(item.uid, boots[item.itemid].id)
        doSendMagicEffect(getCreaturePosition(cid),28)
        doPlayerSendTextMessage(cid,27,"You have successfully repaired your boots.")
        else
            doPlayerSendCancel(cid, RET_NOTENOUGHMONEY)
        end
    end
    return true
end

actions.xml
Code:
<action itemid="12671" event="script" value="repairshoes.lua"/>

But it won't work :/
 
Lua:
local boots = {
    [12671] = {id = 6132}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if boots[item.itemid] then
        doTransformItem(item.uid, boots[item.itemid].id)
        doSendMagicEffect(getCreaturePosition(cid),28)
        doPlayerSendTextMessage(cid,27,"You have successfully repaired your boots.")
        else
            doPlayerSendCancel(cid, RET_NOTENOUGHMONEY)
        end
    end
    return true
end


Are you looking the output program to catch any error? Because the code that you pasted seems that not run correctly.

There is a if to check if the item exists. There is a lost else that executes "doPlayerSendCancel(cid, RET_NOTENOUGHMONEY)"

Maybe you need something like this:

Lua:
[CODE=lua]local boots = {

    [12671] = {id = 6132}

}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local lBoots = boots[item.itemid]
   
    if not lBoots then
        return false
    end
   
    doTransformItem(item.uid, boots[item.itemid].id)
    doSendMagicEffect(getCreaturePosition(cid),28)
    doPlayerSendTextMessage(cid,27,"You have successfully repaired your boots.")

    return true

end
 
Are you looking the output program to catch any error? Because the code that you pasted seems that not run correctly.

There is a if to check if the item exists. There is a lost else that executes "doPlayerSendCancel(cid, RET_NOTENOUGHMONEY)"

Maybe you need something like this:

Lua:
[CODE=lua]local boots = {

    [12671] = {id = 6132}

}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local lBoots = boots[item.itemid]
  
    if not lBoots then
        return false
    end
  
    doTransformItem(item.uid, boots[item.itemid].id)
    doSendMagicEffect(getCreaturePosition(cid),28)
    doPlayerSendTextMessage(cid,27,"You have successfully repaired your boots.")

    return true

end
Still doesn't work :/ No error in the console as well :(
 
Still doesn't work :/ No error in the console as well :(

What you need, 1 or 2?

1- A item, like a "obsidian knife", to use on your worn soft-boots and it will transform to a brand new soft-boots?
2 - Use a worn soft boots and it will transform to a brand new soft boots?

I searched on the declaration of doTransformItem(uid, newItemId). The first argument is the item to be transformed - worn soft-boots - the second one is the item that the first one will become - brand-new soft-boots.

On your code, you are calling doTransformItem() with the item that is being used on the first argument and the new item on the second (this looks right).
What is itemEx?

Try to make some debug-code to get more information here. As an example:

Lua:
[CODE=lua]local boots = {
    [12671] = {id = 6132}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local lBoots = boots[item.itemid]
 
    if not lBoots then
        print('lBoots is nil')
        return false
    end
   
    print('item id is ' .. item.itemid)
    print('fromPos is ' .. fromPosition)
    print('itemEx is ' .. itemEx)
    print('toPos is ' .. toPosition)
   
    doTransformItem(item.uid, boots[item.itemid].id)
    doSendMagicEffect(getCreaturePosition(cid),28)
    doPlayerSendTextMessage(cid,27,"You have successfully repaired your boots.")

    return true

end

You can search on action of obsidianKnife and the NPC which repairs worn soft-boots and get how these works. Maybe the solution for your script is a mix of them
 
What you need, 1 or 2?

1- A item, like a "obsidian knife", to use on your worn soft-boots and it will transform to a brand new soft-boots?
2 - Use a worn soft boots and it will transform to a brand new soft boots?

I searched on the declaration of doTransformItem(uid, newItemId). The first argument is the item to be transformed - worn soft-boots - the second one is the item that the first one will become - brand-new soft-boots.

On your code, you are calling doTransformItem() with the item that is being used on the first argument and the new item on the second (this looks right).
What is itemEx?

Try to make some debug-code to get more information here. As an example:

Lua:
[CODE=lua]local boots = {
    [12671] = {id = 6132}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local lBoots = boots[item.itemid]
 
    if not lBoots then
        print('lBoots is nil')
        return false
    end
  
    print('item id is ' .. item.itemid)
    print('fromPos is ' .. fromPosition)
    print('itemEx is ' .. itemEx)
    print('toPos is ' .. toPosition)
  
    doTransformItem(item.uid, boots[item.itemid].id)
    doSendMagicEffect(getCreaturePosition(cid),28)
    doPlayerSendTextMessage(cid,27,"You have successfully repaired your boots.")

    return true

end

You can search on action of obsidianKnife and the NPC which repairs worn soft-boots and get how these works. Maybe the solution for your script is a mix of them
I feel kinda stupid... I tried everything except using the item on myself and the script... kinda worked. I want to use the repair item on the boots and repair them. I also don't want the repair tool to disappear.

What happened now was that when I used the tool on my player the tool itself transformed into a new pair of soft boots and I kept the other pair.
 
I'm trying to create an item that when used repairs soft boots. I have this code:

actions/scripts/repairshoes.lua
Lua:
local boots = {
    [12671] = {id = 6132}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if boots[item.itemid] then
        doTransformItem(item.uid, boots[item.itemid].id)
        doSendMagicEffect(getCreaturePosition(cid),28)
        doPlayerSendTextMessage(cid,27,"You have successfully repaired your boots.")
        else
            doPlayerSendCancel(cid, RET_NOTENOUGHMONEY)
        end
    end
    return true
end

actions.xml
Code:
<action itemid="12671" event="script" value="repairshoes.lua"/>

But it won't work :/
Lua:
local config = {
    remove = true
}

config.boots = {
    [12671] = { newId = 6132, money = 1 }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isCreature(itemEx.uid) then
        return false
    end
    
    local val = config.boots[itemEx.itemid]
    if not val then
        return false
    end

    if val.money then
        if not doPlayerRemoveMoney(cid, val.money) then
            return doPlayerSendCancel(cid, RET_NOTENOUGHMONEY)
        end
    end

    if config.remove then
        doRemoveItem(item.uid, 1)
    end

    doTransformItem(itemEx.uid, val.newId, 1)
    doSendMagicEffect(getThingPosition(cid), 28)
    doPlayerSendTextMessage(cid, 27, "You have successfully repaired your boots.")
    return true
end
 
Lua:
local config = {
    remove = true
}

config.boots = {
    [12671] = { newId = 6132, money = 1 }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isCreature(itemEx.uid) then
        return false
    end
  
    local val = config.boots[itemEx.itemid]
    if not val then
        return false
    end

    if val.money then
        if not doPlayerRemoveMoney(cid, val.money) then
            return doPlayerSendCancel(cid, RET_NOTENOUGHMONEY)
        end
    end

    if config.remove then
        doRemoveItem(item.uid, 1)
    end

    doTransformItem(itemEx.uid, val.newId, 1)
    doSendMagicEffect(getThingPosition(cid), 28)
    doPlayerSendTextMessage(cid, 27, "You have successfully repaired your boots.")
    return true
end
Still doesn't work :( Using TSF 0.4 if that helps?
 
Still doesn't work :( Using TSF 0.4 if that helps?
Sorry, I misunderstood, I thought you wanted to use an item on the boots.

Lua:
local boots = {
    [12671] = { newId = 6132, money = 1 }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)   
    local val = boots[item.itemid]
    if not val then
        return false
    end

    if val.money then
        if not doPlayerRemoveMoney(cid, val.money) then
            return doPlayerSendCancel(cid, RET_NOTENOUGHMONEY)
        end
    end

    doTransformItem(item.uid, val.newId, 1)
    doSendMagicEffect(getThingPosition(cid), 28)
    doPlayerSendTextMessage(cid, 27, "You have successfully repaired your boots.")
    return true
end
 
Sorry, I misunderstood, I thought you wanted to use an item on the boots.

Lua:
local boots = {
    [12671] = { newId = 6132, money = 1 }
}

function onUse(cid, item, fromPosition, itemEx, toPosition) 
    local val = boots[item.itemid]
    if not val then
        return false
    end

    if val.money then
        if not doPlayerRemoveMoney(cid, val.money) then
            return doPlayerSendCancel(cid, RET_NOTENOUGHMONEY)
        end
    end

    doTransformItem(item.uid, val.newId, 1)
    doSendMagicEffect(getThingPosition(cid), 28)
    doPlayerSendTextMessage(cid, 27, "You have successfully repaired your boots.")
    return true
end
Yeah that's what I want :p I want to use a repair tool on the boots to recharge them. When I tried your latest script the repair tool just transformed to a new pair leaving me with 2 pair of boots :/

The script you posted first didn't do anything at all :(
 
Yeah that's what I want :p I want to use a repair tool on the boots to recharge them. When I tried your latest script the repair tool just transformed to a new pair leaving me with 2 pair of boots :/

The script you posted first didn't do anything at all :(
Use this script that was posted earlier.

In actions.xml put the item you want to use on the soft boots to repair them.
XML:
<action itemid="1111111" script="softboots_repair_item.lua" />
 
Tried it again, nothing happens at all with that script :/
Very strange.

Try this, then.
I've coded it from scratch for you.

change 111111 to the 'repair tool' you want to use.
XML:
<action itemid="111111" event="script" value="repairshoes.lua"/>
Lua:
local repaireableItems = {
    [12671] = {transformTo = 6132, successText = "You have successfully repaired your boots."}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isCreature(itemEx.uid) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "This tool cannot be used on creatures.")
        return true
    end
   
    local index = repaireableItems[itemEx.itemid]
    if not index then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "This item cannot be repaired with this tool.")
        return true
    end
   
    doTransformItem(itemEx.uid, index.transformTo)
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
    doPlayerSendTextMessage(cid, 27, index.successText)
    return true
end
 
Very strange.

Try this, then.
I've coded it from scratch for you.

change 111111 to the 'repair tool' you want to use.
XML:
<action itemid="111111" event="script" value="repairshoes.lua"/>
Lua:
local repaireableItems = {
    [12671] = {transformTo = 6132, successText = "You have successfully repaired your boots."}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isCreature(itemEx.uid) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "This tool cannot be used on creatures.")
        return true
    end
  
    local index = repaireableItems[itemEx.itemid]
    if not index then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "This item cannot be repaired with this tool.")
        return true
    end
  
    doTransformItem(itemEx.uid, index.transformTo)
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
    doPlayerSendTextMessage(cid, 27, index.successText)
    return true
end
Nothing happens when I use the tool on the boots :/ The "This tool cannot be used on creatures." message appears when using it on the player though.

I don't get the message "This item cannot be repaired with this tool." when using it on other objects.
 
Nothing happens when I use the tool on the boots :/ The "This tool cannot be used on creatures." message appears when using it on the player though.

I don't get the message "This item cannot be repaired with this tool." when using it on other objects.
Try
Lua:
local config = {
    remove = true
}

config.boots = {
    [12671] = { newId = 6132, money = 1 }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isCreature(itemEx.uid) then
        return false
    end
   
    local val = config.boots[itemEx.itemid]
    if not val then
        return false
    end

    if val.money then
        if not doPlayerRemoveMoney(cid, val.money) then
            return doPlayerSendCancel(cid, RET_NOTENOUGHMONEY)
        end
    end

    if config.remove then
        doRemoveItem(item.uid, 1)
    end

    doTransformItem(itemEx.uid, val.newId, 1)
    doSendMagicEffect(getThingPosition(cid), 28)
    doPlayerSendTextMessage(cid, 27, "You have successfully repaired your boots.")
    return true
end

actoins.xml

<action itemid="tool-id" event="script" value="repairshoes.lua"/>
 
Back
Top