General > Developers Corner

Weapon Organization In Spawn Menu

(1/2) > >>

Reaper_007_:
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.

JamminR:
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: ---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)

--- End code ---

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.

Reaper_007_:
This would have to be done for each separate rank, correct? (This code)

JamminR:
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: ---... 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

--- End code ---
Are you familiar with arrays? (aka multi-layer tables)?
I forget what they're called in java/javascript. Lists perhaps.


Reaper_007_:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version