• Food ENT.Use
    4 replies, posted
Hey everybody, I'm running a ZombieRP server and in order to keep the Cook job active without hungermod, I wish to add a function, that gives the player 15 health points, whenever the player eats the food. Quite simple; [lua] function ENT:Use( activator, caller ) self:Remove() if ( activator:IsPlayer() ) then local health = activator:Health() activator:SetHealth( health + 15 ) end end[/lua] But what I'm requesting here is a funtion, that denies the player to get more HP, when he reaches the maximum amount of HP (In this case 100).
[lua]function ENT:Use( activator, caller ) self:Remove() if ( activator:IsPlayer() ) then local health = activator:Health() if health + 15 > 100 then health = 100 else health = health + 15 end activator:SetHealth( health ) end end[/lua]
Also, would this work? [lua]function ENT:SetUseType(SIMPLE_USE(activator, caller))[/lua]
[QUOTE=Baf;31708063]Also, would this work? [lua]function ENT:SetUseType(SIMPLE_USE(activator, caller))[/lua][/QUOTE] No, what you need to do is add: [lua] self:SetUseType( SIMPLE_USE ) [/lua] To the ENT:Initialize() function.
[lua] function ENT:Initialize() self.Entity:SetModel("models/props_junk/garbage_takeoutcarton001a.mdl") self.Entity:SetUseType(SIMPLE_USE) self.Entity:PhysicsInit(SOLID_VPHYSICS) self.Entity:SetMoveType(MOVETYPE_VPHYSICS) self.Entity:SetSolid(SOLID_VPHYSICS) local phys = self.Entity:GetPhysicsObject() if phys and phys:IsValid() then phys:Wake() end self.damage = 10 end[/lua] I suppose this is what you mean. Edit: Yeah, it worked.
Sorry, you need to Log In to post a reply to this thread.