Ulysses

General => Developers Corner => Topic started by: Deathtitan77 on May 01, 2013, 09:20:53 AM

Title: GMod lua function to set HP?
Post by: Deathtitan77 on May 01, 2013, 09:20:53 AM
I am wondering if there is a Gmod lua function to set the HP of a player; currently maurits.tv is down, so if you could help. Please do so.
Title: Re: GMod lua function to set HP?
Post by: nathan736 on May 01, 2013, 09:36:52 AM
yes
Entity:SetHealth( number newHealth )
http://wiki.garrysmod.com/page/Entity/SetHealth
wiki.jpg
Title: Re: GMod lua function to set HP?
Post by: Deathtitan77 on May 01, 2013, 10:03:48 AM
Entity:SetHealth( number newHealth )

Where do I insert the number, or what do I do exactly?
Title: Re: GMod lua function to set HP?
Post by: MrPresident on May 01, 2013, 12:32:25 PM
inside the parenthesis.

ent:SetHealth(100)

^^ for example ^^
Title: Re: GMod lua function to set HP?
Post by: Deathtitan77 on May 02, 2013, 04:33:29 AM
I am wondering if there is a Gmod lua function to set the HP of a player; currently maurits.tv is down, so if you could help. Please do so.
Anyways, I found out it was:

ply:SetHealth( 100)

Thanks anyway.
Title: Re: GMod lua function to set HP?
Post by: MrPresident on May 02, 2013, 10:27:31 AM
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.
Title: Re: GMod lua function to set HP?
Post by: Megiddo on May 02, 2013, 10:46:58 AM
Helpful Wikipedia article on what is-a (http://en.wikipedia.org/wiki/Is-a) means. :)
Title: Re: GMod lua function to set HP?
Post by: 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:

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
Title: Re: GMod lua function to set HP?
Post by: Decicus on March 28, 2014, 11:36:49 AM
So, if I wanted the player to spawn with 160 health, for example, I would do:
Code: [Select]
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
Why create two functions when you could have just put pl:SetMaxHealth in your PlayerSpawn function?
Title: Re: GMod lua function to set HP?
Post by: Neku on March 28, 2014, 03:00:16 PM
No, all you need to do is

Code: [Select]
function GM:PlayerSpawn( pl )

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

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

Title: Re: GMod lua function to set HP?
Post by: JamminR on March 28, 2014, 05:04:43 PM
Both seem like it would overwrite the original Gmod Playerspawn hook.
Shouldn't hook.add be used?
Code: [Select]
function myspawnaddhealth
blah
end
hook.Add("PlayerSpawn","SpawnWithHealth", myspawnaddhealth)
Title: Re: GMod lua function to set HP?
Post by: Neku on March 29, 2014, 12:43:08 AM
Both seem like it would overwrite the original Gmod Playerspawn hook.
Shouldn't hook.add be used?
Code: [Select]
function myspawnaddhealth
blah
end
hook.Add("PlayerSpawn","SpawnWithHealth", myspawnaddhealth)

Oh, my bad, my bad. JamminR would be correct there. You would indeed use a hook
for a function like this.