NPC Collecting items missions

70011983

Ners
Joined
Nov 21, 2011
Messages
354
Best answers
1
Reaction score
51
Location
Croatia
If instead doPlayerSendTextMessage I put doCreatureSay it debugs, why?
Using 8,54
 

Eldin

Eldin Projects
Premium User
Joined
Jun 12, 2008
Messages
1,304
Best answers
0
Reaction score
534
Location
Sweden
Might use it on my TFS 1.0, should be possible as it works for 0.2.

Kind Regards,
Eldin.
 

70011983

Ners
Joined
Nov 21, 2011
Messages
354
Best answers
1
Reaction score
51
Location
Croatia
Oh well, nevermind fixed it, wrote it like this:
doCreatureSay(cid, "You received "..x.rewardexp.." experience.", TALKTYPE_ORANGE_1, cid)
and now it works, I think I forgot to write the last 'cid'
 
OP
Limos

Limos

Premium User
Joined
Jun 7, 2010
Messages
10,018
Best answers
7
Reaction score
2,959
Location
Netherlands
Yes, should also work on TFS 1.0 (It's tested on TFS 0.2).
 
OP
Limos

Limos

Premium User
Joined
Jun 7, 2010
Messages
10,018
Best answers
7
Reaction score
2,959
Location
Netherlands
You can add it above or under this line (between else and end).
Code:
selfSay("Thanks alot! I can finish my research now.", cid)
You can use doPlayerAddOutfit to add the addon (1, 2 or 3 for both addons).
Code:
doPlayerAddOutfit(cid, looktype, addons)
If you use TFS 0.3/0.4, you can also use
Code:
doPlayerAddOutfitId(cid, outfitId, addons)
 

jogui1

Server developer
Joined
Feb 13, 2009
Messages
107
Best answers
0
Reaction score
12
Hey maybe a stupid question but how do i make him reward more than 1 items of diffrent kinds?
 
OP
Limos

Limos

Premium User
Joined
Jun 7, 2010
Messages
10,018
Best answers
7
Reaction score
2,959
Location
Netherlands
Change rewarditem to a table with more tables like items.
Code:
rewarditem = {
   {id = 2160, count = 1},
   {id = 2112, count = 1}
}
Then to add the item, use a loop just like with items.
Code:
for r = 1, #x.rewarditem do
     doPlayerAddItem(cid, x.rewarditem[r].id, x.rewarditem[r].count)
end
For the textmessage you can use the function getItemsFromTable to get the items a player received in the textmessage.
Code:
doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..getItemsFromTable(x.rewarditem)..".")
 

therrax

Member
Joined
Jul 12, 2012
Messages
258
Best answers
1
Reaction score
8
@Limos
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/itemsmissions.lua:onCreatureSay
data/npc/scripts/itemsmissions.lua:152: attempt to call global 'getItemInfo' (a
nil value)
stack traceback:
        [C]: in function 'getItemInfo'
        data/npc/scripts/itemsmissions.lua:152: in function 'getItemsFromTable'
        data/npc/scripts/itemsmissions.lua:195: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:393: in function 'onCreatureSay'
        data/npc/scripts/itemsmissions.lua:10: in function <data/npc/scripts/ite
msmissions.lua:10>
Could You convert it for TFS 1.0?
 

StreamSide

Joseluis Gonzalez
Support Team
Joined
Aug 31, 2007
Messages
3,352
Best answers
34
Reaction score
852
Location
Arica - Chile
@Limos
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/itemsmissions.lua:onCreatureSay
data/npc/scripts/itemsmissions.lua:152: attempt to call global 'getItemInfo' (a
nil value)
stack traceback:
        [C]: in function 'getItemInfo'
        data/npc/scripts/itemsmissions.lua:152: in function 'getItemsFromTable'
        data/npc/scripts/itemsmissions.lua:195: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:393: in function 'onCreatureSay'
        data/npc/scripts/itemsmissions.lua:10: in function <data/npc/scripts/ite
msmissions.lua:10>
Could You convert it for TFS 1.0?
try doing it by urself, is not hard just take a look at mod&functions subforum and play with the info :rolleyes:
 
