Crafting progress & added new file for backend

master
AlmTech Software 5 years ago
parent 699fb181b5
commit 32131a1812
  1. 66
      gamemode/engine/lib/server/sv_crafting.lua
  2. 26
      gamemode/engine/lib/sh_recipe.lua
  3. 2
      gamemode/init.lua

@ -0,0 +1,66 @@
-- __ _ _______ _ __
-- / / /\ | | |__ __| | | \ \
-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \
-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > >
-- \ \ / ____ \| | | | | | | | __/ (__| | | | / /
-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/
Quantum.Server.Crafting = {}
local function setPlayerIsCrafting( pl, iscrafting )
pl.iscrafting = iscrafting
pl:SetNWBool( "Quantum_Craft_IsCrafting", iscrafting )
end
local function isPlayerCrafting( pl ) return pl.iscrafting end
local function cancelCrafting( pl )
if( timer.Exists( "Quantum_Crafting_" .. pl:SteamID64() ) ) then
timer.Stop( "Quantum_Crafting_" .. pl:SteamID64() )
end
end
function Quantum.Server.Crafting.MakeItem( pl, itemid )
local recipe = Quantum.Recipe.Get( itemid )
local char = Quantum.Server.Char.GetCurrentCharacter( pl )
local inv = Quantum.Server.Char.GetInventory( char )
if( recipe != nil ) then
local canMake, failedReq = Quantum.Recipe.CanMake( inv, itemid )
if( canMake ) then
cancelCrafting( pl ) -- stop the crafting if the player is allready crafting something
-- and then craft this item instead
setPlayerIsCrafting( pl, true )
timer.Create( "Quantum_Crafting_" ..pl:SteamID64(), recipe.delay, 1, function()
-- remove the ingridients from the players inv
-- create item
end)
else
-- Dont make the item
Quantum.Server.Notify.Deny( pl, "You don't have sufficient resources to create that item!" )
end
end
setPlayerIsCrafting( pl, false ) -- when everything is done then set this to false
end
local function isMoving( vec )
return vec.x != 0 || vec.y != 0 || vec.z != 0
end
hook.Add( "Move", "Quantum_Velocity_test", function( ply, mv ) -- a hook to check if the player is moving when crafting
if( ply.isloaded ) then
if( isPlayerCrafting( ply ) ) then
if( isMoving( mv:GetVelocity() ) ) then
cancelCrafting( ply ) -- if so then make the player stop crafting
end
end
end
end)

@ -13,10 +13,11 @@ function Quantum.Recipe.Add( itemid, station, tbl )
if( Quantum.Item.Get( itemid ) == nil ) then return end if( Quantum.Item.Get( itemid ) == nil ) then return end
local returnTbl = { local returnTbl = {
name = tbl.name || "Secret Recipe" -- name of the recipe name = tbl.name || "Secret Recipe", -- name of the recipe
station = station, station = station, -- where you can craft it ( at what "crafting table" can you make it at )
creates = itemid -- what the recipe creates creates = itemid, -- what the recipe creates
amount = tbl.amount -- how much you get from 1 craft delay = tbl.delay || Quantum.MinCraftDelay,
amount = tbl.amount || 1, -- how much you get from 1 craft
recipe = tbl.recipe || {} recipe = tbl.recipe || {}
} }
@ -63,20 +64,3 @@ function Quantum.Recipe.CanMake( inv, itemid )
end end
end end
function Quantum.Recipe.MakeItem( pl, itemid )
local recipe = Quantum.Recipe.Get( itemid )
local char = Quantum.Server.Char.GetCurrentCharacter( pl )
local inv = Quantum.Server.Char.GetInventory( char )
if( recipe != nil ) then
local canMake, failedReq = Quantum.Recipe.CanMake( inv, itemid )
if( canMake ) then
-- create item
else
-- Dont make the item
return
end
end
end

@ -14,6 +14,7 @@ if SERVER then
AddCSLuaFile( "settings/sh_settings.lua" ) AddCSLuaFile( "settings/sh_settings.lua" )
AddCSLuaFile( "settings/sh_items.lua" ) AddCSLuaFile( "settings/sh_items.lua" )
AddCSLuaFile( "settings/sh_effects.lua" ) AddCSLuaFile( "settings/sh_effects.lua" )
AddCSLuaFile( "settings/sh_recipes.lua" )
AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" ) AddCSLuaFile( "shared.lua" )
@ -114,6 +115,7 @@ if SERVER then
local function loadAllItemsAndEffects() local function loadAllItemsAndEffects()
include( "settings/sh_items.lua" ) include( "settings/sh_items.lua" )
include( "settings/sh_effects.lua" ) include( "settings/sh_effects.lua" )
include( "settings/sh_recipes.lua" )
end end
local function loadPlugins() local function loadPlugins()

Loading…
Cancel
Save