diff --git a/entities/entities/q_crafting_station/cl_init.lua b/entities/entities/q_crafting_station/cl_init.lua new file mode 100644 index 0000000..d615b1b --- /dev/null +++ b/entities/entities/q_crafting_station/cl_init.lua @@ -0,0 +1,12 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +include( "shared.lua" ) + +function ENT:Draw() + self:DrawModel() +end \ No newline at end of file diff --git a/entities/entities/q_crafting_station/init.lua b/entities/entities/q_crafting_station/init.lua new file mode 100644 index 0000000..b30f4de --- /dev/null +++ b/entities/entities/q_crafting_station/init.lua @@ -0,0 +1,50 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +AddCSLuaFile( "cl_init.lua" ) +AddCSLuaFile( "shared.lua" ) + +include( "shared.lua" ) + +function ENT:Initialize() + + self:PhysicsInit( SOLID_BSP ) + self:SetMoveType( MOVETYPE_VPHYSICS ) + self:SetSolid( SOLID_VPHYSICS ) + self:SetCollisionGroup( COLLISION_GROUP_NONE ) + + local physObj = self:GetPhysicsObject() + if( IsValid( physObj ) ) then + physObj:EnableMotion( false ) -- dont want it to move + end + +end + +function ENT:Use( activator, caller ) + if( activator:IsPlayer() ) then + + end +end + +function ENT:InitializeStation( stationid, pos, ang ) + if( pos == nil || ang == nil ) then return end + + local stationTbl = Quantum.Station.Get( stationid ) + + if( stationTbl != nil ) then + self:SetModel( stationTbl.model ) + self.stationid = stationid + + self:SetNWString( "q_station_id", stationid ) + + self:SetPos( pos ) + self:SetAngles( ang ) + else + Quantum.Error( "Station Table could not be found '" .. stationid .. "'!" ) + self:Remove() + end +end \ No newline at end of file diff --git a/entities/entities/q_crafting_station/shared.lua b/entities/entities/q_crafting_station/shared.lua new file mode 100644 index 0000000..0ed8dda --- /dev/null +++ b/entities/entities/q_crafting_station/shared.lua @@ -0,0 +1,15 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +ENT.Type = "anim" +ENT.Base = "base_entity" + +ENT.PrintName = "Quantum Item" +ENT.Author = "AlmTech" +ENT.Contact = "elias@almtech.se" +ENT.Spawnable = false +ENT.AdminSpawnable = false \ No newline at end of file diff --git a/gamemode/cl_init.lua b/gamemode/cl_init.lua index 581c34b..af68375 100644 --- a/gamemode/cl_init.lua +++ b/gamemode/cl_init.lua @@ -49,6 +49,8 @@ if CLIENT then local function loadAllItemsAndEffects() include( "settings/sh_items.lua" ) include( "settings/sh_effects.lua" ) + include( "settings/sh_crafting_stations.lua" ) + include( "settings/sh_recipes.lua" ) end local function loadPlugins() diff --git a/gamemode/engine/lib/sh_recipe.lua b/gamemode/engine/lib/sh_recipe.lua index 6dd84f7..3a22542 100644 --- a/gamemode/engine/lib/sh_recipe.lua +++ b/gamemode/engine/lib/sh_recipe.lua @@ -24,6 +24,11 @@ function Quantum.Recipe.Add( itemid, station, tbl ) Quantum.Recipes[ itemid ] = returnTbl Quantum.Recipes[ itemid ].delay = math.Clamp( Quantum.Recipes[ itemid ].delay, Quantum.MinCraftDelay, Quantum.MaxCraftDelay ) + -- add the recipe to the stations recipe list -- + if( returnTbl.station != nil ) then + table.insert( Quantum.Stations[ returnTbl.station ].recipes, itemid ) + end + return returnTbl end diff --git a/gamemode/engine/lib/sh_station.lua b/gamemode/engine/lib/sh_station.lua new file mode 100644 index 0000000..6a2c606 --- /dev/null +++ b/gamemode/engine/lib/sh_station.lua @@ -0,0 +1,66 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +Quantum.Station = {} + +Quantum.Stations = {} + +function Quantum.Station.Add( id, tbl ) + + local returnTbl = { + stationid = id, + name = tbl.name || "Crafting Station", -- name of the station + model = tbl.model || "models/props_phx/facepunch_barrel.mdl", + recipes = tbl.recipes || {} + } + + Quantum.Stations[ id ] = returnTbl + + return returnTbl +end + +function Quantum.Station.Get( id ) + return Quantum.Stations[id] +end + +if SERVER then + Quantum.Server.Station = {} + + function Quantum.Server.Station.Spawn( stationid, pos, ang ) -- internal function + local ent = ents.Create( "q_crafting_station" ) + if( IsValid( ent ) ) then + ent:InitializeStation( stationid, pos, ang ) + ent:Spawn() + end + end + + local function floorVectorString( vec ) + return tostring(math.floor( vec.x )) .. ", " .. tostring(math.floor( vec.y )) .. ", " .. tostring(math.floor( vec.z )) + end + + function Quantum.Server.Station.Create( id, tbl ) + local stationTbl = Quantum.Station.Get( id ) + + if( stationTbl != nil ) then + Quantum.Server.Station.Spawn( id, tbl.pos, tbl.ang ) + end + end + + function Quantum.Server.Station.Remove( station ) + if( IsValid( station ) ) then + station:Remove() + end + end + + function Quantum.Server.Station.RemoveAll() + for i, station in pairs( ents.FindByClass( "q_crafting_station" ) ) do + Quantum.Server.Station.Remove( station ) + end + end + + Quantum.Server.Station.RemoveAll() -- remove all stations on lua refresh +end \ No newline at end of file diff --git a/gamemode/init.lua b/gamemode/init.lua index 33880d6..ba39ee5 100644 --- a/gamemode/init.lua +++ b/gamemode/init.lua @@ -15,6 +15,7 @@ if SERVER then AddCSLuaFile( "settings/sh_items.lua" ) AddCSLuaFile( "settings/sh_effects.lua" ) AddCSLuaFile( "settings/sh_recipes.lua" ) + AddCSLuaFile( "settings/sh_crafting_stations.lua" ) AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) @@ -115,9 +116,18 @@ if SERVER then local function loadAllItemsAndEffects() include( "settings/sh_items.lua" ) include( "settings/sh_effects.lua" ) + include( "settings/sh_crafting_stations.lua" ) include( "settings/sh_recipes.lua" ) end + local function loadStations() + include( "settings/sv_crafting_stations_locations.lua" ) + end + hook.Add( "PostGamemodeLoaded", "Quantum_Init_Stations_Load", function() + Quantum.Debug( "Spawning crafting stations..." ) + loadStations() + end) + local function loadPlugins() @@ -152,5 +162,6 @@ if SERVER then end Quantum.Server.Load() + loadStations() MsgC( "\n" ) end diff --git a/gamemode/settings/sh_crafting_stations.lua b/gamemode/settings/sh_crafting_stations.lua new file mode 100644 index 0000000..601511d --- /dev/null +++ b/gamemode/settings/sh_crafting_stations.lua @@ -0,0 +1,12 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +-- Add all of the station "categories" here -- +Quantum.Station.Add( "barrel", { + name = "Crafting Barrel", + model = "models/props_phx/facepunch_barrel.mdl" +}) diff --git a/gamemode/settings/sv_crafting_stations_locations.lua b/gamemode/settings/sv_crafting_stations_locations.lua new file mode 100644 index 0000000..6a7f645 --- /dev/null +++ b/gamemode/settings/sv_crafting_stations_locations.lua @@ -0,0 +1,11 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +Quantum.Server.Station.Create( "barrel", { + pos = Vector( 10, 0, 0 ), + ang = Angle( 0, 0, 0 ) +}) \ No newline at end of file diff --git a/gamemode/shared.lua b/gamemode/shared.lua index cb23c19..6d12251 100644 --- a/gamemode/shared.lua +++ b/gamemode/shared.lua @@ -11,7 +11,7 @@ GM.Email = "elias@almtech.se" GM.Website = "N/A" Quantum = {} -Quantum.Version = "v0.3-alpha" +Quantum.Version = "v0.4-alpha" include( "engine/sh_debug.lua" ) -- add the debug functions and stuff