Development Modification - GmodRaMTeam/research_and_manufacturing GitHub Wiki
Adding Research Categories
This is not for the faint of heart yet. It requires adding some LUA to a few different files. In the future I plan to streamline this process to make it much easier. Adding weapons/categories in future updates will be targeted at only having to init them Serverside/Clientside
Serverside
Initing it
In gamemode/init.lua
you'll find the code to init all the categories/research for each team under the local function InitTeamVariables()
Research Objects are laid out like so:
Team->ResearchManager->ResearchCategory->ResearchTechnology.
So at the top of InitTeamVariables()
we do:
local newResearchManager = ResearchManager({
team_index = ID,
team_name = TeamInfo['Name']
})
local armorCat = newResearchManager:add_category({
key = 'armor',
name = 'Armor',
})
armorCat:add_technology({
key = 'armor_one', -- This is required
name = 'Armor Type I', -- This is required
tier = 1, -- This is required
})
This inits our Research Manager for the team (team_index/team_name fields), adds a category with key/name fields, and adds a technology with fields key/name/tier.
If you're adding a weapon/gadget or something else that is an actual SWEP for the player, you should use the class
field to store what your object class is.
local weapCat = newResearchManager:add_category({
key = 'weapons',
name = 'Weapons',
})
weapCat:add_technology({
key = 'revolver',
name = 'Revolver',
class = 'weapon_ram_revolver',
tier = 1
})
So the possible fields for a Research Category are:
key: What key do we check ResearchManager's categories for?
name: What is the name of this category?
And for Research Technologies:
key: What key do we check in this technology's category?
name: What is this technologies' name?
class: If this is a weapon, what class do we give?
tier: What tier of research should this be? (1 is lower, 6 is higher)
reqs: Table of Technology `key`s. Represents what we must research first in order to unlock this.
So let's say we want to add some M9K default weapons. If the weapon category already exists, and per say we want to add the orbital strike as a higher tier than the default gluon gun, after the gluon gun's technology definition add this:
weapCat:add_technology({
key = 'orbital_strike',
name = 'Orbital Strike',
class = 'm9k_orbital_strike',
tier = 9,
reqs = { 'egon' }
})
This adds a weapon with key orbital_strike
to the weapon category, with name Orbital Strike
, a class of m9k_orbital_strike
, a tier of 9 (Higher than the gluon gun), and a requirements table set to the gluon gun's key so we have to research that first.
Adding it to Player Spawns
Great but now how do we give player's weapons on ammo pickup? Or on spawn?
For Re-Supply/Ammo-crates
Open ram_ammo_stock.lua
under entities/entities/
(Under RaM's gamemode folder) and look for the function signature: function ENT:Touch(ent)
In here we'll find every condition for currently adding ammo. For the example of adding the orbital strike and making it so you can hold 1 extra round we need to do the following.
Add this chunk to the ENT:Touch()
function:
if self:CheckTechRequirement(ent:Team(), 'weapons', 'orbital_strike') then
self:CheckPlayerWeaponAndGive(ent, 'm9k_orbital_strike')
self:GivePlayerAmmo(ent, 'SatCannon', 'OrbitalAmmoMax', true, true)
end
Breaking it down
Here's what this code does:
if self:CheckTechRequirement(ent:Team(), 'weapons', 'orbital_strike') then
:
- If we have on this team researched this technology key
self:CheckPlayerWeaponAndGive(ent, 'm9k_orbital_strike')
:
- If the player we touched does not have this weapon, give it
self:GivePlayerAmmo(ent, 'SatCannon', 'OrbitalAmmoMax', true, true)
:
- Give the player type
SatCannon
ammo, with a max ofOrbitalAmmoMax
. This is a custom ammo type, and we should use gadget counts (1) instead of (20) for number of rounds to give.
The last thing to do in this file, is at the top of ram_ammo_stock.lua
define ENT.OrbitalAmmoMax = 2
. This sets the maximum amount of ammo to have for that type.
For Player Spawns:
This code is much simpler. Open player_ram.lua
under gamemode/player_class
. Look for the function PLAYER:Loadout()
.
Under the code chunk
if ResearchManager.categories['weapons'].techs['egon'].researched then
self.Player:Give( "weapon_ram_egon" )
end
Add
if ResearchManager.categories['weapons'].techs['orbital_strike'].researched then
self.Player:Give( "m9k_orbital_strike" )
end
Tah-dah! You're all done with the serverside work for adding a new weapon.
Clientside
The clientside is much simpler. We only worry about what details we want to show on menus, etc. Not the actual behavior.
Goto the file cl_init.lua
under gamemode
. Look for the function InitTeamVariables()
again. This should look like the same definition as the serverside part, except the Technologies have more fields for details.
If we're still following the example, we essentially do the samething as the serverside init and throw this in under the Egon's init.
weapCat:add_technology({
key = 'orbital_strike',
name = 'Orbital Strike',
description = 'M9K Specialties' Orbital Cannon',
class = 'm9k_orbital_strike',
tier = 9,
reqs = { 'egon' }
})
Note: Not all of these fields are required. The server is authoratative on reqs, and class. The only things we really care about here are tier for sorting the techs right on the menu, description, and name as this is what's shown to the user. For convenience we check reqs clientside on the research table to disable the vote button for techs we cannot do yet.
Finished
From here you should be finished. You should be able to restart your RaM game and see the changes. If not please contact us on the repo with an Issue, or contact me directly via the Discord server.