Probably The biggest Noob Question Ever!

Hey guys I want to make a script that will do a console command when your health is bellow 20,
This is basicly what I know, Don’t flame me for being the ultimate noob xD
(I do the comand “say lol” because of testing)
This is it:

If health=20< then “say lol”

This is probably 100% wrong, please don’t flame if it is!

[lua]function HealthLoss( ent, inflictor, attacker, amount, dmginfo )
if ( ent:IsPlayer() ) then
if ( ent:Health() < 20 ) then
ent:ConCommand( “say Change this to whatever console command you want” )
end
end
end

hook.Add( “EntityTakeDamage”, “HealthLoss”, HealthLoss )[/lua]
Untested, but should work. Put it in your garrysmod\lua\autorun\server folder.
See here for a list of all stuff you can do with players.

For people who can’t see lua tags:



function HealthLoss( ent, inflictor, attacker, amount, dmginfo )
    if ( ent:IsPlayer() ) then
        if ( ent:Health() < 20 ) then
            ent:ConCommand( "say Change this to whatever console command you want" )
        end
    end
end

hook.Add( "EntityTakeDamage", "HealthLoss", HealthLoss )

thank you so much, ill try it now

Yep, that’s correct, should to do the trick.

:o
It doesn’t
It’s in lua/autorun/server

Try placing it in just lua/autorun. Also when in doubt use lua_openscript to run the script manually.

Does it say anything in console about “Server prevented using FCVAR_SERVER_CAN_EXECUTE on player” or something?

Thanks for affirming that, mate. Let me escort you to the exit. walks you to the GTFO door and gives u a Firm Boot in the ass

Ehm, he said he wasn’t sure if it worked, I just confirmed for convenience. Think before posting a dumb reply.

I lol’d

One thing: while we all like to be self-deprecating once in a while, please don’t overdo it. We get it that you’re new to Lua coding, we’re not going to flame you.

Thanks :smiley:

i have found the nice side of facepunch