Added ammo entity

This commit is contained in:
Arctic 2022-07-31 21:07:32 +10:00
parent 4ee53ff9e8
commit d2a3546b27
30 changed files with 202 additions and 0 deletions

171
lua/entities/arc9_ammo.lua Normal file
View File

@ -0,0 +1,171 @@
AddCSLuaFile()
ENT.Type = "anim"
ENT.Base = "base_entity"
ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
ENT.PrintName = "Ammo Pickup"
ENT.Category = "ARC-9 - Ammo"
ENT.Spawnable = true
ENT.Model = "models/weapons/tacint/ammoboxes/ammo_bag-1.mdl"
ENT.ModelOptions = nil
ENT.InfiniteUse = false
ENT.OpeningAnim = false
ENT.NextUse = 0
ENT.Open = false
function ENT:Initialize()
local model = self.Model
if self.ModelOptions then
model = table.Random(self.ModelOptions)
end
self:SetModel(model)
if SERVER then
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetCollisionGroup(COLLISION_GROUP_WEAPON)
self:SetUseType(CONTINUOUS_USE)
self:PhysWake()
self:SetTrigger(true) -- Enables Touch() to be called even when not colliding
self:UseTriggerBounds(true, 24)
end
end
local function ClampedGiveAmmo(ply, ammo, amt, clamp)
local count = ply:GetAmmoCount(ammo)
if count >= clamp then
return false
elseif count + amt > clamp then
amt = math.max(clamp - count, 0)
end
ply:GiveAmmo(amt, ammo)
return true
end
function ENT:ApplyAmmo(ply)
if self.NextUse > CurTime() then return end
local wpn = ply:GetActiveWeapon()
local ammotype = wpn:GetPrimaryAmmoType()
local clipsize = wpn:GetMaxClip1()
local supplyamount = clipsize * 1
local max = clipsize * 6
local t2
if wpn.ARC9 then
ammotype = wpn:GetProcessedValue("Ammo")
clipsize = wpn:GetProcessedValue("ClipSize")
max = wpn:GetProcessedValue("SupplyLimit") * clipsize
if max <= 0 then
max = 1
end
if wpn:GetProcessedValue("UBGL") then
local ammotype2 = wpn:GetProcessedValue("UBGLAmmo")
local clipsize2 = wpn:GetProcessedValue("UBGLClipSize")
local supplyamount2 = clipsize2 * 1
local max2 = clipsize2 * wpn:GetProcessedValue("SecondarySupplyLimit")
t2 = ClampedGiveAmmo(ply, ammotype2, supplyamount2, max2)
end
end
local t = ClampedGiveAmmo(ply, ammotype, supplyamount, max)
if t or t2 then
if self.OpeningAnim and !self.Open then
local seq = self:LookupSequence("open")
self:ResetSequence(seq)
self:EmitSound("items/ammocrate_open.wav")
self.Open = true
end
self.NextUse = CurTime() + 1
if !self.InfiniteUse then
self:Remove()
end
end
end
ENT.CollisionSoundsHard = {
"physics/cardboard/cardboard_box_impact_hard1.wav",
"physics/cardboard/cardboard_box_impact_hard2.wav",
"physics/cardboard/cardboard_box_impact_hard3.wav",
"physics/cardboard/cardboard_box_impact_hard4.wav",
"physics/cardboard/cardboard_box_impact_hard5.wav",
"physics/cardboard/cardboard_box_impact_hard6.wav",
"physics/cardboard/cardboard_box_impact_hard7.wav",
}
ENT.CollisionSoundsSoft = {
"physics/cardboard/cardboard_box_impact_soft1.wav",
"physics/cardboard/cardboard_box_impact_soft2.wav",
"physics/cardboard/cardboard_box_impact_soft3.wav",
"physics/cardboard/cardboard_box_impact_soft4.wav",
"physics/cardboard/cardboard_box_impact_soft5.wav",
"physics/cardboard/cardboard_box_impact_soft6.wav",
"physics/cardboard/cardboard_box_impact_soft7.wav",
}
function ENT:PhysicsCollide(data)
if data.DeltaTime < 0.1 then return end
if data.Speed > 25 then
self:EmitSound(self.CollisionSoundsHard[math.random(#self.CollisionSoundsHard)])
else
self:EmitSound(self.CollisionSoundsSoft[math.random(#self.CollisionSoundsSoft)])
end
end
if SERVER then
function ENT:Use(ply)
if !ply:IsPlayer() then return end
self:ApplyAmmo(ply)
end
function ENT:Think()
if self.Open and (self.NextUse + 0.1) < CurTime() then
local seq = self:LookupSequence("close")
self:ResetSequence(seq)
self:EmitSound("items/ammocrate_close.wav")
self.Open = false
end
self:NextThink(CurTime())
return true
end
function ENT:Touch(ply)
if !ply:IsPlayer() then return end
self:ApplyAmmo(ply)
end
elseif CLIENT then
function ENT:DrawTranslucent()
self:Draw()
end
function ENT:Draw()
self:DrawModel()
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,5 @@
vertexlitgeneric
{
$baseTexture "models/tacint/props_misc/ammo_bag-1"
$bumpmap "models/tacint/props_misc/ammo_bag-1_normal"
}

Binary file not shown.

View File

@ -0,0 +1,17 @@
vertexlitgeneric
{
$baseTexture "models/tacint/props_misc/bomb_display_armed"
$translucent 1
Proxies
{
// This is a sine proxy
Sine
{
resultVar $alpha
sineperiod 0.73
sinemin 0.06
sinemax 1.0
}
}
}

View File

@ -0,0 +1,5 @@
vertexlitgeneric
{
$baseTexture "models/tacint/props_misc/bomb_display_safe"
$translucent 1
}

View File

@ -0,0 +1,4 @@
vertexlitgeneric
{
$baseTexture "models/tacint/props_misc/bomb_suitcase-1"
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.