Jump to content
Sign in to follow this  
Sirex1

Having trouble passing vehicle in init.sqf.

Recommended Posts

This is my first time scripting and i am making an mechanized infantry tactic script and i am having some trouble.

First is passing the vehicles from init.sqf to my script. It is for BMP-3 that i have named "ifv1", "ifv2","ifv3", "ifv4" in mission editor.

	
_ifvArray=[];
{
	if (side _x == "EAST" && _x name!=null) {
		if(!((assignedVehicle _x) in _ifvArray))
		{
		        _ifvArray=_ifvArray+[_x assignedVehicle];
		};
	};
}forEach allUnits;
hint "start";	
null = [_ifvArray] execVM "mechInfTac\mechInfTac_init.sqf";

The hint start won't show.

I used null = [ifv1,ifv2,ifv3,ifv4] execVM "mechInfTac\mechInfTac_init.sqf"; with "" around ifvX and not "" around ifvX, neither worked. But i later realized that either mean a simple string or unknow object, correct?

Then it problem with a for loop in my mechInfTac_init.sqf script.

	
if (!isServer) exitWith {};

private ["_ifvArray"];
_ifvArray = _this select 0;
_ifvInfantryArray=[objNull,objNull];

       hint "a";

// Connects cargo infantry with IFV
for [{_a=0}, {_a<4}, {_a=_a+1}] do {

	hint "b";
	_ifvInfantryArray set _a assignedCargo (_ifvArray select _a);
		// sleep 0.1;
}; 
hint "c";

I have written more code for the actual tactics but that requires that this first basic assignment code works. The goal is to make this very generic and dynamic for easy use in other peoples script but just now i am just testing so sorry if the code is a bit static.

So does anyone spot the problem?

Thanks on beforehand!

Share this post


Link to post
Share on other sites

This belongs to Mission editing & scripting asa this here is the addons related part of the editing forum.

Share this post


Link to post
Share on other sites

Okay i was unsure. Could a moderator move this please?

Share this post


Link to post
Share on other sites

Anyone knows what's wrong?

(Yeah i am bumbing but to be fair my thread was moved here and did not originate on the first page in this section)

Share this post


Link to post
Share on other sites

You could skip all that and just do this maybe?

Place Functions module first.

myGrp = [getMarkerPos "spawnlocation", EAST ,(configFile >> "CfgGroups" >> "East" >> "BIS_TK" >> "Mechanized" >> "TK_MechanizedInfantrySquadBMP2")] call bis_fnc_spawngroup;

Share this post


Link to post
Share on other sites

I don't belive i have explained my intention good enough.

What i want is a system that goes through (right now just my 4 BMP-3) in general all combat vehicles on the map, put these in an array "_ifvArray" then find out their infantry (right now they are in the cargo from start that is why my code is written to search cargo) and put these in an mulit dimensional array "_ifvInfantryArray" .

Both the ifv and it's soldiers will have the same index nunmber which will make it easy for me to script the tactics later on. With your solution i would still have the problem of marking the vehicles and it's infantry in the correct array/index.

From this light do you think you can help me with the code i have written?

My main question that i need help with is simply, how do i pass vehicles object form init.sgf to my script file. Is it "null = [_ifvArray] execVM "mechInfTac\mechInfTac_init.sqf";" or another syntax? Why won't my current init code work?

Edited by Sirex1

Share this post


Link to post
Share on other sites

Adding -showScriptErrors to your game shortcut will display syntax errors on screen which is quite helpful for figuring out SQF errors. There's also squint that can help catch errors too.

As far as the code itself, it seems to me that you're trying to replicate stuff that's already automatic in game. Like the crew command will automatically report back who's in a vehicle, so having nested arrays created at game start is redundant, at least for me, since you'll be able to check who's in a vehicle at anytime. I think I'm just too tired to figure out what you're trying to do here. :) Hopefully -showScriptErrors will help you though. :)

Share this post


Link to post
Share on other sites

Squint flagged the line

_ifvInfantryArray set _a assignedCargo (_ifvArray select _a);

as having errors. I'm not sure what you really wanted to write here but I'm pretty sure this is not it !

Share this post


Link to post
Share on other sites

Thank guys! The -showScriptErrors worked and i was able to search through my code. Turn out it was mayorly syntax error, like missing "then" after if statement and that i didn't always have variable after commands like "assignedCargo" and "name". Also i had " if (side _x == "east") " when correct was " if (side _x == east) ".

I am now having some difficulty with "forEach" statements. This is the _ifvInfantryArray code.

	for [{_a=0}, {_a<=4}, {_a=_a+1}] do 
{
	_ifvInfantryArray set [_a, assignedCargo (_ifvArray select _a)];
		hint "b";
}; 

And this is the code that is not working.

		{
	commandGetOut _x; 
	_x setBehaviour "combat";
	} forEach _ifvInfantryArray;

The error message is:

"Error setBehaviour: Type Array, expectet Object,group"

I have tried with "forEach group _ifvInfantryArray;" but then i get "Error group: Type Array, expectet Object".

