• 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 TFS 1.0 NPC Follow range

Karain

Jack of all trades
Joined
Jul 9, 2009
Messages
338
Solutions
3
Reaction score
147
Location
Egypt
Hello, i was trying to make a smarter NPC that will react to your words and attitude. if you offend her she will stop responding to players and follow the offender, and attacking him.


it was going well until the NPC stops following you if you get more than 3 sqm away from the NPC, i have no idea why that happens, maybe source code?

Here's the code:

Code:
local hostile = 0

function onCreatureSay(cid, type, msg)
    local player = Player(cid)
    if msg=="Piss off" then
        hostile = cid
        selfSay("Fuck off, "..player:getName().."!")
    end
    return true
end

function onThink()
    local npc = Creature(getNpcCid())
    if hostile ~= 0 then
        local player = Creature(hostile)
        selfSay("attacking: "..player:getName())  -- this works even after i stay 3 sqm away
        if selfFollow(hostile) then   -- will return false after being 3 sqm away
            selfSay("Persuing!")
        end
    else
        local string = ""
        local playersNearby = Game.getSpectators(getNpcPos(),false, true, 0, 5, 0, 5)
        if playersNearby ~= nil or playersNearby ~= 0 then
            for p=1,#playersNearby do
                string = string.." "..playersNearby[p]:getName().." - "
            end
        end
        selfSay("Nearby Players:"..string)
    end
    return true
end

Thanks in advance
 
Could it be a simple thing as a "range to talk" in the NPC file that is making a conflict?

Cool script by the way. :)

Kind Regards,
Eldin.
 
Could it be a simple thing as a "range to talk" in the NPC file that is making a conflict?

Cool script by the way. :)

Kind Regards,
Eldin.

the only thing that was related to talk range was npchandler, which i removed from this specific script

Code:
npc:setTarget(target)
npc:setFollowCreature(target, true)

the code runs, but the npc doesn't follow me at all =/
 
Back
Top