Getting player stamina when he dies

marceloSRmarceloSR REGISTERED Posts: 47 Seed
edited December 2015 in Mods
I was trying to check if the player died when he was starving by using
LocalPlayer.Die = function (self, source) local deathCause = "Health" if Player.m_energy <= 0.0 then deathCause = "Starve" end LocalPlayer_Die(self, source) end

(I get the Player from another function, it is the player Pawn)

However, when I try this I get the error: attempt to compare table with number.
I don´t quite understand what is the problem. Is m_energy part of an array??
I know it is a property from the Survival Player class, but the Local_Player inherit this class, so I should be able to access it right?

Comments

  • RawrRawr REGISTERED, Tester Posts: 510 Seed
    Had a quick look through BasePlayer.lua and it seems like m_energy is a table, try Player.m_engery:Value()
    Programmer, designer, artist.
  • marceloSRmarceloSR REGISTERED Posts: 47 Seed
    Thank you, Rawr, it worked out!

    However it is strange, because on the survival player script they compare the energy without addressing it as a table value

    if self.m_energy <= 0.0 then -- TODO: needs porting --m_status |= eStatusStarving; if self.m_health / self.m_maxHealth < 0.33 then self.m_triggerHurtEffects = true else self.m_triggerHurtEffects = false end self:ModifyHealth(-1.0) else

    But as long as it is working it should be fine! haha
  • RawrRawr REGISTERED, Tester Posts: 510 Seed
    Good question.
    Programmer, designer, artist.
  • johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
    edited December 2015
    wow, yeah that logic doesn't do anything. Looks like it's old left over code from back when m_energy was a number variable.

    Here is the function (BasePlayer:_UpdateEnergy) responsible for starving:
    -------------------------------------------------------------------------------
    -- Called once a frame to update the state of the player's energy.
    function BasePlayer:_UpdateEnergy( dt )
    -- Increment the one second energy timer.
    self.m_energyTimer = self.m_energyTimer + dt

    -- If it's time to tick energy.
    if self.m_energyTimer >= 1.0 then

    self:_ModifyEnergy(BasePlayer.EnergyRegenPerSecond)

    -- Reset the timer
    -- TODO: Aren't we losing any overflow time from the current dt by doing it this way?
    self.m_energyTimer = 0.0

    -- Are we starving?
    if self.m_energy:Value() <= 0.0 then
    self:ApplyDamage({ damage = 1.0, category = "Starving" })
    end
    end
    end
    My Blog
    jc.png
      yt.png  t.png  
  • MaylyonMaylyon REGISTERED, Developers Posts: 1 Developer
    edited December 2015
    I like the "TODO" in that code. Wouldn't it just need to decrement by 1.0? :p
  • RawrRawr REGISTERED, Tester Posts: 510 Seed
    There's definitely some quality comments around the place :chuffed:
    Programmer, designer, artist.
  • marceloSRmarceloSR REGISTERED Posts: 47 Seed
    hahaha, ok.
    I'm glad I found something that you can remove to make the code cleaner :p
Sign In or Register to comment.