Jump to content

How can i use self.entity:Release()


fhl42
 Share

Recommended Posts

when i use self.entity:Release() the exe crashes when playing and use the health when i keep the player in idle anim its not crashing but when i move or rotate player with weapon the exe crashes, can someone say how to use it

i use it in Health pickup when enemy dead it pops out of the enemy a health box, tutorial was on youtube

i am new to lua i am a beginner here is the healthpickup script

Script.health = 15.0 --float "Health"
Script.useOnce = true --bool "Use once"

function Script:Start()
    if self.health < 0 then
        error("Health can't be a negative value.")
    end
end

function Script:Use(player)
    if player.script.health < player.script.maxHealth then
        player.script:ReceiveHealth(self.health)
        if self.useOnce then
            self.entity:Release()
        end
    end
end

Link to comment
Share on other sites

You could also try releasing after hiding either immediately or after a few seconds.  I've had some funky issues in the past when trying to release an entity but it's still performing actions, so my solution was to hide it then release after a few seconds - worked well in my projects. 

Just remember, you're hiding that item, not destroying it. Not much of an issue on a small scale but on a larger project you'll probably want to scrap the band-aid solution for a proper one. 

  • Like 1
Link to comment
Share on other sites

(You could also try releasing after hiding ) :) Its working thanks you people for helping

Script.health = 15.0 --float "Health"
Script.useOnce = true --bool "Use once"
Script.ReleaseTimer=0
Script.ReleaseDelay=5000--float "Corpse Time"

function Script:Start()
    if self.health < 0 then
        error("Health can't be a negative value.")
    end
end

function Script:UpdatePhysics()
    if self.ReleaseTimer ~= 0 and self.ReleaseTimer < Time:GetCurrent() then
       self.entity:Release()
    end
end

function Script:Use(player)
    if player.script.health < player.script.maxHealth then
        player.script:ReceiveHealth(self.health)
        if self.useOnce then
            self.entity:Hide()
            self.ReleaseTimer = Time:GetCurrent() + self.ReleaseDelay
        end
    end
end

  • Like 1
  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...