JvIasterMind Posted October 22, 2012 Share Posted October 22, 2012 I am working on teaching myself Lua for modifying ET. So far, it has been going very well, but I ran into a problem that I am having a hard time figuring out. I'm trying to use the following function... clientnum = et.G_ClientNumberFromString( string ) Here is the code that I am using... function et_ClientCommand(clientNum, command) if et.trap_Argv(0) == "listclientnumber" then if et.trap_Argc() == 2 then local targetClientNum = et.G_ClientNumberFromString(et.trap_Argv(1)) et.trap_SendServerCommand(clientNum, string.format("cpm \"%d\"", targetClientNum)) else et.trap_SendServerCommand(clientNum, "cpm \"Error: Need two arguments!\"") end return 1 end return 0 end When I execute the command to run the above code (e.g. "/listclientnumber JvI" in my game console), ET gives an unknown command error due to the G_ClientNumberFromString line. Even if I manually put a string instead of using the argument for the parameter, I still have this problem. If I remove that line and modify the line below it to just print text, it works exactly as intended. The client number function was directly from the lua.html that's located in the silent zip archive. Am I using it incorrectly, or is the documentation possibly out of date? My second question is what is the best way to print text to a clients console? I noticed cpm acts just like echo and also flashes the text on the left side of the main screen. I'd prefer if there was a way of only printing to the console instead so my custom command behaves closer to the built in admin commands. For my last question, is there any way to define standard admin commands that start with '!' instead of the console commands that start with '/' through Lua. I know you can map the admin commands to the console commands, but then I need to restrict the level in the script as well as the shrubbot.cfg file to prevent everyone from using it. Or perhaps there is another way to do this? Thanks,JvIasterMind Quote Link to comment Share on other sites More sharing options...
Sol Posted October 22, 2012 Share Posted October 22, 2012 When I execute the command to run the above code (e.g. "/listclientnumber JvI" in my game console), ET gives an unknown command error due to the G_ClientNumberFromString line. Even if I manually put a string instead of using the argument for the parameter, I still have this problem. If I remove that line and modify the line below it to just print text, it works exactly as intended. The client number function was directly from the lua.html that's located in the silent zip archive. Am I using it incorrectly, or is the documentation possibly out of date?G_ClientNumberFromString is bugged, you can do it by yourself or just search algorithm for it. My second question is what is the best way to print text to a clients console? I noticed cpm acts just like echo and also flashes the text on the left side of the main screen. I'd prefer if there was a way of only printing to the console instead so my custom command behaves closer to the built in admin commands.this is my small API ( http://mygamingtalk.com/forums/topic/2018-small-lua-server-api/?do=findComment&comment=8157 ) a lot of easier with it but you can also use et.trap_SendServerCommand( clientnum, 'print "text"' ) it's exactly what do you want "print" printing text into client's console.For my last question, is there any way to define standard admin commands that start with '!' instead of the console commands that start with '/' through Lua. I know you can map the admin commands to the console commands, but then I need to restrict the level in the script as well as the shrubbot.cfg file to prevent everyone from using it. Or perhaps there is another way to do this?It's possible to use shrubbot into LUA too, but its some work to do then you have to prase it and use it. Quote Link to comment Share on other sites More sharing options...
Management gaoesa Posted October 22, 2012 Management Share Posted October 22, 2012 Would it be possible to use Lua calls in shrubbot custom commands? Maybe trapping server console commands in Lua script? EDIT:It looks like the et.G_ClientNumberFromString would be actually just et.ClientNumberFromString. Does that work? Quote Link to comment Share on other sites More sharing options...
Sol Posted October 22, 2012 Share Posted October 22, 2012 It looks like the et.G_ClientNumberFromString would be actually just et.ClientNumberFromString. Does that work?et.ClientNumberFromString works indeed so, there is mistake in doscs.Would it be possible to use Lua calls in shrubbot custom commands? Maybe trapping server console commands in Lua script?something like shrubbot file but for lua, because shrubbot would be have errors probably yes? Quote Link to comment Share on other sites More sharing options...
Management gaoesa Posted October 22, 2012 Management Share Posted October 22, 2012 I was thinking something like this: [command] command = example exec = mycommand param1 param2 desc = Invoking Lua from custom commands levels = 0 1 2 3 4 5 And in the Lua script somthing like function et_ConsoleCommand() -- check if it is a command to intercept -- if so, read parameters and execute the associated Lua functions end About the ClientNumberFromString, it seems to be the same thing with the ETPub. I'm wondering if it should be fixed to match the documentation or if documentation should be fixed to match the current function name. It depends about which syntax is more used and changing it would cause bigger problems. Quote Link to comment Share on other sites More sharing options...
JvIasterMind Posted October 22, 2012 Author Share Posted October 22, 2012 this is my small API ( http://mygamingtalk....-api/#entry8157 ) a lot of easier with it but you can also use et.trap_SendServerCommand( clientnum, 'print "text"' ) it's exactly what do you want "print" printing text into client's console. Your API looks very nice! I just skimmed the file and already learned a lot! For now, though, I am going to start by manually coding so I learn it better. I'll look into it again after I feel more comfortable with the scripting. et.ClientNumberFromString works indeed so, there is mistake in doscs. That is great to know! I know I could have coded something similar myself, but I figure it is better not to reinvent the wheel. I'll play with that command later today. I was thinking something like this: [command] command = example exec = mycommand param1 param2 desc = Invoking Lua from custom commands levels = 0 1 2 3 4 5 And in the Lua script somthing like function et_ConsoleCommand() -- check if it is a command to intercept -- if so, read parameters and execute the associated Lua functions end About the ClientNumberFromString, it seems to be the same thing with the ETPub. I'm wondering if it should be fixed to match the documentation or if documentation should be fixed to match the current function name. It depends about which syntax is more used and changing it would cause bigger problems. Is that functionality already available, or are you thinking of possibly adding it? Either way, I think that would be great functionality to have because the '/' commands feel kind of awkward in silEnT and seem to be a lot less flexible. Just out of curiosity, I am guessing that et_ConsoleCommand() intercepts rcon commands and server console commands? Would this mean you would be able to also run the Lua script through rcon? Quote Link to comment Share on other sites More sharing options...
Management gaoesa Posted October 22, 2012 Management Share Posted October 22, 2012 Is that functionality already available, or are you thinking of possibly adding it? Either way, I think that would be great functionality to have because the '/' commands feel kind of awkward in silEnT and seem to be a lot less flexible. The custom commands are an existing feature. http://mygamingtalk.com/wiki/index.php/Silent_Shrubbot#shrubbot.cfg Just out of curiosity, I am guessing that et_ConsoleCommand() intercepts rcon commands and server console commands? Would this mean you would be able to also run the Lua script through rcon? That is precisely what I was thinking. I'm not sure what you mean by runing Lua scripts through rcon, but there is no rcon command to execute scripts. However, the script that is loaded on map start can be triggered to do things. Quote Link to comment Share on other sites More sharing options...
Sol Posted October 22, 2012 Share Posted October 22, 2012 Just out of curiosity, I am guessing that et_ConsoleCommand() intercepts rcon commands and server console commands? Would this mean you would be able to also run the Lua script through rcon?What do you mean exactly, et_ConsoleCommand() callback is looking for cmds via rcon only.I was thinking something like this: [command] command = example exec = mycommand param1 param2 desc = Invoking Lua from custom commands levels = 0 1 2 3 4 5 And in the Lua script somthing like function et_ConsoleCommand() -- check if it is a command to intercept -- if so, read parameters and execute the associated Lua functions end Yea, this is nice idea too. Quote Link to comment Share on other sites More sharing options...
JvIasterMind Posted October 22, 2012 Author Share Posted October 22, 2012 Is there any way you could create a wiki section for the lua api? The documentation for the api is pretty poor, especially when trying to find out what the available fields are in the gentity struct. The best resource I found was looking at etpub's source code directly (and that isn't commented very well). I think it would be a huge benefit to the ET community to have better documentation for this and all in one place. If you do create the section in the wiki, I'd be willing to help populate it with information and add examples as I learn this stuff if you would be willing to give me editing rights. Quote Link to comment Share on other sites More sharing options...
Management gaoesa Posted October 22, 2012 Management Share Posted October 22, 2012 That is a good suggestion. The major problem with the current documentation is that it is describing the differences to the ETPro's documentation. http://wolfwiki.anime.net/index.php/Lua_Mod_API Quote Link to comment Share on other sites More sharing options...
JvIasterMind Posted October 22, 2012 Author Share Posted October 22, 2012 (edited) The custom commands are an existing feature. http://mygamingtalk....ot#shrubbot.cfg I know about the custom commands already... I was actually asking about the calling a lua function through the exec line like in your example. Is that functionality available currently? That is precisely what I was thinking. I'm not sure what you mean by runing Lua scripts through rcon, but there is no rcon command to execute scripts. However, the script that is loaded on map start can be triggered to do things. I meant if you run the same command as the exec line through rcon, it would have the exact same effect of running the script, correct? I was just wondering how et_ConsoleCommand() worked, since I haven't looked into it yet. Edited October 22, 2012 by JvIasterMind Quote Link to comment Share on other sites More sharing options...
JvIasterMind Posted October 22, 2012 Author Share Posted October 22, 2012 That is a good suggestion. The major problem with the current documentation is that it is describing the differences to the ETPro's documentation. http://wolfwiki.anim...php/Lua_Mod_API Couldn't the documentation cover the etpro documentation as well as the changes? It would be a lot better if all of it is in one place instead of needing to check both sources independently. Quote Link to comment Share on other sites More sharing options...
Sol Posted October 22, 2012 Share Posted October 22, 2012 I know about the custom commands already... I was actually asking about the calling a lua function through the exec line like in your example. Is that functionality available currently?something like this [command] command = ammo exec = lua ammo desc = bla bla bla levels = 0 1 2 3 4 5 function et_ConsoleCommand( cmd ) -- <-- there is a cmd if cmd == "lua" then -- commands here if et.trap_Argv( 1 ) == "ammo" then et.gentity_set( tonumber(et.trap_Argv( 2 )), "ps.ammo", tonumber(et.trap_Argv( 3 )) ) -- it needs 2 extra parametrs or just use et_ClientCommand callback end end end Quote Link to comment Share on other sites More sharing options...
JvIasterMind Posted October 22, 2012 Author Share Posted October 22, 2012 something like this [command] command = ammo exec = lua ammo desc = bla bla bla levels = 0 1 2 3 4 5 function et_ConsoleCommand( cmd ) -- <-- there is a cmd if cmd == "lua" then -- commands here if et.trap_Argv( 1 ) == "ammo" then et.gentity_set( tonumber(et.trap_Argv( 2 )), "ps.ammo", tonumber(et.trap_Argv( 3 )) ) -- it needs 2 extra parametrs or just use et_ClientCommand callback end end end Nice! So we can do that already? I'll experiment with it later today! Quote Link to comment Share on other sites More sharing options...
Management gaoesa Posted October 22, 2012 Management Share Posted October 22, 2012 Parameter substitution should also work. [command] command = ammo exec = lua ammo [1] desc = bla bla bla levels = 0 1 2 3 4 5 The benefit of this approach is that you can use the inbuilt admin system to control who has access to the commands and the commands also work in the exact same way as inbuilt shrubbot commands. I.e. no need to handle admin levels, console writes and chat writes in scripts. The downside is that there is some amount of replication and dependencies between shrubbot.cfg and Lua scripts. Nice! So we can do that already? I'll experiment with it later today! That should work. Let us know how it works out. Quote Link to comment Share on other sites More sharing options...
JvIasterMind Posted October 22, 2012 Author Share Posted October 22, 2012 Quick question: In defining a command like this, how do you get the clientNum that executed the command. Is it just the next unused parameter? So if the exec line was "exec = lua ammo [1]", the clientNum would be in "et.trap_Argv(3)"? Quote Link to comment Share on other sites More sharing options...
Management gaoesa Posted October 22, 2012 Management Share Posted October 22, 2012 et.trap_Argv(0) = the actual command, in this case "lua"et.trap_Argv(1) = ammoet.trap_Argv(2) = [1] Quote Link to comment Share on other sites More sharing options...
JvIasterMind Posted October 22, 2012 Author Share Posted October 22, 2012 I understand that part, but can you also get the clientNum of the player that executed the command? Maybe my question is better served with a simple example. Lets say that you want all players with level 2, 4, and 5 to have a command called !sayname. Now, lets define !sayname as a command that does a global chat (from the player that executed the command) of the name of the player in a slot that was passed as a parameter. Here is the code I would start with (following the examples in this thread)... [command] command = sayname exec = sayname [1] desc = bla bla bla levels = 2 4 5 function et_ConsoleCommand(command) if et.trap_Argv(0) == "sayname" then if et.trap_Argc() == 2 then local targetSlotNum = et.trap_Argv(1) local targetName = et.gentity_get(targetSlotNum, "pers.netname") local clientNum = ??? -- How do I get this? et.G_Say(clientNum, et.SAY_ALL, targetName) else -- Error: Need two parameters end return 1 end return 0 end Quote Link to comment Share on other sites More sharing options...
Sol Posted October 22, 2012 Share Posted October 22, 2012 (edited) Like I said, you have to use 2 parametrs or just get it from et_ClientCommand() callback.for example: clientnum = 0 -- global variable!!! function et_ClientCommand( num, cmd ) -- for example, sayname is also simillar command ( !sayname ) if et.trap_Argv( 1 ) == "!sayname" then clientnum = num end end function et_ConsoleCommand(command) if et.trap_Argv(0) == "sayname" then if et.trap_Argc() == 2 then local targetSlotNum = et.trap_Argv(1) local targetName = et.gentity_get(targetSlotNum, "pers.netname") local clientNum = clientnum et.G_Say(clientNum, et.SAY_ALL, targetName) else -- Error: Need two parameters end return 1 end return 0 end but it works for !sayname command only, you can also check for last client who used command like: function et_ClientCommand( num, cmd ) -- check for silent commands too if string.find(cmd, "!") or string.find(et.trap_Argv( 1 ), "!") then clientnum = num end end Edited October 22, 2012 by Sol Quote Link to comment Share on other sites More sharing options...
JvIasterMind Posted October 22, 2012 Author Share Posted October 22, 2012 (edited) Oh, so you do both the et_ClientCommand() and the et_ConsoleCommand() in the same script and only use the et_ClientCommand() function to set the clientNum? I suppose then you would want to return 0 in the et_ClientCommand() so it doesn't appear to be a valid command to the client? And in your example, shouldn't it be et.trap_Argv(0) instead of et.trap_Argv( 1 )? So the full code would be... [command] command = sayname exec = sayname [1] desc = Say a player's name levels = 2 4 5 clientNum = 0 function et_ClientCommand(num, cmd) if et.trap_Argv(0) == "sayname" then clientNum = num end return 0 end function et_ConsoleCommand(cmd) if et.trap_Argv(0) == "sayname" then if et.trap_Argc() == 2 then local targetSlotNum = et.trap_Argv(1) local targetName = et.gentity_get(targetSlotNum, "pers.netname") et.G_Say(clientNum, et.SAY_ALL, targetName) else et.trap_SendServerCommand(clientNum, 'print "Error: Need two parameters"') end return 1 end return 0 end Edited October 22, 2012 by JvIasterMind Quote Link to comment Share on other sites More sharing options...
Sol Posted October 22, 2012 Share Posted October 22, 2012 (edited) Oh, so you do both the et_ClientCommand() and the et_ConsoleCommand() in the same script and only use the et_ClientCommand() function to set the clientNum? I suppose then you would want to return 0 in the et_ClientCommand() so it doesn't appear to be a valid command to the client? And in your example, shouldn't it be et.trap_Argv(0) instead of et.trap_Argv( 1 )?Yes, but anyway better to make your own shrubbot for commands etc. than this because of comfort.My solution solves this problem but its not good enough, you can't be sure about clientnum completly in this case. Edited October 22, 2012 by Sol Quote Link to comment Share on other sites More sharing options...
Management gaoesa Posted October 22, 2012 Management Share Posted October 22, 2012 There is a replacement for the client number. I couldn't find it documented, but I remembered there was a bug report about it. [command] command = sayname exec = sayname [1] [i] desc = Say a player's name levels = 2 4 5 The is replaced with the client number of the calling client. EDIT:Now added into the Wiki documentation. Quote Link to comment Share on other sites More sharing options...
JvIasterMind Posted October 22, 2012 Author Share Posted October 22, 2012 There is a replacement for the client number. I couldn't find it documented, but I remembered there was a bug report about it. [command] command = sayname exec = sayname [1] [i] desc = Say a player's name levels = 2 4 5 The is replaced with the client number of the calling client. EDIT:Now added into the Wiki documentation. OK, that is great news! Seems like a much better solution than using et_ClientCommand() to set a global variable. I'll experiment with all of this in a few hour. Quote Link to comment Share on other sites More sharing options...
JvIasterMind Posted October 24, 2012 Author Share Posted October 24, 2012 That worked really well gaoesa! The only behavior that I thought was a bit strange was that if you have multiple parameters in the exec line the user does not specify the last one, it passes the replacement string as that parameter. So, if you have the line exec = saynameplusmore [1] [2], and you plan for allowing the user to leave off the second parameter (so saynameplusmore would act like sayname), et.trap_Argv(3) would end up containing "[2]" by default (which makes et.trap_Argc() equal to 4 in both cases). That behavior is different from the standard et_ClientCommand() behavior, so it's worth noting. Quote Link to comment Share on other sites More sharing options...
Management gaoesa Posted October 24, 2012 Management Share Posted October 24, 2012 Indeed that is buggy. Will look into fixing it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.