Jump to content

Recommended Posts

Fortunately, _I_ don't have to do that ;) From what I gather (this was after a couple of pints), the person/s involved want to try to implement some sort of Kinect and/or Glowpie + geolocator interface for an art school final or something. They got coders who might be able to pull this off, but don't necessarily want to reinvent the wheel. Tricky but intriguing, I admit.

You could try to write some inbetween application that interprets kinect movements and sends key presses (certain actions binded to keyboard/mouse actions).

Share this post


Link to post
Share on other sites

Working with the Python Plugin. Tutorial/Howto..

1st of all i like to say. im not an expert in Python or Sqf. but i manage to do what i want to do.

Lets do some basics.

let say we want to make a python script that returns a greeting to you.

this is simple. we need 2 files for this to work. a sqf file and a py file.

the init.sqf must be placed in your mission folder.

Example:

C:\Users\YOURNAME\Documents\ArmA 2\missions\test.utes\init.sqf

And the py file in Example.

C:\Program Files (x86)\Steam\steamapps\common\arma 2\@Arma2NET\Python\basic.py

now in the init file you need to put this.

init.sqf

("Arma2Net.Unmanaged" callExtension "Py import basic");

this will import our basic.py file.

to return the greeting you also need to put this in a sqf file. for simplicity we have it in the init.sqf aswell.

init.sqf

("Arma2Net.Unmanaged" callExtension "Py import basic");

// get the return string from python.
_pycode = format["Py basic.HelloWorld('%1')",name player];
_res = call compile ("Arma2Net.Unmanaged" callExtension _pycode); 

// display the string.
titletext[_res,"PLAIN"];

ok so thats all done. now we move on to our py file.

basic.py

def HelloWorld(playername):
 greeting ="Python says hello to you "+playername
 return greeting

thats all.. simple huh?

*** System Time Example ***

lets extend the basic.py with 1 more function that will set the system time as mission time.

import datetime
def sys_time():
 t = datetime.datetime.now().strftime('%Y %m %d %H %M').split()
 year = int(t[0])
 month = int(t[1])
 day = int(t[2])
 hour = int(t[3])
 min = int(t[4])
 return [year,month,day,hour,min]

as before in our init file we need to import our module

init.sqf

("Arma2Net.Unmanaged" callExtension "Py import basic"); // note. this is only done once. 

when you are working on a *.py script with arma2net python plugin you should always reloade it after changes are done to the file.

("Arma2Net.Unmanaged" callExtension "Py import basic");
("Arma2Net.Unmanaged" callExtension "Py reload(basic)");

so our fully init.sqf should now look like.

("Arma2Net.Unmanaged" callExtension "Py import basic");
("Arma2Net.Unmanaged" callExtension "Py reload(basic)");

_date =  call compile ("Arma2Net.Unmanaged" callExtension "Py basic.sys_time()");
setdate _date;

thats all, your mission has now set the time to your system time :)

*** Working with Classes and instances ***

we have this file.

TestModule.py

class TestClass:
 def __init__(self):
   self.x = 0
 def increment(self):
   self.x +=1
   return self.x
 def decrement(self):
   self.x -=1
   return self.x

we can start by importing the module

("Arma2Net.Unmanaged" callExtension "Py import TestModule");

create instances of a class object.


// this will be the variable names
_instance_A = "TEST_A"; 
_instance_B = "TEST_B";

_pycode = format["Py %1 = TestModule.TestClass()",_instance_A];
("Arma2Net.Unmanaged" callExtension _pycode);
// this would be the same as TEST_A = TestModule.TestClass() in python

_pycode = format["Py %1 =  TestModule.TestClass()",_instance_B];
("Arma2Net.Unmanaged" callExtension _pycode);
// this would be the same as TEST_B = TestModule.TestClass() in python


// Show result of TEST_A & TEST_B
_pycode = format["Py %1.x",_instance_A];
_resA = call compile ("Arma2Net.Unmanaged" callExtension _pycode);    

_pycode = format["Py %1.x",_instance_B];
_resB = call compile ("Arma2Net.Unmanaged" callExtension _pycode);    

// in this case both _resA and _resB would return 0

hint format["%1\n%2",_resA,_resB];
sleep 3;

_pycode = format["Py %1.increment()",_instance_A];
_resA = call compile ("Arma2Net.Unmanaged" callExtension _pycode);

_pycode = format["Py %1.decrement()",_instance_B];
_resB = call compile ("Arma2Net.Unmanaged" callExtension _pycode);    

hint format["%1\n%2",_resA,_resB];

// _resA is now 1
// _resB is now -1

simple :D

download the examples http://ibattle.org//Downloads/Arma2Stuff/Py-test.zip

Edited by nuxil

Share this post


Link to post
Share on other sites

Thanks. Would you like to mirror the examples somewhere else? I can't figure out how to use Filedump to download them :/

These examples would be useful on a A2N wiki page.

Share this post


Link to post
Share on other sites

