Jump to content

Recommended Posts

so I tried several approaches, it seems functions are not firing at all.
my first try :

Spoiler



local function addmissingpushevents(act)
  if stacksize > 1 then
    for i = 2, stacksize do
      act.doer:PushEvent("killed", {victim = murdered})
    end
  end
end 

AddComponentPostInit("ACTIONS.MURDER",addmissingpushevents)

 

In the above I was trying to see if the environment is kept. (e.g. in the original ACTIONS.MURDER there's a stacksize variable... )

2nd Try :

Spoiler

local function giveadditionalnaughtiness(victim)
  print("givenaughtiness")
  if victim and victim.prefab then
    local stacksize = 0
    if victim.components.stackable then
      print("stack")
      stacksize = victim.components.stackable.stacksize - 1 -- the game should have added the naughtiness already once
      print(stacksize)
      if stacksize > 0 then
        if victim.prefab == "pigman" then
          if not victim.components.werebeast or not victim.components.werebeast:IsInWereState() then
            self:OnNaughtyAction(3 * stacksize)
          end
        elseif victim.prefab == "babybeefalo" then
          self:OnNaughtyAction(6 * stacksize)
        elseif victim.prefab == "teenbird" then
          self:OnNaughtyAction(2 * stacksize)
        elseif victim.prefab == "smallbird" then
          self:OnNaughtyAction(6 * stacksize)
        elseif victim.prefab == "beefalo" then
          self:OnNaughtyAction(4 * stacksize)
        elseif victim.prefab == "crow" then
          self:OnNaughtyAction(1 * stacksize)
        elseif victim.prefab == "robin" then
          self:OnNaughtyAction(2 * stacksize)
        elseif victim.prefab == "robin_winter" then
          self:OnNaughtyAction(2 * stacksize)
        elseif victim.prefab == "butterfly" then
          self:OnNaughtyAction(1 * stacksize)
        elseif victim.prefab == "rabbit" then
          self:OnNaughtyAction(1 * stacksize)
        elseif victim.prefab == "tallbird" then
          self:OnNaughtyAction(2 * stacksize)
        elseif victim.prefab == "bunnyman" then
          self:OnNaughtyAction(3 * stacksize)
        elseif victim.prefab == "penguin" then
          self:OnNaughtyAction(2 * stacksize)
        end
      end
    end
  end
end

AddComponentPostInit("onkilledother",giveadditionalnaughtiness)

 

the component I was trying to add postinit for were :

ACTIONS.MURDER from actions.lua or kramped:onkilledother from kramped.lua

Link to comment
https://forums.kleientertainment.com/forums/topic/68035-addcomponentpostinit/
Share on other sites

You entirely misunderstand:

  • Component - code that can be given to any entity without having to be rewritten
  • Action - just that, something a creature can do actively, is determined by components
  • Event - something that happens in or to an entity, can be listened for to trigger a function when it happens

So this would be the way to do it:

AddComponentPostInit("kramped",
    function(self, inst)
        local onkilledother_old = self.onkilledother
        self.onkilledother = function(self, victim)
            if(victim)
            then
                if(victim.prefab=="crow")
                then
                    self:OnNaughtyAction(100)
                else
                    if(onkilledother_old)
                    then
                        onkilledother_old(self, victim)
                    end
                end
            end
        end
    end
)

This is for Don't Starve and not DST.  DST has a bad conforming file.

Edited by CarlZalph
This is DS subforum, not DST

@Mobbstar I get that I'm missing something however I'm not sure what xD & I'm sorry to say your explanation doesn't enlighten me much. Still thanks for trying to help me out :)

Thanks Carl

I think I get what I was missing. I thought the addcomponentpostinit could be used on functions inside the component xD

EDIT: SUCCESS ;) now getting the right amount of naughtiness when murdering stacks.

Edited by whismerhill

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