diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-04-22 15:33:10 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-04-22 15:33:10 -0400 |
| commit | 4820a793f8c9a504510a6b6bf4d8b4c6391cd6cc (patch) | |
| tree | 9ab751aad126fdba38b3bee0fdb6a8189b9abbc1 /gamemode/processes.lua | |
| parent | 9a50a5880f3d263cd351f4786c222ac7f0b78517 (diff) | |
| download | gmstranded-4820a793f8c9a504510a6b6bf4d8b4c6391cd6cc.tar.gz gmstranded-4820a793f8c9a504510a6b6bf4d8b4c6391cd6cc.tar.bz2 gmstranded-4820a793f8c9a504510a6b6bf4d8b4c6391cd6cc.zip | |
Refactored planting process code
Diffstat (limited to 'gamemode/processes.lua')
| -rw-r--r-- | gamemode/processes.lua | 166 |
1 files changed, 30 insertions, 136 deletions
diff --git a/gamemode/processes.lua b/gamemode/processes.lua index d1f024a..d898271 100644 --- a/gamemode/processes.lua +++ b/gamemode/processes.lua @@ -1,7 +1,3 @@ - -local PlayerMeta = FindMetaTable( "Player" ) -local EntityMeta = FindMetaTable( "Entity" ) - GMS.Processes = {} function GMS.RegisterProcess( name, tbl ) @@ -700,141 +696,39 @@ GMS.RegisterProcess( "SproutCollect", PROCESS ) /*--------------------------------------------------------- Plant Melon ---------------------------------------------------------*/ -local PROCESS = {} - -function PROCESS:OnStart() - self.Owner:MakeProcessBar( "Planting Watermelon", self.Time, self.Cancel ) -end - -function PROCESS:OnStop() - self.Owner:DecResource( "Melon_Seeds", 1 ) - self.Owner:IncXP( "Planting", math.Clamp( math.Round( 50 / self.Owner:GetSkill( "Planting" ) ), 1, 1000 ) ) - self.Owner:SendMessage( "Successfully planted.", 3, Color( 10, 200, 10, 255 ) ) - - local ent = ents.Create( "gms_seed" ) - SPropProtection.PlayerMakePropOwner( self.Owner, ent ) - ent:SetPos( self.Data.Pos ) - ent:Setup( "melon", 160 - math.Clamp( self.Owner:GetSkill( "Planting" ), 0, 60 ) + math.random( -20, 20 ), self.Owner ) - ent:Spawn() -end - -GMS.RegisterProcess( "PlantMelon", PROCESS ) - -/*--------------------------------------------------------- - Plant Banana ----------------------------------------------------------*/ -local PROCESS = {} - -function PROCESS:OnStart() - self.Owner:MakeProcessBar( "Planting Banana", self.Time, self.Cancel ) -end - -function PROCESS:OnStop() - self.Owner:DecResource( "Banana_Seeds", 1 ) - self.Owner:IncXP( "Planting", math.Clamp( math.Round( 50 / self.Owner:GetSkill( "Planting" ) ), 1, 1000 ) ) - self.Owner:SendMessage( "Successfully planted.", 3, Color( 10, 200, 10, 255 ) ) - - local ent = ents.Create( "gms_seed" ) - SPropProtection.PlayerMakePropOwner( self.Owner , ent ) - ent:SetPos( self.Data.Pos ) - ent:Setup( "banana", 160 - math.Clamp( self.Owner:GetSkill( "Planting" ), 0, 60 ) + math.random( -20, 20 ), self.Owner ) - ent:Spawn() -end - -GMS.RegisterProcess( "PlantBanana", PROCESS ) - -/*--------------------------------------------------------- - Plant Orange ----------------------------------------------------------*/ -local PROCESS = {} - -function PROCESS:OnStart() - self.Owner:MakeProcessBar( "Planting Orange", self.Time, self.Cancel ) -end - -function PROCESS:OnStop() - self.Owner:DecResource( "Orange_Seeds", 1 ) - self.Owner:IncXP( "Planting", math.Clamp( math.Round( 50 / self.Owner:GetSkill( "Planting" ) ) , 1, 1000 ) ) - self.Owner:SendMessage( "Successfully planted.", 3, Color( 10, 200, 10, 255 ) ) - - local ent = ents.Create( "gms_seed" ) - SPropProtection.PlayerMakePropOwner( self.Owner, ent ) - ent:SetPos( self.Data.Pos ) - ent:Setup( "orange", 160 - math.Clamp( self.Owner:GetSkill( "Planting" ), 0, 60 ) + math.random( -20, 20 ), self.Owner ) - ent:Spawn() -end - -GMS.RegisterProcess( "PlantOrange", PROCESS ) - -/*--------------------------------------------------------- - Plant Grain ----------------------------------------------------------*/ -local PROCESS = {} - -function PROCESS:OnStart() - self.Owner:MakeProcessBar( "Planting Grain", self.Time, self.Cancel ) -end - -function PROCESS:OnStop() - self.Owner:DecResource( "Grain_Seeds", 1 ) - self.Owner:IncXP( "Planting", math.Clamp( math.Round( 50 / self.Owner:GetSkill( "Planting" ) ), 1, 1000 ) ) - self.Owner:SendMessage( "Successfully planted.", 3, Color( 10, 200, 10, 255 ) ) - - local ent = ents.Create( "gms_seed" ) - SPropProtection.PlayerMakePropOwner( self.Owner, ent ) - ent:SetPos( self.Data.Pos ) - ent:Setup( "grain", 160 - math.Clamp( self.Owner:GetSkill( "Planting" ), 0, 60 ) + math.random( -20, 20 ), self.Owner ) - ent:Spawn() -end - -GMS.RegisterProcess( "PlantGrain", PROCESS ) - -/*--------------------------------------------------------- - Plant Bush ----------------------------------------------------------*/ -local PROCESS = {} - -function PROCESS:OnStart() - self.Owner:MakeProcessBar( "Planting Berry Bush", self.Time, self.Cancel ) -end - -function PROCESS:OnStop() - self.Owner:DecResource( "Berries", 1 ) - self.Owner:IncXP( "Planting", math.Clamp( math.Round( 50 / self.Owner:GetSkill( "Planting" ) ), 1, 1000 ) ) - self.Owner:SendMessage( "Successfully planted.", 3, Color( 10, 200, 10, 255 ) ) - - local ent = ents.Create( "gms_seed" ) - SPropProtection.PlayerMakePropOwner( self.Owner, ent ) - ent:SetPos( self.Data.Pos ) - ent:Setup( "berry", 160 - math.Clamp( self.Owner:GetSkill( "Planting" ), 0, 60 ) + math.random( -20, 20 ), self.Owner ) - ent:Spawn() -end - -GMS.RegisterProcess( "PlantBush", PROCESS ) - -/*--------------------------------------------------------- - Plant Tree ----------------------------------------------------------*/ -local PROCESS = {} - -function PROCESS:OnStart() - self.Owner:MakeProcessBar( "Planting Tree", self.Time, self.Cancel ) -end - -function PROCESS:OnStop() - self.Owner:DecResource( "Sprouts", 1 ) - self.Owner:IncXP( "Planting", math.Clamp( math.Round( 50 / self.Owner:GetSkill( "Planting" ) ), 1, 1000 ) ) - self.Owner:SendMessage( "Successfully planted.", 3, Color( 10, 200, 10, 255 ) ) +/*Alright, let's refactor this planting code*/ +local plant_generic = { + {"Watermelon","Melon_Seeds","melon","PlantMelon"}, + {"Banana","Banana_Seeds","banana","PlantBanana"}, + {"Orange","Orange_Seeds","orange","PlantOrange"}, + {"Grain","Grain_Seeds","grain","PlantGrain"}, + {"Berry Bush","Berries","berry","PlantBush"}, + {"Tree","Sprouts","tree","PlantTree"}, +} + +for k,v in pairs(plant_generic) do + local PROCESS = {} + function PROCESS:OnStart() + print("time:" .. self.Time) + print("Cancel") + print(self.Cancel) + self.Owner:MakeProcessBar( "Planting " .. v[1], self.Time, self.Cancel) + end + function PROCESS:OnStop() + self.Owner:DecResource(v[2],1) + self.Owner:IncXP( "Planting", math.Clamp( math.Round(50 / self.Owner:GetSkill("Planting")),1,1000)) + self.Owner:SendMessage( "Successfully planted.", 3, Color(10,200,10,255)) + + local ent = ents.Create("gms_seed") + SPropProtection.PlayerMakePropOwner(self.Owner, ent) + ent:SetPos( self.Data.Pos) + ent:Setup(v[3],160-math.Clamp(self.Owner:GetSkill("planting"),0,60) + math.Round(-20,20),self.Owner) + ent:Spawn() + end - local ent = ents.Create( "gms_seed" ) - SPropProtection.PlayerMakePropOwner( self.Owner, ent ) - ent:SetPos( self.Data.Pos ) - ent:Setup( "tree", 240 - math.Clamp( self.Owner:GetSkill( "Planting" ), 0, 60 ) + math.random( -20, 20 ), self.Owner ) - ent:Spawn() + GMS.RegisterProcess(v[4], PROCESS) end -GMS.RegisterProcess( "PlantTree", PROCESS ) - /*--------------------------------------------------------- Assembling ---------------------------------------------------------*/ |
