• 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!

Solved Help with my own NPC

GOD TonyX

New Member
Joined
Jul 13, 2012
Messages
19
Reaction score
0
Location
Spain
[Sorry i am not good at english, i never has studied it]

I am working to create the first server 9.54 on Spain. I'm trying to create a full map by myshelf with NPC, monster, quest, etc. I had created a town with 64 Houses and 2 Guild Houses and a depot area too. Now i am trying to make some NPC to sell items like food, weapons, armor and others for task or quest. I DON'T want COPY - PASTE because i hate it. I want learn to create NPC and copy a sample can't show me how to create a NPC. I study informatic so i know what is an if - elseif loop too and all this things. But there are a loot of functions in the guide: http://otland.net/f481/scripting-guide-74030/

And he explain the principal functions but dont make a little sample for every one of the principal samples. And if you dont see a sample without programing the function is like be mother and father for first time and try to change a diaper without being taught. So If someone want to explain not only for me, to all admins that want to create a NPC for themself GO please and a lot of dudes are going to be resolved.

If anyone want plase solve this:

NPC .XML

<?xml version="1.0" encoding="UTF-8"?>
<npc name="The King" script="data/npc/scripts/the king.lua" walkinterval="2000" floorchange="0">
<health now="185" max="185"/>
<look corpse="2317" addons="0" feet="114" legs="114" body="94" head="20" type="266"/>
<parameters>
<parameter key="message_greet" value="Bienvenido a mi castillo. ¿Quieres que te ofrezca alguna mision?"/>
<parameter key="message_farewall" value="Que tu camino se ilumine ante tus ojos."/>
<parameter key="message_walkaway" value="Que maleducado. La gente suele decir adios..."/>
</parameters>
</npc>

NPC .LUA

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)
if(not npcHandler:isFocused(cid)) then
return false
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

if(msgcontains(msg, 'mision')) then
selfSay('Quieres que te encomiende una mision ¿no? Bueno como sabras para ganarte mi respeto tendras que ir haciendo misiones poco a poco, para que pueda encargarte cada vez missiones que te traigan mas recompensas.', cid)
selfSay('Bueno ahora mismo atravesamos un momento muy amargo en la ciudad ya que las alcantarillas han sido invadidas por mounstruos. Una patrulla anda en las alcantarillas, busca al capitan y pidele que te entregue un libro. ¿Aceptas la mision?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'si') and talkState[talkUser] == 1) then
talkState[talkUser] = 0
selfSay('¡Bien! Muchas gracias por acerte cargo de esta tarea. La haria encantado pero perdi mi espada y hasta que no la encuentre no podre ayudar en las labores de defensa.')
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Si no quieres por ahora, mas tarde podras realizar mis misiones. Recuerda que te llevaras dinero honor gloria y mucha experiencia.', cid)
end
return true
end

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


The error

There are no error on the server console but when the server start and you go to the position where i put it in Remere's Map Editor it don't appear (AND YES I SEE IT BEFORE) i see it because i create the NPC as default only with look type and he appear and say Hi and Bye. After a few updates because i try script without a guide only with the functions he desappear and i try to delete spawn.xml and create it again delete the monster spawner with the NPC and replace it. Modify the .LUA to the last version (when i see it) i try to create it with other name and the same .LUA and i try to create a new NPC with default.lua and it don't appear too.

¿Solution? Thanks for helping. And if you want create a small guide with the functions and his uses with small samples ¡UBERSUPERTHANKS!
 
Last edited:
Say me where and how i know a little PHP, HTML and i know C, C++. But i dont see never Lua only to create this server.

He meant posting on this forum...
put
LUA:
[/B] around your scripts it will make them easier to read and udnerstand.

[code=lua]
<?xml version="1.0" encoding="UTF-8"?>
 <npc name="The King" script="data/npc/scripts/the king.lua" walkinterval="2000" floorchange="0">
 <health now="185" max="185"/>
 <look corpse="2317" addons="0" feet="114" legs="114" body="94" head="20" type="266"/>
 <parameters>
 <parameter key="message_greet" value="Bienvenido a mi castillo. ¿Quieres que te ofrezca alguna mision?"/>
 <parameter key="message_farewall" value="Que tu camino se ilumine ante tus ojos."/>
 <parameter key="message_walkaway" value="Que maleducado. La gente suele decir adios..."/>
 </parameters>
 </npc>

LUA:
local keywordHandler = KeywordHandler:new()
 local npcHandler = NpcHandler:new(keywordHandler)
 NpcSystem.parseParameters(npcHandler)
 local talkState = {}

 function onCreatureAppear(cid) npcHandlernCreatureAppear(cid) end
 function onCreatureDisappear(cid) npcHandlernCreatureDisappear(cid) end
 function onCreatureSay(cid, type, msg) npcHandlernCreatureSay(cid, type, msg) end
 function onThink() npcHandlernThink() 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, 'mision')) then
 selfSay('Quieres que te encomiende una mision ¿no? Bueno como sabras para ganarte mi respeto tendras que ir haciendo misiones poco a poco, para que pueda encargarte cada vez missiones que te traigan mas recompensas.', cid)
 selfSay('Bueno ahora mismo atravesamos un momento muy amargo en la ciudad ya que las alcantarillas han sido invadidas por mounstruos. Una patrulla anda en las alcantarillas, busca al capitan y pidele que te entregue un libro. ¿Aceptas la mision?', cid)
 talkState[talkUser] = 1
 elseif(msgcontains(msg, 'si') and talkState[talkUser] == 1) then
 talkState[talkUser] = 0
 selfSay('¡Bien! Muchas gracias por acerte cargo de esta tarea. La haria encantado pero perdi mi espada y hasta que no la encuentre no podre ayudar en las labores de defensa.') 
 elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
 talkState[talkUser] = 0
 selfSay('Si no quieres por ahora, mas tarde podras realizar mis misiones. Recuerda que te llevaras dinero honor gloria y mucha experiencia.', cid)
 end
 return true
 end

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

