• Spawn with weapons?
    13 replies, posted
[B]is there a code to make something like this:[/B] [IMG]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/images/8/80/DComboBox.png[/IMG] [CODE]local TestingComboBox = vgui.Create( "DComboBox", DermaFrame ) TestingComboBox:SetPos( 10, 35 ) TestingComboBox:SetSize( 100, 185 ) TestingComboBox:SetMultiple( false ) -- Don't use this unless you know extensive knowledge about tables TestingComboBox:AddItem( "Add" ) -- Add our options TestingComboBox:AddItem( "Some" ) TestingComboBox:AddItem( "Options" ) TestingComboBox:AddItem( "Here" ) local MainMenuSheet = vgui.Create( "DPanel", DermaFrame ) -- We create a panel so we can draw shit on; if we use the frame, it comes up transparent for some reason MainMenuSheet:SetPos( 125, 50 ) MainMenuSheet:SetSize( DermaFrame:GetWide() - 25, DermaFrame:GetTall() - 25 ) MainMenuSheet.Paint = function() if TestingComboBox:GetSelectedItems() and TestingComboBox:GetSelectedItems()[1] then -- make sure something is selected if not we get uber spam of errors local OurStringThing = "Your selection is: "..TestingComboBox:GetSelectedItems()[1]:GetValue().."!" -- This was a pain in the ass to figure out; this gets the name of the option chosen surface.SetFont( "default" ) surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextPos( 50, 50 ) surface.DrawText( OurStringThing ) -- Draws the text end end[/CODE] [B]with a funcion that if you choose something (like on the picture) one of those "selections" that you will after death spawn with choosen gun?[/B]
You could try something along the lines of: [CODE]local function SelectingWeapon( ply ) if TestingComboBox:GetSelectedItems()[1]:GetValue() == "Magnum" then ply:Give( weapon_357 ) ply:Kill() end if TestingComboBox:GetSelectedItems()[1]:GetValue() == "Pistol" then ply:Give( weapon_pistol ) ply:Kill() end end hook.Add( "PlayerSpawn", "WeaponSelect", SelectingWeapon )[/CODE] Although you could make buttons on the frame instead and then link the functions: [CODE]local function GiveMagnum( ply ) ply:Give( "weapon_357" ) ply:Kill() frame:SetVisible(false) end hook.Add("PlayerSpawn","Magnuml",GiveMagnum) local function GivePistol( ply ) ply:Give( "weapon_pistol" ) ply:Kill() frame:SetVisible(false) end hook.Add("PlayerSpawn","Pistol",GivePistol) [/CODE] So you would link the function names to the DoClick on the buttons.
[QUOTE=goosey;40610487]You could try something along the lines of: [CODE]local function SelectingWeapon( ply ) if TestingComboBox:GetSelectedItems()[1]:GetValue() == "Magnum" then ply:Give( weapon_357 ) ply:Kill() end if TestingComboBox:GetSelectedItems()[1]:GetValue() == "Pistol" then ply:Give( weapon_pistol ) ply:Kill() end end hook.Add( "PlayerSpawn", "WeaponSelect", SelectingWeapon )[/CODE] Although you could make buttons on the frame instead and then link the functions: [CODE]local function GiveMagnum( ply ) ply:Give( "weapon_357" ) ply:Kill() frame:SetVisible(false) end hook.Add("PlayerSpawn","Magnuml",GiveMagnum) local function GivePistol( ply ) ply:Give( "weapon_pistol" ) ply:Kill() frame:SetVisible(false) end hook.Add("PlayerSpawn","Pistol",GivePistol) [/CODE] So you would link the function names to the DoClick on the buttons.[/QUOTE] This don't work (i tried with a button), i just press it, kill myself, and i respawn with nothing :/ [editline]13th May 2013[/editline] anyone?
bump :/ ?
Lets go over this code ply:Give( "weapon_357" ) --Give them a gun ply:Kill() -- kill them Because that makes sense. Try something like this instead. [code] local function GiveMagnum( ply ) ply:Give( "weapon_357" ) --See how the player doesn't die after getting the gun... amazing! frame:SetVisible(false) end hook.Add("PlayerSpawn","Magnuml",GiveMagnum) [/code] You could even just kill them, then when they spawn the function will run. This will effect everyone because PlayerSpawn is ran every time a player spawns. To prevent this you could do something like respawn the player, and then giving them the weapon. [lua] local function SAW(ply) ply:Spawn() ply:Give("weapon_357") end [/lua]
Alright ok, I'm new to coding in general and was just trying to help. Thanks for the pointers, however, could you do this: [CODE]local function SelectingWeapon( ply ) if TestingComboBox:GetSelectedItems()[1]:GetValue() == "Magnum" then -- If they have Magnum selected then ply:Give( weapon_357 ) -- give them the gun end if TestingComboBox:GetSelectedItems()[1]:GetValue() == "Pistol" then ply:Give( weapon_pistol ) end end hook.Add( "PlayerSpawn", "WeaponSelect", SelectingWeapon ) --Checking everytime someone spawns[/CODE] Use the hook to check if he has selected a certain value, and if he has, give him the correct guns every time he spawns.
It would work if they die after they push the button. I don't touch derma because I hate it. But the best would be to instead of using a hook use the ply:Spawn() and then give them a weapon, so that they are re-spawned and then given the weapon.
[QUOTE=Pandaman09;40633790]It would work if they die after they push the button. I don't touch derma because I hate it. But the best would be to instead of using a hook use the ply:Spawn() and then give them a weapon, so that they are re-spawned and then given the weapon.[/QUOTE] But would they then be given the gun every time they spawned?
I think you could make it so when a player respawns, straight after their death a derma menu automatically opens and the player can choose what gun they want and they would get it. [editline]14th May 2013[/editline] You could try to create the derma menu and open it whenever a player respawns for them to choose. In addition to this, you could make it even better by freezing the player and giving them temporary god mode until they choose their weapon which would then unfreeze them, remove the god mode and give them their weapon. Refer to this hook for where to put the code in: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index249d.html[/url]
[QUOTE=goosey;40639142]But would they then be given the gun every time they spawned?[/QUOTE] No, if you just call in the derma to respawn the person once and give them the weapon it will not, right now it will only work if they die while pressing the button (when the respawn hook is called)
okay,i could do that they choose, but then they can just click all the buttons and get all of them ? :/ i could also try to add "strip guns" to it, but then it would strip all my pistols and attachments (i use attachments mod)
You should make a derma menu open on spawn using the PlayerSpawn hook which will have buttons to select which weapon you want. The button should have this code (or something similar): [CODE] pl:Give("weaponnameinhere") frame:SetVisible(false) [/CODE]
so, i made it when they respawn, there popsup a weapon chooser which spawns them gun, you get a weapon, how do i get so they can choose only ONE gun?, ONE pistol, and one Attachment
You ARE aware that the derma menu is clientside, and the player:Give() function is serverside, right? You need to get the client to tell the server what their weapon choice is. I suggest a client cvar, and using player:GetInfo() on spawn.
Sorry, you need to Log In to post a reply to this thread.