Kevin1003 Posted February 20, 2016 Share Posted February 20, 2016 Hi, I'm try to make a player list using the SDK-PHP (MTA) and this tutorial: https://forum.multitheftauto.com/viewtopic.php?f=148&t=87499&start=0 The error: Catchable fatal error: Object of class Element could not be converted to string in C:\xampp\htdocs\mta\mta_tut.php on line 24 mta_tut.php <?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" => "hb123" #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 ) { echo $playerName . "<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 Link to comment
tosfera Posted February 20, 2016 Share Posted February 20, 2016 That's in the php file, line 24. You're echoing $playerName but $playerName is an object. I think the player should have stats like ping, score, name, etc. I'm just not sure atm, you should try to call some functions like; echo $playerName->username; Even though, you're returning playerelements, not their names. If you would get the names of every single player on the server and return that as a table, your loop will work. Link to comment
Kevin1003 Posted February 20, 2016 Author Share Posted February 20, 2016 That's in the php file, line 24. You're echoing $playerName but $playerName is an object. I think the player should have stats like ping, score, name, etc. I'm just not sure atm, you should try to call some functions like; echo $playerName->username; Even though, you're returning playerelements, not their names. If you would get the names of every single player on the server and return that as a table, your loop will work. doesn't work Error: Notice: Undefined property: Element::$username in C:\xampp\htdocs\mta\mta_tut.php on line 24 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now