Recommended Posts

FurryEskimo    44

I'm trying to detect how many followers a player has when they save/leave the game, but so this doesn't seem possible.  Any ideas?

This is what I tried, but the results were simply zero.

local function OnSave(inst, data)
	print("Number of Forever Hound Followers on Save: " .. inst.components.leader:CountFollowers("hound"))
end

Seems to me like the game dismisses your followers before saving your character's information.
I'm trying to give the player an item for each follower they had when they exited the game.

Share this post


Link to post
Share on other sites
CarlZalph    5027

@FurryEskimo

In player_common.lua function OnDespawn:

inst:PushEvent("player_despawn")
inst.components.leader:RemoveAllFollowers()

So thankfully there's an event that's pushed right before all followers get nuked, in your case you can listen for it and give the items then.

  • Like 1
  • Health 1

Share this post


Link to post
Share on other sites
FurryEskimo    44

I’ll check.
The hope is to give the player a summoning item for each follower, but this might cause them to drop the items when the player tries leaving.  I’m not sure how Webber’s spiders remember him.  I haven’t had a chance to read this code about Domestication.

Update:  It seems to be working!

local function player_despawn(inst, data)
	print("Number of Forever Friend Followers on Save: " .. inst.components.leader:CountFollowers("ForeverFriend"))

	local Test = 0
	repeat
		inst.components.inventory:GiveItem(SpawnPrefab("houndcollar"))
		Test = Test + 1
	until( Test >= inst.components.leader:CountFollowers("ForeverFriend") )
end


	inst:ListenForEvent("player_despawn", player_despawn)

I just need to work this into the default player prefab and it should be good to go.

Edited by FurryEskimo

Share this post


Link to post
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