|
|
@ -13,11 +13,14 @@ local function setPlayerIsCrafting( pl, iscrafting ) |
|
|
|
pl:SetNWBool( "Quantum_Craft_IsCrafting", iscrafting ) |
|
|
|
pl:SetNWBool( "Quantum_Craft_IsCrafting", iscrafting ) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
local function isPlayerCrafting( pl ) return pl.iscrafting end |
|
|
|
local function isPlayerCrafting( pl ) |
|
|
|
|
|
|
|
return pl.iscrafting |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
local function cancelCrafting( pl ) |
|
|
|
local function cancelCrafting( pl ) |
|
|
|
if( timer.Exists( "Quantum_Crafting_" .. pl:SteamID64() ) ) then |
|
|
|
if( timer.Exists( "Quantum_Crafting_" .. pl:SteamID64() ) ) then |
|
|
|
timer.Stop( "Quantum_Crafting_" .. pl:SteamID64() ) |
|
|
|
timer.Stop( "Quantum_Crafting_" .. pl:SteamID64() ) |
|
|
|
|
|
|
|
setPlayerIsCrafting( pl, false ) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -38,38 +41,47 @@ function Quantum.Server.Crafting.MakeItem( pl, itemid ) |
|
|
|
-- and then craft this item instead |
|
|
|
-- and then craft this item instead |
|
|
|
setPlayerIsCrafting( pl, true ) |
|
|
|
setPlayerIsCrafting( pl, true ) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( isPlayerCrafting( pl ) ) then |
|
|
|
|
|
|
|
|
|
|
|
timer.Create( "Quantum_Crafting_" .. pl:SteamID64(), recipe.delay, 1, function() |
|
|
|
timer.Create( "Quantum_Crafting_" .. pl:SteamID64(), recipe.delay, 1, function() |
|
|
|
-- remove the ingridients from the players inv |
|
|
|
-- remove the ingridients from the players inv |
|
|
|
Quantum.Server.Inventory.FindItemSlots( pl, itemid, inv ) |
|
|
|
Quantum.Server.Inventory.FindItemSlots( pl, itemid, inv ) |
|
|
|
|
|
|
|
|
|
|
|
for k, reqItem in pairs( recipe.recipe ) do |
|
|
|
for k, reqItem in pairs( recipe.recipe ) do |
|
|
|
print( "##", k, reqItem.item ) |
|
|
|
|
|
|
|
Quantum.Server.Inventory.RemoveSlotItem( pl, char, k, reqItem.amount ) |
|
|
|
-- get items |
|
|
|
|
|
|
|
local slots = Quantum.Server.Inventory.FindItemSlots( pl, reqItem.item, inv ) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- loop through all slots and remove them |
|
|
|
|
|
|
|
for i, slot in pairs( slots ) do |
|
|
|
|
|
|
|
Quantum.Server.Inventory.RemoveSlotItem( pl, char, slot, reqItem.amount ) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- create item |
|
|
|
-- create item |
|
|
|
|
|
|
|
|
|
|
|
Quantum.Server.Inventory.GiveItem( pl, recipe.creates, recipe.amount ) |
|
|
|
Quantum.Server.Inventory.GiveItem( pl, recipe.creates, recipe.amount ) |
|
|
|
|
|
|
|
Quantum.Notify.ItemCrafted( pl, Quantum.Item.Get( recipe.creates ), recipe.amount ) |
|
|
|
|
|
|
|
setPlayerIsCrafting( pl, false ) -- when everything is done then set this to false |
|
|
|
end) |
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
else |
|
|
|
else |
|
|
|
-- Dont make the item |
|
|
|
-- Dont make the item |
|
|
|
Quantum.Notify.Deny( pl, "You don not have sufficient resources to create that item!" ) |
|
|
|
Quantum.Notify.Deny( pl, "You don not have sufficient resources to create that item!" ) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
setPlayerIsCrafting( pl, false ) -- when everything is done then set this to false |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
local function isMoving( vec ) |
|
|
|
local function isMoving( vec ) |
|
|
|
return vec.x != 0 || vec.y != 0 || vec.z != 0 |
|
|
|
return vec.x != 0 || vec.y != 0 || vec.z != 0 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
hook.Add( "Move", "Quantum_Velocity_test", function( ply, mv ) -- a hook to check if the player is moving when crafting |
|
|
|
hook.Add( "Move", "Quantum_Crafting_Velocity_Stop", function( ply, mv ) -- a hook to check if the player is moving when crafting |
|
|
|
if( ply.isloaded ) then |
|
|
|
if( ply.isloaded ) then |
|
|
|
if( isPlayerCrafting( ply ) ) then |
|
|
|
|
|
|
|
if( isMoving( mv:GetVelocity() ) ) then |
|
|
|
if( isMoving( mv:GetVelocity() ) ) then |
|
|
|
|
|
|
|
if( isPlayerCrafting( ply ) ) then |
|
|
|
cancelCrafting( ply ) -- if so then make the player stop crafting |
|
|
|
cancelCrafting( ply ) -- if so then make the player stop crafting |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|