Health Help

I have a small code based off of a sound code I found around here that I am trying to modify to be a medic command to add health to a player.
function CallMedic( ply, text )
local health = ply:GetHealth()
if string.find(text, “!medic”) while (health <= 50) then
health + 30
hook.Add( “PlayerSay”, “CallMedic”, CallMedic )[/lua]
What is wrong with this? My entire gamemode stopped working once I added this.

function CallMedic(pl, text)
local HealthAdd = 50 --Set this to the amount of health you want the player to get when calling the medic.
local Health = pl:GetHealth()

if string.find(text, "!medic") while (Health &lt;= 50) then

hook.Add(“PlayerSay”, “CallMedic”, CallMedic)

Alright makes sense, thanks for cleaning it up.


It didn’t work for some reason.

Replace ‘while’ with ‘and’.

Also make sure to cap the player’s health as I think SetHealth doesn’t consider the MaxHealth. This is for only if you’ve changed your max health to lower than 100 or if you decide to make the health boost higher later instead of 50. I just thought I’d tell you anyway:

[lua]function CallMedic( Player, Text )
local Health = Player:GetHealth();

if( string.find( Text, "!medic" ) && Health &lt;= 50 ) then
    local NewHealth = Health + 50;
    local MaxHealth = Player:GetMaxHealth();

    if( NewHealth &gt; MaxHealth ) then
        Player:SetHealth( MaxHealth );
        Player:SetHealth( NewHealth );

hook.Add( “PlayerSay”, “CallMedic”, CallMedic );[/lua]

local function CallMedic( pl, txt )
if txt:lower( ):find( “!medic” ) then
pl:SetHealth( math.min( pl:GetHealth( ) + 50, 50, pl:GetMaxHealth( ) ) )

hook.Add( “PlayerSay”, “CallMedic”, CallMedic )

<3 math functions.

True I forgot about math.min and I even use it myself for stuff. Doh.

Thanks for the reminder. :smiley:

None of these seem to work. I don’t understand what would be going wrong.

Are you adding the hook to the correct file? (init.lua) It is server only.

Are you getting any errors? Check your console.