• 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 greet depending on storagevalue

highclick

New Member
Joined
Mar 21, 2011
Messages
80
Reaction score
4
Hi guys, I'll try too describe as good as possible.

I have an XML NPC:


PHP:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Theresa The Druid" script="TheresaQuest.lua" walkinterval="0" floorchange="0">
    <health now="100" max="100"/>
    <look type="158" head="119" body="39" legs="114" feet="119" addons="0"/>
    <parameters>
        <parameter key="message_greet" value="Silence! You are disturbing the ritual. Either {help} me or be gone!"/>
    </parameters>
</npc>
And then i have a .lua script:


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

local storage = 5000

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, "help") then
         if getPlayerStorageValue(cid, storage) == -1 then
             selfSay("I need some chicken feathers too complete the ritual.Will you get some for me!?", cid)
             talkState[talkUser] = 1
         elseif getPlayerStorageValue(cid, storage) == 1 then
             selfSay("Did you get me the feathers?", cid)
             talkState[talkUser] = 1
         else
             selfSay("Thanks again for the feathers.", cid)
         end
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, storage) == -1 then
             selfSay("You can find some chicken south of temple", cid)
             setPlayerStorageValue(cid, storage, 1)
      
         else
                if doPlayerRemoveItem(cid, 5890, 5) then
                 selfSay("These will do just fine!", cid)
                 doPlayerAddItem(cid, 2148, 99)
                 doPlayerAddExp(cid, 5000)
                 setPlayerStorageValue(cid, storage, 2)
             else
                 selfSay("Where are my feathers!?", cid)
             end
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         selfSay("Ok then.", cid)
         talkState[talkUser] = 0
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())



Okay so, when you've finished her quest and type "hi" then "help" you get the response "Thanks again for the feathers"

I want you too get the "thanks again for the feathers response as soon as you say "hi". You shouldn't have too say "hi" and then "help" too get that response. And also if you haven't done the quest, the NPC should directly ask you for help..



Basicly I'm asking for the NPC too greet you depending on your storagevalue.

Thanks alot.
 
Last edited:
Wow i feel incredibly stupid. I started .lua yesterday and I've been following that exact guide, I've must've overlooked that part. Thank you very much Limos.
 
You can also use greetCallback.

Code:
local function greetCallback(cid)
    local questProgress = getPlayerStorageValue(cid, 123)
    if questProgress < 1 then
        npcHandler:setMessage(MESSAGE_GREET, "test")
    elseif questProgress == 1 then
        npcHandler:setMessage(MESSAGE_GREET, "blabla")
    else
        npcHandler:setMessage(MESSAGE_GREET, "lol")
    end
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
 
Back
Top