Oh Sorry about that. somehow the link is broken for me too.

added the example on my own host.

http://ibattle.org//Downloads/Arma2Stuff/Py-test.zip

you can put these example i posted on your wiki if you like.

the zip file basicly only contains mission files & the py files. so not much explanations in them

Share this post


Link to post
Share on other sites

Exciting stuff. I'm working on getting a VM up as a dedicated server or something so I can start researching the feasibility of a Linux version of Arma2NET.

Share this post


Link to post
Share on other sites

Nice to hear Scott :) Way to go!

Share this post


Link to post
Share on other sites

Arma2NET 1.9 has been released:

- New alternative function call syntax, e.g. ["DateTime", ["now", "HH:mm:ss"]]

- Added outputSize support to Arma2NetMethodAddIn and friends.

- Arma2NetMethodAddIn now optionally formats results as SQF.

- New YAML settings file that can be used to configure Arma2NET.

- The list of plugins to automatically activate on Arma2NET startup can now be configured through YAML.

- The Arma2NET plugin whitelist can now be configured through YAML.

- Added the ability to play a beep sound when Arma2NET is activated. This can be configured through YAML.

- Sharpened text in Arma2NetExplorer.

- Dropped installer banner images to reduce file size.

- Improved return result logic further from version 1.8.

- UtilitiesPlugin and WeatherPlugin dropped from Arma2NET and are now auxiliary plugins.

- Dropped FunctionArgumentsInvalidException in favour of the standard .NET exceptions.

- Error messages vastly improved.

New alternative syntax lets you do things like this:

args = ["DateTime", ["now", ""]];
hint ("Arma2Net.Unmanaged" callExtension str args)

Please bear in mind that it currently won't work for objNull, e.g.

["DateTime", ["now", objNull]];

Settings.yaml can be edited in your favourite text editor. The PublicKeyTokens field is the most useful field. You can add your own entries and Arma2NET will trust plugins with matching public key tokens.

Settings.yaml is (surprisingly!) in the human-readable YAML serialisation format, http://en.wikipedia.org/wiki/Yaml

I'll add documentation regarding the new Arma2NetMethodAddIn additions later.

Arma2NET releases under the "release early, release often" principle, so please reply with feedback and any problems/issues you have with using this update.

https://bitbucket.org/Scott_NZ/arma2net/downloads/Arma2NET-1.9.zip

https://bitbucket.org/Scott_NZ/arma2net/downloads/Arma2NetInstaller-1.9.msi

Share this post


Link to post
Share on other sites

Guys,

This seems to break MySQLPluginAddin with the latest version of Arma2Net 1.9.

I get the following:

05/26/2012 06:57:45 Arma2Net.Managed.Bridge ERROR Caught exception

System.TypeLoadException: Could not load type 'Arma2Net.Managed.FunctionArgumentsInvalidExceptio n' from assembly 'Arma2Net.Managed, Version=1.7.0.0, Culture=neutral, PublicKeyToken=8762987cc8e6095e'.

at Arma2NETMySQLPlugin.Arma2NETMySQLPlugin.Run(String args)

at AddInAdapter.Arma2NetAddInAddInAdapter.Run(String args, Int32 maxResultSize)

at HostAdapter.Arma2NetAddInHostAdapter.Run(String args, Int32 maxResultSize)

at Arma2Net.Managed.AddIns.AddInManager.RunAddIn(Stri ng addInName, String addInArgs, Int32 maxResultSize)

at Arma2Net.Managed.Bridge.Run(String function, Int32 maxResultSize)

Works fine with v1.8

Cheers

Tup

Share this post


Link to post
Share on other sites

@ Tupolov: refer to the reply I made in HeliJunkie's thread.

I've been working on making Arma2NET more accessible.

- I have uploaded a Visual Studio solution with simple and working code (just make sure VS can find the references i.e. Arma2Net.Managed.dll). You can find it here.

- I have overhauled the wiki home page with some words describing what Arma2NET actually is, and I have added the example code.

- I have also overhauled the wiki sandboxing page, and added a page about the new Settings.yaml included with 1.9.

Share this post


Link to post
Share on other sites

Arma2NET 1.10 has been released. This update mainly focuses on bug fixes and internal refactoring which I won't go into detail about here. It also brings some new features, as described below:

- Settings.yaml is now created by the installer.

- Log configuration file option added to Settings.yaml.

- Arma2NET evaluator added to Arma2NET Explorer, providing the ability to test code without needing to start the game.

- Fixed an issue where Arma2NetMethodAddIn methods with UnformattedResultAttribute were sometimes causing a NullReferenceException.

- "<NULL-object>" from the game is now treated as null by Arma2NET.

- Improved error messages for plugins using Arma2NetMethodAddIn.

https://bitbucket.org/Scott_NZ/arma2net/downloads/Arma2NET-1.10.zip

https://bitbucket.org/Scott_NZ/arma2net/downloads/Arma2NetInstaller-1.10.msi