OP
Limos

Limos

Premium User
Joined
Jun 7, 2010
Messages
10,018
Best answers
7
Reaction score
2,959
Location
Netherlands
@Limos
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/itemsmissions.lua:onCreatureSay
data/npc/scripts/itemsmissions.lua:152: attempt to call global 'getItemInfo' (a
nil value)
stack traceback:
        [C]: in function 'getItemInfo'
        data/npc/scripts/itemsmissions.lua:152: in function 'getItemsFromTable'
        data/npc/scripts/itemsmissions.lua:195: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:393: in function 'onCreatureSay'
        data/npc/scripts/itemsmissions.lua:10: in function <data/npc/scripts/ite
msmissions.lua:10>
Could You convert it for TFS 1.0?
Add this in global.lua or at the bottom of compat.lua.
Code:
getItemInfo = getItemDescriptions
 

therrax

Member
Joined
Jul 12, 2012
Messages
258
Best answers
1
Reaction score
8
Thanks :) I dont have errors but I dont get rewards, could You take a look on my script?
Code:
-- Collecting items missions by Limos
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 missions = {
   [1] = {items = {
     {id = 5890, count = 12},
     {id = 5878, count = 20},
     {id = 5896, count = 15},
     {id = 5902, count = 21},
     {id = 5897, count = 35},
     {id = 5894, count = 8}
     },
     message = "Wspaniale! Za kazda misje bedziesz otrzymywal ciekawe nagrody. Przynies mi:",
     level = 80, -- minimum level voor this mission
     rewarditem = {
   {id = 8300, count = 5},
   {id = 8299, count = 5}
},
     rewardexp = 150000
   },
   [2] = {items = {
     {id = 6500, count = 400},
     {id = 5925, count = 50},
     {id = 5922, count = 15},
     {id = 6098, count = 40}
     },
     message = "Dzieki! Potrzebuje teraz:",
     level = 100,
     rewarditem = {id = 6527, count = 5},
     rewardexp = 300000
   },
   [3] = {items = {
     {id = 5909, count = 52},
     {id = 5910, count = 44},
     {id = 5911, count = 45},
     {id = 5912, count = 48},
     {id = 5913, count = 42}
     },
     message = "Jestes niezly, teraz potrzebne:",
     level = 150,
     rewarditem = {id = 6527, count = 10},
     rewardexp = 450000
   },
   [4] = {items = {
     {id = 5809, count = 3},
     {id = 5884, count = 1},
     {id = 5804, count = 1}
     },
     message = "Super! Ale to nie koniec, potrzebuje:",
     level = 180,
     rewarditem = {id = 6527, count = 15},
     rewardexp = 700000
   },
   [5] = {items = {
     {id = 5880, count = 100},
     {id = 5895, count = 100},
     {id = 5015, count = 1},
     {id = 5879, count = 50},
     {id = 4850, count = 1}
     },
     message = "Brawo jestes na serio niezly. Zostalo jeszcze kilka misji:",
     level = 220,
     rewarditem = {
   {id = 9020, count = 2},
   {id = 6527, count = 15}
},
     rewardexp = 950000
   },
      [6] = {items = {
     {id = 5906, count = 100},
     {id = 5882, count = 100},
     {id = 5893, count = 80},
     {id = 5743, count = 60},
     {id = 3967, count = 1}
     },
     message = "Zrobiles na mnie wrazenie. Nasze spotkania niedlugo dobiegna konca. Przynies dla mnie:",
     level = 270,
     rewarditem = {
   {id = 9020, count = 4},
   {id = 6527, count = 25}
},
     rewardexp = 1450000
   },
      [7] = {items = {
     {id = 5954, count = 100},
     {id = 5919, count = 3},
     {id = 5891, count = 100},
     {id = 5943, count = 1}
     },
     message = "Nie wierzylem ze to dostane! Zostaly 3 misje!",
     level = 330,
     rewarditem = {
   {id = 9020, count = 6},
   {id = 6527, count = 55}
},
     rewardexp = 1950000
   },
      [8] = {items = {
     {id = 2151, count = 2000},
     {id = 6500, count = 1000},
     {id = 5808, count = 1},
     {id = 2160, count = 100}
     },
     message = "Przeszedles samego siebie. Teraz najwazniejsze misje dla moich badan! Potrzebne:",
     level = 400,
     rewarditem = {
   {id = 9020, count = 6},
   {id = 6527, count = 85}
},
     rewardexp = 2250000
   },
      [9] = {items = {
     {id = 5903, count = 2},
     {id = 15481, count = 100},
     {id = 15483, count = 100},
     {id = 2160, count = 500},
     {id = 15486, count = 100}
     },
     message = "To juz moje prawie ostatnie badania, jak juz pewnie zauwazyles sa bardzo kosztowne.. Dlatego tez prosilbym Cie o silne wsparcie finansowe oraz o przyniesienie tego:",
     level = 500,
     rewarditem = {
   {id = 9020, count = 6},
   {id = 6527, count = 105}
},
     rewardexp = 350000
   },
      [10] = {items = {
     {id = 2361, count = 15},
     {id = 6566, count = 3},
     {id = 5944, count = 100},
     {id = 2153, count = 1},
     {id = 2154, count = 1},
     {id = 2156, count = 1},
     {id = 1970, count = 1},
     {id = 2160, count = 1000},
     {id = 2156, count = 1}
     },
     message = "W zyciu poswiecilem wszystko by to skonczyc prosze nie zawiedz mnie, zostalo mi tak niewiele.. Weteranie, przynieś mi:",
     level = 600,
     rewarditem = {
   {id = 9020, count = 6},
   {id = 6527, count = 155}
},
     rewardexp = 10000000
   }
}

