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

(tfs 1.3 ) help in npc.

EduardoQuintela

New Member
Joined
Mar 10, 2014
Messages
27
Reaction score
1
Hello community,

I have a npc script that works normally. basically an npc to exchange items. help me to add that the script verifies the vocation of the player to make the exchange, remembering that one or more vocations could exchange the same item. Thank you

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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
local c = {
   ["coin"] = {
     id = 7888,
     items = {    {id = 2132, count = 1}    }
   },
   ["paper"] = {
     id = 7896,
     items = {
       {id = 2131, count = 1}   }
   },
   ["water"] = {
     id = 7902,
     items = { {id = 2130, count = 1}   }
   },
   ["fruit"] = {
     id = 7890,
     items = { {id = 2129, count = 1}   }
   },
   ["spear"] = {
     id = 7903,
     items = { {id = 2133, count = 1}   }
   } 
}
local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, getItemDescriptions(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
     end
     return text
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
     local player = Player(cid)
     local x = c[msg:lower()]
     if x then
         selfSay("You have "..getItemsFromTable(x.items).."?...", cid)
         talkState[talkUser] = 1
         xmsg = msg
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         x = c[xmsg:lower()]
         local n = 0
         for z = 1, #x.items do
             if player:getItemCount(x.items[z].id) >= x.items[z].count then
                 n = n + 1
             end
         end
         if n == #x.items then
             for r = 1, #x.items do
                 player:removeItem(x.items[r].id, x.items[r].count)
             end
             player:addItem(x.id, 1)
         else
             selfSay("You dont have item.", cid)
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         selfSay("Ok.", cid)
         talkState[talkUser] = 0
     end
     return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
And which vocation should exchange what? You need to be more specific, I add the vocation check, easy, and what do I need to do with it? Limit certain items to certain vocations or what?
 
Back
Top