Player Loadout from client

I am working on a menu that would allow you to choose your weapons before spawning. Since you are not yet spawned, giving the weapons as you click would not work. Also, because it is a menu I need to send the weapon choices to the server to give but I do not think Net.SendToServer would work in this case since I would practically be sending an array. How exactly could I network this array from the client to the server?

Don’t trust the client. Have the server send available weapons in a table to the client; open the vgui and let the user choose weapons. Send that to server, and give based on the pre-set table the server sent.

If you allow the client to just send a list of weapons, traitor / detective weapons could be given to them…

Example of networking: https://dl.dropboxusercontent.com/u/26074909/tutoring/networking/networking_booleans.lua.html

Example of networking something to be displayed for x seconds on initial spawn ( This networks to client, then enables a hud paint hook; in theory it is the same except instead of making a hook, just open vgui and populate with net.ReadTable( ); when user clicks the submit button use net.WriteTable( data ), server receives with data = net.ReadTable( ), spawns the player, then gives the weapons from the servers reference of allowed weapons ): https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/display_something_on_initial_spawn.lua.html

Hmmmm, I’ve never really messed about with weapons before; but you could try something like this:

Client-Side: When a weapon is clicked, send the weapon class name to the server along with the player who sent it.
Server-Side: Create a Player metatable with the following methods:


function metaPly:AddSpawnWeapon(wepID)
    if not self.spawnWeaponTable then self.spawnWeaponTable = {} end
    table.insert(self.spawnWeaponTable, wepID)
end



metaPly:SpawnWithWeapons(wepID)
    for k, wep in pairs(self.spawnWeaponTable) do
         ply:Give( wep )
    end
end


Whenever a weapon is received server-side, just add it to the metaPly. After the player has spawn, just called SpawnWithWeapons.
Hope that helps, or at least leads you in the right direction :slight_smile:

Also, remember to add checks in the metaPly:AddSpawnWeapon(wepID) server-side method!!

Thanks to both of you for your replies! They are both great and give me insight on how I should be doing this.

Thanks again!