So ive been trying to figure out how to make some sort of medkit that only can heal a specific type of job in DarkRP. What i came up with is this function on the darkRP forums Player:isCP(). Could i use this to say if [CODE]Player:isCP()[/CODE] then do the healing if not then [CODE]if SERVER then self.Owner:Kill()[/CODE] Is this even possible? thanks in advance and if you didn't notice im not an expert at lua coding xD
Try putting this inside the SWEP:PrimaryFire and SWEP:SecondaryFire (if used)
[LUA]if self.Owner:isCP() then
if SERVER then self.Owner:Kill() end
end[/LUA]
[CODE]ent = self.Owner:GetEyeTrace().Entity
if ent:IsPlayer() and ent:isCP() then
if ent:Health() == ent:GetMaxHealth() or ent:Health() > ent:GetMaxHealth() then return end
ent:SetHealth( ent:Health() + 1 )
else
self.Owner:Kill()
end[/CODE]
This is what I got. Just put it in your primary attack or something.
Edit: Added another check to make sure that if their health is over the limit then they can't be healed infinitely.
[QUOTE=Bubbie;50453386][CODE]ent = self.Owner:GetEyeTrace().Entity
if ent:IsPlayer() and ent:isCP() then
if ent:Health() == ent:GetMaxHealth() then return end
ent:SetHealth( ent:Health() + 1 )
else
self.Owner:Kill()
end[/CODE]
This is what I got. Just put it in your primary attack or something.[/QUOTE]
Just re read the op and realised i was wrong and your code is complete aswell.
The medkit just kills me everytime now and im CP
[QUOTE=Bakken1;50456024]The medkit just kills me everytime now and im CP[/QUOTE]
The basic code I provided only works for healing others.
[QUOTE=Bubbie;50456929]The basic code I provided only works for healing others.[/QUOTE]
after a bit of experimentation i came up with this [CODE]if Player:isCP() then self.Owner:SetHealth(self.Owner:Health() + math.random(300, 500)) end else if SERVER then self.Owner:Kill() end[/CODE] Is this usable? im getting this error [CODE]'end' expected near 'else'
[/CODE]though but i tought i had already ended the line?
(the tought here is that if the player is CP then add somewhere between 300 and 500 hp if not then kill the player)
don't put end before else
[QUOTE=NeatNit;50463795]don't put end before else[/QUOTE]
So like this then? [CODE]if Player:isCP() then self.Owner:SetHealth(self.Owner:Health() + math.random(300, 500)) else if SERVER then self.Owner:Kill() end[/CODE]
But now i get this error [CODE]'end' expected (to close 'if' at line 26) near '<eof>'[/CODE]
you can put another end in the end of that or use elseif instead of else if.
if you can't figure this out on your own then maybe coding is not for you
[QUOTE=NeatNit;50464241]you can put another end in the end of that or use elseif instead of else if.
if you can't figure this out on your own then maybe coding is not for you[/QUOTE]
Well putting elseif helped a lot, i had to change some other things aswell, but it turned out like this [CODE]if self.Owner:isCP() then self.Owner:SetHealth(self.Owner:Health() + math.random(300, 500)) elseif SERVER then self.Owner:Kill() end end[/CODE]
Sorry, you need to Log In to post a reply to this thread.