CSharp SDK: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Update link to reflect CDN usage)
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
__TOC__
__TOC__
Many languages can make HTTP POST requests with JSON, C# can do too. This is C# SDK for MTA. It allows you to call any HTTP exported functions from resources. The SDK itself is very basic and easy to use. It was mainly created to extend [[MTASE|MTA:Script Editor]] functionality. Feel free to modify it however you like but don't remove original author. If you want your changes to be published, please speak to [[User:50p|50p]] on MTA forums [https://forum.multitheftauto.com/memberlist.php?mode=viewprofile&u=19953 HERE]
Many languages can make HTTP POST requests with JSON, C# can do too. This is C# SDK for MTA. It allows you to call any HTTP exported functions from resources. The SDK itself is very basic and easy to use. It was mainly created to extend [[MTASE|MTA:Script Editor]] functionality. Feel free to modify it however you like but don't remove original author. If you want your changes to be published, please speak to [[User:50p|50p]] on MTA forums [https://forum.multitheftauto.com/profile/1687-50p/ HERE]




Line 53: Line 53:
==Download==
==Download==
You can download C# MTA SDK here:
You can download C# MTA SDK here:
*[https://mirror.mtasa.ar/files/mta_csharp_sdk.zip C# MTA SDK 1.0]
*[https://mirror.multitheftauto.com/files/50p_MTA_CSharp_SDK_1.0.rar C# MTA SDK 1.0]


==Contact==
==Contact==
If you have any questions/suggestions you can contact author on MTA forum or IRC '''#mta''' and '''#mtatools''' channels hosted on GTANet.com server.
If you have any questions/suggestions you can contact author on MTA forum or IRC '''#mta''' and '''#mtatools''' channels hosted on GTANet.com server.
*[https://forum.multitheftauto.com/memberlist.php?mode=viewprofile&u=19953 50p]
*[https://forum.multitheftauto.com/profile/1687-50p/ 50p]
 
[[Category:SDK]]

Latest revision as of 10:51, 13 July 2024

Many languages can make HTTP POST requests with JSON, C# can do too. This is C# SDK for MTA. It allows you to call any HTTP exported functions from resources. The SDK itself is very basic and easy to use. It was mainly created to extend MTA:Script Editor functionality. Feel free to modify it however you like but don't remove original author. If you want your changes to be published, please speak to 50p on MTA forums HERE


How to

First of all, you have to include your files in your project. Once you've done this, you are ready to use SDK.

1. Add MTA_SDK.cs and MTA_LuaArgs.cs to your project file and import the SDK namespace in your file:

using MTA_SDK;


2. Create instance of MTA class:

MTA server = new MTA();	//-- default params (for IP and port, respectively) are: "localhost" and 22005

OR

//-- if you don't want to make a call to your local server then you can connect to remote server with the following parameters:
MTA server = new MTA( "IP", port );

OR

//-- if you get errors about authorization then you should use the account you created on your server 
//-- (the account that is allowed to visit HTTP sites of your server, preferably admin):
MTA server = new MTA( "IP", port, "username", "password" );


3. Create instance of MTA_LuaArgs class to create list of arguments that is passed to the function call:

MTA_LuaArgs luaArgs = new MTA_LuaArgs( );
luaArgs.AddValue( "hello" );
luaArgs.AddValue( "world" );

OR

MTA_LuaArgs luaArgs = new MTA_LuaArgs( "hello", "world" );


4. Call function exported from resource (in meta.xml: <export function="functionName" http="true" />, REMEMBER! http attribute has to be true!):

string returned = server.CallFunction( "sampleResource", "functionName", luaArgs );


And here is the sample Lua function (functionName) that we're trying to call:

function functionName( param1, param2 )
	outputChatBox( "Function called from SDK with args: " .. param1 .. ", " .. param2 );
	return true;
end

Download

You can download C# MTA SDK here:

Contact

If you have any questions/suggestions you can contact author on MTA forum or IRC #mta and #mtatools channels hosted on GTANet.com server.