BBQ Fanatic
New Member
- Joined
- Jul 10, 2022
- Messages
- 13
- Reaction score
- 3
Hi there.
I'd like to understand few rules about npc.lua syntax, because after doing a research i'm a bit confused.
I generally wanted to make some Quest NPCs, so I was searching through OtLand for some examples, but most of them were posted in 2009/10, so I'm not sure wether they're good or not.
As first I tried to make simple NPC, who wants an item from us and gives other as reward. I used this solution as a base. My attempt looks like this:
But the entire storage thing seems to not working. No storage is applied at all, and dialogue always looks like that:
So I've been looking at NPC scripts in Resources board, then I discovered a different(?) ways to NPC syntax.
Just to be clear, I don't want you to fix my NPC (but solution + explaination will be appreciated), because I'm gonna have plenty of them, different each. I'd like to understand these few things I don't right now, to be able to create custom NPC by myself.
I'd like to understand few rules about npc.lua syntax, because after doing a research i'm a bit confused.
I generally wanted to make some Quest NPCs, so I was searching through OtLand for some examples, but most of them were posted in 2009/10, so I'm not sure wether they're good or not.
As first I tried to make simple NPC, who wants an item from us and gives other as reward. I used this solution as a base. My attempt looks like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Beggar" script="beggar.lua" walkinterval="0" floorchange="0">
<health now="150" max="150"/>
<look type="148" head="40" body="45" legs="99" feet="79"/>
<parameters>
<parameter key="message_greet" value="Hi. Will you help me?"/>
</parameters>
</npc>
Code:
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 talkState = {}
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, 'yes') or msgcontains(msg, 'help') then
if getPlayerStorageValue(cid, 5569) == 0 then
npcHandler:say("I need small diamond. Do you have one?", cid)
if msgcontains(msg, 'yes') then
if getPlayerItemCount(cid, 2145) >= 1 then
doPlayerRemoveItem(cid, 2145, 1)
doPlayerAddExp(cid, 300)
doPlayerAddItem(cid, 2159, 1)
npcHandler:say('Thank you.', cid)
setPlayerStorageValue(cid, 5569, 1)
else
npcHandler:say("Liar! You don't have it!", cid)
end
else
npcHandler:say("Come back when you get it.", cid)
end
else
npcHandler:say("You've already helped me.", cid)
end
else
npcHandler:say("Nevermind.", cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
But the entire storage thing seems to not working. No storage is applied at all, and dialogue always looks like that:
19:11 God [999]: hi
19:11 Beggar: Hi. Will you help me?
19:11 God [999]: yes
19:11 Beggar: You've already helped me.
So I've been looking at NPC scripts in Resources board, then I discovered a different(?) ways to NPC syntax.
- Sometimes it's
selfSay
, sometimesnpcHandler:say
. - What is the purpose of
talkState
? I feel like this is the thing that's missing in my npc. - Default NPCs like The Oracle or Bless has a completely different syntax, which I don't understand at all. I also saw few community NPC scripts with that kind of syntax.
npcHandler.topic[cid]
- what is this? It looks like different wany to type talkState, but dunno.
Just to be clear, I don't want you to fix my NPC (but solution + explaination will be appreciated), because I'm gonna have plenty of them, different each. I'd like to understand these few things I don't right now, to be able to create custom NPC by myself.