Ulysses
General => Developers Corner => Topic started 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.
-
yes
Entity:SetHealth( number newHealth )
http://wiki.garrysmod.com/page/Entity/SetHealth
wiki.jpg
-
Entity:SetHealth( number newHealth )
Where do I insert the number, or what do I do exactly?
-
inside the parenthesis.
ent:SetHealth(100)
^^ for example ^^
-
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.
-
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.
-
Helpful Wikipedia article on what is-a (http://en.wikipedia.org/wiki/Is-a) means. :)
-
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
-
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
Why create two functions when you could have just put pl:SetMaxHealth in your PlayerSpawn function?
-
No, all you need to do is
function GM:PlayerSpawn( pl )
player_manager.SetPlayerClass( pl, "player_sandbox" )
BaseClass.PlayerSpawn( self, pl )
pl:SetMaxHealth( 160 )
pl:SetHealth( 160 )
end
-
Both seem like it would overwrite the original Gmod Playerspawn hook.
Shouldn't hook.add be used?
function myspawnaddhealth
blah
end
hook.Add("PlayerSpawn","SpawnWithHealth", myspawnaddhealth)
-
Both seem like it would overwrite the original Gmod Playerspawn hook.
Shouldn't hook.add be used?
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.