Jump to content
feldruebe

make AI perform custom action [SOLVED]

Recommended Posts

i want a plane to perform an action, when it reaches a checkpoint, but it wont.

When it reaches the Waypoint, nothing happens, it just flies on to the next waypoint.

 

Here is the line that keeps on breaking the script;

_wp1 setWaypointStatements ["true", str(_plane action ["User",_plane,0])];

everything else in the script works fine. Only thing i am not sure about is, whether i have to take a "0" or a "1" in the end, because before the part above, there is an action added to the plane and removed again.

What is wrong with performing the action?

Share this post


Link to post
Share on other sites

Not sure you can replace the quoted syntax by str(). Test with a hint. Your string str fires at once.

write:

_wp1 setWaypointStatements ["true", "_plane action ['User',_plane,0]"];

and check if _plane is defined.

Share this post


Link to post
Share on other sites

it works with a hint, just tested it.

I also already tried your version. The problem there is, _plane is not defined in this string, and i dont know how to change that.

Share this post


Link to post
Share on other sites
_wp1 setWaypointStatements [
   "true",
   format[ "_plane = %1 call BIS_fnc_objectFromNetID; _plane action ['User',_plane,0]", str( _plane call BIS_fnc_netID ) ]];

Use the BI functions and format its netID as STRING( str ) into the waypoint expression. Then convert it back into an object within the expression.

 

Not tested and typed from my sofa on my HTPC with a PS3 controller via onscreen keyboard, oh the joy. So check for mistakes :) .

  • Like 2

Share this post


Link to post
Share on other sites

I never used these commands and I'm  struggling to understand them, it also still throws up local variable error for me in the last _plane reference .

I replaced the action with _plane setdamage 1  to make it easier to test and then remove the last underscore from _plane so the code would at least run but nothing happens.

 

I've only ever done before by using call compile format for the entire line although that was for trigger statements

 

 

Share this post


Link to post
Share on other sites
14 hours ago, Larrow said:

_wp1 setWaypointStatements [
   "true",
   format[ "_plane = %1 call BIS_fnc_objectFromNetID; _plane action ['User',_plane,0]", str( _plane call BIS_fnc_netID ) ]];

Use the BI functions and format its netID as STRING( str ) into the waypoint expression. Then convert it back into an object within the expression.

 

Not tested and typed from my sofa on my HTPC with a PS3 controller via onscreen keyboard, oh the joy. So check for mistakes :) .

 

tested it, same result.

i also tested somethin similar;

_wp1 setWaypointStatements ["true", str(_plane) + " action ['User',_plane,0]"];

but it says, that it misses a semicolon :C

Share this post


Link to post
Share on other sites
17 hours ago, Larrow said:

Use the BI functions and format its netID as STRING( str ) into the waypoint expression


Just want to point out if you can avoid str you should, especially like in this case

 

format ["a = %1", str 123]

 

is slower than
 

format ["a = '%1'", 123]



while the result is identical

Share this post


Link to post
Share on other sites
1 hour ago, killzone_kid said:


Just want to point out if you can avoid str you should, especially like in this case

is slower than

while the result is identical

Ok cool Ill have to have a look at the saving. I just never bother as it means messing around with placing ""/' correctly( especially in longer more complicated statements ), where as format str is just write it and forget about it, as the format sorts it all out for you and you know its formatted in properly as a string.

 

On 22/06/2017 at 3:43 PM, feldruebe said:

there is an action added to the plane and removed again.

Who's in the plane? AI or client?

Whats the locality of the plane?

Why add an action, then force the use of said action, then remove action? Why not just run the code the action performs from the waypoint statement?

 

7 hours ago, f2k sel said:

it also still throws up local variable error for me in the last _plane reference

 

3 hours ago, feldruebe said:

tested it, same result.

 

Works fine for me.

  • Open fresh VR map
  • Place down player
  • Place manned BlackWasp
  • Add to BlackWasps init...
h = [ this ] spawn {
	params[ "_plane" ];
	systemChat str _plane;
	_actionId = _plane addAction [ "todo", {
		hint "Action Done";
	}];
	_wp = group driver _plane addWaypoint[ _plane getPos[ 500, getDir _plane ], 5 ];
	_wp setWaypointStatements[ "true", format[ "_plane = %1 call BIS_fnc_objectFromNetId; _plane action[ 'User', _plane, %2 ];", str ( _plane call BIS_fnc_netId ), _actionID ] ];
};

Plane starts to taxi towards waypoint, when he gets within completion range you see the hint "Action Done".

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
2 minutes ago, Larrow said:

Who's in the plane? AI or client?

Why add an action, then force the use of said action, then remove action? Why not just run the code the action performs from the waypoint statement?

The plane is AI controlled

 

About that action stuff: i made a script for a Useraction, and wanted to recycle it. The plane loads a cargobox (Action A), and when it passes the waypoint it should drop it (--> Action B).

If I used execVM for this task i still would have the same problem, of "_plane" being undefined

 

12 minutes ago, Larrow said:

Works fine for me.

  • Open fresh VR map
  • Place down player
  • Place manned BlackWasp
  • Add to BlackWasps init...

h = [ this ] spawn {
	params[ "_plane" ];
	systemChat str _plane;
	_actionId = _plane addAction [ "todo", {
		hint "Action Done";
	}];
	_wp = group driver _plane addWaypoint[ _plane getPos[ 500, getDir _plane ], 5 ];
	_wp setWaypointStatements[ "true", format[ "_plane = %1 call BIS_fnc_objectFromNetId; _plane action[ 'User', _plane, %2 ];", str ( _plane call BIS_fnc_netId ), _actionID ] ];
};

Plane starts to taxi towards waypoint, when he gets within completion range you see the hint "Action Done".

Gonna try that again some other day. Thanks for trying to help, maybe i'm just a bit too dumb at the moment :D

Share this post


Link to post
Share on other sites
10 minutes ago, feldruebe said:

If I used execVM for this task i still would have the same problem, of "_plane" being undefined

There are variables passed into the waypoint expression that you could use instead..

  • this refers to the group leader
  • thisList refers to an array containing each unit in the group

..that you could possibly use to get your reference to the pilot/plane dependant on how the group is setup.

2D editor waypoint onAct info and setWaypointStatement

  • Like 1

Share this post


Link to post
Share on other sites

Larrow that code does work but if you set the vehicle variable name in the editor  to _plane  that's when it  throws up the local variable error.

Share this post


Link to post
Share on other sites
18 hours ago, f2k sel said:

Larrow that code does work but if you set the vehicle variable name in the editor  to _plane  that's when it  throws up the local variable error.

Well don't do that then :D.

If you remove my script and just try to preview a mission with an Object that has vehicle variable name starting with an underscore you will still see the error "Local variable in Global space". ( Does not always happen on first preview but if you return to editor and preview again you will see the error appear ).

For example..

  • Load up Arma a fresh
  • open editor
  • place player
  • place another unit, set vehicle variable name as _bob
  • preview
  • return to editor
  • preview again
  • straight away "Local variable in Global space" error

Giving an Object a vehicle variable name starting with an underscore is a bad idea. Said vehicle variable name is also converted into a missionNamespace( Global ) variable, so you would now have a global variable, holding a reference to the Object, called _plane which is extremely confusing as local variables start with an underscore.

IMHO I don't think it should be allowed and should be bought to BI's attention as an Eden bug. TICKET

  • Like 1

Share this post


Link to post
Share on other sites

Personally I try and avoid using local variable names, in this instance I was trying to short cut creating an object with local name.

 

Share this post


Link to post
Share on other sites

Thanks very much guys, it works now!

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

×