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

npc check house

theduck

Member
Joined
Dec 6, 2018
Messages
246
Reaction score
20
I would like to know if it is possible a check to put in a npc that he only spoke to whoever was invited in the house I tried several things more without success
 
Solution
I gave sample function but I was kinda out of loop for a while. I looked briefly into TFS1.x source.

This maybe should be the correct way of doing this:
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 onGreet_Callback(cid)
    local npc = Npc()
    local player = Player(cid)...
I would like to know if it is possible a check to put in a npc that he only spoke to whoever was invited in the house I tried several things more without success

Yeh, its possible. Everything is possible * motivation *
First of all, TFS version? Take a look in your luascript.cpp in your sources, have a function related with that I guess.. just call that function in a NPC script using the player houseId.
 
I would like to know if it is possible a check to put in a npc that he only spoke to whoever was invited in the house I tried several things more without success
Try this out:
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 house_id = 1 -- SET HOUSE ID HERE

local function onGreet_Callback(cid)
    local player = Player(cid)
    local access_list = House(house_id):getAccessList(GUEST_LIST)
    if access_list and access_list:find(player:getName()) then
        npcHandler:say("Go away.", cid)
        npcHandler:releaseFocus(cid)
        npcHandler:resetNpc(cid)
        return false
    else
        npcHandler:setMessage(MESSAGE_GREET, "Hello.")
    end
    return true
end

local function onSay_Callback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onSay_Callback)
npcHandler:setCallback(CALLBACK_GREET, onGreet_Callback)
npcHandler:addModule(FocusModule:new())
 
I would like to know if it is possible a check to put in a npc that he only spoke to whoever was invited in the house I tried several things more without success
Realized I did this backwards lol. Here's the fix:
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 house_id = 1 -- SET HOUSE ID HERE

local function onGreet_Callback(cid)
    local player = Player(cid)
    local access_list = House(house_id):getAccessList(GUEST_LIST)
    if access_list and access_list:find(player:getName()) then
        npcHandler:setMessage(MESSAGE_GREET, "Hello.")
    else
        npcHandler:say("Go away.", cid)
        npcHandler:releaseFocus(cid)
        npcHandler:resetNpc(cid)
        return false
    end
    return true
end

local function onSay_Callback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onSay_Callback)
npcHandler:setCallback(CALLBACK_GREET, onGreet_Callback)
npcHandler:addModule(FocusModule:new())
 
Realized I did this backwards lol. Here's the fix:
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 house_id = 1 -- SET HOUSE ID HERE

local function onGreet_Callback(cid)
    local player = Player(cid)
    local access_list = House(house_id):getAccessList(GUEST_LIST)
    if access_list and access_list:find(player:getName()) then
        npcHandler:setMessage(MESSAGE_GREET, "Hello.")
    else
        npcHandler:say("Go away.", cid)
        npcHandler:releaseFocus(cid)
        npcHandler:resetNpc(cid)
        return false
    end
    return true
end

local function onSay_Callback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onSay_Callback)
npcHandler:setCallback(CALLBACK_GREET, onGreet_Callback)
npcHandler:addModule(FocusModule:new())
Is it possible to do this for all houses?
without needing to boot the id of each house
 
Is it possible to do this for all houses?
without needing to boot the id of each house

As long as you have getTileHouseInfo(pos) or simillar available then yes.

With the code above, grab npc position [inside the house], use it in getTileHouseInfo(pos) which then returns you a dynamic house id depending on where npc is standing.
 
Is it possible to do this for all houses?
without needing to boot the id of each house
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 onGreet_Callback(cid)
    local npc = Npc()
    local house_id = npc and getTileHouseInfo(npc:getPosition())
    local access_list = house_id and House(house_id):getAccessList(GUEST_LIST)
    if access_list and access_list:find(player:getName()) then
        npcHandler:setMessage(MESSAGE_GREET, "Hello.")
    else
        npcHandler:say("Go away.", cid)
        npcHandler:releaseFocus(cid)
        npcHandler:resetNpc(cid)
        return false
    end
    return true
end

local function onSay_Callback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onSay_Callback)
npcHandler:setCallback(CALLBACK_GREET, onGreet_Callback)
npcHandler:addModule(FocusModule:new())
 
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 onGreet_Callback(cid)
    local npc = Npc()
    local house_id = npc and getTileHouseInfo(npc:getPosition())
    local access_list = house_id and House(house_id):getAccessList(GUEST_LIST)
    if access_list and access_list:find(player:getName()) then
        npcHandler:setMessage(MESSAGE_GREET, "Hello.")
    else
        npcHandler:say("Go away.", cid)
        npcHandler:releaseFocus(cid)
        npcHandler:resetNpc(cid)
        return false
    end
    return true