Anyone know what the correct commands/syntax is to make this work?

Share this post


Link to post
Share on other sites

assignedCargo returns an array, which means you are saving, for example with 2 vehicles with 3 people in them:

_ifvInfantryArray set [_a, [unit1,unit2,unit3]];
_ifvInfantryArray set [_a, [unit4,unit5,unit6]];

Which means, when you run the foreach:

{
 // display content of _x
} foreach _ifvInfantryArray;

Will show as arrays:

[unit1,unit2,unit3]

[unit4,unit5,unit6]

And since setBehaviour needs to be given to a unit or group, you have to foreach the _x as well.

{
 commandGetOut _x;
 {
   _x setBehaviour "combat";
 } foreach _x;
} foreach _ifvInfantryArray;

Share this post


Link to post
Share on other sites

Thank you for the answer! It took a while to answer because i decided to make a basic workable code first. So this is what i got, a test mission.

http://www.mediafire.com/?w1zpr60zkwaudgp

So right now what the code does is that if the IFV get close enough to the enemy, then it own infantry will dismount and engage, and it will follow its infantry. Once resistance is neutralized all infantry will mount up again.

The mayor problem now is that the code is static and not flexible. I want it to be able to work with every IFV on both side and even if the infantry is not in cargo when the map starts also be able to give in game commands to the IFV how it should behave, like engage not engage, ignore all enemy, never dismount. Also could anyone tell me how i force cargo to stay in?

I need to be able to assign more values to each IFV to make this happen, like engage true or false and what distance to dismount. Am i correct in that the easiest (only?) way to do this is whit multi-dimensional arrays? I tried to make the _ifvArray in init.sqf multi-dimensional but then the code couldn't lock on to the vehicle in the script and i couldn't use the values. Could someone help me just get a multi-dimensional framework working so i can continue work with that? Because i am at a loss here.

Also i would appreciate feedback on the infantry combat bit :p. Please make a direct comparison in the provided test mission by trying with my script and it disabled.

P.S Thanks! Will try that.

Edited by Sirex1

Share this post


Link to post
Share on other sites

set/getvariable to assign variables/values to objects.

Share this post


Link to post
Share on other sites

Having some trouble with the variables. Getting "Error ==; Type Any, expected xxxxx, xxxx, xxxxx, xxxxx, xxxx". What i can tell from the "getVarible" decription this means that the variable is undefined, but i don't understand why that is.

Here is the assignment code, i have two versions, none of them work,

	// Connects cargo infantry with IFV
for [{_a=0}, {_a<= count _ifvArray}, {_a=_a+1}] do 
{
	_ifvInfantryArray set [_a, assignedCargo (_ifvArray select _a)];
	(_ifvArray select _a)  setVariable ["_contact", false, true];
	(_ifvArray select _a)  setVariable ["_engaging", false, true];
	(_ifvArray select _a)  setVariable ["_pullout", false, true];
	(_ifvArray select _a)  setVariable ["_ignoreEnemy", false, true];
	(_ifvArray select _a)  setVariable ["_target", [objNull, objNull], true];
	(_ifvArray select _a)  setVariable ["_targetAssigned", false, true];
	(_ifvArray select _a)  setVariable ["_clear", true, true];
	(_ifvArray select _a)  setVariable ["_follow", false, true];
	(_ifvArray select _a)  setVariable ["_followedSoldier", objNull, true];
	(_ifvArray select _a)  setVariable ["_distance", 150, true];
		hint "b";
}; 

/*
{
	_x  setVariable ["_contact", false, true];
	_x  setVariable ["_engaging", false, true];
	_x  setVariable ["_pullout", false, true];
	_x  setVariable ["_ignoreEnemy", false, true];
	_x  setVariable ["_target", [objNull, objNull], true];
	_x  setVariable ["_targetAssigned", false, true];
	_x  setVariable ["_clear", true, true];
	_x  setVariable ["_follow", false, true];
	_x  setVariable ["_followedSoldier", objNull, true];
	_x  setVariable ["_distance", 150, true];
} forEach _ifvArray;
*/

And here is the if code that gives the error, line that gives error in bold.

	// Check if any IFV has seen any enemy.
