Jump to content

How to get the number of players from the server?


Vestorn

Recommended Posts

6 hours ago, IIYAMA said:

@Весторн

Насколько я помню, существует встроенный метод. Но сам никогда им не пользовался. (Может быть, кто-то еще знает)

 

Но это пользовательский(доступный) метод ресурсов, который вы можете использовать:

https://wiki.multitheftauto.com/wiki/Resource_Web_Access

https://wiki.multitheftauto.com/wiki/HttpWrite

 

Oh, I don't think that's it. I specifically need to get monitoring of my server on my Web site. I searched the forum, everyone was talking about Gameq, but now it does not work and now I'm looking for an alternative. Tried https://mtasa.com/api/ but unfortunately couldn't reparse process

Link to comment
  • Moderators
5 hours ago, Vestorn said:

Oh, I don't think that's it. I specifically need to get monitoring of my server on my Web site.

It can full fill that part if you want, since MTA has a build in webserver,

but you might want to add some serverside stuff for your website as middleware for anti-abuse performance reasons.

 

Anyway I leave an example below for those that are interested.

 

Resource name: webserver

Filename: meta.xml

<meta>
    <info
          version="1.0.0"
          name="webserver"
          type="script"
          description="Web server info" />
    <html src="playerCount.html" />
    <script src="main_s.lua"
            type="server" />
    <export function="getPlayerCount"
            http="true" />
</meta>

 

 

Method: 1

Filename: playerCount.html

<* httpWrite( #getElementsByType ( "player" ) ) *>

URL: http://127.0.0.1:22005/webserver/playerCount.html

Returns: <what ever you want>


 

Method: 2

Filename: main_s.lua

function getPlayerCount() return #getElementsByType( "player" ) end

URL: http://127.0.0.1:22005/webserver/call/getPlayerCount

Returns: JSON


 

 

Skip login?

(it is not recommended to skip for production, use middleware instead for the credentials)

 Add:

<right name="resource.webserver.http" access="true"></right>

Under default:

<acl name="Default">
  <right name="resource.webserver.http" access="true"></right>

 

  • Like 1
Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...