Karain
Jack of all trades
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:
Thanks in advance
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