• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

NPC Problem

Hrsha

Member
Joined
May 30, 2010
Messages
450
Reaction score
21
Location
Egypt
hello otlanders

this script gives me error
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)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	--[[
	REMEMBER TO SET YOUR STORAGE AS YOURSTORAGE!
	]]--
	local storage = YOURSTORAGE
	if(msgcontains(msg, 'quest') or msgcontains(msg, 'crystal')) then
		if(getPlayerStorageValue(cid, storage) < 1) then
			npcHandler:say("Hey, I have super quest for you. Bring me please {10 crystal coins}.", cid)
			setPlayerStorageValue(cid, storage, 1)
		elseif(getPlayerStorageValue(cid, storage) == 1) then
			npcHandler:say("Do you have 10 crystal coins for me?", cid)
			talkState[talkUser] = 1
		elseif(getPlayerStorageValue(cid, storage) == 2) then
			npcHandler:say("Sorry, you have already done my super quest.", cid)
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 100000) == TRUE) then
			npcHandler:say("Thanks! As I said, here\'s 20 crystal coins!", cid)
			doPlayerAddItem(cid, 2160, 20)
			setPlayerStorageValue(cid, storage, 2)
			talkState[talkUser] = 0
		else
			npcHandler:say("Sorry, you don\'t have enough money.", cid)
			talkState[talkUser] = 0
		end
	elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
		npcHandler:say("Then not.", cid)
		talkState[talkUser] = 0
	end
	return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

[20:23:26.515] [Error - NpcScript Interface]
[20:23:26.515] data/npc/scripts/anni.lua:onCreatureSay
[20:23:26.515] Description:
[20:23:26.515] data/npc/scripts/anni.lua:21: attempt to call global 'etPlayerIte
mCount' (a nil value)
[20:23:26.515] stack traceback:
[20:23:26.515] data/npc/scripts/anni.lua:21: in function 'callback'
[20:23:26.515] data/npc/lib/npcsystem/npchandler.lua:423: in function 'onCreatu
reSay'
[20:23:26.515] data/npc/scripts/anni.lua:7: in function <data/npc/scripts/anni.
lua:7>

Edited..
 
Last edited:
LUA:
if msgcontains(msg, 'dam ci item') then
    if getPlayerItemCount(cid, itemid) >= how_many then
    doPlayerAddOutfit(cid, outfit_id, 0)
    doTeleportThing(cid, {x=,y=,z=})
    selfSay('u have been teleported', cid)
    else
    selfSay('you dont have special item', cid)
    end
end


2:
LUA:
if msgcontains(msg, '1') then
  if getPlayerVipDays(cid) >= 1 then
  doTeleportThing(cid, {x=,y=,z=})
  selfSay('u have been teleported', cid)
  else
 selfSay('you haven\'t got vip!', cid)
end
end
 
omg ? how to do npc like this ? lol

all npc's which i have looks like this

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Tidas" script="data/npc/scripts/default.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="132" head="79" body="80" legs="81" feet="82" addons="3"/>
	<parameters>
		<parameter key="module_shop" value="1"/>
		<parameter key="shop_sellable" value="sword ring,2207,1000;axe ring,2208,1000;club ring,2209,1000;dwarven ring,2213,1000;ring of healing,2214,2000;might ring,2164,3000;stealth ring,2165,1500;power ring,2166,200;energy ring,2167,800;life ring,2168,900;time ring,2169,2800"/>
	</parameters>
</npc>
 
....

go to data --> npc --> scripts

create for example hmm

noobek.lua

and paste:

LUA:
-- start shit
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
--returns how many msgs he have said already
function cancelNPCTalk(events)
  local ret=1
  for aux=1,table.getn(events) do
     if events[aux].done==FALSE then
        stopEvent(events[aux].event)
     else
        ret=ret+1
     end
  end
  events=nil
  return(ret)
end
 
function doCreatureSayWithDelay(cid,text,type,delay,e)
   if delay<=0 then
      doCreatureSay(cid,text,type)
   else
      local func=function(pars)
                    doCreatureSay(pars.cid,pars.text,pars.type)
                    pars.e.done=TRUE
                 end
      e.done=FALSE
      e.event=addEvent(func,delay,{cid=cid, text=text, type=type, e=e})
   end
end

function doNPCTalkALot(msgs,interval)
  local e={}
  local ret={}
  if interval==nil then interval=3000 end --3 seconds is default time between messages
  for aux=1,table.getn(msgs) do
      e[aux]={}
      doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_PRIVATE_NP,(aux-1)*interval,e[aux])
      table.insert(ret,e[aux])
  end
  return(ret)
end
--end shit :P





function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end      
-- zmienne lokalne
   local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    local namee = getPlayerName(cid)


	

if msgcontains(msg, 'dam ci item') then
    if getPlayerItemCount(cid, itemid) >= how_many then
    doPlayerAddOutfit(cid, outfit_id, 0)
    doTeleportThing(cid, {x=,y=,z=})
    selfSay('u have been teleported', cid)
    else
    selfSay('you dont have special item', cid)
    end
elseif msgcontains(msg, '1') then
	if getPlayerVipDays(cid) >= 1 then
	doTeleportThing(cid, {x=,y=,z=})
	selfSay('u have been teleported', cid)
	else
	selfSay('you haven\'t got vip!', cid)
	end
end
return true
end

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



and in xml file change:

<npc name="Tidas" script="data/npc/scripts/default.lua"

to

<npc name="Tidas" script="data/npc/scripts/noobek.lua"
 
this script gives me error
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)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	--[[
	REMEMBER TO SET YOUR STORAGE AS YOURSTORAGE!
	]]--
	local storage = YOURSTORAGE
	if(msgcontains(msg, 'quest') or msgcontains(msg, 'crystal')) then
		if(getPlayerStorageValue(cid, storage) < 1) then
			npcHandler:say("Hey, I have super quest for you. Bring me please {10 crystal coins}.", cid)
			setPlayerStorageValue(cid, storage, 1)
		elseif(getPlayerStorageValue(cid, storage) == 1) then
			npcHandler:say("Do you have 10 crystal coins for me?", cid)
			talkState[talkUser] = 1
		elseif(getPlayerStorageValue(cid, storage) == 2) then
			npcHandler:say("Sorry, you have already done my super quest.", cid)
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 100000) == TRUE) then
			npcHandler:say("Thanks! As I said, here\'s 20 crystal coins!", cid)
			doPlayerAddItem(cid, 2160, 20)
			setPlayerStorageValue(cid, storage, 2)
			talkState[talkUser] = 0
		else
			npcHandler:say("Sorry, you don\'t have enough money.", cid)
			talkState[talkUser] = 0
		end
	elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
		npcHandler:say("Then not.", cid)
		talkState[talkUser] = 0
	end
	return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

[20:23:26.515] [Error - NpcScript Interface]
[20:23:26.515] data/npc/scripts/anni.lua:onCreatureSay
[20:23:26.515] Description:
[20:23:26.515] data/npc/scripts/anni.lua:21: attempt to call global 'etPlayerIte
mCount' (a nil value)
[20:23:26.515] stack traceback:
[20:23:26.515] data/npc/scripts/anni.lua:21: in function 'callback'
[20:23:26.515] data/npc/lib/npcsystem/npchandler.lua:423: in function 'onCreatu
reSay'
[20:23:26.515] data/npc/scripts/anni.lua:7: in function <data/npc/scripts/anni.
lua:7>
 
Last edited:
Back
Top