• 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!

NPC Storage Addon

niivalerio

New Member
Joined
Jun 24, 2012
Messages
7
Reaction score
0
Hello, everybody!

I'm trying to make a storage NPC, but there is some error who i can't understand can someone help me??

The NPC needs to work like this:


Player: hi
NPC: Hello, |PLAYERNAME| what bring you here?
Player: addon
NPC: To get insectoid addon full you need to have storage x. Do you have it?
(only give the addon if it has X storage)
Player: yes
NPC: Here it is...
 
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Test" script="test.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100" />
    <look type="128" head="0" body="0" legs="0" feet="0" addons="0" />
    <parameters>
        <parameter key="message_greet" value="Hello, |PLAYERNAME|. What brings you here?"/>
    </parameters>
</npc>

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, "addon") then
        selfSay("To receive the {full insectoid outfit} you need to have the storage {12345}. Do you have it?", cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        if getPlayerStorageValue(cid, 12345) == 1 then
            doPlayerAddOutfit(cid, 466, 3)
            doPlayerAddOutfit(cid, 465, 3)
            setPlayerStorageValue(cid, 12345, 2)
            selfSay("Here it is.", cid)
        else
            selfSay("You don't have it....", cid)
        end
      
        talkState[talkUser] = 0
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay("Then no...", cid)
        talkState[talkUser] = 0
        npcHandler:releaseFocus(cid)
    end
    return true
end

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