local storage = 45550

local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, getItemInfo(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " i "
         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)

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     local xstorage = getPlayerStorageValue(cid, storage)
     local x = missions[xstorage]

     if not npcHandler:isFocused(cid) then
         return false
     end

     if msgcontains(msg, 'misja') then
         if xstorage == -1 then
             selfSay("Jestem badaczem, przeprowadzam rozne eksperymenty, chcialbys dla mnie troche popracowac?", cid)
             talkState[talkUser] = 1
         elseif x then
             if getPlayerLevel(cid) >= x.level then
                 selfSay("Zdobyles dla mnie {przedmioty} o ktore Cie prosilem?", cid)
                 talkState[talkUser] = 1
             else
                 selfSay("Misja jest dla poziomu "..x.level..", odwiedz mnie pozniej..", cid)
             end
         else
             selfSay("Dzieki znowu za przedmioty, duzo mi pomoga!", cid)
             npcHandler:releaseFocus(cid)
         end
     elseif msgcontains(msg, 'tak') and talkState[talkUser] == 1 then
         if xstorage == -1 then
             setPlayerStorageValue(cid, storage, 1)
             local x = missions[getPlayerStorageValue(cid, storage)]
             selfSay(x.message.." "..getItemsFromTable(x.items)..".", cid)
         elseif x then
             local amount = 0
             for i = 1, #x.items do
                 if getPlayerItemCount(cid, x.items[i].id) >= x.items[i].count then
                     amount = amount + 1
                 end
             end
             if amount == #x.items then
                 for i = 1, #x.items do
                     doPlayerRemoveItem(cid, x.items[i].id, x.items[i].count)
                 end
                 if x.rewarditem then
                     local count, info = x.rewarditem.count, getItemInfo(x.rewarditem.id)
                     for r = 1, #x.rewarditem do
     doPlayerAddItem(cid, x.rewarditem[r].id, x.rewarditem[r].count)
