• 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] Response when player have storage

tarjei

Necronian Engineer
Joined
May 25, 2008
Messages
505
Reaction score
126
Location
Poland
Hello : )
Is it possible to make npc which does response only when player have storage = 5000, 1?

Storage 5000 = 1
Npc does response

Storage 5000 = 0
Npc doesn't response

Thx for any answers :D
 
Code:
    local storage = 5000
    if msgcontains(msg, 'hola amigo') and getPlayerStorageValue(cid, storage) == 1 then
        selfSay("Aeeee! Q puta e vc! 8D", cid)
    end


okay? :w00t:
 
@Edit: Seconds and i'll be first...
Try this (it will sell aol if 5000 = 1)

Code:
local focus = 0
local talk_start = 0
local target = 0
local following = false
local attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end


function onCreatureTurn(creature)

end

function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)

  	if (msgcontains(msg, 'hi') and focus == 0) and getDistanceToCreature(cid) < 4 then
  		selfSay('Hello ' .. creatureGetName(cid) .. '! I sell aols (10k).')
  		focus = cid
  		talk_start = os.clock()

  	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

  	elseif focus == cid then
		talk_start = os.clock()

		if msgcontains(msg, 'aol') [COLOR="Red"][B]and getPlayerStorageValue(cid, 5000) ~= 1[/B][/COLOR] then
			buy(cid,2173,1,10000)

			elseif msgcontains(msg, 'no') and getDistanceToCreature(cid) < 4 then
				selfSay('Ok than.')
				talk_state = 0

		elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
			selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
			focus = 0
			talk_start = 0
		end
  	end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
  			selfSay('Next Please...')
  		end
 		focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
 			selfSay('Good bye then.')
 			focus = 0
 		end
 	end
end
 
@Edit: Seconds and i'll be first...
Try this (it will sell aol if 5000 = 1)

Code:
local focus = 0
local talk_start = 0
local target = 0
local following = false
local attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end


function onCreatureTurn(creature)

end

function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)

  	if (msgcontains(msg, 'hi') and focus == 0) and getDistanceToCreature(cid) < 4 then
  		selfSay('Hello ' .. creatureGetName(cid) .. '! I sell aols (10k).')
  		focus = cid
  		talk_start = os.clock()

  	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

  	elseif focus == cid then
		talk_start = os.clock()

		if msgcontains(msg, 'aol') [COLOR="Red"][B]and getPlayerStorageValue(cid, 5000) ~= 1[/B][/COLOR] then
			buy(cid,2173,1,10000)

			elseif msgcontains(msg, 'no') and getDistanceToCreature(cid) < 4 then
				selfSay('Ok than.')
				talk_state = 0

		elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
			selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
			focus = 0
			talk_start = 0
		end
  	end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
  			selfSay('Next Please...')
  		end
 		focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
 			selfSay('Good bye then.')
 			focus = 0
 		end
 	end
end

Actually, it will sell aol if the storage is other (~=) than 1.
Whats more, there is no function "buy()" in tfs, also the npc layout is kinda different now.
 
i kno but i need something else....:p if player have storage npc say something and you can talk with him but if npc dont have storage npc say all the one thing you knowe npc on svargrond talk onbly when you have barbarian test:p
 
Youll have to set onGreetCallback, look on the forums for The Oracle, then You will know how to do it ;)
 
Thx Marcinek ;] I dont even though about Oracle :pP //For Tfs 0.3pl1

@ There a little problem :
Oracle npc doesnt work ;/

local LEVEL = 8

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



-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end
-- OTServ event handling functions end


function oracle(cid, message, keywords, parameters, node)
if(cid ~= npcHandler.focuses) then
return false
end

local cityNode = node:getParent():getParent()
local vocNode = node:getParent()

local destination = cityNode:getParameters().destination
local townid = cityNode:getParameters().townid
local voc = vocNode:getParameters().voc

