• running cs lua through server side file
    8 replies, posted
i'd like learn how to make a clientside lua file run on a players chat message for example, writing !help would open a cs lua file. if anyone has any examples themselves or know sites that could make this function more clear, it would be appreciated.
You could just use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/OnPlayerChat]OnPlayerChat[/url] and check if the text is !help, then just run whatever code you want...you probably shouldn't be trying to run a CSLua file from a client because that could be exploited pretty easily...unless you want that to happen, then you could use something like [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/RunString]RunString[/url] after doing [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/File/Read]File:Read[/url] on the CSLua file What are you trying to do? There's probably a less dangerous alternative [CODE] hook.Add( 'OnPlayerChat', 'UNIQUE_NAME', function( ply, txt, team, dead ) if txt == '!help' then --put the code here or do whatever you want to read the lua file end return false -- this stops the chat message from being surpressed end ) [/CODE]
let me try to explain more, i have a client side script that ive made, and i want it to open on the player once they've typed !help sorry for any confusion, trying your example now.
Well, can't you just put the script inside the 'if' statement? [CODE] hook.Add( 'OnPlayerChat', 'UNIQUE_NAME', function( ply, txt, team, dead ) if txt == '!help' then --Insert the code you want to run end return false end ) [/CODE] It'd be a lot easier to put the contents of the file your script is in inside the 'if' statement than trying to actually RUN the whole file
i did the following example and put my derma code into the if statement, put it into E:\garry\garrysmod\addons\Hmenu\lua\server, and it still doesn't seem to be working
That's because [URL="https://wiki.garrysmod.com/page/GM/OnPlayerChat"]OnPlayerChat[/URL] is a clientside hook. I thought you said your script was clientside? [QUOTE=FelixCrimson;49567760]i have a [B]client side[/B] script that ive made, and i want it to open on the player once they've typed !help[/QUOTE] [QUOTE=FelixCrimson;49567705]i'd like learn how to make a [B]clientside[/B] lua file run on a players chat message[/QUOTE] If you want it to work serverside, you should use [URL="https://wiki.garrysmod.com/page/GM/PlayerSay"]PlayerSay[/URL] instead: [CODE] hook.Add( 'PlayerSay', 'UNIQUE_NAME', function( ply, text, team ) if text == '!help' then --Your code here end end ) [/CODE] Also, try putting the file in this file path instead: [CODE] C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod\addons\Hmenu\lua\autorun\server [/CODE] Perhaps then it'll work. I've never heard of GMod running any Lua files from the E: drive...
I think you're over-complicating it - the net library would do fine
Why use the net library when there are two versions of the PlayerSay function- one clientside and one serverside?
Yeah if it's not using any data generated from server-side code, keep it all client-side.
Sorry, you need to Log In to post a reply to this thread.