Hello,
I wrote a simple script, that is supposed to show people the server rules when they spawn.
The problem is, that it doesnt show up... the console command can be entered but it doesn't do anything! i put the file in the lua/autorun folder of my server.
Script:
[lua]function init()
local DermaPanel = vgui.Create("DFrame")
DermaPanel:SetSize( 336, 215 )
DermaPanel:SetTitle("Welcome to Hellspawn's Fun Server!")
DermaPanel:SetVisible(true)
DermaPanel:SetDraggable(false)
DermaPanel:SetBackgroundBlur(true)
DermaPanel:ShowCloseButton(false)
DermaPanel:MakePopup()
DermaPanel:Center()
local DermaLabel = vgui.Create("DLabel")
DermaLabel:SetText( [[
THE RULES
1. Dont spam or build Contraptions that lag the Server.
2. Play nice, dont touch other Players Stuff without asking them.
3. Respect the Admins and they will respect you.
4. No random Deathmatch!!!
5. Type Accepted in the box below and click the OK button.
]] )
DermaLabel:SetParent(DermaPanel)
DermaLabel:SizeToContents()
DermaLabel:SetPos(10, 25)
local DermaLabel1 = vgui.Create("DLabel")
DermaLabel1:SetText("Read the rules first!")
DermaLabel1:SetParent(DermaPanel)
DermaLabel1:SizeToContents()
DermaLabel1:SetPos(230,185)
DermaLabel1:SetColor(Color(255,0,0))
DermaLabel1:SetVisible(false)
local DermaText = vgui.Create("TextEntry")
DermaText:SetParent(DermaPanel)
DermaText:SetSize(70,25)
DermaText:SetPos(98,180)
local DermaButton = vgui.Create("DButton")
DermaButton:SetParent(DermaPanel)
DermaButton:SetSize(50,25)
DermaButton:SetPos(173,180)
DermaButton:SetText("OK")
DermaButton.DoClick = function()
if DermaText:GetValue() == ("Accepted") then
DermaPanel:Close()
else DermaLabel1:SetVisible(true)
end
end
end
hook.Add("init","ShowMenu",init)
concommand.Add("rules", init)[/lua]
First of all, your Hook will never work because hooks are case sensitive and your name is incorrect. It is not "init", it is "Initialize".
[del]Second, both your concommand and your hook will never be set. This is because you create them [b]inside the "init" function[/b]: that is, until init() is run you don't actually create the concommand or the hook. You need to make the concommand outside of the function, in an autorun file or something.[/del]
Ohhh, ok never mind. You ought to fix your indentation.
You can't just create hooks, there is a set list of them and they must match.
[editline]15th January 2011[/editline]
Also Entoros, He is ending the function before he creates them, so the concommand would work just not the hook I'm pretty sure.
[QUOTE=c-unit;27438174]You can't just create hooks, there is a set list of them and they must match.
[/QUOTE]
What? [url]http://wiki.garrysmod.com/?title=Hook[/url]
Oohh, didn't see that, darn bad formatting. Thanks c-unit. But yeah, my guess is the file isn't being run.
Mike&Ike: c-unit means you can't just do hook.Add("LOLHook","fjkls",myFunc) and have it work.
[QUOTE=Entoros;27440624]Oohh, didn't see that, darn bad formatting. Thanks c-unit. But yeah, my guess is the file isn't being run.
Mike&Ike: c-unit means you can't just do hook.Add("LOLHook","fjkls",myFunc) and have it work.[/QUOTE]
Exactly, like some people post with hook.Add("bunnyhop", "asd", function) and are dumbfounded at why nothing happens when they run the bunnyhop command in the console
So i must rename the hook or function? I'm a little confused...
Change function to something like GameInit and #3 argument of the hook also to GameInit
[QUOTE=Netheous;27442063]Change function to something like GameInit and #3 argument of the hook also to GameInit[/QUOTE]
I tried that. It still doesnt work :(
Dude it's because init hook is wrong, it's Initialize.
Sorry about that i misunderstood. I would use the player initial spawn since that way it will run once they are in game. [url]http://wiki.garrysmod.com/?title=Gamemode.PlayerInitialSpawn[/url] this might also help [url]http://wiki.garrysmod.com/?title=Gamemode_Hooks[/url]
Before we get too caught up in hooks, let's take a step back: where is this file located?
lua/autorun
He said before.
In which case you'll get lots of errors as the vgui library isn't available serverside, nor will the file be sent to the client.
Try something like this at the top:
[lua]
include( "thisfile.lua" )
if SERVER then -- only run this next bit on the server
AddCSLuaFile("thisfile.lua") -- make sure file is sent to client
hook.Add("PlayerInitialSpawn", "your hook name", function( ply ) -- Create a hook thats called when the player spawns, this isn't available clientside so we'll have to do it on the server and tell the client from there
SendUserMessage( "Init", ply ) -- Send a usermessage to the player
end)
return -- stop anything below this being ran serverside
end
-- put all your other code here
-- then instead of using hook.Add we want to hook to the usermessage we just sent from the server
usermessage.Hook( "Init", init )
[/lua]
Too much :downs: in this thread.
[editline]16th January 2011[/editline]
[lua]function ShowRules()
local DermaPanel = vgui.Create("DFrame")
DermaPanel:SetSize( 336, 215 )
DermaPanel:SetTitle("Welcome to Hellspawn's Fun Server!")
DermaPanel:SetVisible(true)
DermaPanel:SetDraggable(false)
DermaPanel:SetBackgroundBlur(true)
DermaPanel:ShowCloseButton(false)
DermaPanel:MakePopup()
DermaPanel:Center()
local DermaLabel = vgui.Create("DLabel")
DermaLabel:SetText( [[
THE RULES
1. Dont spam or build Contraptions that lag the Server.
2. Play nice, dont touch other Players Stuff without asking them.
3. Respect the Admins and they will respect you.
4. No random Deathmatch!!!
5. Type Accepted in the box below and click the OK button.
]] )
DermaLabel:SetParent(DermaPanel)
DermaLabel:SizeToContents()
DermaLabel:SetPos(10, 25)
local DermaLabel1 = vgui.Create("DLabel")
DermaLabel1:SetText("Read the rules first!")
DermaLabel1:SetParent(DermaPanel)
DermaLabel1:SizeToContents()
DermaLabel1:SetPos(230,185)
DermaLabel1:SetColor(Color(255,0,0))
DermaLabel1:SetVisible(false)
local DermaText = vgui.Create("TextEntry")
DermaText:SetParent(DermaPanel)
DermaText:SetSize(70,25)
DermaText:SetPos(98,180)
local DermaButton = vgui.Create("DButton")
DermaButton:SetParent(DermaPanel)
DermaButton:SetSize(50,25)
DermaButton:SetPos(173,180)
DermaButton:SetText("OK")
DermaButton.DoClick = function()
if DermaText:GetValue() == ("Accepted") then
DermaPanel:Close()
else
DermaLabel1:SetVisible(true)
end
end
end
concommand.Add("rules", ShowRules)
-- hook.Add(HOOK_TYPE , HOOK_UNIQUEIDENTIFIER, function
hook.Add("InitPostEntity" , "You're all retarded and giving out incorrect advice" , ShowRules)
[/lua]
[QUOTE=|FlapJack|;27453109]Too much :downs: in this thread.
[editline]16th January 2011[/editline]
[lua]function ShowRules()
local DermaPanel = vgui.Create("DFrame")
DermaPanel:SetSize( 336, 215 )
DermaPanel:SetTitle("Welcome to Hellspawn's Fun Server!")
DermaPanel:SetVisible(true)
DermaPanel:SetDraggable(false)
DermaPanel:SetBackgroundBlur(true)
DermaPanel:ShowCloseButton(false)
DermaPanel:MakePopup()
DermaPanel:Center()
local DermaLabel = vgui.Create("DLabel")
DermaLabel:SetText( [[
THE RULES
1. Dont spam or build Contraptions that lag the Server.
2. Play nice, dont touch other Players Stuff without asking them.
3. Respect the Admins and they will respect you.
4. No random Deathmatch!!!
5. Type Accepted in the box below and click the OK button.
]] )
DermaLabel:SetParent(DermaPanel)
DermaLabel:SizeToContents()
DermaLabel:SetPos(10, 25)
local DermaLabel1 = vgui.Create("DLabel")
DermaLabel1:SetText("Read the rules first!")
DermaLabel1:SetParent(DermaPanel)
DermaLabel1:SizeToContents()
DermaLabel1:SetPos(230,185)
DermaLabel1:SetColor(Color(255,0,0))
DermaLabel1:SetVisible(false)
local DermaText = vgui.Create("TextEntry")
DermaText:SetParent(DermaPanel)
DermaText:SetSize(70,25)
DermaText:SetPos(98,180)
local DermaButton = vgui.Create("DButton")
DermaButton:SetParent(DermaPanel)
DermaButton:SetSize(50,25)
DermaButton:SetPos(173,180)
DermaButton:SetText("OK")
DermaButton.DoClick = function()
if DermaText:GetValue() == ("Accepted") then
DermaPanel:Close()
else
DermaLabel1:SetVisible(true)
end
end
end
concommand.Add("rules", ShowRules)
-- hook.Add(HOOK_TYPE , HOOK_UNIQUEIDENTIFIER, function
hook.Add("InitPostEntity" , "You're all retarded and giving out incorrect advice" , ShowRules)
[/lua][/QUOTE]
it still doesn't work... I believe it has something to do with the directory. i have uploaded it in an addon. maybe that is the problem?
Where is it in the addons file structure?
You may be missing an info.txt
Have you called AddCSLuaFile on the path?
Eg: addons/Some_Rules/lua/autorun/client/rules.lua
AddCSLuaFile("autorun/client/rules.lua")
[QUOTE=|FlapJack|;27459287]Have you called AddCSLuaFile on the path?
Eg: addons/Some_Rules/lua/autorun/client/rules.lua
AddCSLuaFile("autorun/client/rules.lua")[/QUOTE]
Maybe my earlier post wasn't so 'dumb', as you rated it, eh?
[QUOTE=Drakehawke;27453047]lua/autorun
He said before.
In which case you'll get lots of errors as the vgui library isn't available serverside, nor will the file be sent to the client.
Try something like this at the top:
[lua]
include( "thisfile.lua" )
if SERVER then -- only run this next bit on the server
AddCSLuaFile("thisfile.lua") -- make sure file is sent to client
hook.Add("PlayerInitialSpawn", "your hook name", function( ply ) -- Create a hook thats called when the player spawns, this isn't available clientside so we'll have to do it on the server and tell the client from there
SendUserMessage( "Init", ply ) -- Send a usermessage to the player
end)
return -- stop anything below this being ran serverside
end
-- put all your other code here
-- then instead of using hook.Add we want to hook to the usermessage we just sent from the server
usermessage.Hook( "Init", init )
[/lua][/QUOTE]
[QUOTE=Drakehawke;27459995]Maybe my earlier post wasn't so 'dumb', as you rated it, eh?[/QUOTE]
Your post is still dumb. You're networking from the server to tell the client that they spawned when you don't even need to.
[QUOTE=|FlapJack|;27459287]Have you called AddCSLuaFile on the path?
Eg: addons/Some_Rules/lua/autorun/client/rules.lua
AddCSLuaFile("autorun/client/rules.lua")[/QUOTE]
It STILL doesnt work D: i tried EVERYTHING!
-snip-
Use what flapjack posted in post #40
Or instead of using a hook, just find GM:InitialSpawn( ply ) ( I believe this is it, correct me if I'm wrong ) and then ply:RunConsoleCommand( "rules" )
[QUOTE=InfernalCookie;28094505]Or instead of using a hook, just find GM:InitialSpawn( ply ) ( I believe this is it, correct me if I'm wrong ) and then ply:RunConsoleCommand( "rules" )[/QUOTE]
You mean ply:ConCommand( "rules" )
Pshh.. amateurs.
[QUOTE=Derek_SM;28095596]You mean ply:ConCommand( "rules" )
Pshh.. amateurs.[/QUOTE]
[img]http://gyazo.com/ae001cb6092416908d75f33e1275ca6b.png[/img]
RunConsoleCommand works just as good......
Regardless, I am new anyways...
RunConsoleCommand is not a meta command, it gets called on the client you get called on, or if you run it on the server it's like doing game.ConsoleCommand.
[QUOTE=InfernalCookie;28116022]RunConsoleCommand works just as good......
Regardless, I am new anyways...[/QUOTE]
player:RunConsoleCommand() does not exist..So no it doesn't.
[QUOTE=Chocolate Unit;28135735]player:RunConsoleCommand() does not exist..So no it doesn't.[/QUOTE]
Shut up.
For OP:
You may want to use a timer thats set to 8 seconds or so, it happens that PostInitEntity is being called before the derma/vgui library has been loaded completly.
[QUOTE=Wizard of Ass;28140283]Shut up.[/QUOTE]
y u gotta b like dat D:
[QUOTE=Chocolate Unit;28140335]y u gotta b like dat D:[/QUOTE]
Because you are acting like an idiot.
Sorry, you need to Log In to post a reply to this thread.