LiF Baron Script: Get all currently active players

Place for sharing your game modifications for Life is Feudal: Your Own

MH6
 
Posts: 29
Joined: 22 Sep 2014, 14:59

LiF Baron Script: Get all currently active players

Post by MH6 » 01 Oct 2014, 23:54

I'm working on an interactive LiF mapping system (Baron) and part of this system requires a list of all currently active players on the server. As Steam Server Query does not reliably return this information, I wrote a script to store that information in the SQL database.

http://pastebin.com/M2FN2kwm

You just need to save this in the root folder of your dedicated server (as e.g. "baron.cs"), and add this line to your main.cs file:

Code: Select all
exec("baron.cs");


Next time you start your server, it will save all active players to the baron_players table every 10 seconds, or whatever you specify in the script. The baron_players table is just a table with an auto-increment integer ID and a CharacterID integer field.

You can then query this table to fetch all active players. Other in-game data can be stored as well, such as player name, position, health, etc.

Hope someone finds it useful, as it seems to be a common question in the modding community.

P.S.- For more adventurous modders, you can most likely hook into client connect/disconnect events and update a list that way, so you don't have to poll every # of seconds. I just didn't feel the need to do so.

User avatar
Somerlot
 
Posts: 50
Joined: 26 Sep 2014, 01:27

Re: LiF Baron Script: Get all currently active players

Post by Somerlot » 02 Oct 2014, 08:19

Not sure how much it helps but when you use OpenOptionsPlayers in console it brings up the active players window. There might be a way to capture the information being fed into that window but I dont know that much about scripting.
Image

User avatar
Vamyan
 
Posts: 198
Joined: 23 Oct 2014, 22:29

Re: LiF Baron Script: Get all currently active players

Post by Vamyan » 30 Oct 2014, 05:37

Finally got annoyed by all the red text ERRR spam... optimum fix is to use dbi.Query() instead of dbi.Execute().

Simplest method is to change the sqlExecute() function to this:

Code: Select all
function sqlExecute(%sql)
{
   dbi.Query($nullobj,sqlNullCallback,%sql);
}


Memnon
 
Posts: 1
Joined: 08 Jan 2015, 16:15

Re: LiF Baron Script: Get all currently active players

Post by Memnon » 08 Jan 2015, 16:20

Hi

I added this script to my server. But I am not sure how to query
The SQL database? Can someone please explain how to do this. I use heidi SQL


User avatar
KhaimovMR
 
Posts: 77
Joined: 10 Oct 2015, 01:39

Re: LiF Baron Script: Get all currently active players

Post by KhaimovMR » 19 Nov 2015, 18:35

If anybody's interested - i've implemented idea of this script in server control panel v0.9.7.
You can download it in this thread - LiFDS-CP v0.9.7

Return to Game mods