General > Developers Corner

GMod lua function to set HP?

<< < (2/3) > >>

MrPresident:
You do realize that a PLAYER is an ENTITY right?


the ent in ent:SetHealth(100) is just whatever entity's (to include a player) health you want to set.

Megiddo:
Helpful Wikipedia article on what is-a means. :)

RogerThatGaming:
So, if I wanted the player to spawn with 160 health, for example, I would do:

function GM:PlayerSpawn( pl )

   player_manager.SetPlayerClass( pl, "player_sandbox" )
   
   BaseClass.PlayerSpawn( self, pl )
   
   pl:SetHealth( 160 )
   
end

BUT I WOULD FIRST HAVE TO

function HealthMax( )

       ply:SetMaxHealth( 160 )

end

Is that right?! Thanks

Decicus:

--- Quote from: RogerThatGaming on March 28, 2014, 10:33:05 AM ---So, if I wanted the player to spawn with 160 health, for example, I would do:

--- Code: ---function GM:PlayerSpawn( pl )

player_manager.SetPlayerClass( pl, "player_sandbox" )
   
BaseClass.PlayerSpawn( self, pl )

pl:SetHealth( 160 )

end

BUT I WOULD FIRST HAVE TO

function HealthMax( )

       ply:SetMaxHealth( 160 )

end

--- End code ---
Is that right?! Thanks

--- End quote ---
Why create two functions when you could have just put pl:SetMaxHealth in your PlayerSpawn function?

Neku:
No, all you need to do is


--- Code: --- function GM:PlayerSpawn( pl )

   player_manager.SetPlayerClass( pl, "player_sandbox" )
   
   BaseClass.PlayerSpawn( self, pl )

   pl:SetMaxHealth( 160 )
   pl:SetHealth( 160 )
   
end

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version