• 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 NPC CHANGE ITEM. tfs 1.3

EduardoQuintela

New Member
Joined
Mar 10, 2014
Messages
27
Reaction score
1
Hello community,
I want to add in my script that npc only perform the change if the player has any of the specified vocations.

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 = {
   ["item1"] = {
     id = 0,
     items = {    {id = 7896, count = 1}    }
   },
   ["item2"] = {
     id = 7888,
     items = {    {id = 2132, count = 1}    }
   },
   ["item3"] = {
     id = 7896,
     items = {
       {id = 2131, count = 1}   }
   },
   ["item4"] = {
     id = 7902,
     items = { {id = 2130, count = 1}   }
   },
   ["item5"] = {
     id = 7890,
     items = { {id = 2129, count = 1}   }
   },
   ["item6"] = {
     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())
 
Back
Top Bottom