Began work on crafting system

master
AlmTech Software 5 years ago
parent edad87b41f
commit b90a255d03
  1. 12
      gamemode/engine/core/client/cl_holster.lua
  2. 14
      gamemode/engine/lib/server/sv_inventory.lua
  3. 82
      gamemode/engine/lib/sh_recipe.lua
  4. 2
      gamemode/settings/sh_settings.lua

@ -32,9 +32,11 @@ function Quantum.Client.Holster.SwitchHolster()
local curWep= getCurEquippedWeapon()
if( curWep != nil && curWep != "quantum_hands" ) then
local wepEnt = client:GetWeapon( curWep )
client:SelectWeapon( client:GetWeapon( curWep ) )
print(wepEnt)
input.SelectWeapon( wepEnt )
else
client:SelectWeapon( client:GetWeapon( "quantum_hands" ) )
local wepEnt = client:GetWeapon( "quantum_hands" )
input.SelectWeapon( wepEnt )
end
end
end
@ -57,7 +59,7 @@ function Quantum.Client.Holster.CheckBind()
end
hook.Add( "Think", "Quantum_Client_Holster_Hook", function()
-- if( !Quantum.Client.IsInMenu ) then
-- Quantum.Client.Holster.CheckBind()
-- end
if( !Quantum.Client.IsInMenu ) then
Quantum.Client.Holster.CheckBind()
end
end)

@ -188,6 +188,20 @@ function Quantum.Server.Inventory.FindStackable( char, item )
end
end
function Quantum.Server.Inventory.GetItemAmount( char, itemid, inv )
inv = inv || Quantum.Server.Char.GetInventory( char )
local amount = 0
for pos, item in pairs( inv ) do
if( item[1] == itemid && item[2] != nil ) then
if( item[2] > 0 ) then
amount = amount + item[2]
end
end
end
return amount
end
function Quantum.Server.Inventory.FindItemSpot( char )
local inv = Quantum.Server.Char.GetInventory( char )
local pos = 0

@ -0,0 +1,82 @@
-- __ _ _______ _ __
-- / / /\ | | |__ __| | | \ \
-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \
-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > >
-- \ \ / ____ \| | | | | | | | __/ (__| | | | / /
-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/
Quantum.Recipe = {}
Quantum.Recipes = {}
function Quantum.Recipe.Add( itemid, station, tbl )
if( Quantum.Item.Get( itemid ) == nil ) then return end
local returnTbl = {
name = tbl.name || "Secret Recipe" -- name of the recipe
station = station,
creates = itemid -- what the recipe creates
amount = tbl.amount -- how much you get from 1 craft
recipe = tbl.recipe || {}
}
Quantum.Recipes[ itemid ] = returnTbl
return returnTbl
end
function Quantum.Recipe.Get( itemid )
return Quantum.Recipes[itemid]
end
function Quantum.Recipe.GetAvailableAmountForReq( recipe, pos, inv )
if( inv != nil ) then
return Quantum.Server.Inventory.GetItemAmount( nil, recipe[pos].item, inv )
end
end
function Quantum.Recipe.GetNeededAmountForReq( recipe, pos, inv )
if( inv != nil ) then
return Quantum.Recipe.GetAvailableAmountForReq( recipe, pos, inv ) - recipe[pos].amount
end
end
local function canMakeReq( diff ) return diff >= 0 end
function Quantum.Recipe.CanMake( inv, itemid )
if( inv != nil && itemid != nil ) then
local recipeTbl = Quantum.Recipe.Get( itemid )
local rTbl = recipeTbl.recipe
local canMake = {}
local failedReq = {}
for i, req in pairs( rTbl ) do
canMake[i] = canMakeReq( Quantum.Recipe.GetNeededAmountForReq( rTbl, i, inv ) )
if( !canMake[i] ) then
failedReq[i] = req.item
end
end
return #failedReq <= 0, failedReq
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

@ -30,7 +30,7 @@ Quantum.Money = {
Quantum.Bind = {
OpenInventory = KEY_TAB,
HolsterMain = KEY_F
HolsterMain = KEY_Q
}
Quantum.Models = {

Loading…
Cancel
Save