diff --git a/entities/entities/q_crafting_station/cl_init.lua b/entities/entities/q_crafting_station/cl_init.lua index 09e7851..cf8f254 100644 --- a/entities/entities/q_crafting_station/cl_init.lua +++ b/entities/entities/q_crafting_station/cl_init.lua @@ -21,10 +21,9 @@ local scale = Quantum.Client.ResolutionScale local padding = 10 * scale function ENT:Draw() - if( !stationTbl ) then - stationTbl = Quantum.Station.Get( self:GetNWInt( "q_station_id" ) ) - stationName = stationTbl.name - end + stationTbl = Quantum.Station.Get( self:GetNWInt( "q_station_id" ) ) + stationName = stationTbl.name + self:DrawModel() if( stationTbl.showname == true ) then diff --git a/entities/entities/q_node/init.lua b/entities/entities/q_node/init.lua index bfe91e3..eb69999 100644 --- a/entities/entities/q_node/init.lua +++ b/entities/entities/q_node/init.lua @@ -37,8 +37,27 @@ function ENT:InitializeNode( nodeid, pos, ang ) self:SetPos( pos ) self:SetAngles( ang ) + self:SetHealth( nodeTbl.health ) + print( "#########", self:Health() ) else Quantum.Error( "Node Table could not be found '" .. nodeid .. "'!" ) self:Remove() end +end + +function ENT:OnTakeDamage( dmgInfo ) + if( !self.m_bApplyingDamage ) then + self.m_bApplyingDamage = true + + self:TakeDamageInfo( dmgInfo ) + print( self:Health() ) + + local attacker = dmgInfo:GetAttacker() + local wep = attacker:GetActiveWeapon() + if( IsValid( wep ) && IsValid( attacker ) ) then + Quantum.Node.Gather( attacker, wep:GetClass(), self ) + end + + self.m_bApplyingDamage = false + end end \ No newline at end of file diff --git a/gamemode/engine/lib/server/sv_inventory.lua b/gamemode/engine/lib/server/sv_inventory.lua index 8a5f40cd..1dea845 100644 --- a/gamemode/engine/lib/server/sv_inventory.lua +++ b/gamemode/engine/lib/server/sv_inventory.lua @@ -223,7 +223,7 @@ end local function sortItem( pl, char, itemid, amount ) - Quantum.Debug( "--Stacking Debug--" ) + -- Quantum.Debug( "--Stacking Debug--" ) local item = Quantum.Item.Get( itemid ) local slotitem = Quantum.Server.Inventory.GetSlotItem( char, index ) @@ -252,7 +252,7 @@ local function sortItem( pl, char, itemid, amount ) local setAmt = math.Clamp( add, 1, stacksize ) Quantum.Server.Inventory.SetSlotItem( pl, char, index, itemid, setAmt ) - print( "1", itemid, setAmt, rest, index ) + --print( "1", itemid, setAmt, rest, index ) end else @@ -261,7 +261,7 @@ local function sortItem( pl, char, itemid, amount ) rest = rest - setAmt Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, setAmt ) - print( "2", itemid, setAmt, rest, pos ) + --print( "2", itemid, setAmt, rest, pos ) end while( rest >= stacksize ) do @@ -278,7 +278,7 @@ local function sortItem( pl, char, itemid, amount ) local pos = Quantum.Server.Inventory.FindItemSpot( char ) Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, setAmt ) - print( "3", itemid, setAmt, rest, pos ) + --print( "3", itemid, setAmt, rest, pos ) else index = index + 1 itemInSlot = Quantum.Server.Inventory.GetSlotItem( char, index ) @@ -288,7 +288,7 @@ local function sortItem( pl, char, itemid, amount ) rest = rest - ( stacksize - itemInSlot[2] ) Quantum.Server.Inventory.SetSlotItem( pl, char, index, itemid, stacksize ) - print( "4", itemid, stacksize, rest, index ) + --print( "4", itemid, stacksize, rest, index ) if( rest <= 0 ) then rest = 0 @@ -298,18 +298,18 @@ local function sortItem( pl, char, itemid, amount ) else rest = rest - stacksize Quantum.Server.Inventory.SetSlotItem( pl, char, index, itemid, stacksize ) - print( "5", itemid, stacksize, rest, index ) + --print( "5", itemid, stacksize, rest, index ) end end end local stackIndex = Quantum.Server.Inventory.FindStackable( char, item ) - print( "stackIndex=", stackIndex ) + --print( "stackIndex=", stackIndex ) local pos if( stackIndex == nil ) then pos = Quantum.Server.Inventory.FindItemSpot( char ) Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, rest ) - print( "6", itemid, rest, rest, pos ) + --print( "6", itemid, rest, rest, pos ) else if( rest > 0 ) then pos = stackIndex @@ -321,11 +321,11 @@ local function sortItem( pl, char, itemid, amount ) if( rest <= 0 ) then Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, setAmt ) - print( "7", itemid, setAmt, rest, pos ) + --print( "7", itemid, setAmt, rest, pos ) end end end - Quantum.Debug( "--End of Stacking Debug--" ) + -- Quantum.Debug( "--End of Stacking Debug--" ) end function Quantum.Server.Inventory.GiveItem( pl, itemid, amount ) -- Quantum.Server.Inventory.GiveItem( Entity(1), "test2", 21 ) diff --git a/gamemode/engine/lib/sh_node.lua b/gamemode/engine/lib/sh_node.lua index 814c468..52947bb 100644 --- a/gamemode/engine/lib/sh_node.lua +++ b/gamemode/engine/lib/sh_node.lua @@ -15,7 +15,9 @@ function Quantum.Node.Create( nodeid, tbl ) model = tbl.model, toolids = tbl.toolids || { "q_hands" }, give = tbl.give || {}, - giveprobability = tbl.giveprobability || 1 + giveprobability = tbl.giveprobability || 1, + health = tbl.health || Quantum.Server.DefaultNodeHealth, + respawn = tbl.respawn || Quantum.Server.DefaultNodeRespawnTimer } node.id = nodeid @@ -29,13 +31,13 @@ end if SERVER then - function Quantum.Node.Spawn( nodeid, vec, ang, respawndelay, probability ) + function Quantum.Node.Spawn( nodeid, vec, ang ) local node = Quantum.Node.Get( nodeid ) local ent = ents.Create( "q_node" ) ent.node = node - ent.respawndelay = respawndelay || 30 - ent.probability = probability || 1 + ent.respawndelay = node.respawn || 30 + ent.probability = node.probability || 1 ent:SetModel( node.model ) ent:SetPos( vec ) ent:SetAngles( ang ) @@ -48,9 +50,10 @@ if SERVER then if( ent.node != nil ) then local nodeid = nodeTbl.id + local pos, ang = ent:GetPos(), ent:GetAngles() timer.Simple( ent.respawndelay, function() - Quantum.Node.Spawn( nodeid, ent:GetPos(), ent:GetAngles(), ent.respawndelay, ent.probability ) -- respawn it after x seconds + Quantum.Node.Spawn( nodeid, pos, ang, nodeTbl.respawn, nodeTbl.probability ) -- respawn it after x seconds end) ent:Remove() -- remove the node @@ -84,7 +87,7 @@ if SERVER then Quantum.Debug( "----Node-Spawning-Info----" ) PrintTable(v) Quantum.Debug( "--------------------------" ) - Quantum.Node.Spawn( v.id, v.pos, v.ang, nodeTbl.respawndelay, nodeTbl.probability ) + Quantum.Node.Spawn( v.id, v.pos, v.ang ) else Quantum.Error( "Tried to spawn an invalid node ('" .. v.id .. "')!" ) end @@ -107,10 +110,9 @@ if SERVER then end) local function randomizeLootTable( tbl, prob ) - local n = math.Rand( 0.00000000001, 1 ) - Quantum.Debug( "Probability: " .. n .. " <= " .. prob ) + local n = math.Rand( 0.001, 1 ) if( n <= prob ) then - local index = table.random( 1, #tbl ) + local index = math.random( 1, #tbl ) return tbl[index].item, tbl[index].amount || 1 end end @@ -122,7 +124,7 @@ if SERVER then local nodeid = nodeTbl.id local toolids = nodeTbl.toolids - if( #toolids > 1 ) then + if( #toolids > 0 ) then local canGather = false for i, t in pairs( toolids ) do @@ -134,16 +136,14 @@ if SERVER then if( canGather ) then local loot, amount = randomizeLootTable( nodeTbl.give, nodeTbl.giveprobability ) - if( loot != nil ) then Quantum.Server.Inventory.GiveItem( pl, loot, amount ) local itemTbl = Quantum.Item.Get( loot ) - Quantum.Notify.ItemGathered( pl, itemTbl.name, amount ) + Quantum.Notify.ItemGathered( pl, itemTbl, amount ) else return end end - end end end diff --git a/gamemode/engine/lib/sh_station.lua b/gamemode/engine/lib/sh_station.lua index 99b249a..7ea3cc0 100644 --- a/gamemode/engine/lib/sh_station.lua +++ b/gamemode/engine/lib/sh_station.lua @@ -112,9 +112,15 @@ if SERVER then if( key == IN_USE ) then local ent = pl:GetEyeTraceNoCursor().Entity if( ent:GetClass() == "q_crafting_station" ) then - if( ent:GetPos():Distance( pl:GetPos() ) <= 100 ) then - pl:SetLocalVelocity( Vector( 0, 0, 0 ) ) - Quantum.Net.OpenMenu( pl, "crafting", { stationEnt = ent, station = ent.stationid } ) + local stationTbl = Quantum.Station.Get( ent.stationid ) + + if( stationTbl != nil ) then + if( stationTbl.recipes != nil ) then + if( ent:GetPos():Distance( pl:GetPos() ) <= 100 ) then + pl:SetLocalVelocity( Vector( 0, 0, 0 ) ) + Quantum.Net.OpenMenu( pl, "crafting", { stationEnt = ent, station = ent.stationid } ) + end + end end end end diff --git a/gamemode/engine/vars/sv_vars.lua b/gamemode/engine/vars/sv_vars.lua index 77fd27b..d5c920f 100644 --- a/gamemode/engine/vars/sv_vars.lua +++ b/gamemode/engine/vars/sv_vars.lua @@ -3,4 +3,8 @@ -- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ -- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > -- \ \ / ____ \| | | | | | | | __/ (__| | | | / / --- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ \ No newline at end of file +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +Quantum.Server.DefaultNodeHealth = 10 + +Quantum.Server.DefaultNodeRespawnTimer = 30 \ No newline at end of file diff --git a/gamemode/settings/sh_items.lua b/gamemode/settings/sh_items.lua index cb7a2d4..a73b8f4 100644 --- a/gamemode/settings/sh_items.lua +++ b/gamemode/settings/sh_items.lua @@ -47,8 +47,6 @@ Quantum.Item.Create( "potatoe", { equipeffect = "equip_potatoe" } ) --- weapon_gta_sa_jetpack.lua - Quantum.Item.Create( "jetpack", { name = "Jetpack", desc = "A jet engine strapped onto your back? Sounds fun!", @@ -58,4 +56,17 @@ Quantum.Item.Create( "jetpack", { rarity = Quantum.Rarity.Legendary, equipslot = Quantum.EquipSlots.Weapon, equipgive = "weapon_gta_sa_jetpack" +} ) + +---- TOOLS ---- + +Quantum.Item.Create( "pickaxe", { + name = "Pickaxe", + desc = "This could be used for mining.", + model = "models/weapons/w_mgs_pickaxe.mdl", + stack = 1, + soulbound = false, + rarity = Quantum.Rarity.Common, + equipslot = Quantum.EquipSlots.Weapon, + equipgive = "tool_pickaxe" } ) \ No newline at end of file diff --git a/gamemode/settings/sh_nodes.lua b/gamemode/settings/sh_nodes.lua index 33d0920..71e8739 100644 --- a/gamemode/settings/sh_nodes.lua +++ b/gamemode/settings/sh_nodes.lua @@ -5,24 +5,28 @@ -- \ \ / ____ \| | | | | | | | __/ (__| | | | / / -- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ -local betaTools = { "q_hands" } +local miningTools = { "tool_pickaxe" } Quantum.Node.Create( "stone", { name = "Stone", model = "models/props/cs_militia/militiarock05.mdl", - toolids = betaTools, + toolids = miningTools, give = { { item = "test2", amount = 1 } }, - giveprobability = 1/2 + giveprobability = 1/2, + health = 20, + respawn = 10 } ) Quantum.Node.Create( "bigstone", { name = "Big Stone", model = "models/props/cs_militia/militiarock03.mdl", - toolids = betaTools, + toolids = miningTools, give = { { item = "test2", amount = 1 } }, - giveprobability = 3/4 + giveprobability = 3/4, + health = 20, + respawn = 10 } ) \ No newline at end of file