Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google Log In with Steam Sign In
  • Create Account
Photo

Lua API Questions

- - - - - lua api scripting

  • Please log in to reply
65 replies to this topic

#41
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction
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)?

#42
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland

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.

#43
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction

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!

#44
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction
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.

#45
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction

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.

#46
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland
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.

#47
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland
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.

#48
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction

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!

#49
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction

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.



#50
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction

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, 21 December 2012 - 06:18 PM.


#51
OFFLINE   Dragonji

Dragonji

    Advanced Member

  • Members
  • PipPipPipPip
  • 514 posts
142
On the road to fame
  • LocationPoland
Anybody know the answer?
I think it's not possible at the moment, otherwise it'd be documented.
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.
I wrote a similar script but didn't find a way to get client's specific cvar so I just used a work-around, I scan for a specific rate amount (userinfo) and if it matches the one defined for disabled sounds, the server doesn't send playsound request to the client.

Indeed, it'd be great to have a possibility to check client's cvar value so we can create better scripts! :)
Dzwiek = {
[0] = "path/to/sound.wav"
[1] = "path/to/sound.wav"
-- etc.
}

client_sounds = { }

function et_InitGame(levelTime, randomSeed, restart)
    sv_maxclients = tonumber(et.trap_Cvar_Get("sv_maxclients"))
end

function et_ClientBegin(id)
    CheckRate(id)
end

function et_ClientDisconnect(id)
    client_sounds[id] = 0
end

function CheckRate(id)
    local rs = et.Info_ValueForKey(et.trap_GetUserinfo(id), "rate")
    if rs == "45123" then
        client_sounds[id] = 0
    else
        client_sounds[id] = 1
    end
end

function et_ConsoleCommand()
    if et.trap_Argv(0) == "pfsound" then
        if et.trap_Argc() == 2 then
            local indeks = tonumber(et.trap_Argv(1))
            PlaySound(Dzwiek[indeks])
        else
            sayClients("chat","^1ERROR: Not enough parameters given!")
        end
    end
end

function PlaySound(sound)
    local odtworz = et.G_SoundIndex(sound)
    for i=0, sv_maxclients-1 do
        if client_sounds[i] == 1 then
            et.G_ClientSound(i, odtworz)
        end
    end
end


#52
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland

It's not as simple as a Lua script asking the client for cvar value and then stop waiting to get the answer for it.



#53
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction
I think it's not possible at the moment, otherwise it'd be documented.I wrote a similar script but didn't find a way to get client's specific cvar so I just used a work-around, I scan for a specific rate amount (userinfo) and if it matches the one defined for disabled sounds, the server doesn't send playsound request to the client.

 

That is an interesting workaround. Thanks for posting the code... very fun to see how other people accomplish similar scripts!



#54
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction
It's not as simple as a Lua script asking the client for cvar value and then stop waiting to get the answer for it.

 

Hmmm... I guess I didn't think about the network part of it!

 

 

I have a few questions if you don't mind answering them... (Keep in mind, I am not that good at coding, so the following questions might be just a bunch of nonsense.  :P )

 

Doesn't silEnT have to read all the client cvars when they connect to the server and also when they modify them to make sure they comply with the cvar restrictions? Could the server just keep all the cvars in memory for the connected clients (or does it already)?

 

What about only allowing the accessing function to be during the et_ClientConnect or et_InitGame callbacks so the time it takes to get the value wouldn't be as critical and maybe there could be some kind of timeout where the value would return nil or something?

 

Also, there is the Userinfo string with some cvars already. Could an alternative to that be implemented in much the same way with different values (or certain cvars added to that string)? Most of the values in that string seem like ones that wouldn't change during game, but I do see that it has a name field. How is that field kept up up-to-date? Maybe the same could be done with cvars with a set prefix like lua_ or similar?



#55
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland
Doesn't silEnT have to read all the client cvars when they connect to the server and also when they modify them to make sure they comply with the cvar restrictions?

Cvar restrictions are completely client side. Server only tells what cvars are restricted.

 

 

What about only allowing the accessing function to be during the et_ClientConnect or et_InitGame callbacks so the time it takes to get the value wouldn't be as critical and maybe there could be some kind of timeout where the value would return nil or something?

The server is always, except during intermission, time critical.

 

 

Also, there is the Userinfo string with some cvars already.

This is handled by the engine. Mods can define cvars to be included into it. However, it's not practically good thing to add cvars that are not relevant to it.

 

There are ways, but not simple solutions. At the moment I can not say if there will be anything made for this purpose.



#56
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction

Ok, all that makes a lot of sense. Thanks for answering all my questions!

 

Also, thanks for thinking about and considering the idea! I really appreciate all the work you put into the mod and how great your support is in these forums!



#57
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland

In the next version it is possible to query client cvars with Lua. It works 2 parts. First API function to issue query, when the result is ready, a hook funtion in the Lua script is called with the client number, cvar name and cvar value. There is also option for logging these to the g_cheatLog.



#58
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction

Thank you very much gaoesa!!! I'm really looking forward to this addition!  :D



#59
OFFLINE   Dragonji

Dragonji

    Advanced Member

  • Members
  • PipPipPipPip
  • 514 posts
142
On the road to fame
  • LocationPoland
Got a question. In the Lua docs, the description of G_shrubbot_permission says:

Tells if the given player entity has the given shrubbot flag set.
(...)

  • ent is the player entity that is checked


What is ent? Slot number?

Edited by Dragonji, 17 March 2013 - 04:09 PM.


#60
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland

It is the slot number, starting from 0. Fixed in the docs.







Also tagged with one or more of these keywords: lua, api, scripting

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users