iwalidza Posted April 22, 2020 Share Posted April 22, 2020 iam try to get test string form Lua to php with php sdk thats my cods Lua function getAllPlayersForWebsite ( ) local players = {} for k, player in ipairs( getElementsByType ("player") ) do local name = getPlayerName( player ) table.insert( players, name ) end return players end function getPlayersNumber () return "test" end meta <meta> <script src="devS.Lua" type="server"/> <export function="getAllPlayersForWebsite" type="server" http="true" /> <export function="getPlayersNumber" type="server" http="true" /> </meta> php <?php include "sdk/mta_sdk.php"; $MY_SERVER = [ "host" => "localhost", "http_port" => 22005, "http_user" => "php", "http_pass" => "phpphp" ]; $SERVER = new mta ( $MY_SERVER['host'], $MY_SERVER['http_port'], $MY_SERVER['http_user'], $MY_SERVER['http_pass'] ); try { $RESOURCE = $SERVER->getResource ( "dev2" ); $RESULT[] = $RESOURCE->call ( "getAllPlayersForWebsite" ); foreach ( $RESULT [ 0 ] [ 0 ] as $index=>$playerName ) { print_r ( $playerName ); echo "<br /><br />"; } $RESULT[] = $RESOURCE->call ( "getPlayersNumber" ); foreach ( $RESULT [ 0 ] [ 0 ] as $index=>$sting ) { print_r ( $sting ); 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 ); } ?> result print to me walidza walidza Link to comment
Master_MTA Posted April 22, 2020 Share Posted April 22, 2020 2 minutes ago, iwalidza said: walidza use latest version of php sdk firs't Link to comment
iwalidza Posted April 22, 2020 Author Share Posted April 22, 2020 Just now, Master_MTA said: use latest version of php sdk firs't idont know how to use Link to comment
Master_MTA Posted April 22, 2020 Share Posted April 22, 2020 Just now, iwalidza said: idont know how to use follow wiki explaining 1 Link to comment
iwalidza Posted April 22, 2020 Author Share Posted April 22, 2020 4 minutes ago, Master_MTA said: follow wiki explaining iam try to follow https://wiki.multitheftauto.com/wiki/PHP_SDK but i don't understand anything 12 minutes ago, Master_MTA said: follow wiki explaining see that img https://prnt.sc/s3ot3t Link to comment
Master_MTA Posted April 22, 2020 Share Posted April 22, 2020 19 minutes ago, iwalidza said: see that img try this composer require php-http/curl-client guzzlehttp/psr7 php-http/message in ur cmd Link to comment
iwalidza Posted April 22, 2020 Author Share Posted April 22, 2020 its done see the img https://prnt.sc/s3p0ko 9 minutes ago, Master_MTA said: try this composer require php-http/curl-client guzzlehttp/psr7 php-http/message in ur cmd Link to comment
Master_MTA Posted April 22, 2020 Share Posted April 22, 2020 Just now, iwalidza said: its done see the img https://prnt.sc/s3p0ko now it's great just follow wiki now Link to comment
iwalidza Posted April 22, 2020 Author Share Posted April 22, 2020 what i need to do now Just now, Master_MTA said: now it's great just follow wiki now https://prnt.sc/s3p1xl error Link to comment
Master_MTA Posted April 22, 2020 Share Posted April 22, 2020 1 minute ago, iwalidza said: what i need to do now https://prnt.sc/s3p1xl ur php code remove your require or include and add this require "vendor/autoload.php"; or where is ur autoload.php file exist in Link to comment
iwalidza Posted April 22, 2020 Author Share Posted April 22, 2020 the php file https://prnt.sc/s3p37w and autoload.php file exist in https://prnt.sc/s3p3mv 4 minutes ago, Master_MTA said: ur php code remove your require or include and add this require "vendor/autoload.php"; or where is ur autoload.php file exist in Link to comment
Master_MTA Posted April 22, 2020 Share Posted April 22, 2020 2 minutes ago, iwalidza said: autoload.php file exist in so how is it? is there any wrong now? Link to comment
iwalidza Posted April 22, 2020 Author Share Posted April 22, 2020 Just now, Master_MTA said: so how is it? is there any wrong now? yup i have https://prnt.sc/s3p4x8 Link to comment
Master_MTA Posted April 22, 2020 Share Posted April 22, 2020 2 minutes ago, iwalidza said: yup i have https://prnt.sc/s3p4x8 you must run this command pro composer require multitheftauto/mtasa-php-sdk after running this command : composer require php-http/curl-client guzzlehttp/psr7 php-http/message Link to comment
iwalidza Posted April 22, 2020 Author Share Posted April 22, 2020 Just now, Master_MTA said: you must run this command pro composer require multitheftauto/mtasa-php-sdk after running this command : composer require php-http/curl-client guzzlehttp/psr7 php-http/message but where? https://prnt.sc/s3p6te Link to comment
Master_MTA Posted April 22, 2020 Share Posted April 22, 2020 (edited) Just now, iwalidza said: but where? https://prnt.sc/s3p6te cmd at this position press shift +right click press on open power shell here or open cmd here then run this command: composer require multitheftauto/mtasa-php-sdk Edited April 22, 2020 by Master_MTA Link to comment
iwalidza Posted April 22, 2020 Author Share Posted April 22, 2020 https://prnt.sc/s3p7uw 2 minutes ago, Master_MTA said: cmd And where i can found more information about php sdk ? Link to comment
Master_MTA Posted April 22, 2020 Share Posted April 22, 2020 (edited) 3 minutes ago, iwalidza said: https://prnt.sc/s3p7uw display ur php code here not photo and this notic is okay u should call this page from mta sa server to return value for u if u wanna call mta server instead u should see this example on wiki <?php require_once('vendor/autoload.php'); use MultiTheftAuto\Sdk\Mta; use MultiTheftAuto\Sdk\Model\Server; use MultiTheftAuto\Sdk\Model\Authentication; $server = new Server('127.0.0.1', 22005); $auth = new Authentication('myUser', 'myPassword'); $mta = new Mta($server, $auth); $response = $mta->getResource('someResource')->call('callableFunction', $arg1, $arg2, $arg3, ...); // or $response = $mta->getResource('someResource')->call->callableFunction($arg1, $arg2, $arg3, ...); var_dump($response); Edited April 22, 2020 by Master_MTA 1 Link to comment
iwalidza Posted April 22, 2020 Author Share Posted April 22, 2020 5 minutes ago, Master_MTA said: display ur php code here not photo and this notic is okay u should call this page from mta sa server to return value for u if u wanna call mta server instead u should see this example on wiki <?php require_once('vendor/autoload.php'); use MultiTheftAuto\Sdk\Mta; use MultiTheftAuto\Sdk\Model\Server; use MultiTheftAuto\Sdk\Model\Authentication; $server = new Server('127.0.0.1', 22005); $auth = new Authentication('myUser', 'myPassword'); $mta = new Mta($server, $auth); $response = $mta->getResource('someResource')->call('callableFunction', $arg1, $arg2, $arg3, ...); // or $response = $mta->getResource('someResource')->call->callableFunction($arg1, $arg2, $arg3, ...); var_dump($response); https://prnt.sc/s3panr oh oh sorry Link to comment
Master_MTA Posted April 22, 2020 Share Posted April 22, 2020 (edited) 1 minute ago, iwalidza said: $response = $mta->getResource('someResource')->call('callableFunction', $arg1, $arg2, $arg3, ...); // or $response = $mta->getResource('someResource')->call->callableFunction($arg1, $arg2, $arg3, ...); bro change this with your own details that mean u have syntax error cuze ...); +add username and password + your server ip and port Edited April 22, 2020 by Master_MTA Link to comment
iwalidza Posted April 22, 2020 Author Share Posted April 22, 2020 $response = $mta->getResource('dev2')->call('getPlayersNumber', $arg1); echo $response; function getPlayersNumber () return #getElementsByType('player') end like that? 2 minutes ago, Master_MTA said: bro change this with your own details that mean u have syntax error cuze ...); Link to comment
Master_MTA Posted April 22, 2020 Share Posted April 22, 2020 1 minute ago, iwalidza said: $response = $mta->getResource('dev2')->call('getPlayersNumber', $arg1); echo $response; function getPlayersNumber () return #getElementsByType('player') end like that? u should learn about php a little <?php require_once('vendor/autoload.php'); use MultiTheftAuto\Sdk\Mta; use MultiTheftAuto\Sdk\Model\Server; use MultiTheftAuto\Sdk\Model\Authentication; $server = new Server('your ip', your port); $auth = new Authentication('your username', 'your password'); $mta = new Mta($server, $auth); $response = $mta->getResource('dev2')->call('getPlayersNumber'); var_dump($response); // or you can do like this echo $response[0]; 1 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