• 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 setPlayerStorageValue Bug

njitram

New Member
Joined
May 15, 2008
Messages
14
Reaction score
0
Hellow

I have a small problem with the creation of LUA files for NPC's:

mining.lua
PHP:
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
 
function creatureSayCallback(cid, type, msg)

    if(npcHandler.focus ~= cid) then
        return false
    end
    
    if msgcontains(msg,'spells') or msgcontains(msg,'help') then
            npcHandler:say('Hello i can teach you mining for free')
    end
return 1   
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
 
    if msgcontains(msg,'mining') or msgcontains(msg,'help') then
            setPlayerStorageValue(cid,40001,1)
            setPlayerStorageValue(cid,40002,1)
            setPlayerStorageValue(cid,40003,1)
            setPlayerStorageValue(cid,40004,1)
            npcHandler:say('Here you go!')
    end
 
npcHandler:addModule(FocusModule:new())

Twan.xml
PHP:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Twan" script="data/npc/scripts/mining.lua" autowalk="1" floorchange="0">
	<health now="100" max="100"/>
	<look type="138" head="57" body="59" legs="40" feet="76" addons="0"/>
	<parameters>
	</parameters>
</npc>

This dont work, why im not sure.. can some one help me out?
 
Last edited:
Its not function bug, its your bug ;(
Code:
 setPlayerStorageValue(1,40004)
should look like this:
Code:
 setPlayerStorageValue(cid,40004,1)
 
hey well still aint working:

Item could not be summoned.
/n Twan
Item could not be summoned.
/n twan

Console doesnt give a bug
 
[09/07/2008 16:39:57] Lua Script Error: [Npc interface]
[09/07/2008 16:39:57] data/npc/scripts/mining.lua

[09/07/2008 16:39:57] data/npc/lib/npc.lua:9: bad argument #1 to 'find' (string expected, got nil)
[09/07/2008 16:39:57] Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/mining.lua
 
hehe thats a blank line

between
function onThink() npcHandler:eek:nThink() end

function creatureSayCallback(cid, type, msg)
 
try this

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

-- OTServ event handling functions start
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
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return false
	end
    
    if msgcontains(msg,'spells') or msgcontains(msg,'help') then
            selfSay('Hello i can teach you mining for free. If you would like to learn mining please say mining')

    elseif msgcontains(msg,'mining') then
            setPlayerStorageValue(cid,40001,1)
            setPlayerStorageValue(cid,40002,1)
            setPlayerStorageValue(cid,40003,1)
            setPlayerStorageValue(cid,40004,1)
            npcHandler:say('Here you go!')
    end
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top