Jump to content

Other people can't see follower


Recommended Posts

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) do
if k.prefab=="nightmarepet" then
k:Remove() print("nightmarepet removed")
end
end
end



local function SpawnNightmarepet(player)
if player:HasTag("playerghost") then return false end
for k,v in pairs(player.components.leader.followers) do
if k.prefab=="nightmarepet" then return false
end
end

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
 
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() then
return 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")
end
end,
{"monster", "_health", "player"} -- see entityreplica.lua
)
end

SetSharedLootTable( '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)
end

local function MakeShadowCreature(data)

local bank = data.bank
local build = data.build

local 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 stategraph
inst.components.locomotor.walkspeed = data.speed
inst.sounds = sounds
inst: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)

-- end

inst: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)
end
end
)

return inst
end

return Prefab("monsters/"..data.name, fn, assets, prefabs)
end


local 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) do
table.insert(ret, MakeShadowCreature(v))
end


return 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 by codelyoko373
Link to comment
Share on other sites

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
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
 Share

×
  • Create New...