ULX

Author Topic: GMod lua function to set HP?  (Read 33377 times)

0 Members and 1 Guest are viewing this topic.

Offline Deathtitan77

  • Jr. Member
  • **
  • Posts: 63
  • Karma: 6
GMod lua function to set HP?
« 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.

Offline nathan736

  • Full Member
  • ***
  • Posts: 143
  • Karma: 4
Re: GMod lua function to set HP?
« Reply #1 on: May 01, 2013, 09:36:52 AM »
yes
Entity:SetHealth( number newHealth )
http://wiki.garrysmod.com/page/Entity/SetHealth
wiki.jpg
a person asked me how to code lua and i said this " its like building a rocket up side down then  realizing you did it all wrong."

Offline Deathtitan77

  • Jr. Member
  • **
  • Posts: 63
  • Karma: 6
Re: GMod lua function to set HP?
« Reply #2 on: May 01, 2013, 10:03:48 AM »
Entity:SetHealth( number newHealth )

Where do I insert the number, or what do I do exactly?

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: GMod lua function to set HP?
« Reply #3 on: May 01, 2013, 12:32:25 PM »
inside the parenthesis.

ent:SetHealth(100)

^^ for example ^^

Offline Deathtitan77

  • Jr. Member
  • **
  • Posts: 63
  • Karma: 6
Re: GMod lua function to set HP?
« Reply #4 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.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: GMod lua function to set HP?
« Reply #5 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.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: GMod lua function to set HP?
« Reply #6 on: May 02, 2013, 10:46:58 AM »
Helpful Wikipedia article on what is-a means. :)
Experiencing God's grace one day at a time.

Offline RogerThatGaming

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Re: GMod lua function to set HP?
« Reply #7 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
« Last Edit: March 28, 2014, 10:43:26 AM by RogerThatGaming »

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: GMod lua function to set HP?
« Reply #8 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?
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: GMod lua function to set HP?
« Reply #9 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

Out of the Garry's Mod business.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: GMod lua function to set HP?
« Reply #10 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)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: GMod lua function to set HP?
« Reply #11 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.
Out of the Garry's Mod business.