diff --git a/gamemode/cl_init.lua b/gamemode/cl_init.lua index 6625b96..581c34b 100644 --- a/gamemode/cl_init.lua +++ b/gamemode/cl_init.lua @@ -51,6 +51,17 @@ if CLIENT then include( "settings/sh_effects.lua" ) end + local function loadPlugins() + local fol = GM.FolderName .. "/plugins/" + local pluginFiles = file.Find( fol .. "plugin_*.lua", "LUA" ) + + if( #pluginFiles > 0 ) then + for _, file in pairs( pluginFiles ) do + include( fol .. file ) + end + end + end + function Quantum.Client.Load() local fol = GM.FolderName .. "/gamemode/engine/core/" @@ -60,9 +71,13 @@ if CLIENT then Quantum.Debug( "Loaded all files." ) - -- add all of the items + -- add all of the items & effects loadAllItemsAndEffects() Quantum.Debug( "Loaded all items & effects." ) + + -- load all of the plugins + loadPlugins() + Quantum.Debug( "Loaded all plugins." ) end Quantum.Client.Load() diff --git a/gamemode/engine/lib/server/sv_inventory.lua b/gamemode/engine/lib/server/sv_inventory.lua index dfd3892..d3c5eff 100644 --- a/gamemode/engine/lib/server/sv_inventory.lua +++ b/gamemode/engine/lib/server/sv_inventory.lua @@ -44,6 +44,10 @@ function Quantum.Server.Inventory.EquipItem( pl, itemindex ) if( itemTbl.equipeffect != nil ) then Quantum.Effect.Give( pl, itemTbl.equipeffect ) -- give the player the effect end + if( itemTbl.equipgive != nil ) then + pl:Give( itemTbl.equipgive ) + pl:SelectWeapon( itemTbl.equipgive ) + end Quantum.Debug( tostring(pl) .. " equipped item (" .. tostring(slotitem[1]) .. ") - (" .. tostring(itemindex) .. ")" ) -- NETWORKING -- Quantum.Net.Inventory.SetEquipItem( pl, itemindex, equipslot ) @@ -66,7 +70,11 @@ function Quantum.Server.Inventory.UnEquipItem( pl, equipslot, char ) if( itemTbl.equipeffect != nil ) then -- remove the items effect Quantum.Effect.Remove( pl, itemTbl.equipeffect ) end - + + if( itemTbl.equipgive != nil ) then + pl:StripWeapon( itemTbl.equipgive ) + pl:SelectWeapon( "quantum_hands" ) + end Quantum.Debug( tostring(pl) .. " unequipped item (" .. tostring( itemTbl.id ) .. ") - (" .. tostring( char.equipped[equipslot] ) .. ")" ) char.equipped[equipslot] = nil diff --git a/gamemode/engine/lib/sh_items.lua b/gamemode/engine/lib/sh_items.lua index b9f30c6..7f10d30 100644 --- a/gamemode/engine/lib/sh_items.lua +++ b/gamemode/engine/lib/sh_items.lua @@ -17,6 +17,7 @@ function Quantum.Item.Create( itemid, args ) stack = args.stack || 1, -- items max stack size soulbound = args.soulbound, -- if item could be dropped/traded to other players equipslot = args.equipslot, -- slot for the equipable + equipgive = args.equipgive, equipeffect = args.equipeffect, -- equip buff like in other MMO RPG games rarity = args.rarity || Quantum.Rarity.Trash, -- rarity of the item useeffect = args.useeffect, -- use effect diff --git a/gamemode/init.lua b/gamemode/init.lua index 9897f19..76eecf8 100644 --- a/gamemode/init.lua +++ b/gamemode/init.lua @@ -115,6 +115,26 @@ if SERVER then include( "settings/sh_items.lua" ) include( "settings/sh_effects.lua" ) end + + local function loadPlugins() + + + local fol = GM.FolderName .. "/plugins/" + local pluginFiles = file.Find( fol .. "plugin_*.lua", "LUA" ) + + if( #pluginFiles > 0 ) then + MsgC( "\n" ) + Quantum.Debug( "Loading plugins...") + for _, file in pairs( pluginFiles ) do + AddCSLuaFile( fol .. file ) + include( fol .. file ) + Quantum.Debug( "Added plugin: " .. fol .. file ) + end + else + MsgC( "\n" ) + Quantum.Debug( "No plugins found." ) + end + end function Quantum.Server.Load() -- Add all of the base files @@ -124,6 +144,9 @@ if SERVER then -- Creation of stuff loadAllItemsAndEffects() + + -- Plugins + loadPlugins() end Quantum.Server.Load() diff --git a/plugins/plugin_addweaponsasitems.lua b/plugins/plugin_addweaponsasitems.lua new file mode 100644 index 0000000..d123085 --- /dev/null +++ b/plugins/plugin_addweaponsasitems.lua @@ -0,0 +1,41 @@ +-- This plugin was made by AlmTech and comes with the master branch of Quantum + +-- This plugin creates items for all of the weapons in the game using "weapons.GetList" +-- https://wiki.garrysmod.com/page/weapons/GetList + +-- Feel free to remove it if you do not like it or to make your own. + +local plugin = {} + +function plugin.getAllWeaponID() + local returnTbl = {} + for _, wep in pairs( weapons.GetList() ) do + if( wep.ClassName != "weapon_base" && wep.ClassName != "quantum_hands" && wep.ClassName != "quantum_keys" ) then -- do not want them + returnTbl[ #returnTbl + 1 ] = wep.ClassName + end + end + + return returnTbl +end + +function plugin.CreateItems( weps ) + for _, wepID in pairs( weps ) do + local swepTbl = weapons.Get( wepID ) + Quantum.Item.Create( wepID, { + name = swepTbl.PrintName , + desc = swepTbl.Purpose, + model = swepTbl.WorldModel, + rarity = Quantum.Rarity.Common, + equipslot = Quantum.EquipSlots.Weapon, + equipgive = wepID + } ) + end +end + +hook.Add( "PostGamemodeLoaded", "Quantum_Plugin_AddAllWeaponsAsItems", function() + local weps = plugin.getAllWeaponID() + plugin.CreateItems( weps ) +end) + +local weps = plugin.getAllWeaponID() +plugin.CreateItems( weps ) \ No newline at end of file