• Running a clientside script on player spawn
    10 replies, posted
Hi all, Im trying to make a basic webpage popup when a player spawns on the server. Before I get carried away, im trying to get the basics to work first. My current files look like this: addons/test/lua/autorun/client/cl_test.lua [CODE]net.Receive('openthetest', function() chat.AddText( "test" ) end)[/CODE] addons/test/lua/autorun/client/sv_test.lua [CODE]util.AddNetworkString('openthetest') hook.Add( "PlayerInitialSpawn", "opentestonspawn", OpenTest) function OpenTest(ply) net.Start('openthetest') net.Send(ply) end[/CODE]
Is that code not working?
Unfortunately not. No script errors. Typo: addons/test/lua/autorun/client/sv_test.lua is addons/test/lua/autorun/server/sv_test.lua
Add a timer. I have a feeling that the code is running on the client before the chat box has had the chance of initialize.
You don't need to network anything if you only need the client to do it. Just run the code directly on the client.
Still nothing. Server side code now looks like this: [code]util.AddNetworkString('openthetest') hook.Add( "PlayerInitialSpawn", "opentestonspawn", OpenTest) function OpenTest(ply) timer.Simple( 10, function() net.Start('openthetest') net.Send(ply) end ) end[/code]
All you need to do is this clientside: [code]local frame = vgui.Create("DFrame") frame:SetSize(100, 100)[/code]
[code][ERROR] addons/test/lua/autorun/client/cl_test.lua:5: attempt to index local 'frame' (a nil value) 1. unknown - addons/test/lua/autorun/client/cl_test.lua:5 [/code] Another problem is that I will need to use serverside either way. When I get it working, I only want the panel to open for certain ulx usergroups.
[QUOTE=joealdred;51808561][code][ERROR] addons/test/lua/autorun/client/cl_test.lua:5: attempt to index local 'frame' (a nil value) 1. unknown - addons/test/lua/autorun/client/cl_test.lua:5 [/code] Another problem is that I will need to use serverside either way. When I get it working, I only want the panel to open for certain ulx usergroups.[/QUOTE] You don't need the server for checking what usergroup the client is in. [url]http://wiki.garrysmod.com/page/Player/IsUserGroup[/url]
Your original code was not working because you were adding a hook with a nil function, so OpenTest was not running. Unlike some scripting languages, lua does not scan through the file and declare all globals before code execution. OpenTest was not defined until line 5 of your code, but you tried using it in the hook on line 3 (if you replaced line 3 with print(OpenTest) it would be nil instead of a function pointer). To fix the issue move your hook.Add to below the function declaration. [QUOTE=joealdred;51808561][code][ERROR] addons/test/lua/autorun/client/cl_test.lua:5: attempt to index local 'frame' (a nil value) 1. unknown - addons/test/lua/autorun/client/cl_test.lua:5 [/code] Another problem is that I will need to use serverside either way. When I get it working, I only want the panel to open for certain ulx usergroups.[/QUOTE] Can you post the code for your cl_init.lua? Also, you can restrict the menu opening to certain ULX Usergroups clientside as Player.IsUserGroup is networked.
Thanks zzaacckk, Works like a charm! Now time to add all the other stuff!
Sorry, you need to Log In to post a reply to this thread.