Codelyy Posted June 6, 2015 Share Posted June 6, 2015 (edited) I am creating a character who has a perk where he summons a shadow creature that will follow him and attack with him. However i have just played with my friend to test it out and he claimed to not to be able to see the shadow creature when i could Here the code for the shadow creature in the character prefab:local function OnDespawn(inst, data)for k,v in pairs(inst.components.leader.followers) doif k.prefab=="nightmarepet" thenk:Remove() print("nightmarepet removed")endendendlocal function SpawnNightmarepet(player)if player:HasTag("playerghost") then return false endfor k,v in pairs(player.components.leader.followers) doif k.prefab=="nightmarepet" then return falseendendlocal 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 And this is the shadow creature prefab: local prefabs ={"nightmarefuel",}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 and inst.components.follower.leader ~= nil and guy:HasTag("abigail"))and not guy:HasTag("player")endend,{"monster", "_health", "player"} -- see entityreplica.lua)endSetSharedLootTable( 'nightmare_creature',{{'nightmarefuel', 1.0},{'nightmarefuel', 0.5},})local function OnAttacked(inst, data)inst.components.combat:SetTarget(data.attacker)inst.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("shadowcreature") and not dude.components.health:IsDead() end, 1)endlocal function MakeShadowCreature(data)local bank = data.banklocal build = data.buildlocal assets={Asset("ANIM", "anim/"..data.build..".zip"),}local sounds ={attack = "dontstarve/sanity/creature"..data.num.."/attack",attack_grunt = "dontstarve/sanity/creature"..data.num.."/attack_grunt",death = "dontstarve/sanity/creature"..data.num.."/die",idle = "dontstarve/sanity/creature"..data.num.."/idle",taunt = "dontstarve/sanity/creature"..data.num.."/taunt",appear = "dontstarve/sanity/creature"..data.num.."/appear",disappear = "dontstarve/sanity/creature"..data.num.."/dissappear",}local function fn()local inst = CreateEntity()local trans = inst.entity:AddTransform()local anim = inst.entity:AddAnimState()local physics = inst.entity:AddPhysics()local sound = inst.entity:AddSoundEmitter()inst.Transform:SetFourFaced()inst:AddTag("shadowcreature")MakeCharacterPhysics(inst, 10, 1.5)RemovePhysicsColliders(inst)inst.Physics:SetCollisionGroup(COLLISION.SANITY)inst.Physics:CollidesWith(COLLISION.SANITY)anim:SetBank(bank)anim:SetBuild(build)anim:PlayAnimation("idle_loop")anim:SetMultColour(1, 1, 1, 0.5)inst:AddComponent("locomotor") -- locomotor must be constructed before the stategraphinst.components.locomotor.walkspeed = data.speedinst.sounds = soundsinst:SetStateGraph("SGshadowcreature")inst:AddTag("monster")inst:AddTag("shadow")inst:AddTag("notraptrigger")local brain = require "brains/nightmarepetbrain"inst:SetBrain(brain)inst:AddComponent("health")inst.components.health:SetMaxHealth(data.health)inst:AddComponent("combat")inst.components.combat:SetDefaultDamage(data.damage)inst.components.combat:SetAttackPeriod(data.attackperiod)inst.components.combat:SetRetargetFunction(3, NormalRetargetFn)inst:AddComponent("lootdropper")inst.components.lootdropper:SetChanceLootTable('nightmare_creature')inst:ListenForEvent("attacked", OnAttacked)-- if GetNightmareClock() then-- inst:ListenForEvent( "phasechange",-- function (source,data)-- dprint("phase:",data.newphase)-- if data.newphase == "dawn" then-- local dawntime = GetNightmareClock():GetDawnTime()-- inst:DoTaskInTime(GetRandomWithVariance(dawntime/2,dawntime/3),-- function()-- -- otherwise we end up with a lot of piles of nightmareful-- inst.components.lootdropper:SetLoot({})-- inst.sg:GoToState("disappear")-- end)-- end-- end,-- TheWorld)-- endinst:AddComponent("knownlocations")inst:ListenForEvent("stopfollowing",function(inst) print("stopsfollowing")if not inst.components.health:IsDead() then inst.components.health:Kill() print("dies") print(inst.components.health.currenthealth)endend)return instendreturn Prefab("monsters/"..data.name, fn, assets, prefabs)endlocal data = {{name="crawlingnightmare", build = "shadow_insanity1_basic", bank = "shadowcreature1", num = 1, speed = TUNING.CRAWLINGHORROR_SPEED, health=TUNING.CRAWLINGHORROR_HEALTH, damage=TUNING.CRAWLINGHORROR_DAMAGE, attackperiod = TUNING.CRAWLINGHORROR_ATTACK_PERIOD, sanityreward = TUNING.SANITY_MED},{name="nightmarepet", build = "shadow_insanity2_basic", bank = "shadowcreature2", num = 2, speed = TUNING.TERRORBEAK_SPEED, health=TUNING.TERRORBEAK_HEALTH, damage=TUNING.TERRORBEAK_DAMAGE, attackperiod = TUNING.TERRORBEAK_ATTACK_PERIOD, sanityreward = TUNING.SANITY_LARGE}}local ret = {}for k,v in pairs(data) dotable.insert(ret, MakeShadowCreature(v))endreturn unpack(ret) I was wondering if anyone know why other players are unable to see the shadow creature when i am and how to fix it? Edited June 7, 2015 by codelyoko373 Link to comment https://forums.kleientertainment.com/forums/topic/54894-other-people-cant-see-follower/ Share on other sites More sharing options...
DarkXero Posted June 6, 2015 Share Posted June 6, 2015 local function fn() local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() local physics = inst.entity:AddPhysics() local sound = inst.entity:AddSoundEmitter() inst.entity:AddNetwork() inst.Transform:SetFourFaced() anim:SetBank(bank) anim:SetBuild(build) anim:PlayAnimation("idle_loop") anim:SetMultColour(1, 1, 1, 0.5) MakeCharacterPhysics(inst, 10, 1.5) RemovePhysicsColliders(inst) inst:AddTag("shadowcreature") inst:AddTag("monster") inst:AddTag("shadow") inst:AddTag("notraptrigger") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst.Physics:SetCollisionGroup(COLLISION.SANITY) inst.Physics:CollidesWith(COLLISION.SANITY) inst:AddComponent("locomotor") -- locomotor must be constructed before the stategraph inst.components.locomotor.walkspeed = data.speed inst.sounds = sounds inst:SetStateGraph("SGshadowcreature") Link to comment https://forums.kleientertainment.com/forums/topic/54894-other-people-cant-see-follower/#findComment-644495 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