Two similar pieces of derma, but one doesn't work.
13 replies, posted
So basically I've been trying to get this basic derma to work and it just doesn't seem to be working. When I compare it to my old work that I did when I first tried learning lua, I can't find anything different besides the names I used for each part. When I replace the broken derma with the one that works, my gamemode suddenly starts working again.
Only problem is, I can't figure out what's wrong with the broken derma since it's pretty much identical.
WORKING
[LUA]
function set_team()
local DermaPanel = vgui.Create("DFrame")
DermaPanel:SetPos(200, 200)
DermaPanel:SetSize(800, 300)
DermaPanel:SetTitle("Choose Your Side")
DermaPanel:SetVisible(true)
DermaPanel:SetDraggable(false)
DermaPanel:ShowCloseButton(false)
DermaPanel:MakePopup()
local DermaHuman = vgui.Create("DButton")
DermaHuman:SetParent(DermaPanel)
DermaHuman:SetText("Humans")
DermaHuman:SetPos(25, 25)
DermaHuman:SetSize(200, 100)
DermaHuman.DoClick = function()
DermaPanel:Close()
RunConsoleCommand("HAssault")
end
local DermaAlien = vgui.Create("DButton")
DermaAlien:SetParent(DermaPanel)
DermaAlien:SetText("Aliens")
DermaAlien:SetPos(25, 175)
DermaAlien:SetSize(200, 100)
DermaAlien.DoClick = function()
DermaPanel:Close()
RunConsoleCommand("AAssault")
end
local DermaChoices = vgui.Create("DListView")
DermaChoices:SetParent(DermaPanel)
DermaChoices:SetPos(300, 25)
DermaChoices:SetSize(475,250)
DermaChoices:SetMultiSelect(false)
DermaChoices:AddColumn("Players")
DermaChoices:AddColumn("Kills")
DermaChoices:AddColumn("Deaths")
for k,v in pairs(player.GetAll()) do
DermaChoices:AddLine(v:Nick(),v:Frags() + v:Deaths(),v:Deaths())
end
end
[/LUA]
BROKEN
[LUA]
function set_team()
local MainMenu = vgui.Create("DFrame")
MainMenu:SetPos(200, 200)
MainMenu:SetSize(800, 300)
MainMenu:SetText("Break the gamemode.")
MainMenu:SetVisible(true)
MainMenu:SetDraggable(false)
MainMenu:ShowCloseButton(true)
MainMenu:MakePopup()
local SpawnButton = vgui.Create("DButton")
SpawnButton:SetParent(MainMenu)
SpawnButton:SetText("Spawn")
SpawnButton:SetPos(50, 50)
SpawnButton:SetSize(200, 100)
SpawnButton:DoClick = function()
MainMenu:Close()
ply:ConCommand("set_team1")
end
end
[/LUA]
I've already isolated the problem to this part specifically.
[editline]28th March 2012[/editline]
The game tells me that set_team is an unknown command when I use the broken one.
Should be a space in line 18
[lua]
ply:ConCommand("set_team1")
[/lua]
should be
[lua]
ply:ConCommand("set_team", "1")
[/lua]
[QUOTE=Icebomb;35336684]Should be a space in line 18
[lua]
ply:ConCommand("set_team1")
[/lua]
should be
[lua]
ply:ConCommand("set_team", "1")
[/lua][/QUOTE]
set_team1 is my function in init.lua which sets the player's team as well as their movement speed
[editline]28th March 2012[/editline]
when I enter set_team1 into console, it assigns me to the team. The derma, however, doesn't exist since the command set_team doesn't exist whenever I use the broken derma.
But it somehow does in the working derma?
use LocalPlayer():ConCommand()
ply doesnt exist on the client.
[QUOTE=Deadman123;35336998]use LocalPlayer():ConCommand()
ply doesnt exist on the client.[/QUOTE]
it's still saying set_team is an unknown command
Did you concommand.Add it?
[QUOTE=Deadman123;35337364]Did you concommand.Add it?[/QUOTE]
Yes, like I said in the OP if I put the working derma in, instead of the broken one, it works fine (except for the functions that buttons perform, but that's because they don't exist in the gamemode).
The working code will make the derma pop up (different derma, same function name) yet the broken one doesn't. I've been comparing the two for hours and changing various things on the broken one trying to fix it, yet it never works.
Thats incredibly odd.
Here's the entire gamemode, like I said it's nothing complicated. Changing the broken derma out with the working one will get the derma to work, but the game functions regardless of whether or not the derma is broken.
cl_init.lua
[LUA]
include('shared.lua')
function set_team()
local MainMenu = vgui.Create("DFrame")
MainMenu:SetPos(200, 200)
MainMenu:SetSize(800, 300)
MainMenu:SetText("Break the gamemode.")
MainMenu:SetVisible(true)
MainMenu:SetDraggable(false)
MainMenu:ShowCloseButton(true)
MainMenu:MakePopup()
local SpawnButton = vgui.Create("DButton")
SpawnButton:SetParent(MainMenu)
SpawnButton:SetText("Spawn")
SpawnButton:SetPos(50, 50)
SpawnButton:SetSize(200, 100)
SpawnButton:DoClick = function()
MainMenu:Close()
LocalPlayer():ConCommand("set_team1")
end
end
concommand.Add("set_team", set_team)
[/LUA]
init.lua
[LUA]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')
function GM:PlayerInitialSpawn(ply)
ply:ConCommand("set_team")
ply:ConCommand("set_spectator")
end
function GM:PlayerLoadout(ply)
ply:StripWeapons()
if ply:Team() == 1 then
ply:Give("weapon_357")
ply:GiveAmmo(999, "357")
end
end
function set_team1(ply)
ply:SetTeam(1)
ply:UnSpectate()
ply:SetHealth(25)
ply:SetWalkSpeed(500)
ply:SetRunSpeed(800)
ply:SetGravity(.5)
ply:Spawn()
ply:PrintMessage(HUD_PRINTTALK, "Break the gamemode.\n")
end
function set_spectator(ply)
ply:SetTeam(2)
ply:Spectate(5)
end
concommand.Add("set_team1",set_team1)
concommand.Add("set_spectator",set_spectator)
[/LUA]
shared.lua
[LUA]
GM.Name = "Unnamed Alpha"
GM.Author = "Valdor"
GM.Email = "N/A"
GM.Website = "N/A"
team.SetUp(1, "Player", Color(0, 162, 232, 255))
team.SetUp(2, "Joining", Color(222, 237, 254, 255))
[/LUA]
Instead of
LocalPlayer():ConCommand("set_team1")
Use
RunConsoleCommand( "set_team1" )
and in
[lua]function GM:PlayerInitialSpawn(ply)
ply:ConCommand("set_team")
ply:ConCommand("set_spectator")
end[/lua]
Why are you making the player run serverside functions when you can just do
[lua]function GM:PlayerInitialSpawn(ply)
set_team1( ply )
set_spectator( ply )
end[/lua]
[QUOTE=Ruzza;35343032]Instead of
LocalPlayer():ConCommand("set_team1")
Use
RunConsoleCommand( "set_team1" )
and in
[lua]function GM:PlayerInitialSpawn(ply)
ply:ConCommand("set_team")
ply:ConCommand("set_spectator")
end[/lua]
Why are you making the player run serverside functions when you can just do
[lua]function GM:PlayerInitialSpawn(ply)
set_team1( ply )
set_spectator( ply )
end[/lua][/QUOTE]
I originally had them do RunConsoleCommand("") for both of them, but like I said I was just messing around with it trying to get the derma to work. I don't believe there's really a point to changing the set_team to set_team1 since I want it to pull up the derma, not assign the player to both team1 and spectator at the same time (guessing it would just end up putting the player on spectator).
However, none of that actually fixes my original problem which is the derma not showing up and instead saying that set_team is an unknown command. The working derma won't give that error yet the broken one will, and I can't find any significant difference between the two that would cause that.
Are you getting any errors at all?
No, the game runs fine but the derma won't launch. When I type set_team in console it just says unknown command.
It becomes a known command, though, when I use the working derma so I'm pretty sure the problem is that I'm either lacking something in the broken one or I mistyped something.
Found out why it didn't work.
[LUA]SpawnButton:DoClick[/LUA]
should have instead been
[LUA]SpawnButton.DoClick[/LUA]
The smallest things make all the difference, thanks lua.
Sorry, you need to Log In to post a reply to this thread.