• 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 responds one word

plus

New Member
Joined
Feb 23, 2025
Messages
2
Reaction score
0
I'm creating an NPC so that if the player gets the magic word right, the player is teleported to a specific area. The NPC can't interact, it just hears the right word and teleports the player, but it's not working.

LUA:
local internalNpcName = "Guardian"
local npcType = Game.createNpcType(internalNpcName)
local npcConfig = {}

npcConfig.name = internalNpcName
npcConfig.description = internalNpcName

npcConfig.health = 100
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 0
npcConfig.walkRadius = 2

npcConfig.outfit = {
    lookTypeEx = 2152,
}

npcConfig.flags = {
    floorchange = false,
}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)

npcType.onThink = function(npc, interval)
    npcHandler:onThink(npc, interval)
end

npcType.onAppear = function(npc, creature)
    npcHandler:onAppear(npc, creature)
end

npcType.onDisappear = function(npc, creature)
    npcHandler:onDisappear(npc, creature)
end

npcType.onMove = function(npc, creature, fromPosition, toPosition)
    npcHandler:onMove(npc, creature, fromPosition, toPosition)
end

npcType.onSay = function(npc, creature, type, message)
    npcHandler:onSay(npc, creature, type, message)
end

npcType.onCloseChannel = function(npc, creature)
    npcHandler:onCloseChannel(npc, creature)
end

local function creatureSayCallback(npc, creature, type, message)
    local player = Player(creature)

    if not npcHandler:checkInteraction(npc, creature) then
        return false
    end

    local topos = { x = 32311, y = 11005, z = 6 }
    player:teleportTo(topos)
end

-- Greeting message
keywordHandler:addGreetKeyword({ "abracadabra" }, {
    npcHandler = npcHandler,
})
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)

-- npcType registering the npcConfig table
npcType:register(npcConfig)

Can anyone tell me what I'm doing wrong?
 
Can try something like this. Not 100% sure if this will work, might need some testing.
Code:
local function teleportPlayer(player)
    local topos = { x = 32311, y = 11005, z = 6 }
    player:teleportTo(topos)
end

keywordHandler:addGreetKeyword({ "abracadabra" }, teleportPlayer {
    npcHandler = npcHandler,
})
 
This is similar to how An Old Dragonlord NPC works. In my files, it uses greetCallback:

LUA:
local function greetCallback(cid)
    local player = Player(cid)
    if not player:removeItem(2787, 1) then
        npcHandler:say('AHHHH THE PAIN OF AGESSS! I NEED MUSSSSHRROOOMSSS TO EASSSE MY PAIN! BRRRING ME MUSHRRROOOMSSS!', cid)
        return false
    end
    player:addItem(2319, 1)
    npcHandler:say('AHHH MUSHRRROOOMSSS! NOW MY PAIN WILL BE EASSSED FOR A WHILE! TAKE THISS AND LEAVE THE DRAGONSSS\' CEMETERY AT ONCE!', cid)
    return false
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
 
Back
Top