Jump to content

Recommended Posts

I am creating a character and one of his perks is to summon a shadow creature when he spawns into the world that will follow him and attack with him

 

Here the spawn code: 

local function SpawnNightmarepet(player)
local pos = Vector3(player.Transform:GetWorldPosition())
local offset = (FindWalkableOffset(pos,math.random()*PI*2,0.5,false))
if offset == nil then
if player.components.talker then
player.components.talker:Say("No Space!", 2.5)
end
return
end
pos=pos+offset
local unit=SpawnPrefab("nightmarepet")
unit.Transform:SetPosition (pos:Get())


unit:AddComponent("follower")
player.components.leader:AddFollower(unit)
unit.spawnedforplayer=player
local brain = require("brains/abigailbrain")
unit:SetBrain(brain)
end

 

However i have just noticed that if i save and quit and then load the save back up. It will spawn another follower and then crash the game with this error:

[00:00:49]: [string "../mods/The Nightmare/scripts/prefabs/night..."]:12: attempt to index field 'follower' (a nil value)
LUA ERROR stack traceback:
../mods/The Nightmare/scripts/prefabs/nightmarecreature.lua:12 in (local) fn (Lua) <9-14>
guy = 108319 - nightmareplayer (valid:true)
scripts/simutil.lua:39 in () ? (Lua) <33-44>
inst = 100578 - nightmarepet (valid:true)
radius = 20
fn = function - ../mods/The Nightmare/scripts/prefabs/nightmarecreature.lua:9
musttags = table: 2C7D1ED0
canttags = nil
mustoneoftags = nil
x = -252.01982116699
y = 0
z = -437.21319580078
ents = table: 2C7D1EF8
i = 1
v = 108319 - nightmareplayer (valid:true)
=(tail call):-1 in () (tail) <-1--1>
scripts/components/combat.lua:167 in (method) TryRetarget (Lua) <160-179>

 

The error seems to call to my NormalRetargetFn function which is this:

local function NormalRetargetFn(inst)
return FindEntity(inst, TUNING.SHADOWCREATURE_TARGET_DIST, function(guy)
if not guy.LightWatcher or guy.LightWatcher:IsInLight() then
return not guy.components.health:IsDead() and inst.components.combat:CanTarget(guy) and not
(inst.components.follower.leader ~= nil and guy:HasTag("abigail")) and not guy:HasTag("player")
end
end,
{"monster", "_health", "player"} -- see entityreplica.lua
)
end

 

It calls to line 12 which is this line: (inst.components.follower.leader ~= nil and guy:HasTag("abigail")) and not guy:HasTag("player")

 

 

Of course i don't want this to happen as i only want one follower so does anyone know a way to stop it from creating more followers everytime i load a safe?

Edited by codelyoko373
Link to comment
https://forums.kleientertainment.com/forums/topic/54750-multiple-followers-error/
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...