Hello please comments! It my first npc... NPC ADDONER! For citizen addon backpack
I used the time lock... Like tibia.com
I used the time lock... Like tibia.com
CITIZEN
Backpack addon
Backpack addon
Code:
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
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 storage = getPlayerStorageValue(cid, 30000)
if msgcontains(msg, "minotaur leather") then
if storage == 2 then
npcHandler:say("Well, if you really like this backpack, I could make one for you, but minotaur leather is hard to come by these days. Are you willing to put some work into this?", cid)
setPlayerStorageValue(cid, 30000, 3)
end
end
talkState[talkUser] = 2
if msgcontains(msg, "yes") then
if storage == 3 then
npcHandler:say("Alright then, if you bring me 100 pieces of fine minotaur leather I will see what I can do for you. You probably have to kill really many minotaurs though... so good luck!", cid)
setPlayerStorageValue(cid, 30000, 4)
end
end
talkState[talkUser] = 3
if msgcontains(msg, "addon") and getPlayerStorageValue(cid, 30000) == 4 then
npcHandler:say("Ah, right, almost forgot about the backpack! Have you brought me 100 pieces of minotaur leather as requested?", cid)
setPlayerStorageValue(cid, 30000, 5)
end
talkState[talkUser] = 4
local block, duration = 30003, 7200
if msgcontains(msg, "yes") and getPlayerStorageValue(cid, 30000) == 5 and talkState[talkUser] == 4 then
if doPlayerRemoveItem(cid,5878,100) then
npcHandler:say("Great! Alright, I need a while to finish this backpack for you. Come ask me later, okay?", cid)
setPlayerStorageValue(cid, 30000, 6)
setPlayerStorageValue(cid, block, os.time())
else
npcHandler:say("You do not have 100 minotaur leathers.", cid)
setPlayerStorageValue(cid, 30000, 4)
if getPlayerItemCount(cid,5878) >= 100 then
end
end
end
talkState[talkUser] = 5
if msgcontains(msg, "addon") and getPlayerStorageValue(cid, 30000) == 6 and talkState[talkUser] == 5 then
if (os.time() - getPlayerStorageValue(cid, block)) >= duration then
npcHandler:say("Just in time! Your backpack is finished. Here you go, I hope you like it.", cid)
doSendMagicEffect(getCreaturePosition(cid), 13)
setPlayerStorageValue(cid, 30000, 7)
doPlayerAddOutfit(cid, 128, 1)
doPlayerAddOutfit(cid, 136, 1)
doSendMagicEffect(getCreaturePosition(cid), 13)
talkState[talkUser] = 6
else
npcHandler:say("I'm not finished, come back later.", cid)
end
end
return true
end
addon = 30000
function talk(cid, message, keywords, parameters, node)
if(not npcHandler:isFocused(cid)) then
return false
end
if isPremium(cid) then
storg = getPlayerStorageValue(cid,addon)
if storg == -1 then
npcHandler:say("Sorry, the backpack I wear is not for sale. It's handmade from rare minotaur leather.", cid)
setPlayerStorageValue(cid,addon,1)
setPlayerStorageValue(cid,30000,2)
end
else
npcHandler:say("Sorry, you don\'t have premium time.", cid)
end
end
node1 = keywordHandler:addKeyword({'addon'}, talk, {})
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Hat addon
Code:
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
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, "yes") and getPlayerStorageValue(cid, 30001) == 2 then
npcHandler:say("Okay, here we go, listen closely! I need a few things... a basic hat of course, maybe a legion helmet would do. Then about 100 chicken feathers... and 50 honeycombs as glue. That's it, come back to me once you gathered it!", cid)
setPlayerStorageValue(cid, 30001, 3)
end
talkState[talkUser] = 2
if msgcontains(msg, "legion") and getPlayerStorageValue(cid, 30001) == 3 and talkState[talkUser] == 2 then
if getPlayerItemCount(cid,2480) >= 1 then
npcHandler:say("Oh, you bring legion helmet?", cid)
setPlayerStorageValue(cid, 30001, 4)
else
npcHandler:say("You do not have legion helmet.", cid)
setPlayerStorageValue(cid, 30001, 3)
end
end
talkState[talkUser] = 3
if msgcontains(msg, "yes") and getPlayerStorageValue(cid, 30001) == 4 and talkState[talkUser] == 3 then
if doPlayerRemoveItem(cid,2480,1) then
npcHandler:say("Good! Now bring 100 chicken feathers. ", cid)
setPlayerStorageValue(cid, 30001, 5)
else
npcHandler:say("You do not have legion helmet.", cid)
setPlayerStorageValue(cid, 30001, 3)
end
end
talkState[talkUser] = 4
if msgcontains(msg, "chicken") and getPlayerStorageValue(cid, 30001) == 5 and talkState[talkUser] == 4 then
if getPlayerItemCount(cid,5890) >= 100 then
npcHandler:say("Oh, you bring 100 chicken feathers?", cid)
setPlayerStorageValue(cid, 30001, 6)
else
npcHandler:say("You do not have 100 chicken feathers.", cid)
setPlayerStorageValue(cid, 30001, 5)
end
end
talkState[talkUser] = 5
if msgcontains(msg, "yes") and getPlayerStorageValue(cid, 30001) == 6 and talkState[talkUser] == 5 then
if doPlayerRemoveItem(cid,5890,100) then
npcHandler:say("Good! Now bring 50 honeycombs. ", cid)
setPlayerStorageValue(cid, 30001, 7)
else
npcHandler:say("You do not have 100 chicken feathers.", cid)
setPlayerStorageValue(cid, 30001, 5)
end
end
talkState[talkUser] = 6
if msgcontains(msg, "honey") and getPlayerStorageValue(cid, 30001) == 7 and talkState[talkUser] == 6 then
if getPlayerItemCount(cid,5902) >= 50 then
npcHandler:say("Oh, you bring 50 honeycombs?", cid)
setPlayerStorageValue(cid, 30001, 8)
else
npcHandler:say("You do not have 50 honeycombs.", cid)
setPlayerStorageValue(cid, 30001, 7)
end
end
talkState[talkUser] = 7
if msgcontains(msg, "yes") and getPlayerStorageValue(cid, 30001) == 8 and talkState[talkUser] == 7 then
if doPlayerRemoveItem(cid,5902,50) then
npcHandler:say("Great job! That must have taken a lot of work. Okay, you put it like this... then glue like this... here!", cid)
setPlayerStorageValue(cid, 30001, 9)
doPlayerAddOutfit(cid, 128, 1)
doPlayerAddOutfit(cid, 136, 1)
doSendMagicEffect(getCreaturePosition(cid), 13)
else
npcHandler:say("You do not have 50 honeycombs.", cid)
setPlayerStorageValue(cid, 30001, 7)
end
end
talkState[talkUser] = 8
return true
end
hat = 30001
function talk(cid, message, keywords, parameters, node)
if(not npcHandler:isFocused(cid)) then
return false
end
if isPremium(cid) then
storg = getPlayerStorageValue(cid,hat)
if storg == -1 then
npcHandler:say("Pretty, isn't it? My friend Amber taught me how to make it, but I could help you with one if you like. What do you say?", cid)
setPlayerStorageValue(cid,hat,1)
setPlayerStorageValue(cid,30001,2)
end
else
npcHandler:say("Sorry, you don\'t have premium time.", cid)
end
end
node1 = keywordHandler:addKeyword({'hat'}, talk, {})
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Last edited: