So basicly i am making a gamemode and i want to register a concommand trough lua, so heres the code:
init.lua
[code]
AddCSLuaFile( "vgui/PLoadout.lua.lua" )
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
--Declare player Variables------------------------------------------------
function FirstSpawn( pl )
pl.MainW = {}
pl.SecW = {}
pl.MeleeW = {}
pl.MainW = ("weapon_shotgun")
pl.SecW = ("weapon_pistol")
pl.MeleeW = ("weapon_crowbar")
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )
-------------------------------------------------------------------------
--Cake Spawning----------------------------------------------------------
function SpawnCake()
CakeSpawn = {}
CakeSpawn = ents.FindByClass( "info_cake_spawn" )
if(CakeSpawn == nil) then
--TODO:
--Insert Error Message
end
end
-------------------------------------------------------------------------
[/code]
cl_init.lua
[code]
include( 'shared.lua' )
include( 'vgui/PLoadout.lua' )
function GM:PositionScoreboard( ScoreBoard )
ScoreBoard:SetSize( 700, ScrH() - 100 )
ScoreBoard:SetPos( (ScrW() - ScoreBoard:GetWide()) / 2, 50 )
end
concommand.Add( "TestVGUI", PLoadoutPanel() )
[/code]
vgui/PLoadout.lua
[code]
include( 'cl_init.lua' )
/*--------------------------------------------
Player Loadout VGUI Panel
--------------------------------------------*/
function PLoadoutPanel()
local aPanel = vgui.Create( "Frame" )
aPanel:SetSize( 800, 500 )
aPanel:SetPos( 100, 100 )
aPanel:SetVisible( true )
aPanel:MakePopup()
local aButton = vgui.Create( "Button", aPanel )
aButton:SetText( "Accept" )
aButton:SetPos( 650, 450 )
aButton:SetWide( 100 )
function aButton:DoClick()
aPanel:SetVisible( false )
end
end
concommand.Add( "TestVGUI", PLoadoutPanel() )
[/code]
Does anyone see why TestVGUI command won't work?
BTW i know i register the command 2 times in 2 different luas but it won't work even if its in only one lua
[lua]concommand.Add( "TestVGUI", PLoadoutPanel() )[/lua]
You are calling the function PLoadoutPanel here, which is passing the return value to concommand.Add.
You don't want to call it, just pass it to concommand.Add, like this:
[lua]concommand.Add( "TestVGUI", PLoadoutPanel )[/lua]
Nope still won't work, so heres the new cl_init and PLoadout
[code]
include( 'shared.lua' )
include( 'vgui/PLoadout.lua' )
function GM:PositionScoreboard( ScoreBoard )
ScoreBoard:SetSize( 700, ScrH() - 100 )
ScoreBoard:SetPos( (ScrW() - ScoreBoard:GetWide()) / 2, 50 )
end
[/code]
[code]
/*--------------------------------------------
Player Loadout VGUI Panel
--------------------------------------------*/
function PLoadoutPanel()
local aPanel = vgui.Create( "Frame" )
aPanel:SetSize( 800, 500 )
aPanel:SetPos( 100, 100 )
aPanel:SetVisible( true )
aPanel:MakePopup()
local aButton = vgui.Create( "Button", aPanel )
aButton:SetText( "Accept" )
aButton:SetPos( 650, 450 )
aButton:SetWide( 100 )
function aButton.DoClick()
aPanel:SetVisible( false )
end
end
concommand.Add( "TestVGUI", PLoadoutPanel )
[/code]
It's like concommand.Add( "TestVGUI", PLoadoutPanel ) never makes it to the client, i don't get why it won't work, no errors or anything
VGUI is client side if (CLIENT) then
make sure you AddCSLuaFile aswell.
If it wouldn't be too much trouble could anyone with a little experience try my code and maybe find out what is wrong, i think cl_init isn't running at all.
But here is the code and downloadlink at the buttom:
cl_init
[code]
include( 'shared.lua' )
include( 'vgui/PLoadout.lua' )
function GM:PositionScoreboard( ScoreBoard )
ScoreBoard:SetSize( 700, ScrH() - 100 )
ScoreBoard:SetPos( (ScrW() - ScoreBoard:GetWide()) / 2, 50 )
end
[/code]
shared
[code]
GM.Name = "CakeWars"
GM.Author = "FPSMango"
GM.Email = ""
GM.Website = ""
DeriveGamemode( "sandbox" )
[/code]
init
[code]
AddCSLuaFile( "vgui/PLoadout.lua" )
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
--Declare player Variables------------------------------------------------
/*---------------------------------------------------------
Name: gamemode:PlayerSpawn( )
Desc: Called when a player spawns
---------------------------------------------------------*/
function GM:PlayerSpawn( pl )
pl.MainW = {}
pl.SecW = {}
pl.MeleeW = {}
pl.MainW = ("weapon_shotgun")
pl.SecW = ("weapon_pistol")
pl.MeleeW = ("weapon_crowbar")
// Stop observer mode
pl:UnSpectate()
hook.Call( "PlayerLoadout", GAMEMODE, pl )
// Set player model
hook.Call( "PlayerSetModel", GAMEMODE, pl )
// Set the player's speed
GAMEMODE:SetPlayerSpeed( pl, 250, 500 )
end
function GM:PlayerLoadout( pl )
pl:Give( pl.MainW )
pl:Give( pl.SecW )
pl:Give( pl.MeleeW )
return true -- this prevents the gamemode's default PlayerLoadout from getting called (this only applies when you're not coding the gamemode itself)
end
--hook.Add( "PlayerLoadout", "LoadoutHook", Loadout)
-------------------------------------------------------------------------
--Cake Spawning----------------------------------------------------------
function SpawnCake()
CakeSpawn = {}
CakeSpawn = ents.FindByClass( "info_cake_spawn" )
if(CakeSpawn == nil) then
--TODO:
--Insert Error Message
end
end
[/code]
PLoadout
[code]
/*--------------------------------------------
Player Loadout VGUI Panel
--------------------------------------------*/
function PLoadoutPanel()
local aPanel = vgui.Create( "Frame" )
aPanel:SetSize( 800, 500 )
aPanel:SetPos( 100, 100 )
aPanel:SetVisible( true )
aPanel:MakePopup()
local aButton = vgui.Create( "Button", aPanel )
aButton:SetText( "Accept" )
aButton:SetPos( 650, 450 )
aButton:SetWide( 100 )
function aButton.DoClick()
aPanel:SetVisible( false )
end
end
function GM:OnPlayerChat( player, strText, bTeamOnly, bPlayerIsDead )
PLoadoutPanel()
end
concommand.Add("LoadoutPanel",PLoadoutPanel)
[/code]
[url]http://www.garrysmod.org/downloads/?a=view&id=91637[/url]
Sorry, you need to Log In to post a reply to this thread.