Jump to content

[HELP] PHP SDK.


iwalidza

Recommended Posts

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
3 minutes ago, iwalidza 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);

 

Edited by Master_MTA
  • Thanks 1
Link to comment
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

  

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 by Master_MTA
Link to comment
$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
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];

 

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