-
Notifications
You must be signed in to change notification settings - Fork 788
/
prop_effect.lua
127 lines (85 loc) · 3.18 KB
/
prop_effect.lua
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
AddCSLuaFile()
if ( CLIENT ) then
CreateConVar( "cl_draweffectrings", "1", 0, "Should the effect green rings be visible?" )
end
ENT.Type = "anim"
ENT.PrintName = ""
ENT.Author = ""
ENT.Contact = ""
ENT.Purpose = ""
ENT.Instructions = ""
ENT.Spawnable = false
ENT.AdminOnly = false
--[[---------------------------------------------------------
Name: Initialize
-----------------------------------------------------------]]
function ENT:Initialize()
local Radius = 4
if ( SERVER ) then
self.AttachedEntity = ents.Create( "prop_dynamic" )
self.AttachedEntity:SetModel( self:GetModel() )
self.AttachedEntity:SetAngles( self:GetAngles() )
self.AttachedEntity:SetPos( self:GetPos() )
self.AttachedEntity:SetSkin( self:GetSkin() )
self.AttachedEntity:Spawn()
self.AttachedEntity:SetParent( self.Entity )
self.AttachedEntity:DrawShadow( false )
self:SetModel( "models/props_junk/watermelon01.mdl" )
self:DeleteOnRemove( self.AttachedEntity )
local min = Vector( 1, 1, 1 ) * Radius * -0.5
local max = Vector( 1, 1, 1 ) * Radius * 0.5
-- Don't use the model's physics - create a box instead
self:PhysicsInitBox( min, max )
-- Set up our physics object here
local phys = self:GetPhysicsObject()
if ( IsValid( phys) ) then
phys:Wake()
phys:EnableGravity( false )
phys:EnableDrag( false )
end
-- Set collision bounds exactly
self:SetCollisionBounds( min, max )
self:DrawShadow( false )
self:SetCollisionGroup( COLLISION_GROUP_WEAPON )
else
self.GripMaterial = Material( "sprites/grip" )
self:SetCollisionBounds( Vector( -Radius, -Radius, -Radius ), Vector( Radius, Radius, Radius ) )
end
end
--[[---------------------------------------------------------
Name: Draw
-----------------------------------------------------------]]
function ENT:Draw()
if ( GetConVarNumber( "cl_draweffectrings" ) == 0 ) then return end
-- Don't draw the grip if there's no chance of us picking it up
local ply = LocalPlayer()
local wep = ply:GetActiveWeapon()
if ( !wep:IsValid() ) then return end
local weapon_name = wep:GetClass()
local tool_mode = gmod_toolmode:GetString()
if ( weapon_name != "weapon_physgun"
&& weapon_name != "weapon_physcannon"
&& weapon_name != "gmod_tool" ) then
return
end
render.SetMaterial( self.GripMaterial )
render.DrawSprite( self:GetPos(), 16, 16, color_white )
end
--[[---------------------------------------------------------
Name: PhysicsUpdate
-----------------------------------------------------------]]
function ENT:PhysicsUpdate( physobj )
-- Don't do anything if the player isn't holding us
if ( !self:IsPlayerHolding() && !self:IsConstrained() ) then
physobj:SetVelocity( Vector(0,0,0) )
physobj:Sleep()
end
end
--[[---------------------------------------------------------
Name: Called after entity 'copy'
-----------------------------------------------------------]]
function ENT:OnEntityCopyTableFinish( tab )
-- We need to store the model of the attached entity
-- Not the one we have here.
tab.Model = self.AttachedEntity:GetModel()
end