Jump to content

Recommended Posts

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)

 

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 by Aquaterion
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 by Aquaterion
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 by Thibooms

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.

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 by Muche
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 by Aquaterion
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 by Aquaterion
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

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

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

    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

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

 

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

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)

 

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 :)

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