for [{ _loop1 = 0 },{ _loop1 < count _ifvArray },{ _loop1 = _loop1 + 1}] do
{

	_enemySide = _AllEast;
	if((side (_ifvArray select _loop1)) == east) then
	{
		_enemySide = _AllWest;
	};

	for [{ _loop2 = 0},{ _loop2 < count _enemySide },{ _loop2 = _loop2 + 1}] do
	{	
 			[b]if ( _ifvArray select _loop1 getVariable "_contact" == false[/b] 
 			&& ifvArray select _loop1 getVariable "_ignoreEnemy" == false 
 			&& ifvArray select _loop1 getVariable "_engaging" == false 
 			&& alive (__enemySide select _loop2) 
 			&& ((crew (_ifvArray select _loop1) select 0 ) knowsAbout (_enemySide select _loop2)) >=0.7 
 			&& ((crew (_ifvArray select _loop1) select 0 ) distance (_enemySide select _loop2)) <=	ifvArray select _loop1 getVariable "_distance") then
 			{		
 				{
 					_x reveal (_enemySide select _loop2) //Reveals the known enemy for his comrades
 				} forEachMember _ifvArray select _loop1;	
 				hint "contact!";
			_ifvArray select _loop1 setVariable ["_contact",true,true];    		
			} else
			{
				_ifvArray select _loop1 setVariable ["_contact",false,true];
			}; 				
	};

Note the above code is cut out of context thus the missing last " };".

Help very much appreciated!

Share this post


Link to post
Share on other sites

You sure the engine can read this right?

_ifvArray select _loop1 getVariable "_contact" == false

Maybe try helping it out with some parenthesis:

((_ifvArray select _loop1) getVariable "_contact") == false

Share this post


Link to post
Share on other sites
You sure the engine can read this right?

_ifvArray select _loop1 getVariable "_contact" == false

Maybe try helping it out with some parenthesis:

((_ifvArray select _loop1) getVariable "_contact") == false

Yeah i tried with that, gives same error on same line so it is not that.

But from the getVariable description it says "Returns Anything if the object is undefined.". But that would suggest that the _ifvArray don't work, but that shouldn't be a problem. The only change i have made there was that i moved the section.

	_ifvArray=[objNull,objNull];
{
	if (side _x == east) then {

		if(!(assignedVehicle _x in _ifvArray)) then
		{
		hint "start";
		_ifvArray=_ifvArray+[assignedVehicle _x];
		}; 
	};
} forEach allUnits; 

From init.sqf to mechInfTac_nit.sqf. But i tried the script immediate after i made that move and it still worked then. So i don't get why i have the problem.

Here is the latest build:

http://www.mediafire.com/?dth9oogscftoft7

Share this post


Link to post
Share on other sites

diag_log _ifvArray;

diag_log (_ifvArray select _loop1) getVariable "_contact";

Etc, to see what is in the array/variable exactly.

Share this post


Link to post
Share on other sites
diag_log _ifvArray;

diag_log (_ifvArray select _loop1) getVariable "_contact";

Etc, to see what is in the array/variable exactly.

Can't find the report file, where is it located?

I put "diag_log _ifvArray;" right before the main loop.

Share this post


Link to post
Share on other sites

I can't recommend Gaia's Debug Console enough for this kind of error hunting. Actual download that works for OA on the last page. Then start using global variables instead of local ones while trying to get stuff to work, change back to local when work done.

Just don't forget to turn if off before you join servers, or you might get yourself banned.

Share this post


Link to post
Share on other sites

Make sure to pretty much always use () around select command, ex (_this select 0) doMove (_this select 1); or you'll often find things not working.

Share this post


Link to post
Share on other sites

Thanks for answers. The main problem was that i had _ifvArray creatd with 3 objNull in the definitions, and these were the reason why i got back Anything from getVariable.

Also the variables don't handle boolean, but i changed to string with false and truth so that worked out. Most of the script is working, but i am having some bugs that i am tring to iron out, but university stared again so i am a bit slow on fixing them. Again thanks for help.

Share this post


Link to post
Share on other sites

Hi again, i have updated my script so it is per IFV based. The limitation now is that the script only works on infantry in cargo from map start, this is because i haven't figures out how to do with units in formation. I want to be able to check continuously for infantry that are to be connected to the vehicles. And if i use some sort of group command then i don't know how i will get around when their is several vehicles and squads under one mans control.

In the future i want to add so that you can give commands like ignore enemy, pull out, and stuff like that. Also i would want to FSM convert it but i haven't found out how to do that. I have the BI toolset 2 with the FSM editor.

Feedback is appreciated. Also feel free to use and work with the code, aslong as you mention me in the code.

http://www.mediafire.com/?gygfav9z2agjcgu

Share this post


Link to post
Share on other sites

Hi!

Could someone tell me the commands for using the ingame custom communicaiton commands. I want from in game to be able to give rules of engamgemnts.

Also if anyone could provide sources for AI scrippting i would be happy, especially how to use the FSM system, i already got the FSM editor.

Edited by Sirex1

Share this post


Link to post
Share on other sites

Hi again long time no see. I think i have a workable version now, just some variable names and other stuff that needs to be changed before release.

The trouble i am having now is the following and is unrelated to my scripts(i think since it hasn't kicked in yet when this happens):

One US marine APC(AAVP) squad has the scripted move order to move about 500 meters in the editor. Normal move waypoint with "Aware". AI Squad commander gives the command to board the AAVP (i tried as a soldier and confirmed this), then directly afterwards he gives group move 500 meters. Then all the soldiers board the APC, then nothing happens. At all.

I tried to play as the driver and myself drove away after boarding, then my scripts kick in and all works. But the ai won't simply go by himself, i can't figure out why. Do i need to use some fancy waypoint algorith for this to work?

Edited by Sirex1

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
Sign in to follow this  

×