Codelyy Posted June 3, 2015 Share Posted June 3, 2015 (edited) 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 thenif player.components.talker thenplayer.components.talker:Say("No Space!", 2.5)endreturnendpos=pos+offsetlocal unit=SpawnPrefab("nightmarepet")unit.Transform:SetPosition (pos:Get())unit:AddComponent("follower")player.components.leader:AddFollower(unit)unit.spawnedforplayer=playerlocal 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 = 20fn = function - ../mods/The Nightmare/scripts/prefabs/nightmarecreature.lua:9musttags = table: 2C7D1ED0canttags = nilmustoneoftags = nilx = -252.01982116699y = 0z = -437.21319580078ents = table: 2C7D1EF8i = 1v = 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() thenreturn 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")endend,{"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 June 3, 2015 by codelyoko373 Link to comment https://forums.kleientertainment.com/forums/topic/54750-multiple-followers-error/ Share on other sites More sharing options...
Seiai Posted June 3, 2015 Share Posted June 3, 2015 add thisinst.OnDespawn = OnSaveright beforeinst.OnSave= OnSavein case anyone wonders, i know his whole prefab Link to comment https://forums.kleientertainment.com/forums/topic/54750-multiple-followers-error/#findComment-643528 Share on other sites More sharing options...
Codelyy Posted June 3, 2015 Author Share Posted June 3, 2015 add thisinst.OnDespawn = OnSaveright beforeinst.OnSave= OnSavein case anyone wonders, i know his whole prefab thanks teach XD Link to comment https://forums.kleientertainment.com/forums/topic/54750-multiple-followers-error/#findComment-643529 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now