From 2909686b5031210eb2b63ac2d266ed77f8841855 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 16 Apr 2016 04:55:44 -0400 Subject: Renamed init_utility.lua to just utility.lua --- gamemode/init.lua | 179 +--------------------------------------------- gamemode/init_utility.lua | 28 -------- gamemode/utility.lua | 28 ++++++++ 3 files changed, 29 insertions(+), 206 deletions(-) delete mode 100644 gamemode/init_utility.lua create mode 100644 gamemode/utility.lua diff --git a/gamemode/init.lua b/gamemode/init.lua index 0dda971..ac34276 100644 --- a/gamemode/init.lua +++ b/gamemode/init.lua @@ -1,7 +1,4 @@ - - - -- Send clientside files AddCSLuaFile( "shared.lua" ) AddCSLuaFile( "cl_init.lua" ) @@ -39,17 +36,7 @@ local PlayerMeta = FindMetaTable( "Player" ) local EntityMeta = FindMetaTable( "Entity" ) --Tribes table -/* Moved to /server/tribes.lua -if ( !GM.Tribes ) then - GM.Tribes = GM.Tribes or {} - table.insert( GM.Tribes, { name = "The Stranded", color = Color( 200, 200, 0 ), password = false } ) - table.insert( GM.Tribes, { name = "Survivalists", color = Color( 225, 225, 225 ), password = false } ) - table.insert( GM.Tribes, { name = "Anonymous", color = Color( 0, 145, 145 ), password = false } ) - table.insert( GM.Tribes, { name = "The Gummies", color = Color( 255, 23, 0 ), password = false } ) - table.insert( GM.Tribes, { name = "The Dynamics", color = Color( 0, 72, 255 ), password = false } ) - table.insert( GM.Tribes, { name = "Scavengers", color = Color( 8, 255, 0 ), password = false } ) -end -*/ +/* Moved to /server/tribes.lua*/ GM.AntlionBarrowSpawns = {} GM.AntlionBarrowSpawns[ "gm_construct" ] = { Vector( -4321.8149, -2551.3449, 257.5130 ) } @@ -1340,170 +1327,6 @@ for k,v in pairs(GM.Plantables) do end) end -/* Refactored, see above -function GM.PlantMelon( ply, cmd, args ) - if ( ply:GetNWInt( "plants" ) >= GetConVarNumber( "gms_PlantLimit" ) ) then - ply:SendMessage( "You have hit the plant limit.", 3, Color( 200, 0, 0, 255 ) ) - return - end - local tr = ply:TraceFromEyes( 150 ) - - if ( tr.HitWorld ) then - if ( tr.MatType == MAT_DIRT or tr.MatType == MAT_GRASS or tr.MatType == MAT_SAND ) and !GMS.IsInWater( tr.HitPos ) then - if ( ply:GetResource( "Melon_Seeds" ) >= 1 ) then - if ( !GMS.ClassIsNearby( tr.HitPos, "gms_seed", 30 ) and !GMS.ClassIsNearby( tr.HitPos, "prop_physics", 50 ) ) then - local data = {} - data.Pos = tr.HitPos - ply:DoProcess( "PlantMelon", 3, data ) - else - ply:SendMessage( "You need more distance between seeds/props.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "You need a watermelon seed.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "You cannot plant on this terrain.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "Aim at the ground to plant.", 3, Color( 200, 0, 0, 255 ) ) - end -end -concommand.Add( "gms_plantmelon", GM.PlantMelon ) - -function GM.PlantBanana( ply, cmd, args ) - if ( ply:GetNWInt( "plants" ) >= GetConVarNumber( "gms_PlantLimit" ) ) then ply:SendMessage( "You have hit the plant limit.", 3, Color( 200, 0, 0, 255 ) ) return end - local tr = ply:TraceFromEyes( 150 ) - - if ( tr.HitWorld ) then - if ( ( tr.MatType == MAT_DIRT or tr.MatType == MAT_GRASS or tr.MatType == MAT_SAND ) and !GMS.IsInWater( tr.HitPos ) ) then - if ( ply:GetResource( "Banana_Seeds" ) >= 1 ) then - if ( !GMS.ClassIsNearby( tr.HitPos, "gms_seed", 30 ) and !GMS.ClassIsNearby( tr.HitPos, "prop_physics", 50 ) ) then - ply:DoProcess( "PlantBanana", 3, { Pos = tr.HitPos } ) - else - ply:SendMessage( "You need more distance between seeds/props.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "You need a banana seed.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "You cannot plant on this terrain.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "Aim at the ground to plant.", 3, Color( 200, 0, 0, 255 ) ) - end -end -concommand.Add( "gms_plantbanana", GM.PlantBanana ) - -function GM.PlantOrange( ply, cmd, args ) - if ( ply:GetNWInt( "plants" ) >= GetConVarNumber( "gms_PlantLimit" ) ) then ply:SendMessage( "You have hit the plant limit.",3,Color( 200,0,0,255 ) ) return end - local tr = ply:TraceFromEyes( 150 ) - - if ( tr.HitWorld ) then - if ( ( tr.MatType == MAT_DIRT or tr.MatType == MAT_GRASS or tr.MatType == MAT_SAND ) and !GMS.IsInWater( tr.HitPos ) ) then - if ( ply:GetResource( "Orange_Seeds" ) >= 1 ) then - if ( !GMS.ClassIsNearby( tr.HitPos, "gms_seed", 30 ) and !GMS.ClassIsNearby( tr.HitPos, "prop_physics", 50 ) ) then - ply:DoProcess( "PlantOrange", 3, { Pos = tr.HitPos } ) - else - ply:SendMessage( "You need more distance between seeds/props.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "You need an orange seed.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "You cannot plant on this terrain.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "Aim at the ground to plant.", 3, Color( 200 ,0, 0, 255 ) ) - end -end -concommand.Add( "gms_plantorange", GM.PlantOrange ) - -function GM.PlantGrain( ply, cmd, args ) - if ( !ply:HasUnlock( "Grain_Planting" ) ) then ply:SendMessage( "You need more planting skill.", 3, Color( 200, 0, 0, 255 ) ) return end - if ( ply:GetNWInt( "plants" ) >= GetConVarNumber( "gms_PlantLimit" ) ) then ply:SendMessage( "You have hit the plant limit.", 3, Color( 200, 0, 0, 255 ) ) return end - local tr = ply:TraceFromEyes( 150 ) - - if ( tr.HitWorld ) then - local nearby = false - - for k, v in pairs( ents.FindInSphere( tr.HitPos, 50 ) ) do - if ( ( v:IsGrainModel() or v:IsProp() or v:GetClass() == "gms_seed" ) and ( tr.HitPos-Vector( v:LocalToWorld( v:OBBCenter() ).x, v:LocalToWorld( v:OBBCenter() ).y, tr.HitPos.z ) ):Length() <= 50 ) then - nearby = true - end - end - - if ( ( tr.MatType == MAT_DIRT or tr.MatType == MAT_GRASS or tr.MatType == MAT_SAND ) and !GMS.IsInWater( tr.HitPos ) ) then - if ( ply:GetResource( "Grain_Seeds" ) >= 1 ) then - if ( !nearby ) then - ply:DoProcess( "PlantGrain", 3, { Pos = tr.HitPos } ) - else - ply:SendMessage( "You need more distance between seeds/props.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "You need a grain seed.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "You cannot plant on this terrain.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "Aim at the ground to plant.", 3, Color( 200, 0, 0, 255 ) ) - end -end -concommand.Add( "gms_plantgrain", GM.PlantGrain ) - -function GM.PlantBush( ply, cmd, args ) - if ( ply:GetNWInt( "plants" ) >= GetConVarNumber( "gms_PlantLimit" ) ) then ply:SendMessage( "You have hit the plant limit.", 3, Color( 200, 0, 0, 255 ) ) return end - local tr = ply:TraceFromEyes( 150 ) - - if ( tr.HitWorld ) then - local nearby = false - - for k, v in pairs( ents.FindInSphere( tr.HitPos, 50 ) ) do - if ( ( v:IsBerryBushModel() or v:IsProp() or v:GetClass() == "gms_seed" ) and ( tr.HitPos-Vector( v:LocalToWorld( v:OBBCenter() ).x, v:LocalToWorld( v:OBBCenter() ).y, tr.HitPos.z ) ):Length() <= 50 ) then - nearby = true - end - end - - if ( ( tr.MatType == MAT_DIRT or tr.MatType == MAT_GRASS or tr.MatType == MAT_SAND ) and !GMS.IsInWater( tr.HitPos ) ) then - if ( ply:GetResource( "Berries" ) >= 1 ) then - if ( !nearby ) then - ply:DoProcess( "PlantBush", 3, { Pos = tr.HitPos } ) - else - ply:SendMessage( "You need more distance between seeds/props.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "You need a berry.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "You cannot plant on this terrain.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "Aim at the ground to plant.", 3, Color( 200, 0, 0, 255 ) ) - end -end -concommand.Add( "gms_plantbush", GM.PlantBush ) - -function GM.PlantTree( ply, cmd, args ) - if ( !ply:HasUnlock( "Sprout_Planting" ) ) then ply:SendMessage( "You need more planting skill.", 3, Color( 200, 0, 0, 255 ) ) return end - local tr = ply:TraceFromEyes( 150 ) - - if ( tr.HitWorld ) then - if ( ( tr.MatType == MAT_DIRT or tr.MatType == MAT_GRASS or tr.MatType == MAT_SAND ) and !GMS.IsInWater( tr.HitPos ) ) then - if ( ply:GetResource( "Sprouts" ) >= 1 ) then - ply:DoProcess( "PlantTree", 5, { Pos = tr.HitPos } ) - else - ply:SendMessage( "You need a sprout.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "You cannot plant on this terrain.", 3, Color( 200, 0, 0, 255 ) ) - end - else - ply:SendMessage( "Aim at the ground to plant.", 3, Color( 200, 0, 0, 255 ) ) - end -end -concommand.Add( "gms_planttree", GM.PlantTree ) -*/ - function GM.DrinkFromBottle( ply, cmd, args ) if ( ply:GetResource( "Water_Bottles" ) < 1 ) then ply:SendMessage( "You need a water bottle.", 3, Color( 200, 0, 0, 255 ) ) return end ply:DoProcess( "DrinkBottle", 1.5 ) diff --git a/gamemode/init_utility.lua b/gamemode/init_utility.lua deleted file mode 100644 index 5346cdc..0000000 --- a/gamemode/init_utility.lua +++ /dev/null @@ -1,28 +0,0 @@ -//Helper functions to refactor the init - -function findRecursive(folderstring,recursive,dofunction) - local folderpath = "gamemodes/" .. GM.GAMEMODE_FOLDER_NAME .. "/gamemode/" .. folderstring .. "/" - local files, directories = file.Find(folderpath .. "*", "MOD") - if(recursive) then - for k,v in pairs(directories) do - addResourceFolder(folderstring..v,recursive) - end - end - for k,v in pairs(files) do - dofunction(folderstring .. "/".. v) - end -end - -//Does AddCSLuaFile() on all files within a folderpath, optionally recursive -//Ex: -// AddCSLuaFolder("client/extras",true) -function AddCSLuaFolder(folderstring,recursive) - findRecursive(folderstring,recursive,function(string) AddCSLuaFile(string) end) -end - -//Does include() on all files within a folderpath, optionally recursive -//Ex: -// includeFolder("server/extras",false) -function includeFolder(folderstring,recursive) - findRecursive(folderstring,recursive,function(string) include(string) end) -end diff --git a/gamemode/utility.lua b/gamemode/utility.lua new file mode 100644 index 0000000..5346cdc --- /dev/null +++ b/gamemode/utility.lua @@ -0,0 +1,28 @@ +//Helper functions to refactor the init + +function findRecursive(folderstring,recursive,dofunction) + local folderpath = "gamemodes/" .. GM.GAMEMODE_FOLDER_NAME .. "/gamemode/" .. folderstring .. "/" + local files, directories = file.Find(folderpath .. "*", "MOD") + if(recursive) then + for k,v in pairs(directories) do + addResourceFolder(folderstring..v,recursive) + end + end + for k,v in pairs(files) do + dofunction(folderstring .. "/".. v) + end +end + +//Does AddCSLuaFile() on all files within a folderpath, optionally recursive +//Ex: +// AddCSLuaFolder("client/extras",true) +function AddCSLuaFolder(folderstring,recursive) + findRecursive(folderstring,recursive,function(string) AddCSLuaFile(string) end) +end + +//Does include() on all files within a folderpath, optionally recursive +//Ex: +// includeFolder("server/extras",false) +function includeFolder(folderstring,recursive) + findRecursive(folderstring,recursive,function(string) include(string) end) +end -- cgit v1.2.3-70-g09d2