Jump to content

Lua API Questions


JvIasterMind
 Share

Recommended Posts

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
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Management
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.

Link to comment
Share on other sites

  • Management

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.

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...
  • Management

I don't know if there is such thing in the LUA (rather not), but we added a server cvar to show the real play time of the player, maybe this would help you.

http://mygamingtalk.com/wiki/Silent_Mod_Server_Cvar#g_realPlayTime

 

EDIT1:

But you could write a lua plugin to track players time in each team, that is possible for sure.

Link to comment
Share on other sites

I'm interested, mind I'd I ask you what would you use this info for? :)

I'd like to give extra XP bonus for every player of a winning team. Of course, to avoid jumping between teams at last seconds of the map just to get XP I'd like to check how long every player was a member of the team.

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...