if(destination ~= nil and voc ~= nil and townid ~= nil) then
if(getPlayerLevel(cid) < parameters.level) then
npcHandler:say('You must first reach level ' .. parameters.level .. '!')
else
if voc == 1 then
doPlayerAddItem(cid,2190,1)
doPlayerSendTextMessage(cid,22,"You are now a Sorcerer. May your new wand give you might!")
end
if voc == 2 then
doPlayerAddItem(cid,2182,1)
doPlayerSendTextMessage(cid,22,"You are now a Druid. May your new rod give you intellect!")
end
if voc == 3 then
doPlayerAddItem(cid,2456,1)
doPlayerAddItem(cid,2544,50)
doPlayerSendTextMessage(cid,22,"You are now a Paladin. May your new Bow and Arrows protect you in dangerous cases!")
end
if voc == 4 then
doPlayerAddItem(cid,2428,1)
doPlayerAddItem(cid,2531,1)
doPlayerSendTextMessage(cid,22,"You are now a Knight. May your new shield and axe give you strength!")
end
doPlayerSetVocation(cid,voc)
doPlayerSetTown(cid,townid)
doTeleportThing(cid,destination)
doSendMagicEffect(destination,12)

end
else
error('Destination:', destination, 'Vocation:', vocation, 'Townid:', townid)
end
npcHandler:resetNpc()
return true
end


function greetCallback(cid)
if(getPlayerLevel(cid) < LEVEL) then
npcHandler:say('CHILD! COME BACK WHEN YOU HAVE GROWN UP!')
return false
else
return true
end
end

-- Set the greeting callback function
npcHandler:setCallback(CALLBACK_GREET, greetCallback)

-- Set the greeting message.
npcHandler:setMessage(MESSAGE_GREET, 'Hello |PLAYERNAME|. Are you prepared to face your destiny?')

-- Pre-create the yes/no nodes.
local yesNode = KeywordNode:new({'yes'}, oracle, {level = LEVEL})
local noNode = KeywordNode:new({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = 'Then what vocation do you want to become?'})