To use the evaluator, type for example DateTime [now, ] into the text box on the Evaluator tab and then hit Enter. Note that Arma2NET Explorer will require a restart each time you update the plugin due to the current AppDomain setup. I'm looking to change this so you can reload plugins on the fly. This is already possible with Python/Ruby code used with PythonPlugin and RubyPlugin however.

Share this post


Link to post
Share on other sites

I don't like this version number. From 1.9 to 1.10... or in my opinion 1.1..

Think this is misleading. Otherwise 1.9 must be 1.09 ...

Share this post


Link to post
Share on other sites

A version is made up of four numbers: the major version, minor version, revision and build. Versions are usually represented as major.minor.revision.build, e.g. 1.0.0.0. I have left off the revision/build numbers when they aren't important. So 1.10 (or 1.10.0.0) means that major version = 1 and minor version = 10.

I can see where you're coming from though, and I do take this into consideration.

Share this post


Link to post
Share on other sites

Two small questions:

1) In the example code on the wiki:

using System.AddIn;
using AddInView;

namespace MyPlugin
{
   [AddIn("MyPlugin")]
   public class MyPlugin : Arma2NetMethodAddIn
   {
       public string Hello()
       {
           return "Hello world!";
       }
   }
}

And calling it in Arma2:

_result = call compile ("Arma2Net.Unmanaged" callExtension "MyPlugin [Hello]");

How would you call the Hello method in Arma2 with parameters/arguments?

2) What's the difference between Arma2NetMethodAddIn and Arma2NetAddIn? I noticed they are both used throughout the various examples on the Wiki.

Thank you very much.

Share this post


Link to post
Share on other sites

If it was for example

using System.AddIn;
using AddInView;

namespace MyPlugin
{
   [AddIn("MyPlugin")]
   public class MyPlugin : Arma2NetMethodAddIn
   {
       public string Hello(string blah)
       {
           return "Hello world!";
       }
   }
}

Then you'd use

_result = call compile ("Arma2Net.Unmanaged" callExtension "MyPlugin [Hello, asdf]");

First element of the array is always the method name, and any elements of the array after that are considered the method's arguments.

Arma2NetAddIn is the most generic addin type. It does not support any of the fancy stuff (e.g. direct calling of methods) like what Arma2NetMethodAddIn does, but Arma2NetAddIn lets you customise how you use and call it. I use it with PythonPlugin and RubyPlugin. It does not analyse the arguments and directly passes them on to the Run method.

_result = call compile ("Arma2Net.Unmanaged" callExtension "Py 1+1");

Share this post


Link to post
Share on other sites

Arma2NET 1.11 changelog:

- Added a scripting system, allowing C# code to be modified at runtime. Errors and warnings are stored in the Arma2NET log.

- Overhauled the Arma2Net.Managed.Expressions namespace.

- Format.SqfAsDouble now uses an invariant culture to improve portability.

- Improved readability of logs and added additional information.

Any code using the Arma2Net.Managed.Expressions namespace might need a recompile.

Documentation about the new scripting system can be found here: https://bitbucket.org/Scott_NZ/arma2net/wiki/Scripts

Download:

ZIP: https://bitbucket.org/Scott_NZ/arma2net/downloads/Arma2NET-1.11.zip

Installer: https://bitbucket.org/Scott_NZ/arma2net/downloads/Arma2NetInstaller-1.11.msi

Share this post


Link to post
Share on other sites

Awesome, you rock!

Another question, in Bridge.cpp, I'm running into the "ResultTooLong" exception. How is this determined? Is there a hard limit as part of the Arma2 method for passing data? I'm curious how you are calculating it because I need to account for it and return appropriately. Cheers!

Share this post


Link to post
Share on other sites

It's passed from Arma 2. Arma2NET has a mechanism for dealing with this - the maxResultSize parameter you've probably seen. With Arma2NetMethodAddIn, you can mark your methods with [MaxResultSize] and then add an 'int maxResultSize' parameter. As long as you don't return something longer than this then it should be fine. If this is too much effort then just make sure you don't return a result >4095 characters.

Share this post


Link to post
Share on other sites

Just a heads up:

There's currently a bug with the new scripting feature which I thought I fixed but it looks like it has gotten past my testing. Make sure that you have at least one line before the C# code such as a blank line or a #r directive.

Also, because of how Mono.CSharp works it'll probably trip up when you try to #r System.dll for example due to there being multiple versions of it. Try to specify the full path to it.

Share this post


Link to post
Share on other sites

Small Arma2NET 1.11.1 update released:

- Fixed issue where script files were being read wrongly.

- Renamed #r directive to //reference so that files can compile normally.

The Scripts wiki page has been updated accordingly.

https://bitbucket.org/Scott_NZ/arma2net/downloads/Arma2NET-1.11.1.zip

https://bitbucket.org/Scott_NZ/arma2net/downloads/Arma2NetInstaller-1.11.1.msi

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×