end

local function onSay_Callback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onSay_Callback)
npcHandler:setCallback(CALLBACK_GREET, onGreet_Callback)
npcHandler:addModule(FocusModule:new())
Code:
2019-04-03 19:40:22 -  Lua Script Error: [Npc interface] 
2019-04-03 19:40:22 -  data/npc/scripts/npclootmakert.lua:onCreatureSay
2019-04-03 19:40:22 -  data/npc/scripts/npclootmakert.lua:14: attempt to index global 'player' (a nil value)
2019-04-03 19:40:22 -  stack traceback:
2019-04-03 19:40:22 -   [C]: in function '__index'
2019-04-03 19:40:22 -   data/npc/scripts/npclootmakert.lua:14: in function 'callback'
2019-04-03 19:40:22 -   data/npc/lib/npcsystem/npchandler.lua:354: in function 'greet'
2019-04-03 19:40:22 -   data/npc/lib/npcsystem/npchandler.lua:544: in function 'onGreet'
2019-04-03 19:40:22 -   data/npc/lib/npcsystem/modules.lua:324: in function 'callback'
2019-04-03 19:40:22 -   data/npc/lib/npcsystem/keywordhandler.lua:31: in function 'processMessage'
2019-04-03 19:40:22 -   data/npc/lib/npcsystem/keywordhandler.lua:186: in function 'processNodeMessage'
2019-04-03 19:40:22 -   data/npc/lib/npcsystem/keywordhandler.lua:154: in function 'processMessage'
2019-04-03 19:40:22 -   data/npc/lib/npcsystem/npchandler.lua:428: in function 'onCreatureSay'
2019-04-03 19:40:22 -   data/npc/scripts/npclootmakert.lua:7: in function <data/npc/scripts/npclootmakert.lua:7>


use tfs1x I put local player = Player (cid) plus the error continues
 
Seems like missing
Lua:
local player = Player(cid)


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 onGreet_Callback(cid)
    local npc = Npc()
    local player = Player(cid)
    
    local house_id = npc and getTileHouseInfo(npc:getPosition())
    local access_list = house_id and House(house_id):getAccessList(GUEST_LIST)
    if access_list and access_list:find(player:getName()) then
        npcHandler:setMessage(MESSAGE_GREET, "Hello.")
    else
        npcHandler:say("Go away.", cid)
        npcHandler:releaseFocus(cid)
        npcHandler:resetNpc(cid)
        return false
    end
    return true
end

local function onSay_Callback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onSay_Callback)
npcHandler:setCallback(CALLBACK_GREET, onGreet_Callback)
npcHandler:addModule(FocusModule:new())

I have no idea if this one will run tho, no way to test :p
 
Seems like missing
Lua:
local player = Player(cid)


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 onGreet_Callback(cid)
    local npc = Npc()
    local player = Player(cid)
   
    local house_id = npc and getTileHouseInfo(npc:getPosition())
    local access_list = house_id and House(house_id):getAccessList(GUEST_LIST)
    if access_list and access_list:find(player:getName()) then
        npcHandler:setMessage(MESSAGE_GREET, "Hello.")
    else
        npcHandler:say("Go away.", cid)
        npcHandler:releaseFocus(cid)
        npcHandler:resetNpc(cid)
        return false
    end
    return true
end

local function onSay_Callback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onSay_Callback)
npcHandler:setCallback(CALLBACK_GREET, onGreet_Callback)
npcHandler:addModule(FocusModule:new())

I have no idea if this one will run tho, no way to test :p
what occurs from what I saw is that he talks to everyone both the guest and the street players
 
I gave sample function but I was kinda out of loop for a while. I looked briefly into TFS1.x source.

This maybe should be the correct way of doing this:
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 onGreet_Callback(cid)
    local npc = Npc()
    local player = Player(cid)
    local tile = npc:getTile()
    local house = tile:getHouse()

    if house then
        local access_list = house:getAccessList(GUEST_LIST)
        if access_list and access_list:find(player:getName()) then
            npcHandler:setMessage(MESSAGE_GREET, "Hello.")
        else
            npcHandler:say("Go away.", cid)
            npcHandler:releaseFocus(cid)
            npcHandler:resetNpc(cid)
            return false
        end
    end

    return true
end

local function onSay_Callback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onSay_Callback)
npcHandler:setCallback(CALLBACK_GREET, onGreet_Callback)
npcHandler:addModule(FocusModule:new())
 
Solution
Back
Top