-- Create the actual keyword structure...
local node1 = keywordHandler:addKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'What city do you wish to live in? Carlin, Thais or Venore?'})
local node2 = node1:addChildKeyword({'carlin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, townid = 2, destination = {x=32360, y=31782, z=7}, text = 'Carlin will be your home-town! So what vocation do you wish to become? Sorcerer, druid, paladin or knight?'})
local node3 = node2:addChildKeyword({'sorcerer'}, StdModule.say, {npcHandler = npcHandler, voc = 1, onlyFocus = true, text = 'So, you wish to be a powerful magician? Are you sure about that? This decision is irreversible!'})
node3:addChildKeywordNode(yesNode)
node3:addChildKeywordNode(noNode)
local node3 = node2:addChildKeyword({'druid'}, StdModule.say, {npcHandler = npcHandler, voc = 2, onlyFocus = true, text = 'A druid! Are you sure? This decision is irreversible!'})
node3:addChildKeywordNode(yesNode)
node3:addChildKeywordNode(noNode)
local node3 = node2:addChildKeyword({'paladin'}, StdModule.say, {npcHandler = npcHandler, voc = 3, onlyFocus = true, text = 'A nimble paladin! Are you sure? This decision is irreversible!'})
node3:addChildKeywordNode(yesNode)
node3:addChildKeywordNode(noNode)
local node3 = node2:addChildKeyword({'knight'}, StdModule.say, {npcHandler = npcHandler, voc = 4, onlyFocus = true, text = 'A valorous knight! Are you sure? This decision is irreversible!'})
node3:addChildKeywordNode(yesNode)
node3:addChildKeywordNode(noNode)

local node2 = node1:addChildKeyword({'thais'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, townid = 5, destination = {x=32369, y=32241, z=7}, text = 'Thais will be your home-town! So what vocation do you wish to become? Sorcerer, druid, paladin or knight?'})
local node3 = node2:addChildKeyword({'sorcerer'}, StdModule.say, {npcHandler = npcHandler, voc = 1, onlyFocus = true, text = 'So, you wish to be a powerful magician? Are you sure about that? This decision is irreversible!'})
node3:addChildKeywordNode(yesNode)
node3:addChildKeywordNode(noNode)
local node3 = node2:addChildKeyword({'druid'}, StdModule.say, {npcHandler = npcHandler, voc = 2, onlyFocus = true, text = 'A mighty druid! Are you sure? This decision is irreversible!'})
node3:addChildKeywordNode(yesNode)
node3:addChildKeywordNode(noNode)
local node3 = node2:addChildKeyword({'paladin'}, StdModule.say, {npcHandler = npcHandler, voc = 3, onlyFocus = true, text = 'A nimble paladin! Are you sure? This decision is irreversible!'})
node3:addChildKeywordNode(yesNode)
node3:addChildKeywordNode(noNode)
local node3 = node2:addChildKeyword({'knight'}, StdModule.say, {npcHandler = npcHandler, voc = 4, onlyFocus = true, text = 'A valorous knight! Are you sure? This decision is irreversible!'})
node3:addChildKeywordNode(yesNode)
node3:addChildKeywordNode(noNode)

local node2 = node1:addChildKeyword({'venore'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, townid = 6, destination = {x=32957, y=32076, z=7}, text = 'Venore will be your home-town! So what vocation do you wish to become? Sorcerer, druid, paladin or knight?'})
local node3 = node2:addChildKeyword({'sorcerer'}, StdModule.say, {npcHandler = npcHandler, voc = 1, onlyFocus = true, text = 'So, you wish to be a powerful magician? Are you sure about that? This decision is irreversible!'})
node3:addChildKeywordNode(yesNode)
node3:addChildKeywordNode(noNode)
local node3 = node2:addChildKeyword({'druid'}, StdModule.say, {npcHandler = npcHandler, voc = 2, onlyFocus = true, text = 'A mighty druid! Are you sure? This decision is irreversible!'})
node3:addChildKeywordNode(yesNode)
node3:addChildKeywordNode(noNode)
local node3 = node2:addChildKeyword({'paladin'}, StdModule.say, {npcHandler = npcHandler, voc = 3, onlyFocus = true, text = 'A nimble paladin! Are you sure? This decision is irreversible!'})
node3:addChildKeywordNode(yesNode)
node3:addChildKeywordNode(noNode)
local node3 = node2:addChildKeyword({'knight'}, StdModule.say, {npcHandler = npcHandler, voc = 4, onlyFocus = true, text = 'A valorous knight! Are you sure? This decision is irreversible!'})
node3:addChildKeywordNode(yesNode)
node3:addChildKeywordNode(noNode)

keywordHandler:addKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Then come back when you are ready.'})

-- Make it react to hi/bye etc.
npcHandler:addModule(FocusModule:new())

Bug:
[30/10/2008 13:21:33] data/npc/lib/npcsystem/npchandler.lua:576: table index is nil
[30/10/2008 13:21:33] stack traceback:
[30/10/2008 13:21:33] data/npc/lib/npcsystem/npchandler.lua:576: in function 'say'
[30/10/2008 13:21:33] data/npc/scripts/oracle.lua:42: in function 'callback'
[30/10/2008 13:21:33] data/npc/lib/npcsystem/npchandler.lua:322: in function 'greet'
[30/10/2008 13:21:33] data/npc/lib/npcsystem/npchandler.lua:490: in function 'onGreet'
[30/10/2008 13:21:33] data/npc/lib/npcsystem/modules.lua:208: in function 'callback'
[30/10/2008 13:21:33] data/npc/lib/npcsystem/keywordhandler.lua:40: in function 'processMessage'
[30/10/2008 13:21:33] data/npc/lib/npcsystem/keywordhandler.lua:168: in function 'processNodeMessage'
[30/10/2008 13:21:33] data/npc/lib/npcsystem/keywordhandler.lua:122: in function 'processMessage'
[30/10/2008 13:21:33] data/npc/lib/npcsystem/npchandler.lua:371: in function 'onCreatureSay'
[30/10/2008 13:21:33] data/npc/scripts/oracle.lua:7: in function <data/npc/scripts/oracle.lua:7>
 
Last edited:
Back
Top