Jump to content

[PHP][SCRIPT] getPlayerPing


Recommended Posts

Hey!

Would someone tell me how to do getPlayerPing for the php sdk library?

I only managed to make a list of players on the server

function listPlayer( )
    local players = {}
    for k, player in ipairs( getElementsByType ("player") ) do
        local player = getPlayerName( player )
        table.insert( players, player )
    end
    return players
end

 

Link to comment
  • Moderators

Send the ping, with the names to the php.

 

local playername = getPlayerName( player )
local ping = getPlayerPing( player )
table.insert( players, {playername, ping} )

 

Edited by gpetersz
  • Thanks 1
Link to comment
  • Moderators
function listPlayer( )
    local table = {}
    for _, player in ipairs( getElementsByType ("player") ) do
        local name = getPlayerName( player )
    	local ping = getPlayerPing( player )
        table.insert( table, {name, ping} )
    end
    return table
end

 

  • Thanks 1
Link to comment
  • Moderators
function listPlayer( )
    local playersTable = {}
    for _, player in ipairs( getElementsByType ("player") ) do
        local name = getPlayerName( player )
    	local ping = getPlayerPing( player )
        table.insert( playersTable, {name, ping} )
    end
    return playersTable
end

addCommandHandler("testfunction", function() -- function test command
    outputChatBox(tostring(toJSON(listPlayer())), getRootElement())
end)

 

  • Thanks 1
Link to comment
27 minutes ago, gpetersz said:

function listPlayer( )
    local playersTable = {}
    for _, player in ipairs( getElementsByType ("player") ) do
        local name = getPlayerName( player )
    	local ping = getPlayerPing( player )
        table.insert( playersTable, {name, ping} )
    end
    return playersTable
end

addCommandHandler("testfunction", function() -- function test command
    outputChatBox(tostring(toJSON(listPlayer())), getRootElement())
end)

 

[ [ [ "Ciastuus", 28 ] ] ]

I create a list of players with information about them in php. And that's how it looks

tpc8OFz.png

The problem is that if there are more players, everything breaks down

@gpetersz do you have a discord?

Edited by cG-Ciasteczkowy
  • Like 1
Link to comment
5 minutes ago, Ahmed Ly said:

function getPlayersName () 
    local playerNames = {}
    for i, player in pairs(getElementsByType("player")) do 
        table.insert(playerNames, getPlayerName(player))
    end
    return unpack(playerNames)
end

 

I just wanted him to read the ping. Will this correct the error related to what I wrote?

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