end
                     doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "otrzymujesz: "..getItemsFromTable(x.rewarditem)..".")
                 end
                 if x.rewardexp then
                     doPlayerAddExp(cid, x.rewardexp)
                     doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Zyskales: "..x.rewardexp.." XP.")
                 end
                 setPlayerStorageValue(cid, storage, xstorage + 1)
                 local x = missions[getPlayerStorageValue(cid, storage)]
                 if x then
                     selfSay(x.message.." "..getItemsFromTable(x.items)..".", cid)
                 else
                     selfSay("Dziekuje Ci za wszystko przyjacielu, dzieki Tobie zakonczylem swoje badania!", cid)
                 end
             else
                 local n = 0
                 for i = 1, #x.items do
                     if getPlayerItemCount(cid, x.items[i].id) < x.items[i].count then
                         n = n + 1
                     end
                 end
                 local text = ""
                 local c = 0
                 for v = 1, #x.items do
                     count, info = x.items[v].count - getPlayerItemCount(cid, x.items[v].id), getItemInfo(x.items[v].id)
                     if getPlayerItemCount(cid, x.items[v].id) < x.items[v].count then
                         c = c + 1
                         local ret = ", "
                         if c == 1 then
                             ret = ""
                         elseif c == n 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
                 end
                 selfSay("Nie masz przedmiotow.. Miales zebrac: "..text..".", cid)
             end
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, 'items') and x then
         selfSay("Przedmioty o które pytalem to: "..getItemsFromTable(x.items)..".", cid)
     elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
         selfSay("Ja Cie do niczego nie zmusze...", cid)
     end
     return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, "Zegnaj!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "A dowidzenia? Tak myslalem... Brudasie...")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
OP
Limos

Limos

Premium User
Joined
Jun 7, 2010
Messages
10,018
Best answers
7
Reaction score
2,959
Location
Netherlands
Remove this
Code:
local count, info = x.rewarditem.count, getItemInfo(x.rewarditem.id)
 

therrax

Member
Joined
Jul 12, 2012
Messages
258
Best answers
1
Reaction score
8
I removed this, I dont have errors but I still dont get rewards :p
 

therrax

Member
Joined
Jul 12, 2012
Messages
258
Best answers
1
Reaction score
8
Ok, I had use It in new character. Thanks Limos! ;)
 

imback1

Unknown member
Joined
Jul 11, 2013
Messages
776
Best answers
1
Reaction score
43
Tested with TFS 0.3.6pl1 8.54 and TFS 0.2.14 9.6



Mitrox.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Mitrox" script="itemsmissions.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="130" head="57" body="114" legs="95" feet="119" addons="0"/>
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|."/>
    </parameters>
</npc>


itemsmissions.lua
Code:
-- Collecting items missions by Limos
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 missions = {
   [1] = {items = {
     {id = 5890, count = 12},
     {id = 5878, count = 20},
     {id = 5896, count = 15},
     {id = 5902, count = 21},
     {id = 5897, count = 35},
     {id = 5894, count = 8}
     },
     message = "Great, I need alot of items, but you can start with",
     level = 15, -- minimum level voor this mission
     rewarditem = {id = 2160, count = 1},
     rewardexp = 15000
   },
   [2] = {items = {
     {id = 5898, count = 20},
     {id = 5921, count = 28},
     {id = 5899, count = 15},
     {id = 5905, count = 25},
     {id = 6097, count = 35},
     {id = 6098, count = 26}
     },
     message = "Thank you, the next items are",
     level = 30,
     rewarditem = {id = 2160, count = 5},
     rewardexp = 40000
   },
   [3] = {items = {
     {id = 5920, count = 45},
     {id = 5879, count = 30},
     {id = 5881, count = 15},
     {id = 5876, count = 18},
     {id = 5877, count = 22}
     },
     message = "Awesome, now get",
     level = 50,
     rewarditem = {id = 2160, count = 15},
     rewardexp = 100000
   },
   [4] = {items = {
     {id = 5913, count = 20},
     {id = 5909, count = 42},
     {id = 5914, count = 38},
     {id = 5911, count = 25},
     {id = 5912, count = 10},
     {id = 5910, count = 10}
     },
     message = "Thanks, now I need",
     level = 70,
     rewarditem = {id = 2160, count = 25},
     rewardexp = 200000
   },
   [5] = {items = {
     {id = 5906, count = 35},
     {id = 5882, count = 42},
     {id = 5893, count = 28},
     {id = 5948, count = 32},
     {id = 5954, count = 22},
     {id = 4850, count = 1}
     },
     message = "Good, only a few items left,",
     level = 100,
     rewarditem = {id = 2160, count = 50},
     rewardexp = 450000
   }
}

