• 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 check storage and give you a addon

Pokurwieniec

New Member
Joined
Feb 1, 2016
Messages
43
Reaction score
1
Hi guys
I need simple npc which checking if you have storage and give you addon to outfit if is true than message here you are if doesn't have storage is false message like sorry blablabla
 
Hi guys
I need simple npc which checking if you have storage and give you addon to outfit if is true than message here you are if doesn't have storage is false message like sorry blablabla
tfs?
nvm..
below is for tfs 0.3.7

data/npc/citizen addon.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Erik" script="data/npc/scripts/addons/citizen.lua" walkinterval="500" floorchange="0">
   <health now="100" max="100"/>
   <look type="128" head="78" body="69" legs="58" feet="76" addons="3"/>
</npc>
data/npc/scripts/addons/citizen.lua
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 greet(cid)  talkState[cid] = 0  return true  end
function getNpcName()  return getCreatureName(getNpcId())  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, "job") then
     selfSay("My job is to show the world how fashionable they can be!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "name") then
     selfSay("My name is " .. getNpcName() .. ".", cid)
     talkState[talkUser] = 0

   -- Addon already given
   elseif msgcontains(msg, "addon") and (getPlayerStorageValue(cid, 45001) == 1) then
     selfSay("You have already received the citizen outfit addons.", cid)
     talkState[talkUser] = 0
 
   -- Addon not given yet
   elseif msgcontains(msg, "addon") and (getPlayerStorageValue(cid, 45001) < 1) then
     selfSay("Would you like to get all citizen outfit addons?", cid)
     talkState[talkUser] = 1
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
     selfSay("Wonderful! Here you are! {Addon Obtained!}", cid)
     doPlayerAddOutfit(cid, 136, 3) -- female
     doPlayerAddOutfit(cid, 128, 3) -- male
     setPlayerStorageValue(cid, 45001, 1)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
     selfSay("Sorry. I only give out free addons for those that say {yes}. Too bad.", cid)
     talkState[talkUser] = 0

   end
   return true
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
hmm something is wrong I don't have 45001 storage but npc gave me addon and he shouldn't :/
doesn't checking storage because i can write addon yes all the time
I'm using 0.4 r3884
 
Oh, you want it backwards?

So if you already have the storage, then give the addons?

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 greet(cid)  talkState[cid] = 0  return true  end
function getNpcName()  return getCreatureName(getNpcId())  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, "job") then
     selfSay("My job is to show the world how fashionable they can be!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "name") then
     selfSay("My name is " .. getNpcName() .. ".", cid)
     talkState[talkUser] = 0
   
   -- Addon already given
   elseif msgcontains(msg, "addon") and (getPlayerStorageValue(cid, 45001) == 2) then
     selfSay("You have already received the citizen outfit addons.", cid)
     talkState[talkUser] = 0
     
   -- Addon not given yet
   elseif msgcontains(msg, "addon") then
     selfSay("Would you like to get all citizen outfit addons?", cid)
     talkState[talkUser] = 1
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 and (getPlayerStorageValue(cid, 45001) == 1) then
     selfSay("Wonderful! Here you are! {Addon Obtained!}", cid)
     doPlayerAddOutfit(cid, 136, 3) -- female
     doPlayerAddOutfit(cid, 128, 3) -- male
     setPlayerStorageValue(cid, 45001, 1)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 and (getPlayerStorageValue(cid, 45001) < 1) then
     selfSay("Sorry. I only give out addons to those that are {worthy}.", cid)
     talkState[talkUser] = 0
     
   elseif msgcontains(msg, "worthy") then
     selfSay("You must do {this random quest} to become worthy of this fine hat and backpack.", cid)
     talkState[talkUser] = 0

   end
   return true
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
thanks man but still this
Code:
-- Addon already given
   elseif msgcontains(msg, "addon") and (getPlayerStorageValue(cid, 45001) == 2) then
     selfSay("You have already received the citizen outfit addons.", cid)
     talkState[talkUser] = 0
seems not working because he giving me addons everytime ;d
 
Oops.
change
Code:
setPlayerStorageValue(cid, 45001, 1)
to
Code:
setPlayerStorageValue(cid, 45001, 2)
 
I don't know doesn't work even having that storage is "Sorry. I only give out addons to those that are worthy."
If you don't have storage (45001, -1), he says that.
If you have completed random quest and obtained storage (45001, 1) then he will give you addon.
After you have obtained addon (45001, 2) he will tell you that you have received it already.

Try this for testing purposes..

Give/Take

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 greet(cid)  talkState[cid] = 0  return true  end
function getNpcName()  return getCreatureName(getNpcId())  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, "job") then
     selfSay("My job is to show the world how fashionable they can be!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "name") then
     selfSay("My name is " .. getNpcName() .. ".", cid)
     talkState[talkUser] = 0
   
   -- Addon already given
   elseif msgcontains(msg, "addon") and (getPlayerStorageValue(cid, 45001) == 2) then
     selfSay("You have already received the citizen outfit addons.", cid)
     talkState[talkUser] = 0
     
   -- Addon not given yet
   elseif msgcontains(msg, "addon") then
     selfSay("Would you like to get all citizen outfit addons?", cid)
     talkState[talkUser] = 1
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 and (getPlayerStorageValue(cid, 45001) == 1) then
     selfSay("Wonderful! Here you are! {Addon Obtained!}", cid)
     doPlayerAddOutfit(cid, 136, 3) -- female
     doPlayerAddOutfit(cid, 128, 3) -- male
     setPlayerStorageValue(cid, 45001, 2)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 and (getPlayerStorageValue(cid, 45001) < 1) then
     selfSay("Sorry. I only give out addons to those that are {worthy}.", cid)
     talkState[talkUser] = 0
     
   elseif msgcontains(msg, "worthy") then
     selfSay("You must do {this random quest} to become worthy of this fine hat and backpack.", cid)
     talkState[talkUser] = 0
     
   elseif msgcontains(msg, "give") then
     selfSay("I have given you +1 to your storage.", cid)
     setPlayerStorageValue(cid, 45001, 1)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "take") then
     selfSay("I have reset your storage.", cid)
     setPlayerStorageValue(cid, 45001, 0)
     talkState[talkUser] = 0

   end
   return true
end

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