• hook.add doesn't work!
    40 replies, posted
[QUOTE=Wizard of Ass;28140283]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] Ok, but where do i put that timer? On top of the whole script or the line above the hook? nevermind. sorry i just started with lua! D: [editline]19th February 2011[/editline] it doesnt help. I dont even get the console commands to work! it just says unknown command!
post whole code
[lua]AddCSLuaFile("autorun/client/da_rules.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() LocalPlayer():ConCommand("say /me accepted the rules.") 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]
It's c-unit, what do you expect?
[QUOTE=Loures;28150990]It's c-unit, what do you expect?[/QUOTE] what is c-unit? (im seriously a lua beginner)
try changing the path of the file to the root lua folder for your addon < I'm assuming this is an addon>. then add a new lua file in the root autorun call "rulestarter.lua" and put this in it : [lua] if SERVER then print("Sending client the files \n"); AddCSLuaFile("autorun/rulestarter.lua"); AddCSLuaFile("da_rules.lua"); end if CLIENT then include( "da_rules.lua" ) end [/lua] from what i can tell, the problem is the code is never run on the server, so there's no way for the server to send the file to the client using the addcsluafile you have on the first line.
AddCSLuaFile is a server sided function. [editline]19th February 2011[/editline] [QUOTE=>_> Ubercake;28152562]what is c-unit? (im seriously a lua beginner)[/QUOTE] I'm a c-unit [editline]19th February 2011[/editline] There is no need to AddCSLuaFile it if it is going in your autorun/client.
[QUOTE=Chocolate Unit;28152897] I'm a c-unit [/QUOTE] :doh: [editline]20th February 2011[/editline] [QUOTE=meka/sniper;28152725]try changing the path of the file to the root lua folder for your addon < I'm assuming this is an addon>. then add a new lua file in the root autorun call "rulestarter.lua" and put this in it : [lua] if SERVER then print("Sending client the files \n"); AddCSLuaFile("autorun/rulestarter.lua"); AddCSLuaFile("da_rules.lua"); end if CLIENT then include( "da_rules.lua" ) end [/lua] from what i can tell, the problem is the code is never run on the server, so there's no way for the server to send the file to the client using the addcsluafile you have on the first line.[/QUOTE] Isn't the rulestarter file supposed to go into the autorun folder instead of the root folder? because of this: "AddCSLuaFile("autorun/rulestarter.lua");"
What i meant by that was just put into lua/autorun < i meant root in terms of just the autorun folder, not inside of a client or server folder>
[QUOTE=Chocolate Unit;28152897]There is no need to AddCSLuaFile it if it is going in your autorun/client.[/QUOTE] Oh really? [editline]20th February 2011[/editline] [lua]if SERVER then AddCSLuaFile("autorun/da_rules.lua") return; end 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() LocalPlayer():ConCommand("say /me accepted the rules.") 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] To be saved in autorun/da_rules.lua [editline]20th February 2011[/editline] Now then - the rest of you. Please, only post if you know what you're talking about. Nothing can be more annoying to a beginner than another beginner talking bullshit.
[QUOTE=|FlapJack|;28156453]Oh really? [editline]20th February 2011[/editline] [lua]if SERVER then AddCSLuaFile("autorun/da_rules.lua") return; end 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() LocalPlayer():ConCommand("say /me accepted the rules.") 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] To be saved in autorun/da_rules.lua [editline]20th February 2011[/editline] Now then - the rest of you. Please, only post if you know what you're talking about. Nothing can be more annoying to a beginner than another beginner talking bullshit.[/QUOTE] Thanks. It finally works!
Sorry, you need to Log In to post a reply to this thread.