Jump to content

Show player problem


Kevin1003

Recommended Posts

I have tried to show the player via the SDK PHP

It works.. but it show only the id

Screenshot:

rXIH8eP.png

My php file:

<?php 
  
include "sdk/mta_sdk.php";   # Include the MTA PHP SDK - Give us the classes and methods that we'll need 
  
  
$MY_SERVER = [ 
    "host" => "localhost",        #The host/IP of your MTA server 
    "http_port" => 22005,         #The HTTP port for your MTA server (Default 22005) 
    "http_user" => "mta_php", #The username that we created in the previous step 
    "http_pass" => "mypassword"     #The password for the username that we created 
]; 
  
#Create a new mta object 
$SERVER = new mta ( $MY_SERVER['host'], $MY_SERVER['http_port'], $MY_SERVER['http_user'], $MY_SERVER['http_pass'] ); 
  
#We'll try to call our function... 
try { 
    
    $RESOURCE = $SERVER->getResource ( "mta_php" ); # We need to get our resource Object 
    
    $RESULT[] = $RESOURCE->call ( "getAllPlayersForWebsite" ); 
  
    foreach ( $RESULT [ 0 ] [ 0 ] as $index=>$playerName ) { 
      print_r ( $playerName ); 
echo "<br /><br />"; 
    } 
  
#Catch any errors that occurred 
} catch ( Exception $e ){ 
    #Output error message 
    echo "<strong>Oops, Something went wrong!</strong><br />Error: {$e->getMessage()}<br /><br />e printout:<br />"; 
    
    #Print the error table 
    print_r ( $e ); 
} 

Server.lua:

function getAllPlayersForWebsite ( ) 
    return getElementsByType ("player"); 
end 

Meta.xml:

<meta> 
<info author="xXMADEXx" type="script" version="1.0" name="MTA PHP" /> 
  
<!-- Include our awesome script --> 
<script src="server.lua" /> 
  
<!-- Export our function -- Make sure to allow HTTP to access it --> 
<export function="getAllPlayersForWebsite" type="server" http="true" /> 
</meta> 

Link to comment
  • Moderators

If you only need a list of player's name on your server:

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

If you also need their ids:

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

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