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

#21
OFFLINE   Sol

Sol

    Regular Member

  • Coders
  • PipPipPip
  • 113 posts
28
On a distinguished road
  • LocationPoland

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 by Sol, 22 October 2012 - 07:34 PM.


#22
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland
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 [i] is replaced with the client number of the calling client.

EDIT:
Now added into the Wiki documentation.

#23
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

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

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 [i] 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. :)

#24
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

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

#25
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland
Indeed that is buggy. Will look into fixing it.

#26
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland
It will be fixed in 0.6.1. The missing parameters are stripped from the command line if not given in the command.

#27
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction
Wow, that was fast! Thanks for looking into it! :)

#28
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

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

#29
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland
The quotes disappear when the custom commands are parsed in from the shrubbot.cfg.

#30
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

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

#31
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland
Yes. This will be fixed.

#32
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction
Alright, thanks! I'm looking forward to it! :)

#33
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

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

#34
OFFLINE   Sol

Sol

    Regular Member

  • Coders
  • PipPipPip
  • 113 posts
28
On a distinguished road
  • LocationPoland

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.

#35
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

  • Members
  • PipPipPip
  • 116 posts
8
A step in the right direction
Do you know of another way to detect if a client is connected that could avoid the bug in the meantime until it's fixed? When it happens, I am pretty sure that the disconnected player doesn't show up in the built-in tab menu/scoreboard.

#36
OFFLINE   Sol

Sol

    Regular Member

  • Coders
  • PipPipPip
  • 113 posts
28
On a distinguished road
  • LocationPoland
[font='courier new', ', courier, monospace} ']et.gentity_get(slot, "ps.ping[/font][font='courier new', ', courier, monospace} ']") < 999 and [/font][font='courier new', ', courier, monospace} ']et.gentity_get(slot, "ps.ping[/font][font='courier new', ', courier, monospace} ']") > 0 [/font]seems good

Edited by Sol, 13 November 2012 - 12:08 AM.


#37
OFFLINE   gaoesa

gaoesa

    Advanced Member

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

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.

#38
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland
Ok. I reread and sol was talking about the script not getting the ClientDisconnected callback. If that is the case, then the "pers.connected" would have wrong information also.

#39
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

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

[font='courier new', ', courier, monospace} ']et.gentity_get(slot, "ps.ping[/font][font='courier new', ', courier, monospace} ']") < 999 and [/font][font='courier new', ', courier, monospace} ']et.gentity_get(slot, "ps.ping[/font][font='courier new', ', courier, monospace} ']") > 0 [/font]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!

#40
OFFLINE   JvIasterMind

JvIasterMind

    Regular Member

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

Ok. I reread and sol was talking about the script not getting the ClientDisconnected callback. If that is the case, then the "pers.connected" would have wrong information also.


I'll add a debug line in my script to see what value for pers.connected is returned next time I encounter the bug.





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