Zackreaver Posted November 21, 2016 Share Posted November 21, 2016 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? Link to comment https://forums.kleientertainment.com/forums/topic/71907-trying-to-despawn-followers-with-character/ Share on other sites More sharing options...
Farxodor Posted November 22, 2016 Share Posted November 22, 2016 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. Link to comment https://forums.kleientertainment.com/forums/topic/71907-trying-to-despawn-followers-with-character/#findComment-840435 Share on other sites More sharing options...
Zackreaver Posted November 22, 2016 Author Share Posted November 22, 2016 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. Link to comment https://forums.kleientertainment.com/forums/topic/71907-trying-to-despawn-followers-with-character/#findComment-840632 Share on other sites More sharing options...
. . . Posted November 22, 2016 Share Posted November 22, 2016 (edited) @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 November 23, 2016 by SuperDavid Link to comment https://forums.kleientertainment.com/forums/topic/71907-trying-to-despawn-followers-with-character/#findComment-840671 Share on other sites More sharing options...
Zackreaver Posted November 23, 2016 Author Share Posted November 23, 2016 I found out my issue, apparently my code wasn't always setting the persists = false, took me some time to figure out that this was the cause. Link to comment https://forums.kleientertainment.com/forums/topic/71907-trying-to-despawn-followers-with-character/#findComment-840765 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