• 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

hasbro

Member
Joined
Feb 15, 2009
Messages
286
Reaction score
6
Hello,
I make one npc and and with help of all the menbers i make my npc in lua..but now i have other problem and doubt, but npc have to words to player can say..transport and rent...but rent work fine i dont know how add other word in npc.. look my script to understand more..

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local storage = 18600;
local startTime = os.time()
local talkState = {}
local newpos = {}
 
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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	if msgcontains(msg, 'rent') then
		selfSay('Do you want to rent a horse for one day at a price of 500 gold?', cid)
	end
	if msgcontains(msg, 'yes') then
		 if not getPlayerMount(cid, 25) then 
		 if doPlayerRemoveMoney(cid, 500) then
		doPlayerAddMount(cid,25)
        setPlayerStorageValue(cid, storage, startTime)
        selfSay('I\'ll give you one of our experienced ones. Take care! Look out for low hanging branches.', cid)
		else
		selfSay('Sorry, you are too poor. I\d rent one to you for free but I\m afraid you might be desperate enough to eat the horse, sorry.', cid)
		end
		else 
		selfSay('You already have this mount.', cid)
	end
	end
	end
	
function talk(cid, message, keywords, parameters, node)
if(not npcHandler:isFocused(cid)) then
return false
end
selfSay('We can bring you to Thais with one of our coaches for 125 gold. Are you interested?', cid)
if msgcontains(msg, 'yes') then
elseif doPlayerRemoveMoney(cid, 125) then
doTeleportThing(cid, newpos)
else
selfSay('You don\'t have enough money.', cid)
end
end

node1 = keywordHandler:addKeyword({'transport'}, talk, {})
	npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
No have editions i create all npc rs.

- - - Updated - - -

You talk about this?
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local days = 1 * 24 * 60 * 60
 
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 horse(cid, message, keywords,parameters,node)
	if(not npcHandler:isFocused(cid)) then
		return false
    end
 
	if getGlobalStorageValue(15906) < 30 then
		doPlayerAddMount(cid, 10)     
		npcHandler:say('Now you have a rented horse for the next 24 hours..', cid)
		local time = os.time() + days
		setCreatureStorageValue(cid, 15905, time) 
		setGlobalStorageValue(15906, math.max(0, getGlobalStorageValue(15906)) + 1) 
	else
		doPlayerSendCancel(cid, "All mounts is rented on this moment. Try Tomorrow.")
	end
end
 
 
local node1 = keywordHandler:addKeyword({'mount'}, horse, {npcHandler = npcHandler, onlyFocus = true, reset = true})
 
Back
Top