• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC [8.0] Cool Addon NPC -TFS-

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,941
Solutions
11
Reaction score
352
So, I've made a NPC that gives you addon + you don't have to put all items together + it checks if you are premmy + easy to be edited for other addon-npcs so I'll just write here this one.

data/npc/scripts/citizenhat.lua
PHP:
--------------------------------------------------------------------------------------------
------------------------------------ Advanced Addon NPC ------------------------------------
---------------------------------- Script made by Sinner -----------------------------------
--------------------------------------------------------------------------------------------
 
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
-- OTServ event handling functions start
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
-- OTServ event handling functions end
 
function creatureSayCallback(cid, type, msg)
-- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
if(npcHandler.focus ~= cid) then
return false
end
 
    if msgcontains(msg, 'help') or msgcontains(msg, 'task') then
    if isPremium(cid) == TRUE then
    task = getPlayerStorageValue(cid, 70000)
    if task == -1 then
        setPlayerStorageValue(cid, 70000, 1)
        selfSay('My neighbour is in need of some items, will you help me and get them?')
        talk_state = 1
 
    elseif task == 2 then
    selfSay('Did you bring me 100 chicken feathers?')
        talk_state = 2
    elseif task == 3 then
    selfSay('You already got 50 honeycombs?')
        talk_state = 3
    elseif task == 4 then
    selfSay('All I need now is a legion helmet. Do you have one already?')
        talk_state = 4
    elseif task == 5 then
    selfSay('Thank you very much, but there is nothing more you can help me in.')
        talk_state = 0
 
    end
    else
    selfSay('Sorry, but only premium players can help me.')
    end
 
 
    elseif msgcontains(msg, 'yes') and talk_state == 1 then
    selfSay('Thank you '..getPlayerName(cid)..'! All she need is 100 chicken feathers, 50 honeycombs and 1 legion helmet. Come back when you have them and ask me about task.')
    setPlayerStorageValue(cid, 70000, 2)
    talk_state = 0
 
    elseif msgcontains(msg, 'no') and talk_state == 1 then
    selfSay('Fine! I will get it myself, pig!')
    talk_state = 0
 
    elseif msgcontains(msg, 'yes') and talk_state == 2 then
    if doPlayerTakeItem(cid, 5890, 100) == 0 then
    selfSay('Thank you '..getPlayerName(cid)..'! Now try to obtain 50 honeycombs please.')
    setPlayerStorageValue(cid, 70000, 3)
    talk_state = 0
 
    else
    selfSay('You do not have them all.')
    end
 
    elseif msgcontains(msg, 'no') and talk_state == 2 then
    selfSay('Come back when you have them then.')
    talk_state = 0
 
    elseif msgcontains(msg, 'yes') and talk_state == 3 then
    if doPlayerTakeItem(cid, 5902, 50) == 0 then
    selfSay('May the gods bless you, we need only legion helmet more. Please get it for me.')
    setPlayerStorageValue(cid, 70000, 4)
    talk_state = 0
 
    else
    selfSay('I need more of them, please get more.')
    end
 
    elseif msgcontains(msg, 'no') and talk_state == 3 then
    selfSay('Hurry please.')
    talk_state = 0
 
    elseif msgcontains(msg, 'yes') and talk_state == 4 then
    if doPlayerTakeItem(cid, 2480, 1) == 0 then
    selfSay('Thank you very much for your help '..getPlayerName(cid)..'! Take this hat as a reward.')
    setPlayerStorageValue(cid, 70000, 5)
    doPlayerAddOutfit(cid, 128, 2)
    doPlayerAddOutfit(cid, 136, 2)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_GREEN)
    talk_state = 0
 
    else
    selfSay('I need a legion helmet!')
    end
 
    elseif msgcontains(msg, 'no') and talk_state == 4 then
    selfSay('Please get it!')
    talk_state = 0
 
    elseif task == 2 and msgcontains(msg, 'chicken') or msgcontains(msg, 'feather') or msgcontains(msg, 'feathers') then
    selfSay('Did you bring me 100 chicken feathers?')
    talk_state = 2
 
    elseif task == 3 and msgcontains(msg, 'honeycomb') or msgcontains(msg, 'honeycombs') then
    selfSay('You already got 50 honeycombs?')
        talk_state = 3
 
    elseif task == 4 and msgcontains(msg, 'legion helmet') then
    selfSay('All I need now is a legion helmet. Do you have one already?')
        talk_state = 4
    end
        return true
        end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Now, data/npc/Kashmir.xml
PHP:
<npc name="Kashmir" script="data/npc/scripts/citizenhat.lua" autowalk="25" floorchange="0" access="5" level="1" maglevel="1">
    <health now="150" max="150"/>
    <look type="136" head="26" body="57" legs="114" feet="0" addons="2"/>
 
        <parameters>
 
        <parameter key="message_greet" value="Welcome in my garden, |PLAYERNAME|. What can I do for you?" />
        <parameter key="message_farewell" value="We will meet again."/>
        <parameter key="message_walkaway" value="Take care!"/>
        <parameter key="message_placedinqueue" value="Wait a minute, |PLAYERNAME|."/>
        <parameter key="message_idletimeout" value="We will meet again, |PLAYERNAME|."/>
        <parameter key="message_alreadyfocused" value="We are already talking."/>
 
        <parameter key="module_keywords" value="1"/>
        <parameter key="keywords" value="addon;job;garden"/>
        <parameter key="keyword_reply1" value="You are talking about my hat? Perhaps I can give you my old one, if you can help me."/>
        <parameter key="keyword_reply2" value="I am kings daughter, I do not need to work."/>
        <parameter key="keyword_reply3" value="Isn't it beautiful?"/>
 
    </parameters>
