Jump to content

Lua API Questions


JvIasterMind
 Share

Recommended Posts

I found another area giving me problems in the admin commands with Lua. It seems like it is not possible to send text with spaces as a single parameter (even enclosing the text in quotes). Instead, the game uses the part after the space as the next parameter and seems to bump all the parameters to the next one.

 

Here is a situation where this behavior would be pretty troublesome. Using the example of !sayname that we have been using, if the target player is named "a i" or similar, you probably wouldn't be able to target that player because passing 'a' or 'i' as the partial name will almost certainly give multiple results. In this case, it would be important to be able to pass ""a i"" as a parameter. Is this because the command line cannot read the quotation marks or is it that they are stripped from the command line when passed to the function?

Link to comment
Share on other sites

Thanks for looking into it! Would you be able to fix that behavior so we can use quotes to allow spaces in arguments?

 

I just tested how arguments are handled using et_ClientCommand() and the quotes work perfectly to allow spaces in the argument. I also discovered that arguments can begin or end with a space (or multiple spaces) as well. I feel that the shrubbot commands should behave in the same way.

Link to comment
Share on other sites

What's the best way to detect if a client is connected to a slot?

 

Currently, I'm getting the silEnT guid using et.gentity_get(slot, "sess.guid") and checking that its length is greater than 0. However, I think there is another bug related to this. Occasionally, a client will disconnect, but I can still pull all of their gclient information from the slot number as if they are still on the server. This makes my current method somewhat unreliable at the moment. It doesn't happen very often (maybe once every 40 disconnects or so). When it does occur, it seems to last until the next map is loaded or until another player connects to the affected slot. Perhaps it's related to a client disconnecting using a more unconventional method? I'll try to do some more testing tonight to see if I can further pinpoint what is causing it.

Link to comment
Share on other sites

However, I think there is another bug related to this. Occasionally, a client will disconnect, but I can still pull all of their gclient information from the slot number as if they are still on the server.

Yes, this is bug indeed probably related with zombie_time/timeout that Disconnect callback is not executed sometimes.

Link to comment
Share on other sites

  • Management
Yes, this is bug indeed probably related with zombie_time/timeout that Disconnect callback is not executed sometimes.

 

Incorrect. The client data is cleared when new clients connect. The Lua does not check if the player is connected or not when accessing the data. You can check if "pers.connected" has exact value "2".

 

et.gentity_get(slot, "pers.connected")

 

Maybe this is a place to extend the Lua a bit. With a new function for checking the clientnumber. Additional info could be if the client is bot also. I don't think that that information is available anywhere.

Link to comment
Share on other sites

et.gentity_get(slot, "ps.ping") < 999 and et.gentity_get(slot, "ps.ping") > 0 seems good

 

This is why we should have the gentity fields documented somewhere. Creative solution!

 

 

Incorrect. The client data is cleared when new clients connect. The Lua does not check if the player is connected or not when accessing the data.

 

Are you saying that the client data is intended to be accessible after a client disconnect? Any clue why it is only sometimes but not often?

 

You can check if "pers.connected" has exact value "2".

et.gentity_get(slot, "pers.connected")

 

This is exactly what I was looking for! Thanks!

 

Maybe this is a place to extend the Lua a bit. With a new function for checking the clientnumber. Additional info could be if the client is bot also. I don't think that that information is available anywhere.

 

I'm all for any additions to the lua api. It is a lot more powerful than I initially imagined. I've had a lot of fun learning it!

Link to comment
Share on other sites

I was wrong. No matter how a person disconnects, the gclient information stays available until another player uses the slot or the map is restarted. I just didn't notice that it was always happening because we had a lot of people shuffling in and out of the server when I was testing the behavior.

 

Luckily, pers.connected does show the correct number... 2 when a player is connected and 0 after they disconnect.

 

This will be fine for my purpose, but is this the intended behavior? I would think that the info would clear when a player disconnects from the server. Perhaps the intent was for players that disconnect and reconnect right away (maybe during disconnected downloads or something)?

Link to comment
Share on other sites

  • Management
Perhaps the intent was for players that disconnect and reconnect right away (maybe during disconnected downloads or something)?

 

I don't know the intent. This is how it has been in the original source as well. But one reason for this could be that it is easy to ensure everything is cleared when new client connects.

 

This is why we should have the gentity fields documented somewhere. Creative solution!

 

I have added the bone of the Lua document to the Wiki. It is intended to be a complete reference of the Lua API for silEnT mod. I would give you the permissions to the Wiki if I knew how. For adding documentation and fixing English.

Link to comment
Share on other sites

I don't know the intent. This is how it has been in the original source as well. But one reason for this could be that it is easy to ensure everything is cleared when new client connects.

Since pers.connected is updated with the disconnect (I noticed that sess.sessionTeam changes as well), I would guess that it would be easy to clear all the info at that time. Although, this shouldn't be a problem as long as pers.connected continues to be reliable.

 

