Ulysses
General => Developers Corner => Topic started by: Reaper_007_ on November 22, 2017, 11:05:13 AM
-
I would like to know if it is possible to organize weapons however you want in the spawn menu? What do I mean by this? I am trying to make the weapons be separated by classes (Ranks), so people in certain ranks can go to that tab and see all the weapons unlocked to them. If this is possible for the entire server and all player see the same please point me in the right direction. Or if you know how it is done Please tell me, Thanks.
-
My guess is - yes.
However, in poking about the Gmod lua wiki, I can't find the 'aha' function or hook that would do it.
I've never tinkered in GUI in Gmod.
Stickly Man or MrPresident could probably give more direction.
Logic in my mind, if it's possible, would be something like below pseudo-code, using a hook that could be used to over-ride what players saw.
function Check_Wep_access (ply)
weps = { } -- There's likely a gmod table of weapons available to the player domain somewhere . It would be assigned to weps
allowed_weps = { } -- Set up for a table in code further down.
for i, v in pairs( weps ) do -- We're cycling through all weapons, v will be the weapon.
if ply:IsUserGroup("custom_group") then -- Is this player part of an allowed group.
allowed_weps[#allowed_weps+1] = v -- add weapon to the table of allowed
end
end
return allowed_weps -- return allowed to game
end
hook.Add( whatever_hooks_Weapons_spawn_menu, blah, blah)
The above would get a bit more complicated as you'd need to know your list of weapons ahead of time, and compare minimum access to any of them for each one.
The weps table could grow to include something like { [ wep = weapon1, min = "min_group" ], [ wep = weapon2, min = "min_group" ] }. Perhaps any not specified would be allowed by default.
-
This would have to be done for each separate rank, correct? (This code)
-
Not if you had a preselected list of weapons within the code already, like suggested in my final sentence.
Then you'd just cycle through k, v like
... other vars already posted
special_weps = { [ wep = weapon1, min = "min_group" ], [ wep = weapon2, min = "min_group" ] }
for k, v in pairs( weps ) do -- We're cycling through all weapons, v will be the weapon.
if v == special_weps[k][wep] and ply:IsUserGroup( special_weps[k][min] ) then -- Is the weapon in the special list, and is the player part of the minimum group?
allowed_weps[#allowed_weps+1] = v -- add weapon to the table of allowed
end
end
... other code
Are you familiar with arrays? (aka multi-layer tables)?
I forget what they're called in java/javascript. Lists perhaps.
-
Yeah, I know arrays. I think I see how this works now. I will try and add the weapon arrays in and post to see if I am right.
-
I've no idea what to use as your menu hook though for spawn menu.
Did you find one?
Or are you editing typical loadout hook?
All my examples are just how it could be done, IF the right spawn menu hook was found.
-
I was thinking about just editing the already there spawn menu. Would make it much easier. This is the path to the spawn menu if you want to take a look at it if it helps.
D:\Steam\steamapps\common\GarrysMod\garrysmod\gamemodes\sandbox\gamemode\spawnmenu\creationmenu\content\contenttypes\weapons.lua
-
Though you can learn alot by looking at source, I'd never edit original code.
That's why Gmod is quite extensible, with hooks, and functions that can be used to overwrite original results.
That file you found even includes your answer of a possible hook to use in it's first line.
Good source reference also - https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/sandbox/gamemode/spawnmenu/creationmenu/content/contenttypes/weapons.lua
hook.Add( "PopulateWeapons")
It's not documented in the Wiki, but perhaps you could tinker, even test disrupting it by returning false in a function that hooks into it.