• Need help with a buy menu
    7 replies, posted
I'm creating a gamemode and i need a buy menu where a player can buy weapons from. I have to have the menu client side because the function to open the menu must be client sided. I would like to either know how i can put [CODE] hook.Add( "Think", "BM_Clients_Key", function() if input.IsKeyDown( KEY_B ) then BuyMenu() end end ) [/CODE] client side seperately while holding the menu server side, so i can run ply:Give in the file, or how to run ply:Give on a seperate server-side file from the client-side buy menu. [CODE] local Shotgun = vgui.Create( "DButton", BackGround ) Shotgun:SetSize( 150, 150 ) Shotgun:SetText( "Shotgun" ) Shotgun:SetPos( 10, 10 ) function Shotgun:DoClick() ply:Give( "weapon_shotgun" ) end [/CODE] While i'm here, i might as well ask how i can get the input:IsKeyDown to run once per press so it doesnt open 60 menus per second
:Give() is a serverside function. You need to do some networking.
I know that it is a serverside function, i just want to know how i can get the player to press "B" in a client-side file and run the buy menu server-side which would allow :Give() to work and thus giving the player a weapon.
[QUOTE=Lawlypops;48610854]I know that it is a serverside function, i just want to know how i can get the player to press "B" in a client-side file and run the buy menu server-side which would allow :Give() to work and thus giving the player a weapon.[/QUOTE] You can't run vgui serverside, you're going to have to network it when they press the button. If you mean you want the player to press the key b, then they're given a weapon you're also going to have to do some networking.
[QUOTE=InfernusN;48611624]You can't run vgui serverside, you're going to have to network it when they press the button. If you mean you want the player to press the key b, then they're given a weapon you're also going to have to do some networking.[/QUOTE] He probably wants the menu to open by pressing "B"
Use the [URL="http://wiki.garrysmod.com/page/Category:net"]net library[/URL] to send a request to the server to run a special function. You should also use the [URL="http://wiki.garrysmod.com/page/GM/KeyPress"]keypress hook[/URL] instead of Think.
[QUOTE]He probably wants the menu to open by pressing "B"[/QUOTE] Correct, and inside the menu is a button the player presses to give them the weapon. [QUOTE]You should also use the keypress hook instead of Think.[/QUOTE] I would you the keypress hook but that requires a pre-set key based on a function (W would be " IN_FORWARD)
[QUOTE=Lawlypops;48618838]Correct, and inside the menu is a button the player presses to give them the weapon. I would you the keypress hook but that requires a pre-set key based on a function (W would be " IN_FORWARD)[/QUOTE] -Snip, misread your reply, again-
Sorry, you need to Log In to post a reply to this thread.