summaryrefslogtreecommitdiff
path: root/entities/weapons/gms_shovel.lua
blob: 8c6491065a38bd95e8a75e12d782cd9f61889b9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
AddCSLuaFile()

SWEP.Slot = 2
SWEP.SlotPos = 1

SWEP.Base = "gms_base_weapon"
SWEP.PrintName = "Shovel"
SWEP.ViewModel = "models/weapons/c_gms_shovel.mdl"
SWEP.WorldModel = "models/weapons/w_gms_shovel.mdl"

SWEP.Purpose = "Dig"
SWEP.Instructions = "Use primary to dig"

SWEP.HoldType = "melee"
SWEP.UseHands = true

SWEP.Primary.Damage = 10
SWEP.Primary.Delay = 1.5
SWEP.HitDistance = 92

function SWEP:PlaySwingSound()
	self:PlaySound( "npc/vort/claw_swing" .. math.random( 1, 2 ) .. ".wav" )
end

function SWEP:PlayHitSound()
	self:PlaySound( "weapons/gms_shovel" .. math.random( 1, 4 ) .. ".wav" )
end

function SWEP:OnHit( tr )

	local ent = tr.Entity
	if ( SERVER && ent:Health() > 0 ) then
		if ( ent:IsNPC() ) then ent:TakeDamage( self.Primary.Damage, self.Owner, self ) end
		self:PlayHitSound()
	end

	if ( !tr.HitWorld || CLIENT ) then
		if ( tr.Hit && SERVER ) then self:PlayHitSound() end
	return end

	if ( tr.MatType == MAT_DIRT || tr.MatType == MAT_GRASS || tr.MatType == MAT_SAND ) then
		self.Owner:DoProcess( "Dig", 5, {
			Sand = ( tr.MatType == MAT_SAND )
		} )
	else
		self.Owner:SendMessage( "Can't dig on this terrain!", 3, Color( 200, 0, 0, 255 ) )
		self:PlayHitSound()
	end

end

function SWEP:DoAnimation( missed )
	if ( missed ) then self:SendWeaponAnim( ACT_VM_MISSCENTER ) return end
	self:SendWeaponAnim( ACT_VM_HITCENTER )
end

function SWEP:DoEffects( tr )
	if ( IsFirstTimePredicted() ) then
		self:PlaySwingAnimation( !tr.HitWorld )
		self:PlaySwingSound()
		self.Owner:SetAnimation( PLAYER_ATTACK1 )
		if ( !tr.HitWorld || ( tr.MatType != MAT_DIRT && tr.MatType != MAT_GRASS && tr.MatType != MAT_SAND ) ) then
			self:DoImpactEffects( tr )
		else
			util.Decal( "impact.sand", tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal )
		end
	end
end