2014-10-02 08:49:54 +08:00
AddCSLuaFile ( )
2018-05-02 06:32:59 +08:00
SWEP.PrintName = " Medical Kit "
SWEP.Description = " An advanced kit of medicine, bandages, and morphine. \n Very useful for keeping a group of survivors healthy. \n Use PRIMARY FIRE to heal other players. \n Use SECONDARY FIRE to heal yourself. \n Healing other players is not only faster but you get a nice point bonus! "
SWEP.Slot = 4
SWEP.SlotPos = 0
2014-10-02 08:49:54 +08:00
2018-05-02 06:32:59 +08:00
if CLIENT then
SWEP.ViewModelFOV = 57
2014-10-02 08:49:54 +08:00
SWEP.ViewModelFlip = false
SWEP.BobScale = 2
SWEP.SwayScale = 1.5
end
SWEP.Base = " weapon_zs_base "
SWEP.WorldModel = " models/weapons/w_medkit.mdl "
SWEP.ViewModel = " models/weapons/c_medkit.mdl "
SWEP.UseHands = true
2018-05-02 06:32:59 +08:00
SWEP.Heal = 15
2014-10-02 08:49:54 +08:00
SWEP.Primary . Delay = 10
SWEP.Primary . ClipSize = 30
SWEP.Primary . DefaultClip = 150
SWEP.Primary . Ammo = " Battery "
2018-05-02 06:32:59 +08:00
SWEP.Secondary . DelayMul = 20 / SWEP.Primary . Delay
SWEP.Secondary . HealMul = 10 / SWEP.Heal
2014-10-02 08:49:54 +08:00
2015-04-19 13:54:47 +08:00
SWEP.Secondary . ClipSize = 1
SWEP.Secondary . DefaultClip = 1
SWEP.Secondary . Ammo = " dummy "
2014-10-02 08:49:54 +08:00
SWEP.WalkSpeed = SPEED_NORMAL
2018-05-02 06:32:59 +08:00
SWEP.HealRange = 36
2014-10-02 08:49:54 +08:00
SWEP.NoMagazine = true
2018-05-02 06:32:59 +08:00
SWEP.AllowQualityWeapons = true
2014-10-02 08:49:54 +08:00
SWEP.HoldType = " slam "
2018-05-02 06:32:59 +08:00
GAMEMODE : SetPrimaryWeaponModifier ( SWEP , WEAPON_MODIFIER_HEALCOOLDOWN , - 0.8 )
GAMEMODE : AttachWeaponModifier ( SWEP , WEAPON_MODIFIER_HEALRANGE , 4 , 1 )
GAMEMODE : AttachWeaponModifier ( SWEP , WEAPON_MODIFIER_HEALING , 1.5 )
GAMEMODE : AddNewRemantleBranch ( SWEP , 1 , " Restoration Kit " , " Always uses the same amount of ammo, increased cooldown " , function ( wept )
wept.FixUsage = true
wept.Primary . Delay = wept.Primary . Delay * 1.3
end )
2014-10-02 08:49:54 +08:00
function SWEP : Initialize ( )
2014-11-12 08:15:49 +08:00
self : SetWeaponHoldType ( self.HoldType )
2018-05-02 06:32:59 +08:00
GAMEMODE : DoChangeDeploySpeed ( self )
2014-10-02 08:49:54 +08:00
end
function SWEP : Think ( )
if self.IdleAnimation and self.IdleAnimation <= CurTime ( ) then
self.IdleAnimation = nil
self : SendWeaponAnim ( ACT_VM_IDLE )
end
end
function SWEP : PrimaryAttack ( )
if not self : CanPrimaryAttack ( ) then return end
2018-05-02 06:32:59 +08:00
local owner = self : GetOwner ( )
local trtbl = owner : CompensatedPenetratingMeleeTrace ( self.HealRange , 2 , nil , nil , true )
local ent
for _ , tr in pairs ( trtbl ) do
local test = tr.Entity
if test and test : IsValidLivingHuman ( ) and gamemode.Call ( " PlayerCanBeHealed " , test ) then
ent = test
break
end
end
2014-10-02 08:49:54 +08:00
2018-05-02 06:32:59 +08:00
if not ent then return end
2014-10-02 08:49:54 +08:00
2018-05-02 06:32:59 +08:00
local multiplier = self.MedicHealMul or 1
local cooldownmultiplier = self.MedicCooldownMul or 1
local healed = owner : HealPlayer ( ent , math.min ( self : GetCombinedPrimaryAmmo ( ) , self.Heal ) )
local totake = self.FixUsage and 15 or math.ceil ( healed / multiplier )
2014-10-02 08:49:54 +08:00
2018-05-02 06:32:59 +08:00
if totake > 0 then
self : SetNextCharge ( CurTime ( ) + self.Primary . Delay * math.min ( 1 , healed / self.Heal ) * cooldownmultiplier )
owner.NextMedKitUse = self : GetNextCharge ( )
2014-10-02 08:49:54 +08:00
2018-05-02 06:32:59 +08:00
self : TakeCombinedPrimaryAmmo ( totake )
2014-10-02 08:49:54 +08:00
2018-05-02 06:32:59 +08:00
self : EmitSound ( " items/medshot4.wav " )
2014-10-02 08:49:54 +08:00
2018-05-02 06:32:59 +08:00
self : SendWeaponAnim ( ACT_VM_PRIMARYATTACK )
2014-10-02 08:49:54 +08:00
2018-05-02 06:32:59 +08:00
owner : DoAttackEvent ( )
self.IdleAnimation = CurTime ( ) + self : SequenceDuration ( )
2014-10-02 08:49:54 +08:00
end
end
function SWEP : SecondaryAttack ( )
2018-05-02 06:32:59 +08:00
local owner = self : GetOwner ( )
2014-10-02 08:49:54 +08:00
if not self : CanPrimaryAttack ( ) or not gamemode.Call ( " PlayerCanBeHealed " , owner ) then return end
2018-05-02 06:32:59 +08:00
local multiplier = self.MedicHealMul or 1
local cooldownmultiplier = self.MedicCooldownMul or 1
local healed = owner : HealPlayer ( owner , math.min ( self : GetCombinedPrimaryAmmo ( ) , self.Heal * self.Secondary . HealMul ) )
local totake = self.FixUsage and 10 or math.ceil ( healed / multiplier )
if totake > 0 then
self : SetNextCharge ( CurTime ( ) + self.Primary . Delay * self.Secondary . DelayMul * math.min ( 1 , healed / self.Heal * self.Secondary . HealMul ) * cooldownmultiplier )
2014-10-02 08:49:54 +08:00
owner.NextMedKitUse = self : GetNextCharge ( )
self : TakeCombinedPrimaryAmmo ( totake )
self : EmitSound ( " items/smallmedkit1.wav " )
self : SendWeaponAnim ( ACT_VM_PRIMARYATTACK )
owner : DoAttackEvent ( )
self.IdleAnimation = CurTime ( ) + self : SequenceDuration ( )
end
end
function SWEP : Deploy ( )
2018-05-02 06:32:59 +08:00
gamemode.Call ( " WeaponDeployed " , self : GetOwner ( ) , self )
2014-10-02 08:49:54 +08:00
self.IdleAnimation = CurTime ( ) + self : SequenceDuration ( )
if CLIENT then
hook.Add ( " PostPlayerDraw " , " PostPlayerDrawMedical " , GAMEMODE.PostPlayerDrawMedical )
2014-11-10 07:28:31 +08:00
GAMEMODE.MedicalAura = true
2014-10-02 08:49:54 +08:00
end
return true
end
function SWEP : Holster ( )
2018-05-02 06:32:59 +08:00
if CLIENT and self : GetOwner ( ) == MySelf then
2014-10-02 08:49:54 +08:00
hook.Remove ( " PostPlayerDraw " , " PostPlayerDrawMedical " )
2014-11-10 07:28:31 +08:00
GAMEMODE.MedicalAura = false
2014-10-02 08:49:54 +08:00
end
return true
end
2014-11-21 15:28:59 +08:00
function SWEP : OnRemove ( )
2018-05-02 06:32:59 +08:00
if CLIENT and self : GetOwner ( ) == MySelf then
2014-11-21 15:28:59 +08:00
hook.Remove ( " PostPlayerDraw " , " PostPlayerDrawMedical " )
GAMEMODE.MedicalAura = false
end
end
2014-10-02 08:49:54 +08:00
function SWEP : Reload ( )
end
function SWEP : SetNextCharge ( tim )
self : SetDTFloat ( 0 , tim )
end
function SWEP : GetNextCharge ( )
return self : GetDTFloat ( 0 )
end
function SWEP : CanPrimaryAttack ( )
2018-05-02 06:32:59 +08:00
local owner = self : GetOwner ( )
2014-10-02 08:49:54 +08:00
if owner : IsHolding ( ) or owner : GetBarricadeGhosting ( ) then return false end
if self : GetPrimaryAmmoCount ( ) <= 0 then
self : EmitSound ( " items/medshotno1.wav " )
self : SetNextCharge ( CurTime ( ) + 0.75 )
owner.NextMedKitUse = self : GetNextCharge ( )
return false
end
return self : GetNextCharge ( ) <= CurTime ( ) and ( owner.NextMedKitUse or 0 ) <= CurTime ( )
end
if not CLIENT then return end
2018-05-02 06:32:59 +08:00
function SWEP : DrawWeaponSelection ( x , y , w , h , alpha )
self : BaseDrawWeaponSelection ( x , y , w , h , alpha )
2014-10-02 08:49:54 +08:00
end
local texGradDown = surface.GetTextureID ( " VGUI/gradient_down " )
function SWEP : DrawHUD ( )
2018-05-02 06:32:59 +08:00
local wid , hei = 384 , 16
2014-10-02 08:49:54 +08:00
local x , y = ScrW ( ) - wid - 32 , ScrH ( ) - hei - 72
local texty = y - 4 - draw.GetFontHeight ( " ZSHUDFontSmall " )
local timeleft = self : GetNextCharge ( ) - CurTime ( )
if 0 < timeleft then
surface.SetDrawColor ( 5 , 5 , 5 , 180 )
surface.DrawRect ( x , y , wid , hei )
2018-05-02 06:32:59 +08:00
surface.SetDrawColor ( 50 , 255 , 50 , 180 )
2014-10-02 08:49:54 +08:00
surface.SetTexture ( texGradDown )
2018-05-02 06:32:59 +08:00
surface.DrawTexturedRect ( x , y , math.min ( 1 , timeleft / math.max ( self.Primary . Delay , self.Primary . Delay * self.Secondary . DelayMul ) ) * wid , hei )
2014-10-02 08:49:54 +08:00
2018-05-02 06:32:59 +08:00
surface.SetDrawColor ( 50 , 255 , 50 , 180 )
2014-10-02 08:49:54 +08:00
surface.DrawOutlinedRect ( x , y , wid , hei )
end
2018-05-02 06:32:59 +08:00
draw.SimpleText ( self.PrintName , " ZSHUDFontSmall " , x , texty , COLOR_GREEN , TEXT_ALIGN_LEFT )
2014-10-02 08:49:54 +08:00
local charges = self : GetPrimaryAmmoCount ( )
if charges > 0 then
draw.SimpleText ( charges , " ZSHUDFontSmall " , x + wid , texty , COLOR_GREEN , TEXT_ALIGN_RIGHT )
else
draw.SimpleText ( charges , " ZSHUDFontSmall " , x + wid , texty , COLOR_DARKRED , TEXT_ALIGN_RIGHT )
end
2018-05-02 06:32:59 +08:00
if GetConVar ( " crosshair " ) : GetInt ( ) == 1 then
2014-10-02 08:49:54 +08:00
self : DrawCrosshairDot ( )
end
end