local storage = 45550

local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, getItemInfo(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)

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     local xstorage = getPlayerStorageValue(cid, storage)
     local x = missions[xstorage]

     if not npcHandler:isFocused(cid) then
         return false
     end

     if msgcontains(msg, 'mission') then
         if xstorage == -1 then
             selfSay("I am a scientist and I am currently doing some research, do you think you can help me out?", cid)
             talkState[talkUser] = 1
         elseif x then
             if getPlayerLevel(cid) >= x.level then
                 selfSay("Did you get the {items} I asked you?", cid)
                 talkState[talkUser] = 1
             else
                 selfSay("The mission I gave you is for level "..x.level..", come back later.", cid)
             end
         else
             selfSay("Thanks again for all your items, it helped me alot.", cid)
             npcHandler:releaseFocus(cid)
         end
     elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
         if xstorage == -1 then
             setPlayerStorageValue(cid, storage, 1)
             local x = missions[getPlayerStorageValue(cid, storage)]
             selfSay(x.message.." "..getItemsFromTable(x.items)..".", cid)
         elseif x then
             local amount = 0
             for i = 1, #x.items do
                 if getPlayerItemCount(cid, x.items[i].id) >= x.items[i].count then
                     amount = amount + 1
                 end
             end
             if amount == #x.items then
                 for i = 1, #x.items do
                     doPlayerRemoveItem(cid, x.items[i].id, x.items[i].count)
                 end
                 if x.rewarditem then
                     local count, info = x.rewarditem.count, getItemInfo(x.rewarditem.id)
                     doPlayerAddItem(cid, x.rewarditem.id, count)
                     doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..(count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)..".")
                 end
                 if x.rewardexp then
                     doPlayerAddExp(cid, x.rewardexp)
                     doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..x.rewardexp.." experience.")
                 end
                 setPlayerStorageValue(cid, storage, xstorage + 1)
                 local x = missions[getPlayerStorageValue(cid, storage)]
                 if x then
                     selfSay(x.message.." "..getItemsFromTable(x.items)..".", cid)
                 else
                     selfSay("Thanks alot! I can finish my research now.", cid)
                 end
             else
                 local n = 0
                 for i = 1, #x.items do
                     if getPlayerItemCount(cid, x.items[i].id) < x.items[i].count then
                         n = n + 1
                     end
                 end
                 local text = ""
                 local c = 0
                 for v = 1, #x.items do
                     count, info = x.items[v].count - getPlayerItemCount(cid, x.items[v].id), getItemInfo(x.items[v].id)
                     if getPlayerItemCount(cid, x.items[v].id) < x.items[v].count then
                         c = c + 1
                         local ret = ", "
                         if c == 1 then
                             ret = ""
                         elseif c == n 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
                 end
                 selfSay("You don't have all items, you still need to get "..text..".", cid)
             end
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, 'items') and x then
         selfSay("The items I asked you are "..getItemsFromTable(x.items)..".", cid)
     elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
         selfSay("Oh well, I guess not then.", cid)
     end
     return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Bye? I guess...")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())



You can remove those lines if you don't want a rewarditem or exp for a certain mission.
Code:
rewarditem = {id = 2160, count = 1}
rewardexp = 15000


How does it work:

The NPC gives missions to collect items, it will start with the first mission.


If you don't have all items, the NPC will tell you which items are still missing.
If you want to know the items from your current mission, you can ask what they are by saying items.


If you have all the items the NPC asked, the items will be removed, you will get the reward and the NPC will give you the next mission.


If you finished the last mission the NPC will thank you, give you the reward of the last mission, remove the items and then it's done.


The amount of missions, items, level, rewards and the storage are as example, you can change this in local missions and local storage.

If you use TFS 0.2 (Mystic Spirit), change script="itemsmissions.lua" to script="data/npc/scripts/itemsmissions.lua" and add this in global.lua.
Code:
getItemInfo = getItemDescriptions
Report bugs.
Also feel free to give suggestions or to ask questions.
00:15 Mitrox: Thanks again for all your items, it helped me alot.
i made these missions (5) ,is it once for character? if it is may you make it once a day for each character
 
Top