Nodes & tools lib & stations bug fix

master
E. Almqvist 5 years ago
parent eb98a7f412
commit 57c649a327
  1. 7
      entities/entities/q_crafting_station/cl_init.lua
  2. 19
      entities/entities/q_node/init.lua
  3. 20
      gamemode/engine/lib/server/sv_inventory.lua
  4. 26
      gamemode/engine/lib/sh_node.lua
  5. 12
      gamemode/engine/lib/sh_station.lua
  6. 4
      gamemode/engine/vars/sv_vars.lua
  7. 15
      gamemode/settings/sh_items.lua
  8. 14
      gamemode/settings/sh_nodes.lua

@ -21,10 +21,9 @@ local scale = Quantum.Client.ResolutionScale
local padding = 10 * scale local padding = 10 * scale
function ENT:Draw() function ENT:Draw()
if( !stationTbl ) then stationTbl = Quantum.Station.Get( self:GetNWInt( "q_station_id" ) )
stationTbl = Quantum.Station.Get( self:GetNWInt( "q_station_id" ) ) stationName = stationTbl.name
stationName = stationTbl.name
end
self:DrawModel() self:DrawModel()
if( stationTbl.showname == true ) then if( stationTbl.showname == true ) then

@ -37,8 +37,27 @@ function ENT:InitializeNode( nodeid, pos, ang )
self:SetPos( pos ) self:SetPos( pos )
self:SetAngles( ang ) self:SetAngles( ang )
self:SetHealth( nodeTbl.health )
print( "#########", self:Health() )
else else
Quantum.Error( "Node Table could not be found '" .. nodeid .. "'!" ) Quantum.Error( "Node Table could not be found '" .. nodeid .. "'!" )
self:Remove() self:Remove()
end end
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

@ -223,7 +223,7 @@ end
local function sortItem( pl, char, itemid, amount ) local function sortItem( pl, char, itemid, amount )
Quantum.Debug( "--Stacking Debug--" ) -- Quantum.Debug( "--Stacking Debug--" )
local item = Quantum.Item.Get( itemid ) local item = Quantum.Item.Get( itemid )
local slotitem = Quantum.Server.Inventory.GetSlotItem( char, index ) 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 ) local setAmt = math.Clamp( add, 1, stacksize )
Quantum.Server.Inventory.SetSlotItem( pl, char, index, itemid, setAmt ) Quantum.Server.Inventory.SetSlotItem( pl, char, index, itemid, setAmt )
print( "1", itemid, setAmt, rest, index ) --print( "1", itemid, setAmt, rest, index )
end end
else else
@ -261,7 +261,7 @@ local function sortItem( pl, char, itemid, amount )
rest = rest - setAmt rest = rest - setAmt
Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, setAmt ) Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, setAmt )
print( "2", itemid, setAmt, rest, pos ) --print( "2", itemid, setAmt, rest, pos )
end end
while( rest >= stacksize ) do while( rest >= stacksize ) do
@ -278,7 +278,7 @@ local function sortItem( pl, char, itemid, amount )
local pos = Quantum.Server.Inventory.FindItemSpot( char ) local pos = Quantum.Server.Inventory.FindItemSpot( char )
Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, setAmt ) Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, setAmt )
print( "3", itemid, setAmt, rest, pos ) --print( "3", itemid, setAmt, rest, pos )
else else
index = index + 1 index = index + 1
itemInSlot = Quantum.Server.Inventory.GetSlotItem( char, index ) itemInSlot = Quantum.Server.Inventory.GetSlotItem( char, index )
@ -288,7 +288,7 @@ local function sortItem( pl, char, itemid, amount )
rest = rest - ( stacksize - itemInSlot[2] ) rest = rest - ( stacksize - itemInSlot[2] )
Quantum.Server.Inventory.SetSlotItem( pl, char, index, itemid, stacksize ) 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 if( rest <= 0 ) then
rest = 0 rest = 0
@ -298,18 +298,18 @@ local function sortItem( pl, char, itemid, amount )
else else
rest = rest - stacksize rest = rest - stacksize
Quantum.Server.Inventory.SetSlotItem( pl, char, index, itemid, 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 end
end end
local stackIndex = Quantum.Server.Inventory.FindStackable( char, item ) local stackIndex = Quantum.Server.Inventory.FindStackable( char, item )
print( "stackIndex=", stackIndex ) --print( "stackIndex=", stackIndex )
local pos local pos
if( stackIndex == nil ) then if( stackIndex == nil ) then
pos = Quantum.Server.Inventory.FindItemSpot( char ) pos = Quantum.Server.Inventory.FindItemSpot( char )
Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, rest ) Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, rest )
print( "6", itemid, rest, rest, pos ) --print( "6", itemid, rest, rest, pos )
else else
if( rest > 0 ) then if( rest > 0 ) then
pos = stackIndex pos = stackIndex
@ -321,11 +321,11 @@ local function sortItem( pl, char, itemid, amount )
if( rest <= 0 ) then if( rest <= 0 ) then
Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, setAmt ) Quantum.Server.Inventory.SetSlotItem( pl, char, pos, itemid, setAmt )
print( "7", itemid, setAmt, rest, pos ) --print( "7", itemid, setAmt, rest, pos )
end end
end end
end end
Quantum.Debug( "--End of Stacking Debug--" ) -- Quantum.Debug( "--End of Stacking Debug--" )
end end
function Quantum.Server.Inventory.GiveItem( pl, itemid, amount ) -- Quantum.Server.Inventory.GiveItem( Entity(1), "test2", 21 ) function Quantum.Server.Inventory.GiveItem( pl, itemid, amount ) -- Quantum.Server.Inventory.GiveItem( Entity(1), "test2", 21 )

