• Execute function on client?
    12 replies, posted
I want a function to be called on all clients aswell as the server when i do a concommand, how would i do that? This is what i have so far: [code] function test() //this is only called on the server i want it to also be client or something similar end concommand.Add("test_command", test) [/code]
[lua]for _, v in pairs( player.GetAll( ) ) do v:ConCommand( "hai" ) end RunConsoleComand( "hai" )[/lua]
[QUOTE=Overv;16816278][lua]for _, v in pairs( player.GetAll( ) ) do v:ConCommand( "hai" ) end RunConsoleComand( "hai" )[/lua][/QUOTE] I tried something similar to that earlier and it says something like "ConCommand Blocked!" in the console [code] if SERVER then function ctest() print("ranhere") end concommand.Add("ctest", ctest) end function test() for k,v in pairs(player.GetAll()) do v:ConCommand("ctest") end end concommand.Add("test_console", test) [/code]
Then do: [lua]BroadcastLua( "LocalPlayer( ):ConCommand( \"ctest\" )" )[/lua]
That doesnt seem to work, i tried it and it calls the ctest() function but it still isnt client side(it doesnt print("ranhere2") in the console) [code] if SERVER then function ctest() print("ranhere") if CLIENT then print("ranhere2") end end concommand.Add("ctest", ctest) end function test() BroadcastLua( "LocalPlayer( ):ConCommand( \"ctest\" )" ) end concommand.Add("test_console", test) [/code]
Why not just call the function directly since it's a global? [lua] BroadcastLua( "ctest( )" ) [/lua]
Instead of suggesting that the guy essentially use SendLua that he should actually learn the proper way of doing it and use a umsg that when hooked on the client, runs his code.
What is wrong with using SendLua or BroadcastLua ninjerss?
Ok that works perfectly, thx for your help.
[QUOTE=ninjerss;16817912]Instead of suggesting that the guy essentially use SendLua that he should actually learn the proper way of doing it and use a umsg that when hooked on the client, runs his code.[/QUOTE] The only time it's a really problem is when the user has the opportunity to inject their own code. Seeing as they do not in this situation, it should be fine.
[QUOTE=Unrealomega;16833259]The only time it's a really problem is when the user has the opportunity to inject their own code. Seeing as they do not in this situation, it should be fine.[/QUOTE] we can inject before sendlua, and we can even block sendlua, besides that, this is the code that should be used instead of sendlua spam. SERVER [code] local function RunTest() --shit u wanna do NWRunTest() end umsg.PoolString("RunTest") function NWRunTest() umsg.Start("RunTest",0) umsg.End() end [/code] CLIENT [code] local function RunTest() --shit u wanna do end usermessage.Hook("RunTest",function (um) RunTest() end) [/code]
[QUOTE=LauIsFun;16837335]we can inject before sendlua, and we can even block sendlua, besides that, this is the code that should be used instead of sendlua spam. SERVER [code] local function RunTest() --shit u wanna do NWRunTest() end umsg.PoolString("RunTest") function NWRunTest() umsg.Start("RunTest",0) umsg.End() end [/code] CLIENT [code] local function RunTest() --shit u wanna do end usermessage.Hook("RunTest",function (um) RunTest() end) [/code][/QUOTE] You called the function on the server before declaring it.
[QUOTE=|FlapJack|;16839859]You called the function on the server before declaring it.[/QUOTE] I didn't call it yet. it's in the function chunk, durp
Sorry, you need to Log In to post a reply to this thread.