• 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 NPC with Trade Box

lutek14

New Member
Joined
Jan 30, 2009
Messages
13
Reaction score
1
I want to add shop to this NPC. But shop will appear only after tell {beer} as is in script (talkstates cannot be removed)


NPC Lua:
local focuses = {}
local talkState = {}

local function isFocused(cid)
for i, v in pairs(focuses) do
if(v == cid) then
return true
end
end
return false
end

local function addFocus(cid)
if(not isFocused(cid)) then
table.insert(focuses, cid)
end
end
local function removeFocus(cid)
for i, v in pairs(focuses) do
if(v == cid) then
table.remove(focuses, i)
break
end
end
end
local function lookAtFocus()
for i, v in pairs(focuses) do
if(isPlayer(v)) then
doNpcSetCreatureFocus(v)
return
end
end
doNpcSetCreatureFocus(0)
end

function onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
if(isFocused(cid)) then
selfSay("Rrrr...")
removeFocus(cid)
end
end

function onCreatureSay(cid, type, msg)
local distance = getDistanceTo(cid) or -1

if((msg == "hi") and not (isFocused(cid)) and (distance <= 4 and distance ~= -1)) then
selfSay("Yup. Hey! Are you Rissam?", cid)
addFocus(cid)
talkState[cid] = 1
end
elseif((msg == "yes") and isFocused(cid)) then
if (talkState[cid] == 1) then
selfSay("I'm not sure... But... What do you want Rissam?! Maybe some {beer}?",cid)
talkState[cid] = 2
elseif((msg == "no") and isFocused(cid)) then
if (talkState[cid] == 1) then
selfSay("Ok... Would you like buy some {beer}?",cid)
talkState[cid] = 2
end
elseif((msg == "beer") and isFocused(cid)) then
if (talkState[cid] == 2) then
selfSay("I've got the best beer...",cid)
talkState[cid] = 3
end
end

function onThink()
for i, focus in pairs(focuses) do
if(not isCreature(focus)) then
removeFocus(focus)
else
local distance = getDistanceTo(focus) or -1
if((distance > 4) or (distance == -1)) then
selfSay("...")
removeFocus(focus)
end
end
end
lookAtFocus()
end

NPC xml:

<?xml version="1.0" encoding="UTF-8"?>
<npc name="Brewer Anton" script="data/npc/scripts/anton.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="132" head="3" body="0" legs="19" feet="95" addons="1"/>
</npc>
 
Back
Top