• 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 set ghost mode in npc, is possible?

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
200
tfs 1.3 8.6
I'm creating a fight npc, after talking to him, you will fight with him.
my idea is after talking, the npc will enter ghost mode (like GM), and summon a monster with the same appearance as the NPC, for the player to fight.

but I'm not able to use the set ghost function for npc, is it possible?
Code:
quest/npc1.lua:17: attempt to call method 'setGhostMode' (a nil value)
Lua:
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 function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, "fight") then
            Npc():setGhostMode(true)
            npcHandler:say("Lets fight!", cid)
            npcHandler.topic[cid] = 1           
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Quick idea:
Just replace the NPC with Monster named same as NPC (when player start fight), make onKill/onDeath script and after defeat this monster, spawn NPC on his place again.
Don't forget to set spawn in RME (map editor) to 0 to prevent spawning double NPC.
Quick idea:
Just replace the NPC with Monster named same as NPC (when player start fight), make onKill/onDeath script and after defeat this monster, spawn NPC on his place again.
Don't forget to set spawn in RME (map editor) to 0 to prevent spawning double NPC.
 
Solution
Quick idea:
Just replace the NPC with Monster named same as NPC (when player start fight), make onKill/onDeath script and after defeat this monster, spawn NPC on his place again.
Don't forget to set spawn in RME (map editor) to 0 to prevent spawning double NPC.
if i use Npc():remove() i need to put in map editor 0 or not?
 
Yes of course, it will spawn anyway if you remove him after X seconds (in RME spawntime/interval).
You always can test it manually by doing that and wait for him to spawn :p
 
Back
Top