Garry's Mod

Garry's Mod

Scavenger Hunter
 This topic has been pinned, so it's probably important
Starfyre  [developer] 9 Apr, 2018 @ 4:33pm
DEVS: Creating an Upgrade
Greetings fellow developers!

Scavenger Hunter utilizes a "modular" type system for detecting addons and plugins for Scavenger Hunter. The process may not be the most *efficient* way of doing it, but it's extremely simple. Once you create your addon, you will want to add it to the F4 menu so clients can buy it and the server can sell it.


STEP 1) Creating the Information
The gamemode requires a couple fields for it to even work in the first place. It is used to detecting the addon/plugin name and handling it appropriately, up to and including cost.


local <MyVarName> = {}
<MyVarName>.id = "some_id_no_spaces"
<MyVarName>.name = "Button Name"
<MyVarName>.short = "Colored Title in F4"
<MyVarName>.description = "As long of a description as you want for your upgrade. No newline break necessary."
<MyVarName>.price = <INT Value> //Price per purchase
<MyVarName>.exec = function() end


STEP 2) Creating the Execution Function
<MyVarName>.exec = function() end is where you will conduct your upgrade when the player has purchased it. This must include the code: ply:SetCredits(ply:GetCredits() - <MyVarName>.price) once the upgrade is successful and all upgrades are complete, or your upgrade will not cost anything.

STEP 3) Adding the Upgrade
Once the following information above is entered into your upgrade, you will need to add it, hook it, or whatever method you need to call it. The gamemode has a shared global table named "power_up". You will add the following hook, as a shared hook, to the end of your shared lua file (or outside a CLIENT/SERVER condition):

hook.Add("OnGamemodeLoaded", "Add<MyName>", function()
table.insert(power_up, <MyVarName>)
end)


Once that is complete, load up the game! If your plugin still fails to load, check for the following problems:

FAILURES / FAQ
1:: Your upgrade names don't match. Ensure that everywhere about that says <MyVarName> all match perfectly. You are adding your table of key-value pairs to the table power_up. The format should be -> power_up[#].price = <value>. The game mode will handle all purchasing, and will check that ".id" matches your info table to call and purchase your upgrade.

2: Your hook.Add() isn't using a unique name, ensure that "Add<MyName>" doesn't match any other upgrades in the server. If I created a hook called "AddHL2Pistol", and you created a modified HL2 9mm Pistol that fires flames instead of bullets, and you named your hook "AddHL2Pistol", the whole upgrade system would fall apart and none of them would load properly. Or at least, it didn't for me. Ensure you are using unique AddMyName's.