Is it possible to give health instead of set health? I'm using some workshop item for Juggernog (from Nazi Zombies). It currently sets health to 100, which is pretty OP to me. I want it to be where players receive 50 health instead of get set to 100.
here's the health function part of the code:
(I've tried Owner:GiveHealth(50) but that didn't work)
[CODE]timer.Simple(3.1,function()
if self.Owner:Alive() then
self.Weapon:EmitSound("hoff/animations/perks/017bf9c0.wav")
self.Weapon:SetNetworkedString("isDrinkingPerk","false")
local plyHealth = self.Owner:Health()
self.Owner:SetHealth(100)
timer.Simple(0.1,function() self.Weapon:Remove() end)
end
end)
end[/CODE]
[code]
timer.Simple(3.1,function()
if self.Owner:Alive() then
self.Weapon:EmitSound("hoff/animations/perks/017bf9c0.wav")
self.Weapon:SetNetworkedString("isDrinkingPerk","false")
local plyHealth = self.Owner:Health()
local newhealth = math.Clamp(plyHealth + 50, 1, 100)
self.Owner:SetHealth(newhealth)
timer.Simple(0.1,function() self.Weapon:Remove() end)
end
end)
[/code]
You can change the 50 to whatever you want, it won't go above 100.
[lua]
local PlayerMetaTable = FindMetaTable("Player")
function PlayerMetaTable:GiveHealth(amount)
self:SetHealth(math.Clamp(self:Health()+amount, 0, 100));
end
[/lua]
Add this in a server-side file and you will have yourself a GiveHealth function.
Just get their health, add 50 to it, and set their health to that number.
[lua]self.Owner:SetHealth( self.Owner:GetHealth() + 50 )[/lua]
If you don't want to go over their max health:
[lua]self.Owner:SetHealth( math.Clamp( self.Owner:GetHealth() + 50, 0, self.Owner:GetMaxHealth() ) )[/lua]
edit: ninja'd
[QUOTE=wh1t3rabbit;45279340]Just get their health, add 50 to it, and set their health to that number.
[lua]self.Owner:SetHealth( self.Owner:GetHealth() + 50 )[/lua]
If you don't want to go over their max health:
[lua]self.Owner:SetHealth( math.Clamp( self.Owner:GetHealth() + 50, 0, self.Owner:GetMaxHealth() ) )[/lua]
edit: ninja'd[/QUOTE]
You sure GetHealth is a real function?
Thanks. I've tried all of these and none have seemed to work. I'm just going to post the whole code in case there's a possibility that some other function is interfering.
lua/weapons/zombies_perk_juggernog
[CODE]
AddCSLuaFile( "shared.lua" )
SWEP.Author = "Hoff"
SWEP.Instructions = "Reach for Juggernog tonight!"
SWEP.Category = "CoD Zombies"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/hoff/animations/perks/juggernog/jug.mdl"
SWEP.WorldModel = ""
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
SWEP.Primary.Delay = 1
SWEP.ViewModelFOV = 60
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.PrintName = "Juggernog"
SWEP.Slot = 3
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
SWEP.CorrectModelPlacement = Vector(0,0,-1)
SWEP.SwayScale = 0.01
SWEP.BobScale = 0.01
function SWEP:Equip(NewOwner)
local oldWep = self.Owner:GetActiveWeapon()
NewOwner:SetActiveWeapon("zombies_perk_juggernog")
timer.Simple(3.8,function() NewOwner:SetActiveWeapon(oldWep) end)
end
function SWEP:Deploy()
--self.Weapon:EmitSound("hoff/animations/perks/017e137a.wav")
self.Weapon:EmitSound("hoff/animations/perks/buy_jug.wav")
self.Weapon:SetNetworkedString("isDrinkingPerk","true")
timer.Simple(0.5,function()
if self.Owner:Alive() then
self.Weapon:EmitSound("hoff/animations/perks/017f11fa.wav")
self.Owner:ViewPunch( Angle( -1, 1, 0 ) )
end
end)
timer.Simple(1.3,function()
if self.Owner:Alive() then
self.Weapon:EmitSound("hoff/animations/perks/0180acfa.wav")
self.Owner:ViewPunch( Angle( -2.5, 0, 0 ) )
end
end)
timer.Simple(2.3,function()
if self.Owner:Alive() then
self.Weapon:EmitSound("hoff/animations/perks/017c99be.wav")
self.Owner:SetNetworkedString("shouldBlurPerkScreen","true")
timer.Simple(0.5,function() self.Owner:SetNetworkedString("shouldBlurPerkScreen","false") end)
umsg.Start( "perkBGBlur", self.Owner )
umsg.End()
end
end)
timer.Simple(3.1,function()
if self.Owner:Alive() then
self.Weapon:EmitSound("hoff/animations/perks/017bf9c0.wav")
self.Weapon:SetNetworkedString("isDrinkingPerk","false")
local plyHealth = self.Owner:Health()
self.Owner:SetHealth(100)
timer.Simple(0.1,function() self.Weapon:Remove() end)
end
end)
end
function perkBlur()
local matBlurScreen = Material( "pp/blurscreen" )
local function perkBlurHUD()
if LocalPlayer():GetNetworkedString("shouldBlurPerkScreen") == "true" then
surface.SetMaterial( matBlurScreen )
surface.SetDrawColor( 255, 255, 255, 255 )
matBlurScreen:SetFloat( "$blur",6 )
render.UpdateScreenEffectTexture()
surface.DrawTexturedRect( 0,0, ScrW(), ScrH() )
surface.SetDrawColor( 0, 0, 0, 60 )
surface.DrawRect( 0,0, ScrW(), ScrH() )
end
end
hook.Add( "HUDPaint", "perkBlurPaint", perkBlurHUD )
timer.Simple(2,function() hook.Remove( "HUDPaint", "perkBlurPaint" ) end)
end
usermessage.Hook("perkBGBlur", perkBlur)
function SWEP:Holster()
if self.Weapon:GetNetworkedString("isDrinkingPerk") == "true" then
return false
else
return true
end
end
function SWEP:PrimaryAttack()
end
function SWEP:GetViewModelPosition( pos, ang )
local Right = ang:Right()
local Up = ang:Up()
local Forward = ang:Forward()
local Mul = 1.0
local Offset = self.CorrectModelPlacement
pos = pos + Offset.x * Right * Mul
pos = pos + Offset.y * Forward * Mul
pos = pos + Offset.z * Up * Mul
return pos, ang
end
function SWEP:SecondaryAttack()
end
function SWEP:ShouldDropOnDie()
return false
end[/CODE]
gamemodes/terrortown/entities/weapons/hoff_perk_juggernog
[CODE]
AddCSLuaFile( "shared.lua" )
SWEP.Author = "Hoff"
SWEP.Instructions = "Reach for Juggernog tonight!"
SWEP.Base = "weapon_tttbase"
SWEP.Kind = WEAPON_EQUIP2
SWEP.AmmoEnt = ""
SWEP.CanBuy = { ROLE_TRAITOR, ROLE_DETECTIVE }
SWEP.InLoadoutFor = nil
SWEP.LimitedStock = true
SWEP.AllowDrop = false
SWEP.IsSilent = false
SWEP.NoSights = false
SWEP.AutoSpawnable = false
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/hoff/animations/perks/juggernog/jug.mdl"
SWEP.WorldModel = ""
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
SWEP.Primary.Delay = 1
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.PrintName = "Juggernog"
SWEP.Slot = 3
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
SWEP.ViewModelFOV = 60
SWEP.CorrectModelPlacement = Vector(0,0,-1)
SWEP.SwayScale = 0.01
SWEP.BobScale = 0.01
function SWEP:Equip(NewOwner)
local oldWep = self.Owner:GetActiveWeapon()
NewOwner:SetActiveWeapon("zombies_perk_juggernog")
timer.Simple(3.8,function() NewOwner:SetActiveWeapon(oldWep) end)
end
function SWEP:Deploy()
--self.Weapon:EmitSound("hoff/animations/perks/017e137a.wav")
self.Weapon:EmitSound("hoff/animations/perks/buy_jug.wav")
self.Weapon:SetNetworkedString("isDrinkingPerk","true")
timer.Simple(0.5,function()
if self.Owner:Alive() then
self.Weapon:EmitSound("hoff/animations/perks/017f11fa.wav")
self.Owner:ViewPunch( Angle( -1, 1, 0 ) )
end
end)
timer.Simple(1.3,function()
if self.Owner:Alive() then
self.Weapon:EmitSound("hoff/animations/perks/0180acfa.wav")
self.Owner:ViewPunch( Angle( -2.5, 0, 0 ) )
end
end)
timer.Simple(2.3,function()
if self.Owner:Alive() then
self.Weapon:EmitSound("hoff/animations/perks/017c99be.wav")
self.Owner:SetNetworkedString("shouldBlurPerkScreen","true")
timer.Simple(0.5,function() self.Owner:SetNetworkedString("shouldBlurPerkScreen","false") end)
umsg.Start( "perkBGBlur", self.Owner )
umsg.End()
end
end)
timer.Simple(3.1,function()
if self.Owner:Alive() then
self.Weapon:EmitSound("hoff/animations/perks/017bf9c0.wav")
self.Weapon:SetNetworkedString("isDrinkingPerk","false")
local plyHealth = self.Owner:Health()
self.Owner:SetHealth(100)
timer.Simple(0.1,function() self.Weapon:Remove() end)
end
end)
end
function perkBlur()
local matBlurScreen = Material( "pp/blurscreen" )
local function perkBlurHUD()
if LocalPlayer():GetNetworkedString("shouldBlurPerkScreen") == "true" then
surface.SetMaterial( matBlurScreen )
surface.SetDrawColor( 255, 255, 255, 255 )
matBlurScreen:SetFloat( "$blur",6 )
render.UpdateScreenEffectTexture()
surface.DrawTexturedRect( 0,0, ScrW(), ScrH() )
surface.SetDrawColor( 0, 0, 0, 60 )
surface.DrawRect( 0,0, ScrW(), ScrH() )
end
end
hook.Add( "HUDPaint", "perkBlurPaint", perkBlurHUD )
timer.Simple(2,function() hook.Remove( "HUDPaint", "perkBlurPaint" ) end)
end
usermessage.Hook("perkBGBlur", perkBlur)
function SWEP:Holster()
if self.Weapon:GetNetworkedString("isDrinkingPerk") == "true" then
return false
else
return true
end
end
function SWEP:PrimaryAttack()
end
function SWEP:GetViewModelPosition( pos, ang )
local Right = ang:Right()
local Up = ang:Up()
local Forward = ang:Forward()
local Mul = 1.0
local Offset = self.CorrectModelPlacement
pos = pos + Offset.x * Right * Mul
pos = pos + Offset.y * Forward * Mul
pos = pos + Offset.z * Up * Mul
return pos, ang
end
function SWEP:SecondaryAttack()
end
function SWEP:ShouldDropOnDie()
return false
end
if CLIENT then
SWEP.Icon = "VGUI/ttt/icon_hoff_juggernog"
SWEP.EquipMenuData = {
type = "Perk Bottle",
desc = "Juggernog Perk.\nAutomatically drink perk to give 100\nhealth. One time purchase."
};
end[/CODE]
From the looks of it, these codes are the same so I don't know why there's two. But, there is.
[QUOTE=KokoNum;45279357]You sure GetHealth is a real function?[/QUOTE]
You're right it's just :Health(). I hate how it isn't the same as all the other Get/Set* functions.
[QUOTE=wh1t3rabbit;45279401]You're right it's just :Health(). I hate how it isn't the same as all the other Get/Set* functions.[/QUOTE]
So shall I do:?
[CODE]self.Owner:SetHealth( math.Clamp( self.Owner:Health() + 50, 0, self.Owner:MaxHealth() ) )[/CODE]
EDIT: I tried this, however it didn't do anything. Also, it caused problems such as playing the sound while dying, and allowing me to use it multiple times as opposed to the regular, working version.
[QUOTE=Gengarism;45279392]Thanks. I've tried all of these and none have seemed to work. I'm just going to post the whole code in case there's a possibility that some other function is interfering.
lua/weapons/zombies_perk_juggernog
gamemodes/terrortown/entities/weapons/hoff_perk_juggernog
From the looks of it, these codes are the same so I don't know why there's two. But, there is.[/QUOTE]
Dude use a lua tag "[lua]"
And i'm not certain what you try to do there it seems you just did SetHealth(100) no matter what so what exactly were u trying to do?
[QUOTE=KokoNum;45279423]Dude use a lua tag "[lua]"
And i'm not certain what you try to do there it seems you just did SetHealth(100) no matter what so what exactly were u trying to do?[/QUOTE]
These are the original codes. I've tried everything people have suggested.
What I want: For it to GIVE them 50 HP INSTEAD of setting it straight up to 100.
Then do self.Owner:SetHealth( plyHealth + 50 )
[QUOTE=Gengarism;45279415]So shall I do:?
[CODE]self.Owner:SetHealth( math.Clamp( self.Owner:Health() + 50, 0, self.Owner:MaxHealth() ) )[/CODE][/QUOTE]
Yes, or any of the ways other people have posted.
[URL="http://pastebin.com/xX42mFtk"]lua/weapons/zombies_perk_juggernog
[/URL]
[URL="http://pastebin.com/32SDmqnr"]gamemodes/terrortown/entities/weapons/hoff_perk_juggernog[/URL]
Literally just replacing stuff. I don't know where this came from:
[code]
self.Owner:SetHealth(="constant numeric">100)
[/code]
[QUOTE=Gengarism;45279429]These are the original codes. I've tried everything people have suggested.
What I want: For it to GIVE them 50 HP INSTEAD of setting it straight up to 100.[/QUOTE]
Well you got 2 options either you use my function so you can easily just Owner:GiveHealth(50)
or you do
[lua]
local plyHealth = self.Owner:Health()
self.Owner:SetHealth(math.Clamp(plyHealth + 50, 0, self.Owner:GetMaxHealth()))
[/lua]
Solved. I really appreciate everyone's help.
:smile:
Sorry, you need to Log In to post a reply to this thread.