• Entity deletion function
    7 replies, posted
Sorry for my english, I'm Russian Hello. I need that if you shoot at the entity, then it delete. My entity is a Combine from addon Zero´s MethLab I have code, but it does not work. There are no errors in the console. function ENT:Initialize() local Health = 100 end if Health <= 0 then self:Destruct() self:Remove() end end function ENT:Destruct() local vPoint = self:GetPos() local effectdata = EffectData() effectdata:SetStart(vPoint) effectdata:SetOrigin(vPoint) effectdata:SetScale(1) util.Effect("Explosion", effectdata) end
ENTITY/OnTakeDamage this function is used when an entity is damaged
not work, There are no errors, but the Entity https://files.facepunch.com/forum/upload/270084/41534430-4e4c-4af8-9c14-209b2ebfd811/unknown - копия.png does not explode.
Use SetHealth and GetHealth instead of the health variable. You'll have to run self:SetHealth(100) in ENT:Initialize. Also, GetDamage will always return a number, no need to do the "or 0" check.
https://files.facepunch.com/forum/upload/270084/f875c441-f1bc-4a3d-9173-1d5dfcd855e0/unknown - копия.png It`s correctly?
No, you have to use self:Health() (with a colon) for retrieving the health and self:SetHealth() for setting the health. You cannot do "self:Health() =" Also, don't use self.BaseClass, use BaseClass with DEFINE_BASECLASS.
It`s correctly? If something is not right, please write the correct code, I just do not quite understand what you mean. https://files.facepunch.com/forum/upload/270084/6b7875cf-fa10-4323-9699-a57230d714b8/unknown - копия.png
You should probably learn some basic Lua before trying to implement this function. You can read some tutorials listed in the sticky here. Here are the relevant functions you need - I added some examples to the pages: Entity/SetHealth Entity/Health
Sorry, you need to Log In to post a reply to this thread.