Jump to content

[SOLVED] Script: How to check if a specified player is online?


Trance

Recommended Posts

Hi!

 

I'm currently writing scripts for some timed events. Some attach to a randomly chosen player. I use this, to see which players are available:

 

local players = {Server():getOnlinePlayers()}

 

The script(s) and everything works fine, but if a player that was chosen logs off, the event may break (stop). So I have to check if a player is still online at some point and handle this.

 

I couldn't find any information about this.

I found that this exists:

server:isOnline(factionIndex)

But I wasn't able to find any documentation about 'isOnline'. I was experimenting a lot, tried variations of 'isOnline' calls....no luck.

 

How do I check if a specific player is (still) online?

 

 

 

Link to comment
Share on other sites

Thanks  for your answer!

 

Here is a (shortened, debug) example of my code, i changed (included) the red part now, and it works as expected:

 

for a, p in ipairs(players) do

    playercount = playercount + 1

    print(a .. " " .. p.name)

    if Server():isOnline(p.index) then

        print("online")

    else

        print("offline")

    end

end

 

I didn't write the red part before and was thinking the player object is enough, but the isOnline() function requires an index and not a player object (I guess). After your answer it was clear! It'd be more logical for me, if it accepts a player object (too) but ok, this is the way! Thanks again!

 

Trance

Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...