• Print

Author Topic: Max hp healing Code needed!  (Read 9259 times)

0 Members and 1 Guest are viewing this topic.

Offline aussie0411

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
Max hp healing Code needed!
« on: May 21, 2016, 09:10:11 am »
Basically I am helping somebody on a star wars rp server and they need to know how to get the medkit to heal to the health the job is set at. For example, a jedi with 500 health that drops to 400 can't be healed back up to 500 but only up to 100 if he is lower than 100. Anything higher than 100 he can't be healed. How do I change that to the hp the job is set at?

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Max hp healing Code needed!
« Reply #1 on: May 21, 2016, 09:19:47 am »
Instead of just using Entity:SetHealth(number hp), you will want to also use Entity:SetMaxHealth(number maxhp) in your job's info, or set max health in the config file however you're told to.
bw81@ulysses-forums ~ % whoami
Homepage

Offline aussie0411

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
Re: Max hp healing Code needed!
« Reply #2 on: May 21, 2016, 09:58:26 am »
Instead of just using Entity:SetHealth(number hp), you will want to also use Entity:SetMaxHealth(number maxhp) in your job's info, or set max health in the config file however you're told to.

Can you change it for me?

AddExtraTeam("Doom Commander", {
    color = Color(63, 127, 79, 255),
    model = {"models/player/asgclonewars/commander_doom/commander_doom.mdl"},
    description = [[Doom CO]],
    weapons = {"weapon_752_t21", "weapon_752_dc15a", "weapon_752_dc17dual"},
    command = "doomco",
    max = 1,
    salary = 400,
    admin = 0,
   PlayerSpawn = function(ply) GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.walkspeed * 1, GAMEMODE.Config.runspeed * 1) ply:SetHealth("500") ply:SetGravity(1) return CLIENT end,
    PlayerDeath = function(ply) GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.walkspeed * 1, GAMEMODE.Config.runspeed * 1) return CLIENT end,
    vote = false,
    hasLicense = false,
category = "Doom",
})

is the default job, can you add in the hp thing or instruct me on how to do so?

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Max hp healing Code needed!
« Reply #3 on: May 21, 2016, 10:54:08 am »
(protip: use [code][/code] tags or [code=lua][/code] for syntax highlighting when posting code)

Notice:
Code: Lua
  1.    PlayerSpawn = function(ply) GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.walkspeed * 1, GAMEMODE.Config.runspeed * 1) ply:SetHealth("500") ply:SetGravity(1) return CLIENT end,

I have no idea what you're doing here, but it doesn't seem syntactically correct. Regardless, if it works, it works.
Anyway, if you add ply:SetMaxHealth(500) after ply:SetHealth("500"), you will accomplish what you're looking for.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Caustic Soda-Senpai

  • Sr. Member
  • ****
  • Posts: 469
  • Karma: 54
  • <Insert something clever here>
    • Steam Page
Re: Max hp healing Code needed!
« Reply #4 on: May 21, 2016, 10:11:43 pm »
(protip: use [code][/code] tags or [code=lua][/code] for syntax highlighting when posting code)

Notice:
Code: Lua
  1.    PlayerSpawn = function(ply) GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.walkspeed * 1, GAMEMODE.Config.runspeed * 1) ply:SetHealth("500") ply:SetGravity(1) return CLIENT end,

I have no idea what you're doing here, but it doesn't seem syntactically correct. Regardless, if it works, it works.
Anyway, if you add ply:SetMaxHealth(500) after ply:SetHealth("500"), you will accomplish what you're looking for.

That doesn't look like it'll run without commas
Once you get to know me, you'll find you'll have never met me at all.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Max hp healing Code needed!
« Reply #5 on: May 22, 2016, 06:39:39 am »
That doesn't look like it'll run without commas
semicolons*
And according to OP, it does. I think Lua doesn't particularly care.

edit: Works in Lua 5.3:
Code: [Select]
$ lua
Lua 5.3.2  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> function hello() print("hello") print("test") print("1 2 3") end
> hello()
hello
test
1 2 3
And in 5.1 (which, IIRC, is what GMod uses):
Code: [Select]
$ lua5.1                                                                                                                                                                               
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> function hello() print("hello") print("test") print("1 2 3") end
> hello()
hello
test
1 2 3
« Last Edit: May 22, 2016, 08:09:22 am by Bytewave »
bw81@ulysses-forums ~ % whoami
Homepage

Offline Caustic Soda-Senpai

  • Sr. Member
  • ****
  • Posts: 469
  • Karma: 54
  • <Insert something clever here>
    • Steam Page
Re: Max hp healing Code needed!
« Reply #6 on: May 22, 2016, 09:26:03 pm »
My mistake, I've been working with too many languages recently.
Once you get to know me, you'll find you'll have never met me at all.

  • Print