Hi! I need help with some coding , i was coding and i noticed that LocalPlayer()GetMaxHealth() Only worked in some lua files , but not in my HP Regeneration addon!
Im not so good im english so im going to tell you what i want to do:
Health Regen Lua File
[CODE]AddCSLuaFile("healthregen.lua")
if ( CLIENT ) then return end
CreateConVar( "healthregen_enabled", 1, FCVAR_ARCHIVE )
CreateConVar( "healthregen_speed", 1, FCVAR_ARCHIVE )
CreateConVar( "healthregen_maxhealth", 100, FCVAR_ARCHIVE )
CreateConVar( "healthregen_delay", 5, FCVAR_ARCHIVE )
local function Think()
local enabled = GetConVarNumber( "healthregen_enabled" ) > 0
local speed = 1 / GetConVarNumber( "healthregen_speed" )
local max = LocalPlayer():GetMaxHealth() -- PROBLEM HERE! It isnt working and it works in another code that i will put at the bottom!
local time = FrameTime()
for _, ply in pairs( player.GetAll() ) do
if ( ply:Alive() ) then
local health = ply:Health()
if ( health < ( ply.LastHealth or 0 ) ) then
ply.HealthRegenNext = CurTime() + GetConVarNumber( "healthregen_delay" )
end
if ( CurTime() > ( ply.HealthRegenNext or 0 ) && enabled ) then
ply.HealthRegen = ( ply.HealthRegen or 0 ) + time
if ( ply.HealthRegen >= speed ) then
local add = math.floor( ply.HealthRegen / speed )
ply.HealthRegen = ply.HealthRegen - ( add * speed )
if ( health < max || speed < 0 ) then
ply:SetHealth( math.min( health + add, max ) )
end
end
end
ply.LastHealth = ply:Health()
end
end
end
hook.Add( "Think", "HealthRegen.Think", Think )[/CODE]
Here i used LocalPlayer()GetMaxHealth() and works perfectly , i used it in another lua file too and woked perfectly!
Bloody Screen Lua File
[CODE]AddCSLuaFile("codhealthsys.lua")
CreateConVar("healthsys", 1, FCVAR_NOTIFY, true)
CreateConVar("healthsys_visual", 1, FCVAR_NOTIFY, true)
CreateConVar("healthsys_heartbeat", "1", FCVAR_NOTIFY, true) --turn the hearthbeat sound off/on
CreateConVar("healthsys_audio", "1", FCVAR_NOTIFY, true) --turn the pain sounds off/on
function Bloomvision() --Huge thanks to Pandaman09 who helped me with this part
if GetConVarNumber("healthsys") == 0 or
GetConVarNumber("healthsys_visual") == 0 then return end
if LocalPlayer():Health() <= LocalPlayer():GetMaxHealth() - (LocalPlayer():GetMaxHealth() * 0.25) then
DrawBloom(0.7, 1.7, 8, 7, 1, 1, 0.75, 0, 0)
end
if LocalPlayer():Health() <= LocalPlayer():GetMaxHealth() - (LocalPlayer():GetMaxHealth() * 0.40) then
DrawBloom(0.30, 5, 5, 0, 1, 0.5, 0.5, 0, 0)
end
if LocalPlayer():Health() <= LocalPlayer():GetMaxHealth() - (LocalPlayer():GetMaxHealth() * 0.60) then
DrawBloom(0.30, 5, 5, 0, 1, 0.5, 0.5, 0, 0)
DrawMaterialOverlay("effects/bleed_overlay", 0.01)
end
if LocalPlayer():Health() <= LocalPlayer():GetMaxHealth() - (LocalPlayer():GetMaxHealth() * 0.80) then
DrawMaterialOverlay("effects/invuln_overlay_red", 0.04)
end
end
hook.Add("RenderScreenspaceEffects", "bloomvision", Bloomvision)
function Healthbeat(victim, attacker)
if GetConVarNumber("healthsys_heartbeat") ==0 then return end
local lowhealtbeat = CreateSound(victim, "player/heartbeat1.wav")
if victim:Health() <=30 and victim:Health() >15 then
lowhealtbeat:PlayEx(0.75, 100)
timer.Create("lowhealtbeat"..victim:SteamID(), GetConVarNumber("healthsys_delay"), 1, function() lowhealtbeat:FadeOut(1.75) end)
elseif victim:Health() <=15 then
lowhealtbeat:Stop()
lowhealtbeat:PlayEx(0.75, 150)
timer.Create("lowhealtbeat"..victim:SteamID(), GetConVarNumber("healthsys_delay"), 1, function() lowhealtbeat:FadeOut(1.75) end)
end
if victim:Health()<=0 then
lowhealtbeat:Stop()
end
end
hook.Add("PlayerHurt", "Healthbeat", Healthbeat)
function HurtSound(victim, attacker)
if GetConVarNumber("healthsys_audio") ==0 then return end
local soundchooser = math.random(1, 5)
if ( victim:Health() < 30 and CurTime() - ( victim.previousHurtSoundTime or 0 ) >= 1.5 ) then
victim.previousHurtSoundTime = CurTime()
if soundchooser == 1 then victim:EmitSound("ambient/voices/citizen_beaten1.wav", 60, 100) end
if soundchooser == 2 then victim:EmitSound("ambient/voices/citizen_beaten2.wav", 60, 100) end
if soundchooser == 3 then victim:EmitSound("ambient/voices/citizen_beaten3.wav", 60, 100) end
if soundchooser == 4 then victim:EmitSound("ambient/voices/citizen_beaten4.wav", 60, 100) end
if soundchooser == 5 then victim:EmitSound("ambient/voices/citizen_beaten5.wav", 60, 100) end
end
end
hook.Add("PlayerHurt", "Hurtsound", HurtSound)[/CODE]
I want to make LocalPlayer():GetMaxHealth() Work in HP Regeneration Lua File.
Please help me D: Im making a big project and this is frustrating me! Thank you for your attention :D!
[highlight](User was banned for this post ("Missed forum desc - use DEVELOPER DISCUSSION for gmod help" - NiandraLades))[/highlight]
Try the gmod programming subforum.
This one is just for general programming things, it doesn't specialize in gmod related lua.
I need to wait 1 hour , thanks for the info
Sorry, you need to Log In to post a reply to this thread.