@ -15,7 +15,9 @@ function Quantum.Node.Create( nodeid, tbl )
model = tbl.model, model = tbl.model,
toolids = tbl.toolids || { "q_hands" }, toolids = tbl.toolids || { "q_hands" },
give = tbl.give || {}, 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 node.id = nodeid
@ -29,13 +31,13 @@ end
if SERVER then 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 node = Quantum.Node.Get( nodeid )
local ent = ents.Create( "q_node" ) local ent = ents.Create( "q_node" )
ent.node = node ent.node = node
ent.respawndelay = respawndelay || 30 ent.respawndelay = node.respawn || 30
ent.probability = probability || 1 ent.probability = node.probability || 1
ent:SetModel( node.model ) ent:SetModel( node.model )
ent:SetPos( vec ) ent:SetPos( vec )
ent:SetAngles( ang ) ent:SetAngles( ang )
@ -48,9 +50,10 @@ if SERVER then
if( ent.node != nil ) then if( ent.node != nil ) then
local nodeid = nodeTbl.id local nodeid = nodeTbl.id
local pos, ang = ent:GetPos(), ent:GetAngles()
timer.Simple( ent.respawndelay, function() 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) end)
ent:Remove() -- remove the node ent:Remove() -- remove the node
@ -84,7 +87,7 @@ if SERVER then
Quantum.Debug( "----Node-Spawning-Info----" ) Quantum.Debug( "----Node-Spawning-Info----" )
PrintTable(v) PrintTable(v)
Quantum.Debug( "--------------------------" ) 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 else
Quantum.Error( "Tried to spawn an invalid node ('" .. v.id .. "')!" ) Quantum.Error( "Tried to spawn an invalid node ('" .. v.id .. "')!" )
end end
@ -107,10 +110,9 @@ if SERVER then
end) end)
local function randomizeLootTable( tbl, prob ) local function randomizeLootTable( tbl, prob )
local n = math.Rand( 0.00000000001, 1 ) local n = math.Rand( 0.001, 1 )
Quantum.Debug( "Probability: " .. n .. " <= " .. prob )
if( n <= prob ) then if( n <= prob ) then
local index = table.random( 1, #tbl ) local index = math.random( 1, #tbl )
return tbl[index].item, tbl[index].amount || 1 return tbl[index].item, tbl[index].amount || 1
end end
end end
@ -122,7 +124,7 @@ if SERVER then
local nodeid = nodeTbl.id local nodeid = nodeTbl.id
local toolids = nodeTbl.toolids local toolids = nodeTbl.toolids
if( #toolids > 1 ) then if( #toolids > 0 ) then
local canGather = false local canGather = false
for i, t in pairs( toolids ) do for i, t in pairs( toolids ) do
@ -134,16 +136,14 @@ if SERVER then
if( canGather ) then if( canGather ) then
local loot, amount = randomizeLootTable( nodeTbl.give, nodeTbl.giveprobability ) local loot, amount = randomizeLootTable( nodeTbl.give, nodeTbl.giveprobability )
if( loot != nil ) then if( loot != nil ) then
Quantum.Server.Inventory.GiveItem( pl, loot, amount ) Quantum.Server.Inventory.GiveItem( pl, loot, amount )
local itemTbl = Quantum.Item.Get( loot ) local itemTbl = Quantum.Item.Get( loot )
Quantum.Notify.ItemGathered( pl, itemTbl.name, amount ) Quantum.Notify.ItemGathered( pl, itemTbl, amount )
else else
return return
end end
end end
end end
end end
end end

@ -112,9 +112,15 @@ if SERVER then
if( key == IN_USE ) then if( key == IN_USE ) then
local ent = pl:GetEyeTraceNoCursor().Entity local ent = pl:GetEyeTraceNoCursor().Entity
if( ent:GetClass() == "q_crafting_station" ) then if( ent:GetClass() == "q_crafting_station" ) then
if( ent:GetPos():Distance( pl:GetPos() ) <= 100 ) then local stationTbl = Quantum.Station.Get( ent.stationid )
pl:SetLocalVelocity( Vector( 0, 0, 0 ) )
Quantum.Net.OpenMenu( pl, "crafting", { stationEnt = ent, station = 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 end
end end

@ -4,3 +4,7 @@
-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > -- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > >
-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / -- \ \ / ____ \| | | | | | | | __/ (__| | | | / /
-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ -- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/
Quantum.Server.DefaultNodeHealth = 10
Quantum.Server.DefaultNodeRespawnTimer = 30

@ -47,8 +47,6 @@ Quantum.Item.Create( "potatoe", {
equipeffect = "equip_potatoe" equipeffect = "equip_potatoe"
} ) } )
-- weapon_gta_sa_jetpack.lua
Quantum.Item.Create( "jetpack", { Quantum.Item.Create( "jetpack", {
name = "Jetpack", name = "Jetpack",
desc = "A jet engine strapped onto your back? Sounds fun!", desc = "A jet engine strapped onto your back? Sounds fun!",
@ -59,3 +57,16 @@ Quantum.Item.Create( "jetpack", {
equipslot = Quantum.EquipSlots.Weapon, equipslot = Quantum.EquipSlots.Weapon,
equipgive = "weapon_gta_sa_jetpack" 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"
} )

@ -5,24 +5,28 @@
-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / -- \ \ / ____ \| | | | | | | | __/ (__| | | | / /
-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ -- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/
local betaTools = { "q_hands" } local miningTools = { "tool_pickaxe" }
Quantum.Node.Create( "stone", { Quantum.Node.Create( "stone", {
name = "Stone", name = "Stone",
model = "models/props/cs_militia/militiarock05.mdl", model = "models/props/cs_militia/militiarock05.mdl",
toolids = betaTools, toolids = miningTools,
give = { give = {
{ item = "test2", amount = 1 } { item = "test2", amount = 1 }
}, },
giveprobability = 1/2 giveprobability = 1/2,
health = 20,
respawn = 10
} ) } )
Quantum.Node.Create( "bigstone", { Quantum.Node.Create( "bigstone", {
name = "Big Stone", name = "Big Stone",
model = "models/props/cs_militia/militiarock03.mdl", model = "models/props/cs_militia/militiarock03.mdl",
toolids = betaTools, toolids = miningTools,
give = { give = {
{ item = "test2", amount = 1 } { item = "test2", amount = 1 }
}, },
giveprobability = 3/4 giveprobability = 3/4,
health = 20,
respawn = 10
} ) } )
Loading…
Cancel
Save