I have added the bone of the Lua document to the Wiki. It is intended to be a complete reference of the Lua API for silEnT mod. I would give you the permissions to the Wiki if I knew how. For adding documentation and fixing English.

Awesome! I skimmed over it and it looks like you have a great start!

 

As for the permissions, my guess is somebody will have to create a wiki account for me since it doesn't seem to use the forum account (says my username isn't registered). I'd definitely love to help out on it if you can figure it out!

Link to comment
Share on other sites

Is there a way to modify the map game rules through lua (such as wm_axis_respawntime and wm_allied_respawntime)? I would like to be able to modify the spawntimes while the map is in progress and using the g_redlimbotime and g_bluelimbotime cvars only allow you to modify the times during the InitGame callback.
Link to comment
Share on other sites

Is there a way to modify the map game rules through lua (such as wm_axis_respawntime and wm_allied_respawntime)? I would like to be able to modify the spawntimes while the map is in progress and using the g_redlimbotime and g_bluelimbotime cvars only allow you to modify the times during the InitGame callback.

 

Anybody? I would have thought that there would be a way to modify the times through the server console, but I am having a hard time finding any info on how to do this online. If it isn't currently possible, would the silEnT devs consider adding a function to be able to modify these types of variables to the lua api?

 

I'll give a little background on what I am working on. I'm trying to use lua to decrease the limbo times of every map by a universal factor. I want it so we don't need to use customized mapscripts every time we add new maps to the server (especially, since we tend to cycle our maps quite a bit). Modifying the g_redlimbotime and g_bluelimbotime cvars during the InitGame callback works great except for maps that change the limbo times in the mapscript for objectives such as building a CP. I would like to be able to decrease those objective modified times as well to keep everything consistent.

Link to comment
Share on other sites

  • Management
Sorry, I started looking this but forgot it. Indeed these values can't be changed from rcon. For some reason these cvars are latched. However, it is possible using et.trap_Cvar_Set function. Using the g_redlimbotime and g_bluelimbotime works.
Link to comment
Share on other sites

  • Management
Additionally if you want to override the script defined spawn times, the g_userAxisRespawnTime and g_userAlliedRespawnTime will do that. Thoe spawn times are set always when the scrip attempts to change the spawn times. If they are set to above 1. These cvars use seconds, not milliseconds unlike the g_redlimbotime and g_bluelimbotime. I'm not really sure what you're trying to do. But if you want to make it dynamic, then there is no way to know the original times after they are changed. I.e. you need to save the original times in the script. However, if the mapscript changes the time to the value you have set yourself, there is no way to know it has done that and then the re-adjustment would perhaps not trigger.
Link to comment
Share on other sites

  • 2 weeks later...

Sorry, I started looking this but forgot it. Indeed these values can't be changed from rcon. For some reason these cvars are latched. However, it is possible using et.trap_Cvar_Set function. Using the g_redlimbotime and g_bluelimbotime works.

 

You where correct. I had a bug in my code that was making it appear like this wasn't possible. I've fixed it now and it works perfectly.

 

Thanks gaoesa!

Link to comment
Share on other sites

  • 3 weeks later...

Is there a way to get a client cvar value through lua (similar to cvarvalue = et.trap_Cvar_Get( cvarname ))? I didn't see a dedicated command, so perhaps it can be done through et.trap_SendConsoleCommand( when, command )? What I would like to do is allow clients to configure some settings related to lua scripts I am writing. I figure that the client setting some cvars for configuration and having the lua script read them would be a good way to do this.

Link to comment
Share on other sites

Anybody know the answer? I tried searching to see if you can get client cvar values through rcon and haven't had any luck. It seems that rcon is not documented very well in the ET community since many of the sites that used to be good are offline now.

 

If it isn't currently possible, maybe it would be a good feature to add to the lua api. One thing to consider, however, is do you think that being able to read all cvars could potentially pose a little bit of a security risk for clients if they have there private password or rcon password set on there command line in their ET shortcut? If that's the case, a couple solutions could be to read all cvars starting with "lua_" or just keep any security related cvars disabled. Otherwise, it would be pretty useful in some cases for lua to be able to read all cvars. An example of this could be on a limited lives server, lua could display a message to any client (shortly after connecting to the server) that has cg_instanttapout set to 0, to change it to 1 if they don't want to see the limited lives popup menu. Additionally, this message could even be shown right after a player dies and they see the menu for the first time!

 

The main way I want to use it currently is to have some configuration options available to the clients. For example, I am working on a script that plays custom sounds on our server. I would like to give the client the option to disable this functionality if they do not want to hear them. The way I am currently planning on doing this is to allow the clients to set a custom cvar such as playsound_disable, so they can just add the line "set playsound_disable "1"" to their config if they want them disabled on our server. This would be excellent functionality because setting cvars is mostly common knowledge in the ET community, and I would be able to avoid workarounds such as having to make players execute a custom command and recording the preference in some type of data file on the server.

Edited by JvIasterMind
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...