Fancy_Fox_Pers Posted April 23, 2016 Author Share Posted April 23, 2016 Just now, rezecib said: Lootdropper is a component that controls items being dropped when something is destroyed. It automatically checks if the prefab it's attached to has a recipe, and if so, drops half of the ingredients. So for Maxwell's minions, the example you were using, instead of having a recipe for shadowlumber, it has a recipe for a shadowlumber_builder. In the code you were looking at initially, the idea is that the shadowlumber_builder gets created, spawns a shadowlumber, and then removes itself. This means that (if shadowlumber had a lootdropper component, which it doesn't) when shadowlumber dies, it doesn't try to drop half of the ingredients of its recipe. If you don't want your wurm to drop half of its recipe on dying, then you should use the same strategy. Oh okay, I see thank you. Yeah I don't want him to drop anything, so I didn't event put a lootcomponent on him. Thanks for the suggestion though, I'll keep it in mind for future creatures 2 minutes ago, Aquaterion said: And what didn't work? whats the error? When I have 4 creatures, I'm not able to craft the wurm anymore, which is good But when I then kill one or more of these, I'm not able to craft one again (recipe doesn't show). Just to be clear, I kept this in the onbuild function : if builder.components.leader:CountFollowers("wurm") >= 4 then -- inst:AddTag("wurm") to the creature builder:RemoveTag("wurm_thibaud_builder") end and this in the main function : inst:ListenForEvent("death", function() local wurmleader = inst.components.follower:GetLeader() if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then local wurms = wurmleader.components.leader:CountFollowers("wurm") if wurmleader.components.leader:CountFollowers("wurm") < 4 then wurmleader:AddTag("wurm_thibaud_builder") end end end) Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755036 Share on other sites More sharing options...
Aquaterion Posted April 23, 2016 Share Posted April 23, 2016 (edited) 36 minutes ago, Thibooms said: Oh okay, I see thank you. Yeah I don't want him to drop anything, so I didn't event put a lootcomponent on him. Thanks for the suggestion though, I'll keep it in mind for future creatures When I have 4 creatures, I'm not able to craft the wurm anymore, which is good But when I then kill one or more of these, I'm not able to craft one again (recipe doesn't show). Just to be clear, I kept this in the onbuild function : if builder.components.leader:CountFollowers("wurm") >= 4 then -- inst:AddTag("wurm") to the creature builder:RemoveTag("wurm_thibaud_builder") end and this in the main function : inst:ListenForEvent("death", function() local wurmleader = inst.components.follower:GetLeader() if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then local wurms = wurmleader.components.leader:CountFollowers("wurm") if wurmleader.components.leader:CountFollowers("wurm") < 4 then wurmleader:AddTag("wurm_thibaud_builder") end end end) no errors? try adding some print("test") to see where its reaching Edited April 23, 2016 by Aquaterion Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755050 Share on other sites More sharing options...
Fancy_Fox_Pers Posted April 23, 2016 Author Share Posted April 23, 2016 1 minute ago, Aquaterion said: no errors? try adding some print("test") to see where its reaching How do I use "print" properly again? Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755054 Share on other sites More sharing options...
Aquaterion Posted April 23, 2016 Share Posted April 23, 2016 (edited) 1 minute ago, Thibooms said: How do I use "print" properly again? just write print("texthere") wherever u want it to print things into the console, maybe even print the variables, like wurmleader Edited April 23, 2016 by Aquaterion Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755055 Share on other sites More sharing options...
Fancy_Fox_Pers Posted April 24, 2016 Author Share Posted April 24, 2016 (edited) 11 hours ago, Aquaterion said: just write print("texthere") wherever u want it to print things into the console, maybe even print the variables, like wurmleader Ok, but I didn't see anything in the log. Did I do this right? if builder.components.leader:CountFollowers("wurm") >= 4 then print("Game knows there are now 4 or more wurms") builder:RemoveTag("wurm_thibaud_builder") print("Character is now unable to craft wurms") end inst:ListenForEvent("death", function() local wurmleader = inst.components.follower:GetLeader() if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then print("Game knows wurmleader can't craft wurms") local wurms = wurmleader.components.leader:CountFollowers("wurm") print("Game counts followers again") if wurmleader.components.leader:CountFollowers("wurm") < 4 then print("Game knows there are less than 4 followers") wurmleader:AddTag("wurm_thibaud_builder") print("Character is now able to craft wurms again") end end end) This is the log I got by the way client_log.txt Edited April 24, 2016 by Thibooms Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755668 Share on other sites More sharing options...
Muche Posted April 24, 2016 Share Posted April 24, 2016 In the log I can see [00:00:46]: Game knows there are now 4 or more wurms [00:00:46]: Character is now unable to craft wurms Since prints in the death listener are after if it's not clear whether it got run. I would add something like this: inst:ListenForEvent("death", function() local wurmleader = inst.components.follower:GetLeader() local _hastag = wurmleader == nil and "nil" or tostring(wurmleader:HasTag("wurm_thibaud_builder")) local _wurms = wurmleader == nil and "nil" or tostring(wurmleader.components.leader:CountFollowers("wurm")) print(string.format("[wurm-death]#1 inst=%s, wurmleader=%s, _hastag=%s, _wurms=%s", tostring(inst), tostring(wurmleader), _hastag, _wurms)) if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then print("[wurm-death]#2 Game knows wurmleader can't craft wurms") local wurms = wurmleader.components.leader:CountFollowers("wurm") print("[wurm-death]#3 Game counts followers again") if wurms < 4 then print("[wurm-death]#4 Game knows there are less than 4 followers") wurmleader:AddTag("wurm_thibaud_builder") print("[wurm-death]#5 Character is now able to craft wurms again") end end end) Possibly some useful debugging functions from debugtools.lua: dumptable, tabletoliststring, tabletodictstring; and from debughelpers.lua: DumpEntity. Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755684 Share on other sites More sharing options...
Fancy_Fox_Pers Posted April 24, 2016 Author Share Posted April 24, 2016 @Muche, Ok I didn't see that at first thanks. I tried it with your code and I do see the two lines you saw, but I still don't see anythin about "can craft wurms again" client_log.txt Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755696 Share on other sites More sharing options...
Muche Posted April 24, 2016 Share Posted April 24, 2016 (edited) But there is [00:01:07]: [wurm-death]#1 inst=109391 - wurm_thibaud, wurmleader=nil, _hastag=nil, _wurms=nil i.e. for some reason the wurm has no leader. In the components/leader.lua there is local ondeath = function() self:RemoveFollower(follower) end self.inst:ListenForEvent("death", ondeath, follower) follower:ListenForEvent("death", ondeath, self.inst) so it's possible that leader's death listener for the follower executed a little bit earlier and removed the connection between them. I would add DumpEntity(inst) in there as well, just to see full status of the dying wurm. Edited April 24, 2016 by Muche Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755704 Share on other sites More sharing options...
Aquaterion Posted April 24, 2016 Share Posted April 24, 2016 (edited) 16 minutes ago, Muche said: But there is [00:01:07]: [wurm-death]#1 inst=109391 - wurm_thibaud, wurmleader=nil, _hastag=nil, _wurms=nil i.e. for some reason the wurm has no leader. In the components/leader.lua there is local ondeath = function() self:RemoveFollower(follower) end self.inst:ListenForEvent("death", ondeath, follower) follower:ListenForEvent("death", ondeath, self.inst) so it's possible that leader's death listener for the follower executed a little bit earlier and removed the connection between them. I would add DumpEntity(inst) in there as well, just to see full status of the dying wurm. Maybe listening for "stopfollowing" would work? altought it takes the "leader" as its variable, not the follower. inst:ListenForEvent("stopfollowing", function(wurmleader) print(wurmleader) if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then print("Game knows wurmleader can't craft wurms") local wurms = wurmleader.components.leader:CountFollowers("wurm") print("Game counts followers again") if wurmleader.components.leader:CountFollowers("wurm") < 4 then print("Game knows there are less than 4 followers") wurmleader:AddTag("wurm_thibaud_builder") print("Character is now able to craft wurms again") end end end) try that Edited April 24, 2016 by Aquaterion Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755710 Share on other sites More sharing options...
Fancy_Fox_Pers Posted April 24, 2016 Author Share Posted April 24, 2016 (edited) 29 minutes ago, Aquaterion said: try that I did, but I don't see anything new :/ client_log.txt Actually wait a second, I might have screwed something up Edited April 24, 2016 by Thibooms Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755720 Share on other sites More sharing options...
Aquaterion Posted April 24, 2016 Share Posted April 24, 2016 (edited) Just now, Thibooms said: I did, but I don't see anything new :/ client_log.txt i still see muche's debug code, did you put it in urself or? because the "leader" shoulda been printed, even if it was nil Edited April 24, 2016 by Aquaterion Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755721 Share on other sites More sharing options...
Fancy_Fox_Pers Posted April 24, 2016 Author Share Posted April 24, 2016 Just now, Aquaterion said: i still see muche's debug code, did you put it in urself or? because the "leader" shoulda been printed, even if it was nil That's what I screwed up I think xD Gimme a sec Ok so now I crashed. I was supposed to do this right? -- inst:ListenForEvent("death", -- function() -- local wurmleader = inst.components.follower:GetLeader() -- if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then -- print("Game knows wurmleader can't craft wurms") -- local wurms = wurmleader.components.leader:CountFollowers("wurm") -- print("Game counts followers again") -- if wurmleader.components.leader:CountFollowers("wurm") < 4 then -- print("Game knows there are less than 4 followers") -- wurmleader:AddTag("wurm_thibaud_builder") -- print("Character is now able to craft wurms again") -- end -- end -- end) inst:ListenForEvent("stopfollowing", function(wurmleader) print(wurmleader) if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then print("Game knows wurmleader can't craft wurms") local wurms = wurmleader.components.leader:CountFollowers("wurm") print("Game counts followers again") if wurmleader.components.leader:CountFollowers("wurm") < 4 then print("Game knows there are less than 4 followers") wurmleader:AddTag("wurm_thibaud_builder") print("Character is now able to craft wurms again") end end end) -- inst:ListenForEvent("death", -- function() -- local wurmleader = inst.components.follower:GetLeader() -- local _hastag = wurmleader == nil and "nil" or tostring(wurmleader:HasTag("wurm_thibaud_builder")) -- local _wurms = wurmleader == nil and "nil" or tostring(wurmleader.components.leader:CountFollowers("wurm")) -- print(string.format("[wurm-death]#1 inst=%s, wurmleader=%s, _hastag=%s, _wurms=%s", tostring(inst), tostring(wurmleader), _hastag, _wurms)) -- if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then -- print("[wurm-death]#2 Game knows wurmleader can't craft wurms") -- local wurms = wurmleader.components.leader:CountFollowers("wurm") -- print("[wurm-death]#3 Game counts followers again") -- if wurms < 4 then -- print("[wurm-death]#4 Game knows there are less than 4 followers") -- wurmleader:AddTag("wurm_thibaud_builder") -- print("[wurm-death]#5 Character is now able to craft wurms again") -- end -- end -- end) I crashed upon attacking a friendly wurm Here's the log : client_log.txt Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755723 Share on other sites More sharing options...
Aquaterion Posted April 24, 2016 Share Posted April 24, 2016 oh wait it does ust the wurm as the first var, not the leader, hmm maybe this? inst:ListenForEvent("stopfollowing", function(inst, wurmleader) print(wurmleader) if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then print("Game knows wurmleader can't craft wurms") local wurms = wurmleader.components.leader:CountFollowers("wurm") print("Game counts followers again") if wurmleader.components.leader:CountFollowers("wurm") < 4 then print("Game knows there are less than 4 followers") wurmleader:AddTag("wurm_thibaud_builder") print("Character is now able to craft wurms again") end end end) if that doesn't work, then I have 1 more try to attempt Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755724 Share on other sites More sharing options...
Fancy_Fox_Pers Posted April 24, 2016 Author Share Posted April 24, 2016 Just now, Aquaterion said: oh wait it does ust the wurm as the first var, not the leader, hmm maybe this? inst:ListenForEvent("stopfollowing", function(inst, wurmleader) print(wurmleader) if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then print("Game knows wurmleader can't craft wurms") local wurms = wurmleader.components.leader:CountFollowers("wurm") print("Game counts followers again") if wurmleader.components.leader:CountFollowers("wurm") < 4 then print("Game knows there are less than 4 followers") wurmleader:AddTag("wurm_thibaud_builder") print("Character is now able to craft wurms again") end end end) if that doesn't work, then I have 1 more try to attempt What did you just change? :S Anyways, it crashed again. It's got a problem with "HasTag" :/ client_log.txt Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755725 Share on other sites More sharing options...
Aquaterion Posted April 24, 2016 Share Posted April 24, 2016 inst:ListenForEvent("stopfollowing", function(inst) print(inst) local wurmleader = inst.components.follower:GetLeader() if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then print("Game knows wurmleader can't craft wurms") local wurms = wurmleader.components.leader:CountFollowers("wurm") print("Game counts followers again") if wurmleader.components.leader:CountFollowers("wurm") < 4 then print("Game knows there are less than 4 followers") wurmleader:AddTag("wurm_thibaud_builder") print("Character is now able to craft wurms again") end end end) let's hope Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755727 Share on other sites More sharing options...
Muche Posted April 24, 2016 Share Posted April 24, 2016 components/leader.lua is doing follower:PushEvent("stopfollowing", {leader = self.inst} ) thus this should work as well: inst:ListenForEvent("stopfollowing", function(inst, data) local wurmleader = data ~= nil and data.leader or nil local _hastag = wurmleader == nil and "nil" or tostring(wurmleader:HasTag("wurm_thibaud_builder")) local _wurms = wurmleader == nil and "nil" or tostring(wurmleader.components.leader:CountFollowers("wurm")) print(string.format("[wurm-stopfollowing]#1 inst=%s, wurmleader=%s, _hastag=%s, _wurms=%s", tostring(inst), tostring(wurmleader), _hastag, _wurms)) ... Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755730 Share on other sites More sharing options...
Aquaterion Posted April 24, 2016 Share Posted April 24, 2016 Just now, Muche said: components/leader.lua is doing follower:PushEvent("stopfollowing", {leader = self.inst} ) thus this should work as well: inst:ListenForEvent("stopfollowing", function(inst, data) local wurmleader = data ~= nil and data.leader or nil local _hastag = wurmleader == nil and "nil" or tostring(wurmleader:HasTag("wurm_thibaud_builder")) local _wurms = wurmleader == nil and "nil" or tostring(wurmleader.components.leader:CountFollowers("wurm")) print(string.format("[wurm-stopfollowing]#1 inst=%s, wurmleader=%s, _hastag=%s, _wurms=%s", tostring(inst), tostring(wurmleader), _hastag, _wurms)) ... yea that was my next attempt, because only a while after I noticed the leader was in a table Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755732 Share on other sites More sharing options...
Fancy_Fox_Pers Posted April 24, 2016 Author Share Posted April 24, 2016 @Aquaterion @Muche Thank you so much for your help, guys! But you've confused me now. What am I supposed to try out? :V Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755744 Share on other sites More sharing options...
Aquaterion Posted April 24, 2016 Share Posted April 24, 2016 Just now, Thibooms said: @Aquaterion @Muche Thank you so much for your help, guys! But you've confused me now. What am I supposed to try out? :V inst:ListenForEvent("stopfollowing", function(inst, data) local wurmleader = data.leader if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then print("Game knows wurmleader can't craft wurms") local wurms = wurmleader.components.leader:CountFollowers("wurm") print("Game counts followers again") if wurmleader.components.leader:CountFollowers("wurm") < 4 then print("Game knows there are less than 4 followers") wurmleader:AddTag("wurm_thibaud_builder") print("Character is now able to craft wurms again") end end end) Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755745 Share on other sites More sharing options...
Fancy_Fox_Pers Posted April 24, 2016 Author Share Posted April 24, 2016 1 minute ago, Aquaterion said: inst:ListenForEvent("stopfollowing", function(inst, data) local wurmleader = data.leader if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then print("Game knows wurmleader can't craft wurms") local wurms = wurmleader.components.leader:CountFollowers("wurm") print("Game counts followers again") if wurmleader.components.leader:CountFollowers("wurm") < 4 then print("Game knows there are less than 4 followers") wurmleader:AddTag("wurm_thibaud_builder") print("Character is now able to craft wurms again") end end end) Great! That works! No need to check the log for printing Link to comment https://forums.kleientertainment.com/forums/topic/66607-making-a-craftable-follower/page/2/#findComment-755747 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