My intention is to set the max health of all jobs to 666. I have been trying this in my jobs.lua file.
TEAM_SWAT = DarkRP.createJob("Swat", {
color = Color(25, 25, 170, 255),
model = {"models/player/ct_urban.mdl"},
description = [[swat]],
weapons = {"arrest_stick", "unarrest_stick", "stunstick", "door_ram", "weaponchecker", "weapon_cuff_tactical"},
command = "Swat",
max = 4,
salary = 85,
admin = 0,
vote = true,
hasLicense = true,
category = "Civil Protection",
PlayerSpawn = function(ply)
ply:SetMaxHealth(666)
end
})
This does not work. I have tried other variations of the same code but yet still failed. If any of you got ideas i would appreciate it!
You probably need to set the health right after that. You only set the max health in your code here.
So essentially i do this right ?
TEAM_SWAT = DarkRP.createJob("Swat", {
color = Color(25, 25, 170, 255),
model = {"models/player/ct_urban.mdl"},
description = [[swat]],
weapons = {"arrest_stick", "unarrest_stick", "stunstick", "door_ram", "weaponchecker", "weapon_cuff_tactical"},
command = "Swat",
max = 4,
salary = 85,
admin = 0,
vote = true,
hasLicense = true,
category = "Civil Protection",
PlayerSpawn = function(ply)
ply:SetMaxHealth(666)
ply:SetHealth(100)
end
})
You can set the health for all players with the PlayerSpawn hook I'm pretty sure. Something like this:
hook.Add( "PlayerSpawn", "shrublake", function( ply )
ply:SetMaxHealth(666)
ply:SetHealth(100)
end)
Put it in an autorun somewhere on the server realm.
Yep, but you probably want to set it to whatever the max health is, you could just write
ply:SetHealth(666)
or you could also use Entity/GetMaxHealth to get the players max health and set it according to that
Doesn‘t set max health only set the health a player can have max? So sethealth would set it to the actual health and maxhealth would say up to this number but not higher?
I will say it again I guess, you need to set the health as well. You are only setting what the health can be at max.
Initially i tried this and it didnt work.
hook.Add( "PlayerSpawn", function( ply )
ply:SetMaxHealth(666)
ply:SetHealth(100)
end)
Then i tried this and it also did not work.
hook.Add( "PlayerSpawn", function( ply )
ply:SetMaxHealth(666)
ply:SetHealth(100)
end)
Use PlayerLoadout not PlayerSpawn
wont do anything for me.
All the code above should have worked. The issue was not the code but the food activator function not checking for maxhealth. Because im nice i will post the first version that i wrote, so it can orientate people in the right direction if they encounter this problem. Its not simplified and only checks for hp not the hunger. You gotta do that yourself. I suggest using math.clamp it will run faster and it looks neater.
replace:
function ENT:Use(activator)
activator:SetHealth(activator:Health()+20)
self.Entity:Remove()
activator:EmitSound("eating_and_drinking/eating_long.wav", 50, 100)
end
With: (if you consume a piece of food that adds 10hp and youre at 595 hp already, you will go up to 605. Next time you consume it you will go down to 600. Thats why i suggest math.clamp so the health values stays between two set amounts)
function ENT:Use(activator)
if (activator:Health() >= 600) then --number can be anything
activator:SetHealth(600)
self.Entity:Remove()
activator:EmitSound("eating_and_drinking/eating.wav", 50, 100)
else
activator:SetHealth(activator:Health()+10)
self.Entity:Remove()
activator:EmitSound("eating_and_drinking/eating.wav", 50, 100)
end
end
Thanks to everyone who took time to help me out with this,( @confuseth , @shrublake & @YunoGasaii ) but i was trying to fix something that was working all along...
Sorry, you need to Log In to post a reply to this thread.