Difference between revisions of "CSharp SDK"
(Created page with '__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 its…')
Revision as of 20:55, 15 October 2009
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
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:
2. Create instance of MTA class:
MTA server = new MTA(); //-- default params (for IP and port, respectively) are: "localhost" and 22005
//-- 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 );
//-- 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" );
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
You can download C# MTA SDK here:
If you have any questions/suggestions you can contact author on MTA forum or IRC #mta and #mtatools channels hosted on GTANet.com server.