|
|
|
@ -13,11 +13,14 @@ local function setPlayerIsCrafting( pl, iscrafting ) |
|
|
|
|
pl:SetNWBool( "Quantum_Craft_IsCrafting", iscrafting ) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
local function isPlayerCrafting( pl ) return pl.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() ) |
|
|
|
|
setPlayerIsCrafting( pl, false ) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -38,38 +41,47 @@ function Quantum.Server.Crafting.MakeItem( pl, itemid ) |
|
|
|
|
-- 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 |
|
|
|
|
Quantum.Server.Inventory.FindItemSlots( pl, itemid, inv ) |
|
|
|
|
if( isPlayerCrafting( pl ) ) then |
|
|
|
|
|
|
|
|
|
timer.Create( "Quantum_Crafting_" .. pl:SteamID64(), recipe.delay, 1, function() |
|
|
|
|
-- remove the ingridients from the players 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 ) |
|
|
|
|
end |
|
|
|
|
-- get items |
|
|
|
|
local slots = Quantum.Server.Inventory.FindItemSlots( pl, reqItem.item, inv ) |
|
|
|
|
|
|
|
|
|
-- create item |
|
|
|
|
-- 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 |
|
|
|
|
|
|
|
|
|
Quantum.Server.Inventory.GiveItem( pl, recipe.creates, recipe.amount ) |
|
|
|
|
-- create item |
|
|
|
|
|
|
|
|
|
end) |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
-- Dont make the item |
|
|
|
|
Quantum.Notify.Deny( pl, "You don not 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 |
|
|
|
|
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( 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 |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|