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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
local EntityMeta = FindMetaTable( "Entity" )
function EntityMeta:SetResourceDropInfo( strType, int )
timer.Simple( 0.5, function() self:SetResourceDropInfoInstant( strType, int ) end )
end
function EntityMeta:SetResourceDropInfoInstant( strType, int )
for k, v in pairs( player.GetAll() ) do
local strType = strType or "Error"
umsg.Start( "gms_SetResourceDropInfo", v )
umsg.String( self:EntIndex() )
umsg.String( string.gsub( strType, "_", " " ) )
umsg.Short( self.Amount )
umsg.End()
end
end
function EntityMeta:SetResPackInfo( strType, int )
for k, v in pairs( player.GetAll() ) do
local strType = strType or "Error"
umsg.Start( "gms_SetResPackInfo", v )
umsg.String( self:EntIndex() )
umsg.String( string.gsub( strType, "_", " " ) )
umsg.Short( int )
umsg.End()
end
end
function EntityMeta:SetFoodInfo( strType )
timer.Simple( 0.5, function() self:SetFoodInfoInstant( strType ) end )
end
function EntityMeta:SetFoodInfoInstant( strType )
for k, v in pairs( player.GetAll() ) do
local strType = strType or "Error"
umsg.Start( "gms_SetFoodDropInfo", v )
umsg.String( self:EntIndex() )
umsg.String( string.gsub( strType, "_", " " ) )
umsg.End()
end
end
function EntityMeta:DropToGround()
local trace = {}
trace.start = self:GetPos()
trace.endpos = trace.start + Vector( 0, 0, -100000 )
trace.mask = MASK_SOLID_BRUSHONLY
trace.filter = self
local tr = util.TraceLine( trace )
self:SetPos( tr.HitPos )
end
GMS.LootableNPCs = { "npc_antlion", "npc_antlionguard", "npc_crow", "npc_seagull", "npc_pigeon", "npc_zombie" }
function EntityMeta:IsLootableNPC()
return table.HasValue( GMS.LootableNPCs, self:GetClass() )
end
function EntityMeta:MakeCampfire()
if ( GetConVarNumber( "gms_campfire" ) <= 0 ) then return end
local min, max = self:OBBMins(), self:OBBMaxs()
local vol = math.abs( max.x - min.x ) * math.abs( max.y - min.y ) * math.abs( max.z - min.z )
local mul = math.min( math.sqrt( vol ) / 200, 1 )
if ( !self.CampFire ) then self:SetHealth( 1337 ) end
self.CampFire = true
timer.Create( "gms_removecampfire_" .. self:EntIndex(), 480 * mul, 1, function() if ( IsValid( self ) ) then self:Fadeout() end end )
if ( GetConVarNumber( "gms_SpreadFire" ) >= 1 ) then
self:Ignite( 360, ( self:OBBMins() - self:OBBMaxs() ):Length() + 10 )
else
self:Ignite( 360, 0.001 )
end
end
/* ----------------------------------------------------------------------------------------------------
Entity Fading
---------------------------------------------------------------------------------------------------- */
GMS.FadingOutProps = {}
GMS.FadingInProps = {}
function EntityMeta:Fadeout( speed )
if ( !IsValid( self ) ) then return end
local speed = speed or 1
for k, v in pairs( player.GetAll() ) do
umsg.Start( "gms_CreateFadingProp", v )
umsg.String( self:GetModel() )
umsg.Vector( self:GetPos() )
local ang = self:GetAngles()
umsg.Vector( Vector( ang.p, ang.y, ang.r ) )
local col = self:GetColor()
umsg.Vector( Vector( col.r, col.g, col.b ) )
umsg.Short( math.Round( speed ) )
umsg.End()
end
self:Remove()
end
--Fadein is serverside
function EntityMeta:Fadein( speed )
self.AlphaFade = 0
self:SetRenderMode( RENDERMODE_TRANSALPHA )
self:SetColor( Color( 255, 255, 255, 0 ) )
self.FadeInSpeed = speed or 4
table.insert( GMS.FadingInProps, self )
end
hook.Add( "Think", "gms_FadePropsThink", function()
if(GMS.FadingInProps == nil) then return end
for k, ent in pairs( GMS.FadingInProps ) do
if ( !ent or ent == NULL ) then
table.remove( GMS.FadingInProps, k )
elseif ( !IsValid( ent ) ) then
table.remove( GMS.FadingInProps, k )
elseif ( ent.AlphaFade >= 255 ) then
table.remove( GMS.FadingInProps, k )
else
ent.AlphaFade = ent.AlphaFade + ent.FadeInSpeed
ent:SetColor( Color( 255, 255, 255, ent.AlphaFade ) )
end
end
end )
/* ----------------------------------------------------------------------------------------------------
Entity rising / lowering ( Used by gms_seed )
---------------------------------------------------------------------------------------------------- */
GM.RisingProps = {}
GM.SinkingProps = {}
function EntityMeta:RiseFromGround( speed, altmax )
local speed = speed or 1
local max;
if ( !altmax ) then
min, max = self:WorldSpaceAABB()
max = max.z
else
max = altmax
end
local tbl = {}
tbl.Origin = self:GetPos().z
tbl.Speed = speed
tbl.Entity = self
self:SetPos( self:GetPos() + Vector( 0, 0, -max + 10 ) )
table.insert( GAMEMODE.RisingProps, tbl )
end
function EntityMeta:SinkIntoGround( speed )
local speed = speed or 1
local tbl = {}
tbl.Origin = self:GetPos().z
tbl.Speed = speed
tbl.Entity = self
tbl.Height = max
table.insert( GAMEMODE.SinkingProps, tbl )
end
hook.Add( "Think", "gms_RiseAndSinkPropsHook", function()
for k, tbl in pairs( GAMEMODE.RisingProps ) do
if ( !IsValid( tbl.Entity ) || tbl.Entity:GetPos().z >= tbl.Origin ) then
table.remove( GAMEMODE.RisingProps, k )
else
tbl.Entity:SetPos( tbl.Entity:GetPos() + Vector( 0, 0, 1 * tbl.Speed ) )
end
end
for k, tbl in pairs( GAMEMODE.SinkingProps ) do
if ( !IsValid( tbl.Entity ) || tbl.Entity:GetPos().z <= tbl.Origin - tbl.Height ) then
table.remove( GAMEMODE.SinkingProps, k )
tbl.Entity:Remove()
else
tbl.Entity:SetPos( tbl.Entity:GetPos() + Vector( 0, 0, -1 * tbl.Speed ) )
end
end
end )
|