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

Solved NPC Repair equipment

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
583
Solutions
2
Reaction score
60
Location
México
Hello otlanders, i got a durability system (TFS 0.X - durability system), when durability is 0 the item breaks and transform the item to itemid = 2256 (metal trash) but sets the name of the broken item:
example:
Lua:
You see dragon hammer.
It weighs 3.00 oz.
ItemID: [2256].

So i need a NPC that repair items (id 2256) in backpack or equipped. at the moment this is what i got, but im a little trapped, when i try to repair all equip, script stops when left weapon is repaired x.x
this is the script for tfs .4

Edit2: I was working on and reach this point, npc repair the equip, but, if the equip is not damaged (have not fought with it) and you ask for a repair, then transform to id = 0(a red/black square) :S

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local charge_price = 50 -- preço por carga em gps. 
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if msgcontains(msg, 'repair all') then
    lefthand = (getItemAttribute(getPlayerSlotItem(cid, CONST_SLOT_LEFT).uid, "name"))
    doTransformItem(getPlayerSlotItem(cid, CONST_SLOT_LEFT).uid, getItemIdByName(lefthand))
    doItemSetAttribute(getPlayerSlotItem(cid, CONST_SLOT_LEFT).uid, "Durability", "Durability: 100/100")
    doItemSetAttribute(getPlayerSlotItem(cid, CONST_SLOT_LEFT).uid , "description","Durability: 100/100")
    righthand = (getItemAttribute(getPlayerSlotItem(cid, CONST_SLOT_RIGHT).uid, "name"))
    doTransformItem(getPlayerSlotItem(cid, CONST_SLOT_RIGHT).uid, getItemIdByName(righthand))
    doItemSetAttribute(getPlayerSlotItem(cid, CONST_SLOT_RIGHT).uid, "Durability", "Durability: 100/100")
    doItemSetAttribute(getPlayerSlotItem(cid, CONST_SLOT_RIGHT).uid , "description","Durability: 100/100")
    head = (getItemAttribute(getPlayerSlotItem(cid, CONST_SLOT_HEAD).uid, "name"))
    doTransformItem(getPlayerSlotItem(cid, CONST_SLOT_HEAD).uid, getItemIdByName(head))
    doItemSetAttribute(getPlayerSlotItem(cid, CONST_SLOT_HEAD).uid, "Durability", "Durability: 100/100")
    doItemSetAttribute(getPlayerSlotItem(cid, CONST_SLOT_HEAD).uid , "description","Durability: 100/100")
    local getArmor = (getItemAttribute(getPlayerSlotItem(cid, CONST_SLOT_ARMOR).uid, "name"))
    doTransformItem(getPlayerSlotItem(cid, CONST_SLOT_ARMOR).uid, getItemIdByName(getArmor))
    doItemSetAttribute(getPlayerSlotItem(cid, CONST_SLOT_ARMOR).uid, "Durability", "Durability: 100/100") 
    doItemSetAttribute(getPlayerSlotItem(cid, CONST_SLOT_ARMOR).uid , "description","Durability: 100/100")
    legs = (getItemAttribute(getPlayerSlotItem(cid, CONST_SLOT_LEGS).uid, "name"))
    doTransformItem(getPlayerSlotItem(cid, CONST_SLOT_LEGS).uid, getItemIdByName(legs))
    doItemSetAttribute(getPlayerSlotItem(cid, CONST_SLOT_LEGS).uid, "Durability", "Durability: 100/100")
    doItemSetAttribute(getPlayerSlotItem(cid, CONST_SLOT_LEGS).uid , "description","Durability: 100/100")
    feet = (getItemAttribute(getPlayerSlotItem(cid, CONST_SLOT_FEET).uid, "name"))
    doTransformItem(getPlayerSlotItem(cid, CONST_SLOT_FEET).uid, getItemIdByName(feet))
    doItemSetAttribute(getPlayerSlotItem(cid, CONST_SLOT_FEET).uid, "Durability", "Durability: 100/100")
    doItemSetAttribute(getPlayerSlotItem(cid, CONST_SLOT_FEET).uid , "description","Durability: 100/100")
            selfSay("Okay, i've fixed your damaged weapon.", cid)
end
if msgcontains(msg, 'repair weapon') then
    selfSay("Which weapon would you like to repair, {left} or {right}?.", cid)   
        elseif msgcontains(msg, 'left') then
            if getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == 2256  then
                selfSay("Okay, i've fixed your damaged weapon.", cid)   
                print(1)
                lefthand = (getItemAttribute(getPlayerSlotItem(cid, CONST_SLOT_LEFT).uid, "name"))
                doRemoveItem(getPlayerSlotItem(cid, CONST_SLOT_LEFT).uid, 1)
                doPlayerAddItem(cid, getItemIdByName(lefthand), 1)
            else
                selfSay("You do not have any weapon in left hands.", cid)       
            end
        elseif msgcontains(msg, 'right') then
            if getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == 2256  then
                selfSay("Okay, i've fixed your damaged weapon.", cid)
            print(1)
                righthand = (getItemAttribute(getPlayerSlotItem(cid, CONST_SLOT_RIGHT).uid, "name"))
                doRemoveItem(getPlayerSlotItem(cid, CONST_SLOT_RIGHT).uid, 1)
                doPlayerAddItem(cid, getItemIdByName(righthand), 1)
                else
                selfSay("You do not have any weapon in your right hand.", cid)   
            end
   
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Solution
Hmmm..Try this one out? XD
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local charge_price = 50 -- preço por carga em gps.
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if msgcontains(msg, 'repair all') then
    if...
lol found the solution, these are some of the situations i will never understand when i make variables:
This was the solution; i added
Lua:
feet = (getItemAttribute(getPlayerSlotItem(cid, CONST_SLOT_FEET).uid, "name")) <--the variable above each doTransformItem
doTransformItem(getPlayerSlotItem(cid, CONST_SLOT_FEET).uid, getItemIdByName(feet)) <-- the item was not being reed bc i did not add the line of above, but it was already on the beginning of script x.x well. its fixed
 
lol found the solution, these are some of the situations i will never understand when i make variables:
This was the solution; i added
Lua:
feet = (getItemAttribute(getPlayerSlotItem(cid, CONST_SLOT_FEET).uid, "name")) <--the variable above each doTransformItem
doTransformItem(getPlayerSlotItem(cid, CONST_SLOT_FEET).uid, getItemIdByName(feet)) <-- the item was not being reed bc i did not add the line of above, but it was already on the beginning of script x.x well. its fixed
Oh, I didn't touch the single repairs when I gave you the script.
Thing is, this var:
Code:
feet = (getItemAttribute(getPlayerSlotItem(cid, CONST_SLOT_FEET).uid, "name"))
Is only retrieving the Item name, for example: Leather Boots

And then this one:
Code:
doTransformItem(getPlayerSlotItem(cid, CONST_SLOT_FEET).uid, getItemIdByName(feet))
Is trying to get an ID based on a Name. Which you already retrieved in the var above, so you pass the parameter 'feet' to the function. Also, it's telling to transform the item that's on the feet slot. That's why you write it two times, one is retrieving it's name, the other one is telling the transform item function in which slot it's the item it has to look for
 
Back
Top