Sup !
I have a problem with the If question of the ComboBox!
I had this code :
[CODE]
local DermaButton = vgui.Create( "DButton", TestingPanel )
DermaButton:SetParent ( DermaPanel )
DermaButton:SetText( "Spawn" )
DermaButton:SetPos( 300, 50 )
DermaButton:SetSize( 40, 50 )
DermaButton.DoClick = function()
<----- Here schould be the if query
end
local ComboBox = vgui.Create( "DComboBox", DermaFrame )
ComboBox:SetPos( 30, 50 )
ComboBox:SetSize( 70, 20 )
ComboBox:SetValue("Pistols")
ComboBox:AddChoice( "weapon_pistol" )
ComboBox:SetParent( DermaPanel )
[/CODE]
And my guess :
[CODE]if ComboBox:ChooseOption( "weapon_pistol" ) then -- <-- This didn't work :(
ply:Give( "wz_pistol" )
end[/CODE]
Iv never used the vgui / derma controls, but I know what the problem is.
All the gui stuff is handled clientside, but you also have ply:Give() in the clientside script, which wont work. What you need to do is when they choose a weapon with your if statement, use the net library to tell the server "I chose the weapon pistol dropdown box" then the server will receive it, then send you the weapon.
When I get a bit of time later, il see if I can write a mockup script for it.
Okey thanks .. I think its too complicated for me. Im trying to learn GLUA . But some things in the wiki are not correct or missing. I hope you can help me later! :)
Tell me about it, Iv been learning for the past three weeks, but iv had alot of practice in it, as Iv been continually writing an admin mod for my server the whole time.
Clientside stuff, you will have to find someone else im afraid, but serverside stuff I should be able to help where I can.
I started 4 days ago to code a gamemode on the Base of fretta. Then 2 days ago I wanted to learn glua . And my Gamemode works ;) But I want to install more things so that the gamemode is better to play.
Do something like this..
lua/autorun/<name>.lua
[lua]
local n = "whatthehell"
if SERVER then
net.Receive(n, function(l, ply)
local w = net.ReadString()
ply:Give(w)
end
end
if CLIENT then
function GetWep(w)
net.Start(n)
net.WriteString(w)
net.SendToServer()
end
end
[/lua]
Add security to it though.
I dont know what to do ... becouse im not done with learning Glua!
[lua]local YourWindow = vgui.Create("DFrame")
YourWindow:SetSize(480,180)
YourWindow:SetTitle('Spawn a weapon')
YourWindow:MakePopup()
local SpawnButton = vgui.Create( "DButton", YourWindow )
SpawnButton:SetText( "Spawn" )
SpawnButton:SetPos( 180, 30 )
SpawnButton:SetSize( 70, 30 )
SpawnButton.DoClick = function()
if YourComboBox:GetValue() == "Pistol" then
chat.AddText(Color(220,190,0),"Selected weapon name: " .. YourComboBox:GetValue())
-- Tell the server to spawn weapon_pistol
else
chat.AddText(Color(220,190,0),"Unknown selection.")
end
end
YourComboBox = vgui.Create( "DComboBox", YourWindow )
YourComboBox:SetPos( 10, 30 )
YourComboBox:SetSize( 170, 30 )
YourComboBox:SetValue( "Choose your weapon!" )
YourComboBox:AddChoice( "Pistol" )
YourComboBox:AddChoice( "Other" )[/lua]
This code will print the selected comboBox option in your chat. To spawn a weapon you need to learn about communication between client and server. Here are two ways how you could do it:
Net libary (best way): [url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url]
Console commands (easy to understand): [url]http://wiki.garrysmod.com/page/concommand/Add[/url]
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexd95c.html[/url]
I'd recommend you to try both ways and start with the easy one.
Sorry, you need to Log In to post a reply to this thread.