if CLIENT then SWEP.WepSelectIcon = surface.GetTextureID( "vgui/hud/item_bandages" ) SWEP.BounceWeaponIcon = true SWEP.DrawWeaponInfoBox = true end SWEP.PrintName = "Bandage" SWEP.Author = "Craft_Pig" SWEP.Purpose = [[ Heals 20HP ]] SWEP.Category = "NMRIH" SWEP.ViewModelFOV = 65 SWEP.ViewModel = "models/weapons/nmrih/items/bandage/v_item_bandages.mdl" SWEP.WorldModel = "models/weapons/nmrih/items/bandage/w_bandages.mdl" SWEP.UseHands = true SWEP.DrawCrosshair = false SWEP.Spawnable = true SWEP.Slot = 0 SWEP.SlotPos = 5 SWEP.DrawAmmo = true SWEP.Primary.Ammo = "bandage" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = 1 SWEP.Primary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.HitDistance = 90 SWEP.PrimaryCD = 1 SWEP.PrimaryHitTime = 0.1 local HealAmount = 20 local ArmorAmount = 0 local InitializeSEF = false function SWEP:Initialize() self:SetHoldType("slam") local FilePathSEF = "lua/SEF/SEF_Functions.lua" if file.Exists(FilePathSEF, "GAME") then InitializeSEF = true else InitializeSEF = false end end function SWEP:Deploy() local owner = self:GetOwner() self:SendWeaponAnim(ACT_VM_DRAW) self.IdleTimer = CurTime() + self.Owner:GetViewModel():SequenceDuration() self.Idle = 0 self.Sprint = 0 self.Walk = 0 self.Give = 0 self.InitializeHealing = 0 self.vmcamera = nil if owner:GetAmmoCount(self.Primary.Ammo) == 0 then owner:StripWeapon("weapon_nmrih_bandage") end -- Reminder return true end local function Heal(owner, weapon) local activeWeapon = owner:GetActiveWeapon() if IsValid(weapon) then if IsValid(owner) and SERVER and activeWeapon:GetClass() == "weapon_nmrih_bandage" then -- Reminder if InitializeSEF == true then owner:ApplyEffect("Healing", 1, 20, 1) owner:RemoveEffect("Bleeding") else owner:SetHealth(math.min(owner:GetMaxHealth(), owner:Health() + HealAmount)) owner:SetArmor(math.min(owner:GetMaxArmor(), owner:Armor() + ArmorAmount)) end owner:RemoveAmmo(1, "bandage") -- Reminder -- owner:EmitSound("nil") weapon:Deploy() end end end function SWEP:PrimaryAttack() local owner = self.Owner if owner:GetAmmoCount(self.Primary.Ammo) == 0 then return end self:SendWeaponAnim(ACT_VM_PRIMARYATTACK) self:SetNextPrimaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration() + 0) self.IdleTimer = CurTime() + self.Owner:GetViewModel():SequenceDuration() self.InitializeHealing = 1 self.Idle = 1 end function SWEP:SecondaryAttack() local owner = self:GetOwner() local dmginfo = DamageInfo() local tr = util.TraceLine( { start = owner:GetShootPos(), endpos = owner:GetShootPos() + owner:GetAimVector() * self.HitDistance, filter = owner, mask = MASK_SHOT_HULL } ) if ( !IsValid( tr.Entity ) ) then tr = util.TraceHull( { start = owner:GetShootPos(), endpos = owner:GetShootPos() + owner:GetAimVector() * self.HitDistance, filter = owner, mins = Vector( -10, -10, -8 ), maxs = Vector( 10, 10, 8 ), mask = MASK_SHOT_HULL } ) end if self.InitializeHealing == 1 then return end self.Owner:SetAnimation( PLAYER_ATTACK1 ) self:SendWeaponAnim(ACT_VM_HITCENTER) self.IdleTimer = CurTime() + self.Owner:GetViewModel():SequenceDuration() self:SetNextSecondaryFire(CurTime() + 0.9) self.Idle = 0 self.Sprint = 0 self.Walk = 0 timer.Create("TimerHitWhen", self.PrimaryHitTime, 1, function() -- Impact Timer if SERVER then if ( SERVER and IsValid( tr.Entity ) and ( tr.Entity:IsNPC() or tr.Entity:IsPlayer() or tr.Entity:Health() > 0 ) ) then dmginfo:SetDamage(10) dmginfo:SetAttacker(self.Owner) dmginfo:SetInflictor(self) dmginfo:SetDamageType(DMG_CRUSH) tr.Entity:TakeDamageInfo(dmginfo) end end end) end function SWEP:Reload() local owner = self:GetOwner() local trace = owner:GetEyeTrace() if self.Give == 1 then return end if IsValid(trace.Entity) and trace.Entity:IsPlayer() then local targetPlayer = trace.Entity self:SendWeaponAnim(ACT_VM_THROW) self.IdleTimer = CurTime() + self.Owner:GetViewModel():SequenceDuration() self.Idle = 0 self.Sprint = 0 self.Walk = 0 self.Give = 1 owner:RemoveAmmo(1, "bandage") if CLIENT then return end timer.Create("TimerNMRIHBandageGive", 1.2, 1, function() if targetPlayer:HasWeapon("weapon_nmrih_bandage") then targetPlayer:GiveAmmo( 1, "bandage") else targetPlayer:Give("weapon_nmrih_bandage") end -- print(owner:Nick() .. " gave a bandage to " .. targetPlayer:Nick()) self:Deploy() end) end end function SWEP:Think() local owner = self.Owner if self.InitializeHealing == 1 and self.IdleTimer <= CurTime() then if IsValid(self) then Heal(owner, self) end end if self.InitializeHealing == 1 then return end if (owner:KeyDown(IN_FORWARD + IN_BACK + IN_MOVELEFT + IN_MOVERIGHT) and owner:KeyDown(IN_SPEED)) then -- If Sprinting if self.Sprint == 0 and self.IdleTimer <= CurTime() then self:SendWeaponAnim(ACT_VM_SPRINT_IDLE) self.Sprint = 1 self.Walk = 0 self.Idle = 0 end elseif (owner:KeyDown(IN_FORWARD + IN_BACK + IN_MOVELEFT + IN_MOVERIGHT)) then -- If Walking if self.Walk == 0 and self.IdleTimer <= CurTime() then self:SendWeaponAnim(ACT_VM_IDLE_LOWERED) self.Walk = 1 self.Sprint = 0 self.Idle = 0 end elseif self.Idle == 0 and self.IdleTimer <= CurTime() then -- Idle Sequence self:SendWeaponAnim(ACT_VM_IDLE) self.Idle = 1 self.Sprint = 0 self.Walk = 0 end end function SWEP:Holster() timer.Remove("TimerHitWhen") timer.Remove("TimerNMRIHBandageGive") return true end function SWEP:PostDrawViewModel( vm ) local attachment = vm:GetAttachment(1) if attachment then self.vmcamera = vm:GetAngles() - attachment.Ang else self.vmcamera = Angle(0, 0, 0) end end function SWEP:CalcView( ply, pos, ang, fov ) self.vmcamera = self.vmcamera or Angle(0, 0, 0) return pos, ang + self.vmcamera, fov end