Author Topic: Weapon Organization In Spawn Menu  (Read 3101 times)

0 Members and 1 Guest are viewing this topic.

Offline Reaper_007_

  • Newbie
  • *
  • Posts: 11
  • Karma: 1
Weapon Organization In Spawn Menu
« 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.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Weapon Organization In Spawn Menu
« Reply #1 on: November 23, 2017, 07:30:07 AM »
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.

Code: [Select]
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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Reaper_007_

  • Newbie
  • *
  • Posts: 11
  • Karma: 1
Re: Weapon Organization In Spawn Menu
« Reply #2 on: November 23, 2017, 04:20:43 PM »
This would have to be done for each separate rank, correct? (This code)

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Weapon Organization In Spawn Menu
« Reply #3 on: November 23, 2017, 08:18:55 PM »
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
Code: [Select]
... 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.


"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Reaper_007_

  • Newbie
  • *
  • Posts: 11
  • Karma: 1
Re: Weapon Organization In Spawn Menu
« Reply #4 on: November 24, 2017, 12:09:46 PM »
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.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Weapon Organization In Spawn Menu
« Reply #5 on: November 24, 2017, 12:33:25 PM »
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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Reaper_007_

  • Newbie
  • *
  • Posts: 11
  • Karma: 1
Re: Weapon Organization In Spawn Menu
« Reply #6 on: November 24, 2017, 05:41:09 PM »
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

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Weapon Organization In Spawn Menu
« Reply #7 on: November 24, 2017, 08:03:48 PM »
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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming