• 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 [TFS 1x +[ NPC Storage

DiegoRulez

Member
Joined
Apr 16, 2012
Messages
93
Reaction score
11
Location
Feira de Santana - Brasil
How to make the NPC only talk to whoever has the 38765 storage, and talk to whoever doesn't have the following message: You didn't do the quest

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 bad_words = {"ass", "fuck", "shit"} -- palavras proibidas

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player, ret = Player(cid), false
    for i = 1, #bad_words do
        ret = msgcontains(msg, bad_words[i])
        if ret then
            break
        end
    end
    if ret then
        player:addHealth(-player:getHealth()+1)
        player:getPosition():sendMagicEffect(CONST_ME_FIREAREA)
        npcHandler:say("TAKE IT!", cid)
    end
    return true
end

-- Promotion
local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
    node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})
   
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
How to make the NPC only talk to whoever has the 38765 storage, and talk to whoever doesn't have the following message: You didn't do the quest

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 bad_words = {"ass", "fuck", "shit"} -- palavras proibidas

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player, ret = Player(cid), false
    for i = 1, #bad_words do
        ret = msgcontains(msg, bad_words[i])
        if ret then
            break
        end
    end
    if ret then
        player:addHealth(-player:getHealth()+1)
        player:getPosition():sendMagicEffect(CONST_ME_FIREAREA)
        npcHandler:say("TAKE IT!", cid)
    end
    return true
end

-- Promotion
local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
    node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})
  
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Hello,

I don't know much about NPCs, but i think what you need is to add a check for the storage in this function...
Maybe im wrong, just trying to help. Let me know if worked.
 
after line 16:

Lua:
    if player:getStorageValue(38765) == -1 then
        npcHandler:say("you didn't do the quest", cid)
        npcHandler:releaseFocus(cid) -- or  'npcHandler:resetNpc(cid)'
        return true
    end
should do the trick
 
Back
Top