Added plugin support & weapon loading

master
AlmTech Software 5 years ago
parent 445dd72a37
commit 9d243bd08e
  1. 17
      gamemode/cl_init.lua
  2. 8
      gamemode/engine/lib/server/sv_inventory.lua
  3. 1
      gamemode/engine/lib/sh_items.lua
  4. 23
      gamemode/init.lua
  5. 41
      plugins/plugin_addweaponsasitems.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()

@ -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 )
@ -67,6 +71,10 @@ function Quantum.Server.Inventory.UnEquipItem( pl, equipslot, char )
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

@ -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

@ -116,6 +116,26 @@ if SERVER 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
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
loadCoreFiles()
@ -124,6 +144,9 @@ if SERVER then
-- Creation of stuff
loadAllItemsAndEffects()
-- Plugins
loadPlugins()
end
Quantum.Server.Load()

@ -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 )
Loading…
Cancel
Save