• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Help with npc scripts

adamox223

New Member
Joined
Oct 21, 2017
Messages
100
Reaction score
4
Hi, i have one problem in npc scripts, can someone fix it? tfs 0.3.6

2cqbhfs.jpg


LUA:
-- Collecting items and monster missions by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)  npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid)  npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)  npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink()  npcHandler:eek:nThink() end

local missions = {
   [1] = {
     items = {
       {id = 8907, count = 1}
   
     },
     message = "Great, for your first mission you need to collect some items, I need",
     level = 100, -- minimum level voor this mission
     rewarditems = {
       {id = 2160, count = 1},
       {id = 1998, count = 1}
     },
     rewardexp = 1000000
   },
 
 
 
   [2] = {
     items = {
       {id = 2314, count = 25}
   
     },
     message = "Great, for your second mission you need to collect some items, I need",
     level = 125, -- minimum level voor this mission
     rewarditems = {
       {id = 2160, count = 1}
     },
     rewardexp = 1800000
   },
 
 
   [3] = {
     items = {
       {id = 2147, count = 5}
   
     },
     message = "Great, for your next mission you need to collect some items, I need",
     level = 150, -- minimum level voor this mission
     rewarditems = {
       {id = 2160, count = 3}
     },
     rewardexp = 2450000
   },
 
 
   [4] = {
     items = {
       {id = 2315, count = 25}
   
     },
     message = "Great, for your next mission you need to collect some items, I need",
     level = 175, -- minimum level voor this mission
     rewarditems = {
       {id = 2160, count = 4}
     },
     rewardexp = 3300000
   },
 
 
  [5] = {
     items = {
       {id = 8908, count = 1}
   
     },
     message = "Great, for your next mission you need to collect some items, I need",
     level = 200, -- minimum level voor this mission
     rewarditems = {
       {id = 2160, count = 5},
       {id = 1685, count = 5}
     },
     rewardexp = 3500000
   },
 
   [5] = {
     items = {
       {id = 2134, count = 1}
   
     },
     message = "Great, for your next mission you need to collect some items, I need",
     level = 225, -- minimum level voor this mission
     rewarditems = {
       {id = 2160, count = 6}
 
     },
     rewardexp = 4100000
   },
 
 
   [6] = {
     monsters = {
       {name = "Akatsuki Member", count = 200, storage = 21900}
   
     },
     message = "Thanks, for your next mission kill",
     level = 250,
     rewarditems = {
       {id = 2160, count = 7},
       {id = 3982, count = 1}
     },
     rewardexp = 4500000
   },
 
   [6] = {
     monsters = {
       {name = "Zetsu Clone", count = 250, storage = 21901}
   
     },
     message = "Thanks, for your next mission kill",
     level = 275,
     rewarditems = {
       {id = 2160, count = 8}

     },
     rewardexp = 4900000
   },
 
   [7] = {
     monsters = {
       {name = "Arena Bosses", count = 5, storage = 21902}
   
     },
     message = "Thanks, for your next mission kill",
     level = 300,
     rewarditems = {
       {id = 2160, count = 10},
       {id = 2146, count = 1}

     },
     rewardexp = 5500000
   }

}

local storage = 34689

local function getItemsMonstersFromTable(imtable)
     local text = ""
     for v = 1, #imtable do
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #imtable then
             ret = " and "
         end
         text = text .. ret
         count = imtable[v].count
         if imtable[v].id then
             info = ItemType(imtable[v].id)
             text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
         else
             text = text .. count .." "..imtable[v].name
         end
     end
     return text
end

function creatureSayCallback(cid, type, msg)
     if not npcHandler:isFocused(cid) then
         return false
     end

     local player = Player(cid)
     local x = missions[getPlayerStorageValue(storage)]

     if msgcontains(msg, 'mission') or msgcontains(msg, 'quest') then
         if getPlayerStorageValue(storage) == -1 then
             selfSay("I have some {mission} for you.", cid)
             npcHandler.topic[cid] = 1
         elseif x then
             if getPlayerLevel(cid) >= x.level then
                 selfSay("Did you "..(x.items and "get "..getItemsMonstersFromTable(x.items) or "kill "..getItemsMonstersFromTable(x.monsters)).."?", cid)
                 npcHandler.topic[cid] = 1
             else
                 selfSay("The mission I gave you is for level "..x.level..", come back later.", cid)
             end
         else
             selfSay("You already did all the missions, great job though.", cid)
             npcHandler:releaseFocus(cid)
         end
     elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
         if getPlayerStorageValue(storage) == -1 then
             setPlayerStorageValue(storage, 1)
             local x = missions[getPlayerStorageValue(storage)]
             selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
         elseif x then
             local imtable = x.items or x.monsters
             local amount = 0
             for it = 1, #imtable do
                 local check = x.items and getPlayerItemCount(imtable[it].id) or getPlayerStorageValue(imtable[it].storage)
                 if check >= imtable[it].count then
                     amount = amount + 1
                 end
             end
             if amount == #imtable then
                 if x.items then
                     for it = 1, #x.items do
                         player:removeItem(x.items[it].id, x.items[it].count)
                     end
                 end
                 if x.rewarditems then
                     for r = 1, #x.rewarditems do
                         doPlayerAddItem(x.rewarditems[r].id, x.rewarditems[r].count)
                     end
                     doPlayerSendTextMessage(MESSAGE_EVENT_DEFAULT, "You received "..getItemsMonstersFromTable(x.rewarditems)..".")
                 end
                 if x.rewardexp then
                     doPlayerAddExp(x.rewardexp)
                     doPlayerSendTextMessage(MESSAGE_EVENT_DEFAULT, "You received "..x.rewardexp.." experience.")
                 end
                 setPlayerStorageValue(storage, getPlayerStorageValue(storage) + 1)
                 local x = missions[getPlayerStorageValue(storage)]
                 if x then
                     selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
                 else
                     selfSay("Well done! You did a great job on all your missions.", cid)
                 end
             else
                 local n = 0
                 for i = 1, #imtable do
                     local check = x.items and getPlayerItemCount(imtable[I].id) or getPlayerStorageValue(imtable[I].storage)
                     if check < imtable[I].count then
                         n = n + 1
                     end
                 end
                 local text = ""
                 local c = 0
                 for v = 1, #imtable do
                     local check = x.items and getPlayerItemCount(imtable[v].id) or getPlayerStorageValue(imtable[v].storage)
                     if check < imtable[v].count then
                         c = c + 1
                         local ret = ", "
                         if c == 1 then
                             ret = ""
                         elseif c == n then
                             ret = " and "
                         end
                         text = text .. ret
                         if x.items then
                             local count, info = imtable[v].count - getPlayerItemCount(imtable[v].id), ItemType(imtable[v].id)
                             text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
                         else
                             local count = imtable[v].count - (getPlayerStorageValue(imtable[v].storage) + 1)
                             text = text .. count.." "..imtable[v].name
                         end
                     end
                 end
                 selfSay(x.items and "You don't have all items, you still need to get "..text.."." or "You didn't kill all monsters, you still need to kill "..text..".", cid)
             end
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
         selfSay("Oh well, I guess not then.", cid)
         npcHandler.topic[cid] = 0
     end
     return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, have a nice day!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
[/I][/I][/I]
 
Last edited by a moderator:
Back
Top