weire Posted February 11, 2025 Share Posted February 11, 2025 (edited) I want to write a mod that need to get current pigman follower, but ThePlayer seems don't have leader component, how do I do? Also if I found pigman by local player = GLOBAL.ThePlayer local x, y, z = player.Transform:GetWorldPosition() local ents = GLOBAL.TheSim:FindEntities(x, y, z, 30, {"pig"}) -- 30 is search radius Should this ents have follower component? Edited February 11, 2025 by weire Link to comment https://forums.kleientertainment.com/forums/topic/163980-how-to-get-current-users-follower-pigman-in-mod/ Share on other sites More sharing options...
Haruhi Kawaii Posted February 13, 2025 Share Posted February 13, 2025 On 2/11/2025 at 6:35 PM, weire said: I want to write a mod that need to get current pigman follower, but ThePlayer seems don't have leader component, how do I do? Also if I found pigman by local player = GLOBAL.ThePlayer local x, y, z = player.Transform:GetWorldPosition() local ents = GLOBAL.TheSim:FindEntities(x, y, z, 30, {"pig"}) -- 30 is search radius Should this ents have follower component? I saw a similar post Link to comment https://forums.kleientertainment.com/forums/topic/163980-how-to-get-current-users-follower-pigman-in-mod/#findComment-1796914 Share on other sites More sharing options...
weire Posted February 14, 2025 Author Share Posted February 14, 2025 thanks i saw that too, but it didn't say how can I got server instance of player, cuz ThePlay is client version in mod. Link to comment https://forums.kleientertainment.com/forums/topic/163980-how-to-get-current-users-follower-pigman-in-mod/#findComment-1797106 Share on other sites More sharing options...
Haruhi Kawaii Posted February 14, 2025 Share Posted February 14, 2025 2 hours ago, weire said: thanks i saw that too, but it didn't say how can I got server instance of player, cuz ThePlay is client version in mod. AddPlayerPostInit(function(inst) if not TheWorld.ismastersim then return inst end --[[ Trigger by somethings... local followers = inst.components.leader:CountFollowers("pig") print(followers) --]] end) You can use that code, trigger by event or something, the code below works when pigman has new leader local function CountFollowers(inst) local leader = inst.components.follower:GetLeader() if leader ~= nil and leader:HasTag("player") then print(leader.components.leader:CountFollowers("pig")) end end AddPrefabPostInit("pigman", function(inst) if not TheWorld.ismastersim then return inst end inst:ListenForEvent("startfollowing", CountFollowers) end) 2 Link to comment https://forums.kleientertainment.com/forums/topic/163980-how-to-get-current-users-follower-pigman-in-mod/#findComment-1797160 Share on other sites More sharing options...
weire Posted February 18, 2025 Author Share Posted February 18, 2025 Thanks! I'm not sure I understand Event right. I saw somewhere said that the event can be only get by the same instance, only the event from TheWorld is global, and the listener need to set the source of listen to ThenWorld. Link to comment https://forums.kleientertainment.com/forums/topic/163980-how-to-get-current-users-follower-pigman-in-mod/#findComment-1798965 Share on other sites More sharing options...
Haruhi Kawaii Posted February 18, 2025 Share Posted February 18, 2025 13 hours ago, weire said: Thanks! I'm not sure I understand Event right. I saw somewhere said that the event can be only get by the same instance, only the event from TheWorld is global, and the listener need to set the source of listen to ThenWorld. Sorry, this is beyond my understanding. I usually use the built-in events in the game and hardly ever pay attention to how they work. Link to comment https://forums.kleientertainment.com/forums/topic/163980-how-to-get-current-users-follower-pigman-in-mod/#findComment-1799313 Share on other sites More sharing options...
weire Posted March 8, 2025 Author Share Posted March 8, 2025 I tried AddPlayerPostInit(function(inst) if not TheWorld.ismastersim then return inst end local followers = inst.components.leader:CountFollowers("pig") print(followers) end) which try to get the followers that player have last time at the begining, but got nothing. Is it because that the follower has not be loaded here? anyway else I can do that? Link to comment https://forums.kleientertainment.com/forums/topic/163980-how-to-get-current-users-follower-pigman-in-mod/#findComment-1805210 Share on other sites More sharing options...
oregu Posted March 10, 2025 Share Posted March 10, 2025 (edited) I looked in the leader component and it looks like it uses a LoadPostPass, not sure what it means right now, but it might be why you aren't getting the right amount of followers. The only way pigs can be counted this way is if theyre able to continue to be loyal after disconnecting. Spoiler local function PigPlayerFollower(inst) if not inst.components.leader then return end local function followerfn(followers) -- what you want to do with num followers post-init print(followers) end local lpp = inst.components.leader.LoadPostPass inst.components.leader.LoadPostPass = function(self, ...) local result = lpp(self, ...) local followers = self:CountFollowers"pig" followerfn(followers) return result end end AddPlayerPostInit(PigPlayerFollower) does something like that give the result you'd expect? this may be a better implementation if it works Spoiler local function PlayerFollower(player, count) -- rename fn to what u want print(player, count) end AddComponentPostInit("leader", function(self) if not self.inst:HasTag"player" then return end local LoadPostPass_old = self.LoadPostPass self.LoadPostPass = function(self, ...) local result = LoadPostPass_old(self, ...) PlayerFollower(self.inst, self:CountFollowers"pig") return result end end) Edited March 10, 2025 by oregu Link to comment https://forums.kleientertainment.com/forums/topic/163980-how-to-get-current-users-follower-pigman-in-mod/#findComment-1805882 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