I couldn't find it or at least didn't find it.
but is there a command similar to making a player regain health, but instead make him lose/drain his health?
just curious because im currently working on something that will need to drain the players health.
You just need to attack the player.
There are a number of ways you can do this.
If you don't need to specify what type of damage the player takes you can use
[url]http://wiki.garrysmod.com/?title=Entity.TakeDamage[/url]
While a bit more refined method is:
[url]http://wiki.garrysmod.com/?title=Entity.TakeDamageInfo[/url]
someEntity:TakeDamage( 15, someAttacker, someAttacker:GetActiveWeapon() )
Sorry for the noobish questions, but could i just make this identify the damage being taken and not the attacker and the weapon? i think like this,
ply.TakeDamage(15) , probably wrong but its worth a shot. if so how could i make it so its any weapon and any attacker on the player? :/
probably doing it all wrong lol.
[QUOTE=ihasaaccount1;29787094]someEntity:TakeDamage( 15, someAttacker, someAttacker:GetActiveWeapon() )
Sorry for the noobish questions, but could i just make this identify the damage being taken and not the attacker and the weapon? i think like this,
ply.TakeDamage(15) , probably wrong but its worth a shot. if so how could i make it so its any weapon and any attacker on the player? :/
probably doing it all wrong lol.[/QUOTE]
Well you CAN do
entity:TakeDamage(15, nil, nil) - but I really wouldn't. Some entities (like the turret) need an inflicter or they error and can cause crashes.
If you don't want an entity or player to be the cause of the damage I would use TakeDamageInfo
[lua]
local dmg = DamageInfo()
dmg:SetDamage(how_much_damage) --Change to how much damage you want to do
dmg:SetDamageLocation(entity:GetPos()) --Change entity to whatever entity you want to take the damage
dmg:SetDamageType(DMG_GENERIC) --Generic damage type, can change to any other damage enum
entity:TakeDamageInfo()
[/lua]
But there you might run into the same problem (but I would think it's rare).
Just had another thought -
Player:SetHealth(math.Approach(Player:Health(), targetHealth, rate))
rate is how much damage will be taken off per call and how fast the drain will depend on how often you call this function.
Thanks for the help. i saw another way for what i was doing and it seemed to work.
-snip-
nvm
Lemme guess... You making a deathmatch gamemode or something with a poison attack? :P
No, I am currently making a script so if a persons health falls below a certain amount, by any sort of damage their health reaches "critical condition" causing it slowly to drain to 0. for realism
Only problem is when it reachs 0, the player doesnt die but just seems to crouch..odd.
[QUOTE=Feihc;29787381]Well you CAN do
entity:TakeDamage(15, nil, nil) - but I really wouldn't. Some entities (like the turret) need an inflicter or they error and can cause crashes.
If you don't want an entity or player to be the cause of the damage I would use TakeDamageInfo
[lua]
local dmg = DamageInfo()
dmg:SetDamage(how_much_damage) --Change to how much damage you want to do
dmg:SetDamageLocation(entity:GetPos()) --Change entity to whatever entity you want to take the damage
dmg:SetDamageType(DMG_GENERIC) --Generic damage type, can change to any other damage enum
entity:TakeDamageInfo()
[/lua]
But there you might run into the same problem (but I would think it's rare).
Just had another thought -
Player:SetHealth(math.Approach(Player:Health(), targetHealth, rate))
rate is how much damage will be taken off per call and how fast the drain will depend on how often you call this function.[/QUOTE]
You don't pass nil as argument, maybe you meant entity:TakeDamage(15, NULL, NULL)
[QUOTE=Loures;29795008]You don't pass nil as argument, maybe you meant entity:TakeDamage(15, NULL, NULL)[/QUOTE]
What are you on about?
nil is the passed argument, nothing more, nothing less.
[QUOTE=Science;29797145]What are you on about?
nil is the passed argument, nothing more, nothing less.[/QUOTE]
[url]http://wiki.garrysmod.com/?title=NULL[/url]
[QUOTE=King Flawless;29797271][url]http://wiki.garrysmod.com/?title=NULL[/url][/QUOTE]
You learn a new thing everyday.
Or in my case, a few.
[QUOTE=Science;29798184]You learn a new thing everyday.
Or in my case, a few.[/QUOTE]
This is your one chance at a fresh start use it wisely, if you continue to post all :smug: or even posting in help threads until you can actually make things your self without requests or help threads then you will continue to be treated the way you have been in the past.
Use it wisely,
[QUOTE=King Flawless;29798227]This is your one chance at a fresh start use it wisely, if you continue to post all :smug: or even posting in help threads until you can actually make things your self without requests or help threads then you will continue to be treated the way you have been in the past.
Use it wisely,[/QUOTE]
:raise: Are you feeling ok, Flawless?
[QUOTE=King Flawless;29798227]This is your one chance at a fresh start use it wisely, if you continue to post all :smug: or even posting in help threads until you can actually make things your self without requests or help threads then you will continue to be treated the way you have been in the past.
Use it wisely,[/QUOTE]
I shall do so, i hope to impress you all mighty lord.
[QUOTE=Science;29798332]I shall do so, i hope to impress you all mighty lord.[/QUOTE]
OK, chance over I warned you about :smug: posting you lasted all of 6 minutes
[QUOTE=Science;29798332]I shall do so, i hope to impress you all mighty lord.[/QUOTE]
you know, he is giving you a second chance even though you were a douche bag, you might want to consider it
[QUOTE=King Flawless;29798369]OK, chance over I warned you about :smug: posting you lasted all of 6 minutes[/QUOTE]
Please tell me how this blows my chance?
I simply responded to your offer and i accept it.
[QUOTE=Science;29798483]Please tell me how this blows my chance?
I simply responded to your offer and i accept it.[/QUOTE]
[QUOTE=Science;29798332]I shall do so, i hope to impress you [b]all mighty lord.[/b][/QUOTE]
[QUOTE=King Flawless;29798494][/QUOTE]
Its called a compliment.
[QUOTE=Science;29798505]Its called a compliment.[/QUOTE]
If your 15 your going to be a virgin for a long time if don't know how to give a compliment and you clearly don't, either way their is nothing you can do about it now.
[QUOTE=King Flawless;29798526]If your 15 your going to be a virgin for a long time if don't know how to give a compliment and you clearly don't, either way their is nothing you can do about it now.[/QUOTE]
Well thats an odd thing to say seen as shits going down tomorrow.
[QUOTE=Science;29798587]Well thats an odd thing to say seen as shits going down tomorrow.[/QUOTE]
What?
[editline]13th May 2011[/editline]
Oh hahaha I think he was refering to losing his V card..lol not happening kid
[QUOTE=Science;29798587]Well thats an odd thing to say seen as shits going down tomorrow.[/QUOTE]
Anyone who talks like this gets rated Optimistic
[QUOTE=c-unitV2;29798620]What?
[editline]13th May 2011[/editline]
Oh hahaha I think he was refering to losing his V card..lol not happening kid[/QUOTE]
Why do you call me kid? You are around 15 yourself.
I do not know any men that would say V card.
OK lets stop de-railing this thread with your two guys's bickering. It was obnoxious in the other thread and now this guys actually trying to get help. Take it to PM's please.
The issue where the player doesn't die when you SetHealth(0) has been there for a while iirc - you need to damage him at least a bit to get it to register it seems. I remember encountering this problem a while back.
I suggest using TakeDamageInfo because it's the most configurable function to use in this type of situation.
[QUOTE=Science;29798656]Why do you call me kid? You are around 15 yourself.
I do not know any men that would say V card.[/QUOTE]
Nope, I'm 17
[QUOTE=Loures;29795008]You don't pass nil as argument, maybe you meant entity:TakeDamage(15, NULL, NULL)[/QUOTE]
Either works.
nil is a "zero value" - the value is there but it isn't anything
NULL is the absence of any data - there isn't any value there at all
I would think that using NULL would flip out on some functions though
[QUOTE=Feihc;29798848]Either works.
nil is a "zero value" - the value is there but it isn't anything
NULL is the absence of any data - there isn't any value there at all
I would think that using NULL would flip out on some functions though[/QUOTE]
Using NULL where an entity is expected is correct form. You can't call nil.IsValid but you can call NULL.IsValid.
[QUOTE=FlapadarV2;29798950]Using NULL where an entity is expected is correct form. You can't call nil.IsValid but you can call NULL.IsValid.[/QUOTE]
Themoreyouknow.jpg - I've always used nil and never had a problem.
Alright guys, i need some help again.
Currently what i have going on works fine until the player reachs his health at 0, his health drains to 0, one he hits that the player just crouch s and doesn't die. this is where im dumbfounded at because i have no idea how to make the player die without running a console command such as "kill" because i have that blocked as of now, any alternatives?
Sorry, you need to Log In to post a reply to this thread.