• 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 with some functions

BugaS

Donżuan
Joined
Mar 12, 2009
Messages
1,219
Reaction score
9
Location
NYC
Hey guys! I request for a NPC which:

- checking another storage (if got, than he say 'you made it, bye'
- give storage on 'hi' (i need it to quest)
- remove item and give another one
- teleport player to position if player got the item

0.4 tfs
 
Hey guys! I request for a NPC which:

- checking another storage (if got, than he say 'you made it, bye'
- give storage on 'hi' (i need it to quest)
- remove item and give another one
- teleport player to position if player got the item

0.4 tfs

Here are some example's on how to do it.

Right now you can only talk to this npc once since when you say hi or hello to him the first time he will set your storageKey value to 0 (default is always -1)

let me know if you need me to explain more

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

local Topic = {}
local Price = {}
local Type = {}

local storageKeyHere = 1337   -- change this to storageKey
local storageValueHere = 0   -- change this to the storageValue you want the npc to assign when you say hi

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)
-- only get focus to player's whit storageValue lower then 0
   if (not npcHandler:isFocused(cid) and getPlayerStorageValue(cid, storageKeyHere) >= 0 and (msgcontains(msg, "hello$") or msgcontains(msg, "hi$"))) then
       npcHandler:say("You made it, Good bye " .. getCreatureName(cid) .. ".", cid) -- msg in npc Channel
       npcHandler:say("You made it, Good bye " .. getCreatureName(cid) .. ".")   -- msg in default chat
       Topic[cid] = nil
       return true
   elseif (not npcHandler:isFocused(cid) and (msgcontains(msg, "hello$") or msgcontains(msg, "hi$"))) then
       npcHandler:addFocus(cid)
       npcHandler:say("Hello, " .. getCreatureName(cid) .. ".", cid) -- msg in npc Channel
       npcHandler:say("Hello, " .. getCreatureName(cid) .. ".")   -- msg in default chat
       doPlayerSetStorageValue(cid, storageKeyHere, storageValueHere)   -- set the storageValue to 0
       Topic[cid] = nil
       return true
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "bye"))) then
       npcHandler:say("Good bye, " .. getCreatureName(cid) .. ".", cid)
       Topic[cid] = nil
       npcHandler:releaseFocus(cid)
       return true
-- Remove item give item Example
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "enchant knight axe"))) then
       npcHandler:say("Do you want to enchant a knight axe to a fiery knight axe, for free?", cid)
       Type[cid] = 2430   -- itemid of a regular knight axe
       Topic[cid] = 1
   elseif (npcHandler:isFocused(cid) and Topic[cid] == 1 and getPlayerItemCount(cid, Type[cid]) > 0 and (msgcontains(msg, "yes"))) then
       npcHandler:say("Here you go.", cid)
       doPlayerRemoveItem(cid, Type[cid], 1)
       Type[cid] = 7750   -- itemid of a fiery knight axe
       doPlayerAddItem(cid, Type[cid], 1, true)
       Type[cid] = nil
       Topic[cid] = nil
   elseif (npcHandler:isFocused(cid) and Topic[cid] == 1 and getPlayerItemCount(cid, Type[cid]) < 1 and (msgcontains(msg, "yes"))) then
       npcHandler:say("Sorry, you don't have any knight axe.", cid)
       Type[cid] = nil
       Topic[cid] = nil
   elseif (npcHandler:isFocused(cid) and Topic[cid] == 1 and (not msgcontains(msg, "yes"))) then
       npcHandler:say("Okey, is there anything else i can do for you?", cid)
       Type[cid] = nil
       Topic[cid] = nil
-- teleport Example of boat npc
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "carlin"))) then
       Price[cid] = 110   -- set the price to use the boat
       npcHandler:say("Do you seek a passage to Carlin for " .. Price[cid] .. " gold?", cid)
       Topic[cid] = 2
   elseif (npcHandler:isFocused(cid) and (msgcontains(msg, "ab'dendriel"))) then
       Price[cid] = 130
       npcHandler:say("Do you seek a passage to Ab'Dendriel for " .. Price[cid] .. " gold?", cid)
       Topic[cid] = 3
   elseif (npcHandler:isFocused(cid) and Topic[cid] == 2 and isPremium(cid) and getPlayerMoney(cid) >= Price[cid] and (msgcontains(msg, "yes"))) then
       -- Note: isPremium(cid) mean's the player needs premium on the account to travel/teleport. Remove it to let free accounts use the boat aswell
       doPlayerRemoveMoney(cid, Price[cid])   -- pay the price to use the boat
       Price[cid] = nil
       npcHandler:say("Set the sails!", cid)
       doTeleportThing(cid, {x= 32387,y= 31821,z = 6})   -- real tibia cords, to carlin
       doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
       Topic[cid] = nil
       npcHandler:releaseFocus(cid)
   elseif (npcHandler:isFocused(cid) and Topic[cid] == 3 and isPremium(cid) and getPlayerMoney(cid) >= Price[cid] and (msgcontains(msg, "yes"))) then
       doPlayerRemoveMoney(cid, Price[cid])
       Price[cid] = nil
       npcHandler:say("Set the sails!", cid)
       doTeleportThing(cid, {x= 32733,y= 31668,z = 6})   -- real tibia cords, to ab'dendriel
       doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
       Topic[cid] = nil
       npcHandler:releaseFocus(cid)
   end
end

npcHandler:setMessage(MESSAGE_WALKAWAY, "Yeah, get lost.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

Edit: Typos
 
Last edited:
Back
Top