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
|
--This file holds a bunch of common functions that happen in items. They're seperated out here so that they're easy to change if there's a bug somewhere.
--Freezes the player, creates the loading bar, and calls ondone when the timer is up.
function startProcessGeneric(player, string, time, ondone)
if(player.InProcess) then
self.Owner:SendMessage("You can't do that much at once!", 3, Color(255, 255, 255, 255))
return
end
player.InProcess = true
player:Freeze(true)
player:MakeProcessBar( string, time, false )
timer.Create( "process", time, 1, function()
player:Freeze(false)
player.InProcess = false
player:StopProcessBar()
ondone()
end)
end
if(SERVER) then
util.AddNetworkString( "gms_plantseed" )
end
local function plant(player, resourcename)
if(CLIENT) then
net.Start("gms_plantseed")
net.WriteString(resourcename)
net.SendToServer()
end
if(SERVER) then
print("Planting " .. resourcename)
local tbl = GMS.Resources[resourcename]
print("Plant table:")
PrintTable(tbl)
if(tbl.GrowTime == nil) then
print(tbl.Name .. " .GrowTime is nil, this might be a bug!")
return
end
if(tbl.OnGrow == nil) then
print(tbl.Name .. " .OnGrow is nil, this might be a bug!")
return
end
local tr = player:GetEyeTrace()
local pent = ents.Create("gms_generic_plantable")
pent:SetPos(tr.HitPos)
pent.GrowTime = tbl.GrowTime
pent.OnGrow = tbl.OnGrow
print("Setting seed's owner to:")
print(player)
pent:SetOwner(player)
pent:Spawn()
end
end
net.Receive( "gms_plantseed", function(len,pl)
local resourcename = net.ReadString()
plant(pl,resourcename)
end)
function genericMakePlantable( tbl )
local plant = function(player)
plant(player,tbl.Name)
end
if(tbl.Actions == nil) then
tbl.Actions = {}
end
tbl.Actions["Plant " .. tbl.Name] = plant
end
GAMEMODE = GAMEMODE or {}
function GAMEMODE.MakeGenericPlantChild( ply, pos, mdl, parent )
local ent = ents.Create( "prop_physics" )
ent:SetAngles( Angle( 0, math.random( 0, 360 ) , 0 ) )
ent:SetModel( mdl )
ent:SetPos( pos )
ent:Spawn()
ent.IsPlantChild = true
ent:SetHealth( 99999 )
ent:Fadein()
local phys = ent:GetPhysicsObject()
if ( phys ) then phys:EnableMotion( false ) end
ent.PlantParent = parent
ent.PlantParentName = parent:GetName()
parent.Children = parent.Children + 1
if ( IsValid( ply ) ) then
SPropProtection.PlayerMakePropOwner( ply, ent )
else
ent:SetNWString( "Owner", "World" )
end
ent.PhysgunDisabled = true
return ent
end
|