I don't quite understand your problem, maybe you could explain more... Are you saying that when you add NPC on mapeditor it doesn't appear in game? have you tried to manually spawn it? /n NPCname
 
Last edited:
Ok, I was trying to create a NPC. Y create only the .XML with default.lua and i put in the map with the map editor and he appear and speak when you say HI and BYE. Later i try to create .Lua to make him speak some few words, like i post you say "mision" because is a spanish NPC and he speak and say the words and you say yes and take the good way and when you say no take the other why so i was happy it works! I see him and i speak to him. But later i upgrade the .LUA

This is the actual .LUA

LUA:
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)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if(msgcontains(msg, 'mision')) then
		selfSay('Quieres que te encomiende una mision ¿no? Bueno como sabras para ganarte mi respeto tendras que ir haciendo misiones poco a poco, para que pueda encargarte cada vez missiones que te traigan mas recompensas.', cid)
		selfSay('Bueno ahora mismo atravesamos un momento muy amargo en la ciudad ya que las alcantarillas han sido invadidas por mounstruos. Una patrulla anda en las alcantarillas, busca al capitan y pidele que te entregue un libro. ¿Aceptas la mision?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'si') and talkState[talkUser] == 1) then
		talkState[talkUser] = 0
		selfSay('¡Bien! Muchas gracias por acerte cargo de esta tarea. La haria encantado pero perdi mi espada y hasta que no la encuentre no podre ayudar en las labores de defensa.')	
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Si no quieres por ahora, mas tarde podras realizar mis misiones. Recuerda que te llevaras dinero honor gloria y mucha experiencia.', cid)
	end

	if(msgcontains(msg, 'libro')) then
		selfSay('¿Has traido el libro que te pedi?', cid)
		talkState[talkUser] = 2
	elseif(msgcontains(msg, 'si') and talkState[talkUser] == 2) then
	if(getPlayerItemCount(cid, 1950) >= 1) then
		talkState[talkUser] = 0
		selfSay('¡Bien! Este libro me sera de mucha utilidad.')
		doPlayerAddExperience(cid, 3000)
		doPlayerAddMoney(cid, 3000)
		doPlayerRemoveItem(cid,1950,1)
	else
		talkState[talkUser] = 0
		selfSay('No tienes el libro. Vuelve a las cloacas y busca al capitan para que te lo de.', cid)
	end
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Si aun no lo has encontrado no se a que esperas. Vuelve cuando lo hayas encontrado. Busca al capitan en las alcantarillas', cid)
	end
return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

I upgrade, save the changes and when i star the server on again i was where the NPC is but he isn't there. Y go to spawn.XML and all its ok he appear. I start Remere's Map Editor and he appear on the map y try to change his position, import him again, remove spawn.xml create it another time saving the map on remere's map editor and he doesn't appear again. I return the .LUA to the last version and he doesn't appear to. And when i do (/n The King) (/n 'The King') (/n "The King") he say me Sorry not possible. I summon a rat to see if i have the right access and it appear. So i don't know what happenned.

12:26 Item could not be summoned.
12:26 /n The King
12:26 Item could not be summoned.
12:26 /n "The King"
12:26 Item could not be summoned.
12:26 /n 'The King'
 
Yes i have it in the correct place

- - - Updated - - -

SOLVED

In NPC.XML i have this:

LUA:
<?xml version="1.0" encoding="UTF-8"?>
 <npc name="The King" script="data/npc/scripts/the king.lua" walkinterval="2000" floorchange="0">
 <health now="185" max="185"/>
 <look corpse="2317" addons="0" feet="114" legs="114" body="94" head="20" type="266"/>
 <parameters>
 <parameter key="message_greet" value="Bienvenido a mi castillo. ¿Quieres que te ofrezca alguna mision?"/>
 <parameter key="message_farewall" value="Que tu camino se ilumine ante tus ojos."/>
 <parameter key="message_walkaway" value="Que maleducado. La gente suele decir adios..."/>
 </parameters>
 </npc>

And Remere's Map Editor doesn't accept the parameters so finally i put:

LUA:
<?xml version="1.0" encoding="UTF-8"?>
 <npc name="The King" script="data/npc/scripts/the king.lua" walkinterval="2000" floorchange="0">
 <health now="185" max="185"/>
 <look corpse="2317" addons="0" feet="114" legs="114" body="94" head="20" type="266"/>
</npc>

This action SOLVE this problem but now the NPC dont do the message what i have removed. If someone know how can i put it without putting it on my .XML send me a primate with the code.
 
Back
Top