zombiesurvival-evolved/gamemodes/zombiesurvival/entities/weapons/weapon_zs_medicalkit.lua

220 lines
6 KiB
Lua
Raw Normal View History

2014-10-02 08:49:54 +08:00
AddCSLuaFile()
SWEP.PrintName = "Medical Kit"
SWEP.Description = "An advanced kit of medicine, bandages, and morphine.\nVery useful for keeping a group of survivors healthy.\nUse PRIMARY FIRE to heal other players.\nUse SECONDARY FIRE to heal yourself.\nHealing 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
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
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"
SWEP.Secondary.DelayMul = 20 / SWEP.Primary.Delay
SWEP.Secondary.HealMul = 10 / SWEP.Heal
2014-10-02 08:49:54 +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
SWEP.HealRange = 36
2014-10-02 08:49:54 +08:00
SWEP.NoMagazine = true
SWEP.AllowQualityWeapons = true
2014-10-02 08:49:54 +08:00
SWEP.HoldType = "slam"
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()
self:SetWeaponHoldType(self.HoldType)
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
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
if not ent then return end
2014-10-02 08:49:54 +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
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
self:TakeCombinedPrimaryAmmo(totake)
2014-10-02 08:49:54 +08:00
self:EmitSound("items/medshot4.wav")
2014-10-02 08:49:54 +08:00
self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
2014-10-02 08:49:54 +08:00
owner:DoAttackEvent()
self.IdleAnimation = CurTime() + self:SequenceDuration()
2014-10-02 08:49:54 +08:00
end
end
function SWEP:SecondaryAttack()
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
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()
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)
GAMEMODE.MedicalAura = true
2014-10-02 08:49:54 +08:00
end
return true
end
function SWEP:Holster()
if CLIENT and self:GetOwner() == MySelf then
2014-10-02 08:49:54 +08:00
hook.Remove("PostPlayerDraw", "PostPlayerDrawMedical")
GAMEMODE.MedicalAura = false
2014-10-02 08:49:54 +08:00
end
return true
end
function SWEP:OnRemove()
if CLIENT and self:GetOwner() == MySelf then
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()
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
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()
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)
surface.SetDrawColor(50, 255, 50, 180)
2014-10-02 08:49:54 +08:00
surface.SetTexture(texGradDown)
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
surface.SetDrawColor(50, 255, 50, 180)
2014-10-02 08:49:54 +08:00
surface.DrawOutlinedRect(x, y, wid, hei)
end
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
if GetConVar("crosshair"):GetInt() == 1 then
2014-10-02 08:49:54 +08:00
self:DrawCrosshairDot()
end
end