• 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!

TFS 1.X+ Is possible get NPC Pos?

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
200
how can i print npc Pos? in this code (line 17)
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 and msgcontains(msg, "help") then
            npcHandler:say("get a dragon ham for me", cid)
            print(NPC_POS)
            npcHandler.topic[cid] = 1
    end
    
    return true
end
    
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
It's getNpcCid()
C++:
int NpcScriptInterface::luaGetNpcCid(lua_State* L)
{
    //getNpcCid()
    Npc* npc = getScriptEnv()->getNpc();
    if (npc) {
        lua_pushnumber(L, npc->getID());
    } else {
        lua_pushnil(L);
    }
    return 1;
}
It's getNpcCid()
C++:
int NpcScriptInterface::luaGetNpcCid(lua_State* L)
{
    //getNpcCid()
    Npc* npc = getScriptEnv()->getNpc();
    if (npc) {
        lua_pushnumber(L, npc->getID());
    } else {
        lua_pushnil(L);
    }
    return 1;
}
 
Solution
Bash:
$ spot getnpcid
/data/npc/lib/npc.lua
189:getNpcCid = getNpcId
🤷‍♂️

Lua:
getThingPos(getNpcCid())



Wait... TFS 1.x? It should just be this:
Lua:
npc:getPosition()
There's no reference to the NPC in the script by default, that's why getNpcCid() is used in the first place.
 
There's no reference to the NPC in the script by default, that's why getNpcCid() is used in the first place.

Yeah, I didn't see this tagged with TFS 1.x at first.

I also like how I sat here with this thread open for hours waiting for a free moment to be able to answer it, even though it had been untouched for a day. But the moment I do, I have something else come up then everyone comes out the wood work, cuz I had intended on covering both versions just in case cuz I don't think this was actually tagged at first. It goes to show Cunningham's Law is in full effect here.

707867192133156945.gif
 
Last edited:
Yeah, I didn't see this tagged with TFS 1.x at first.

I also like how I sat here with this thread open for hours waiting for a free moment to be able to answer it, even though it had been untouched for a day. But the moment I do, I have something else come up then everyone comes out the wood work, cuz I had intended on covering both versions just in case cuz I don't think this was actually tagged at first. It goes to show Cunningham's Law is in full effect here.

707867192133156945.gif
HAahaha tru
 
Back
Top