Jump to content

Recommended Posts

Okay, so I have a character who can have rabbits as followers.

I want the rabbits to despawn when the character leaves the server or the server shuts down, and I want the rabbits to reappear when the character reconnects.

 

I am having trouble getting the rabbits to despawn when the player disconnects or the server shuts down.  What would be a good way to do this?

I would take a look at Maxwell's pet leash system, or perhaps Abigail's mechanics. Since you want the rabbits to be bound to the character, and not just follow like a pig, you may need to create another entity to use as a rabbit follower.

I have looked at them, but no matter what I apply the rabbits refuse to despawn with the character.  However, I did take the "Create a new entity" into consideration, though if it comes to that I'd like to know a good way to retain the rabbit's most up to date script.  As simply copying the Rabbit.lua would result in the follower requiring maintenance should an update ever come to the rabbits in the future.

 

I'm mostly considering my options at the moment, I would like the rabbits that are following the character to simply disappear with the character when the server shuts down or they leave, but for some reason I can't get that behavior to happen.

@Zackreaver You could use this code to make rabbits go in caves & despawn with their leaders.

Inside your rabbit.lua you would put in  local function OnGetItemFromPlayer(inst, giver, item)

local target = giver
if target then
local x, y, z = target.Transform:GetWorldPosition()
if target.components.petleash then
target.components.petleash:SpawnPetAt(x, y, z, "rabbit")
inst.components.health:DoDelta(-99)
end
end

and inside yourcharacter.lua you would put inside master_postinit

inst:AddComponent("petleash")
inst.components.petleash:SetMaxPets(999) -- How many rabbits can get
inst.components.petleash:SetOnSpawnFn(OnSpawnRabbit)

and above master_postinit inside yourcharacter.lua you would put

local function DoSpawnRabbit(rabbit, inst)
  rabbit.owner = inst
end

local function OnSpawnRabbit(inst, rabbit)
  rabbit:DoTaskInTime(0, DoSpawnRabbit, inst)
end

 

The only problem is I don't know how to call upon the newly spawned pet to do stuff for them because i'm not good at coding :(, though this code would achieve what you want

Maybe someone else can say how to do this in a more proper way, because I don't know :)

Edited by SuperDavid

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