</npc>

Done. :)

I will say it again, it is very easy to just copy that script resize it a little and do other NPC for hunter hood addon etc.

Hope you like it !

P.S.
Use the storagevalues for data/XML/quests.xml too!

Same steps as above just other file names.
citizenbp.lua
PHP:
--------------------------------------------------------------------------------------------
------------------------------------ Advanced Addon NPC ------------------------------------
---------------------------------- Script made by Sinner -----------------------------------
--------------------------------------------------------------------------------------------
 
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
-- OTServ event handling functions start
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
-- OTServ event handling functions end
 
function creatureSayCallback(cid, type, msg)
-- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
if(npcHandler.focus ~= cid) then
return false
end
 
    if msgcontains(msg, 'addon') or msgcontains(msg, 'outfit') or msgcontains(msg, 'backpack') then
    if isPremium(cid) == TRUE then
    task = getPlayerStorageValue(cid, 80000)
    if task == -1 then
        setPlayerStorageValue(cid, 80000, 1)
        selfSay('My backpack? You like it, don\'t you? I can make one for you if you will bring me some ingredients... Minotaur leather. It\'s strong enough to carry your stuff and easy to handle with. Get me 100 of it.')
        talk_state = 0
 
    elseif task == 1 then
    selfSay('Do you have all 100 minotaur leathers?')
        talk_state = 1
    elseif task == 2 then
    selfSay('Sorry '..getPlayerName(cid)..', but I gave you that backpack already.')
        talk_state = 0
 
    end
    else
    selfSay('Sorry to say that, but only premium players can have my backpack.')
    end
 
    elseif task == 1 and msgcontains(msg, 'minotaur') or msgcontains(msg, 'leather') or msgcontains(msg, 'leathers') then
    selfSay('Do you have all 100 minotaur leathers?')
        talk_state = 1
 
    elseif msgcontains(msg, 'yes') and talk_state == 1 then
    if doPlayerTakeItem(cid, 5878, 100) == 0 then
    selfSay('As I said, here is your backpack, hope you like it!')
    setPlayerStorageValue(cid, 80000, 2)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_GREEN)
    doPlayerAddOutfit(cid, 128, 1)
    doPlayerAddOutfit(cid, 136, 1)
    talk_state = 0
 
    else
    selfSay('You do not have them all.')
    talk_state = 0
    end
 
    elseif msgcontains(msg, 'no') and talk_state == 1 then
    selfSay('Keep collecting them and come back when you have 100.')
    talk_state = 0
    end
        return true
        end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

citizenbp.xml
PHP:
<npc name="Doug" script="data/npc/scripts/citizenbp.lua" autowalk="25" floorchange="0" access="5" level="1" maglevel="1">
    <health now="150" max="150"/>
    <look type="128" head="144" body="82" legs="114" feet="101" addons="1"/>
 
        <parameters>
 
        <parameter key="message_greet" value="Hi there |PLAYERNAME|! How can I help you today?" />
        <parameter key="message_farewell" value="Bye."/>
        <parameter key="message_walkaway" value="Bye."/>
        <parameter key="message_placedinqueue" value="Give me a minute, |PLAYERNAME|"/>
        <parameter key="message_idletimeout" value="Bye, |PLAYERNAME|."/>
        <parameter key="message_alreadyfocused" value="I am already talking to you."/>
 
        <parameter key="module_keywords" value="1"/>
        <parameter key="keywords" value="job"/>
        <parameter key="keyword_reply1" value="I am a journalist."/>
 
    </parameters>
</npc>

I suppose now you know how to change them so you can make your own cool npcs! =)
 
Last edited by a moderator:
Nice, it works....but...

If you know the last item in their list you can just say the words and the NPC will get the last item only and give you the addon. I`ve done it, and used the code just as it is. Also you could go many times and he would still ask you for all the items. Something in the storagevalue isnt working. Im using TFS 2.8

Some ideas, coulnt you add something so before the npc gives you the addon he checks that you have given him all the things (so you have al the storagevalues set) something like: getStorageValue before he ask again for all items or before he gives you anything, no just check that when you give him the last item he gives you the addon, cause this could cause an EXPLOIT among player, or a headache amongst others if they dont get it and think they have to give the items every single time if they didnt have them all at their first try.

Hope you can fix this, im no script maker, so i let those things up to you, im only a regular user. You guys make this comunity, so keep it up.

YOUR GLOBAL idea is real cool, like regular tibia. Thanks.
and sorry for mi english ;)


FIXED THE ISSUE
Added some code lines here and there and fixed the problem.
Thanks.
 
Last edited:
really good job, but i need all npcs =(((, or just all addon in one script ;çç
 
Back
Top