• 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 Another Npc Problem

Santi

Theres no way im stopping
Joined
Aug 29, 2010
Messages
1,975
Reaction score
152
Location
00
He ain't replying when I say hi.
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 storage = 25600
local s = getPlayerStorageValue(cid, storage)
local newPos = {x=94, y=125, z=7} --- 	
 
function creatureSayCallback(cid, type, msg)
if (msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'hey')) and not npcHandler:isFocused(cid) then
   npcHandler:say('Hello ' .. getCreatureName(cid) .. ' to teleport say {teleport}!', cid)
   npcHandler:addFocus(cid)
   elseif not npcHandler:isFocused(cid) then
return false
 
elseif msgcontains(msg, 'bye') or msgcontains(msg, 'good bye') then
npcHandler:say('Good bye ' .. getCreatureName(cid) .. ' come back if you want to be teleported!', cid)
npcHandler:releaseFocus(cid)
 
elseif msgcontains(msg, 'teleport') then 
local s = getplayerStorageValue(cid,storage)
if s == -1 then
npcHandler:say('Would you like to be teleported?!', cid)
setPlayerStorageValue(cid,storage,1)

elseif msgcontains(msg, 'yes') and s == 1 then
npcHandler:say('Are you ready?', cid)
setPlayerStorageValue(cid,storage,2)
elseif msgcontains(msg, 'yes') and s == 2 then
doTeleportThing(cid,newPos)
end
return true
end
end

Error:

Code:
[19/11/2010 19:22:27] [Error - Npc interface] 
[19/11/2010 19:22:27] data/npc/scripts/melchior.lua
[19/11/2010 19:22:27] Description: 
[19/11/2010 19:22:27] (luaGetCreatureStorage) Creature not found

So if someone can help me please, Ill rep+ of course.
 
get the local s inside the callback function, this will remove the error, but i dont think it will respond to you though
 
try this then
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}
 
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 greetCallback(cid)
	Topic[cid] = 0
	return true
end
local place = {x=95,y=125,z=7}
function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	end
	if msgcontains(msg, 'teleport') then
		npcHandler:say('Would you like to be teleported?!', cid)
		Topic[cid] = 1
	elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
		npcHandler:say('Are you ready?', cid)
		Topic[cid] = 2
	elseif msgcontains(msg, 'no') and Topic[cid] == 1 then
		npcHandler:say('Maybe later then.', cid)
		Topic[cid] = 0
	elseif msgcontains(msg, 'yes') and Topic[cid] == 2 then
		Topic[cid] = 0
		selfSay('Here you are.', cid)
		addEvent(doTeleportThing,50,cid,place)
		addEvent(doSendMagicEffect,100,place,10)
	end
	return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


Xml

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="XXX" script="XXX.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="129" head="79" body="113" legs="105" feet="86" addons="0"/>
        <parameters>
                <parameter key="message_greet" value="Hello |PLAYERNAME|, to teleport say {teleport}!"/>
                <parameter key="message_farewell" value="Good bye |PLAYERNAME|, come back if you want to be teleported!."/>
                
    </parameters>

</npc>
 
Thanks, it works perfectly!
Btw, if I want to set some storage values? just add setPlayerStorageValue? or something with addEvent?
Thanks again :)
 
want to set a player storage when he is teleported? them make it normally setPlayerStorageValue(cid,storage,value) before the selfSay
 
Okay, thanks a lot! Last question haha.
If I set so it gives storage value = 35000 and I want that storage value so you can open a door is this correct?
Lua:
local storage = 35000
function onUse(cid, item, fromPosition, itemEx, toPosition)
if isItemDoor(5114) and getPlayerStorageValue(cid,storage) == -1 then
setPlayerStorageValue(cid,storage,1)
doTransformItem(item.uid,5115)
end
return true
end

Then I just have to set an uniqueID which i put at actions.xml and in the door at RME right?
Thanks once again :p
 
first of all , no need to check for if item is door , you only put the item id in the action.xml line, and then u need to check if the player storage is more than -1 as in the npc he gives them this storage
Lua:
local storage = 35000
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid,storage) > 0 then
		setPlayerStorageValue(cid,storage,-1)
		doTransformItem(item.uid,5115)
	end
	return true
end
 
Back
Top