Jump to content
Sign in to follow this  
demonized

Ai Shoots Flares [script] version 1.3

Recommended Posts

AIsoldierFlare v1.3

arma2oa2011032520343686.png

updated to v1.3 - 25.mar.2011

changelog v1.3

--- major updates ---

- weapons are given dynamically to any AI based on faction.

- all vanilla weapons from A2, OA, BAF, PMC with gl will be used by their respective members if you use them, US units gets us weapons,

russians get russian weapons etc.. there is now not only 1 weapon for each side.

- greatly improved beheaviour of AI´s when using flares, now AI units fire flares based on if other units have lighted up an area nearby.

Ais will now use flares in multiple locations as long as there is a need for it at current position.

- all options are now optional, only need this or unitname to run script.

wep = [this] execVM "scripts\lightsoldflare.sqf"

- AI units keep any AT or AA weapons they had when script started.

- option to remove launcher weapons and replace with rifle magazines instead.

- AI units are also equipped with he grenades for gl, unless they are medics, then they have no room for he grnades as default amount flares is 4.

--- smaller updates ---

- civilians can also be used.

- added random_color option.

- added refill flares, after x amount time y amount times.

- changed ambush options to use ambush only when option is entered.

- added random mode, ambush or normal.

- added beheaviour option, ambush or not is determined by group beheaviour, wps dynamically.

- added option to keep nvg's on units if desired.

- optimized custom weapon options, one for vanilla weapons, one for any weapon, from any addon.

- added option to use sun elevation to determine day or night by CarlGustaffa.

- smaller tweaks.

I wanted AI to shoot FLARES when they got engaged or spotted enemy in the dark.

So they could put pressure on players using NVG´s against opponents that do not have that technological perk.

Now there are all colors flares available through options.

Script works with Arma2, OA, or CO, BAF and PMC, as well as compatible with any addon if using curtom weapons option.

Script works in MP and on dedicated server as well.

Note: v.1.3 is not confirmed on dedi server yet but should be ok.

Script will give AI actual light over a area relative to he flare so they can see in the night when flare is up, a certain distance.

Default game flares is eyecandy for players only when not using this script, AI is blind as a bat if not using this script or similar.

Script can be used by AI from any side, West, East, Guer and Civilian.

Script only works when AI is on foot, it pauses when AI in vehicle and resumes when AI is on foot again.

Script does not care if its day or night so dont add this to your day missions, unless you want to see flares used in daylight.

in v1.3 there is a sun angle option by CarlGustaffa to check day or night, so you can possibly have multiple days missions going without no problem.

Script will equip AI with a weapon based on its faction, russians get russian weapons etc.

Launcher weapons is preserved if not specified otherwise.

Basic Usage:Copy the content from init.sqf to your init.sqf, there is optional EH for players for both MP and SP missions as well.

but this is the only line that is important for the script.

add this line to your init.sqf or in a trigger or something, as long as its activated before any Ai flare script its ok.

AIsoldierFlare_units = [];

add minimum this line with your selection in any soldier/civilian units initline, there are several options you can use if you choose so, but this works.

wep = [this] execVM "scripts\lightsoldflare.sqf";

If any enemy is detected by AI unit or AI´s group in its patrol or current movement:

AI will shoot a flare from its grenade launcher weapon up in the air near or towards enemy detected.

This will not magically create a flare in the air, AI will: if he is still alive, manually shoot the flare into the air.

Also script works on its own, so you can have 100 AI´s using this same script at the same time in same or different groups, script will not interfeer with it self, or make trouble for any other scripts or waypoints.

I tested scripts version 1.2 with upsmon script active as well, and it worked nicely in MP on dedicated server, version 1.3 works nicely with the latest upsmon 5.0.8 R2.

With 1 unit and with 100 units no problems, also in full mission with 50 AI groups using upsmon and no impacts, script works in the background.

It will not conflict with other movement, only make AI unit pause current move for a second to fire flare and then move on as scripted in upsmon(or other scripts) or waypoints.

Readme:

AIsoldierFlare v1.3
By Demonized

add this line in either init.sqf file or in a trigger at mission start:   AIsoldierFlare_units = [];
Units will get weapons based on faction.
Execute with:		wep = [this] execVM "scripts\lightsoldflare.sqf";
       		wep = [this,"ambush","red","sunElev"] execVM "scripts\lightsoldflare.sqf";
       		wep = [this,"random_color","refill",10] execVM "scripts\lightsoldflare.sqf";

unit name must be first argument and these options can be used anywhere in line if desired.
if using: wep = [this] execVM "scripts\lightsoldflare.sqf";	- then all will be randomised, and weapons will be based on faction, US get US weapons etc... 
west units gets green flares, east red, resistance yellow, civ white.

"debug"			- show helpful hints about the scripts beheaviour, this is the same as setting _debugMode to true.

"red"   		- color of flares used.
"green"			- color of flares used.
"yellow"		- color of flares used.
"white"			- color of flares used.
"random_color"   	- random color of flares used - note color will be same on all flares added to inventory of unit.
"refill",x,y		- will refill flares when empty after x amount of time y amount of times.

"sunElev"		- same as _sunElev = true; - use a old sun elevation function to find night or day, note: results may vary +/- ca 1 hour, not recomended.
"ambush"		- wait until enemy detected is close then fire flares.
"random_mode"		- randomly decide if ambush is used for using flares.
"beheaviour"		- decide ambush mode based on group beheaviour, fex: if group is in stealth mode, use "ambush" from above option else normal.
"nvg"			- unit will keep night vision goggles if it had them when script started.

This is only for A2,OA,BAF,PMC vanilla weapons, may work on others but no guarantee, use debug, and run script on player to find out.
"custom","weapon_classname"

This should be used for any weapon that do not work 100% with script, fex ACE weapons, this has no limits, any addons can be used.
"full_custom","weapon_class_name","weapon_bullets_used","custom_flare_classname","weapon_GL_muzzlename"

Examples custom and full_custom:
wep = [this,"red","ambush","custom","M4A1_HWS_GL"] execVM "scripts\lightsoldflare.sqf";
wep = [this,"full_custom","ACE_AK103_GL","ACE_30Rnd_762x39_S_AK47","ACE_SSRed_GP25","ACE_GP25Muzzle_AI","refill",60,5] execVM "scripts\lightsoldflare.sqf";

Credits:

Carl Gustaffa for initial help on v.1 and the crucial light part of script.

Das Attorny for help in understanding cfg files, crucial to new weapon selection.

BI community, and others for everything posted, and everything answered.

Demo mission should work for Arma2, OA, CO since i used baf and pmc units on pmc map:

http://www.4shared.com/file/kgdK6ySg/Demo_AIShootFlares_v1_3Proving.html

Feel free to modify, skin, strip, bash and trample script at will, if you use it in your own releases it would be nice with a credit line.

Also any feedback is welcome, bugs, requests, optimization tips etc.

Enjoy

Edited by Demonized
Updated to version 1.3

Share this post


Link to post
Share on other sites

A preliminary question - is it absolutely necessary for the AI to fire the flares, or can the flares appear, with the assumption being that they were fired by an enemy?

In a quick look of the script, as long as you know the direction of the enemy, just have the unit shoot the flare in that direction? It might reduce the overall code.

It also seems like you could nest a single waituntil nearestenemy loop within a while loop that checks for the flares in the unit's magazine array.

Oops, instead of having that while check 2 parameters, I'd nest an if/then for just the ammo, and if there is ammo, then the _keeplooping would be true. Dunno if you really need to check for alive? If you do, you could just make it if alive and has ammo, then _keeplooping is true.

Just a couple ideas. :)

Edited by TRexian

Share this post


Link to post
Share on other sites

1:yes you can magically just create flares in the air, with a nearestenemy or list of detected side in trigger, however afaik you cannot make a flare being shot in the air without having someone to actually fire it.

but for just creating a flare would make the script a just few lines, but not seem so realistic, as my aim was to have the AI himself shoot the flare, maybe you dont even need a script, everything may possibly be done from a trigger.

2:im not familiar with how to get direction to an enemy, thoug i suspect its something like getdir setdir x,y axis sumthing sumthing.

3:

Oops, instead of having that while check 2 parameters, I'd nest an if/then for just the ammo, and if there is ammo, then the _keeplooping would be true. Dunno if you really need to check for alive? If you do, you could just make it if alive and has ammo, then _keeplooping is true.
i thought that was what i did, unfortunately im not very familiar with while do..

Edit: added second test of while do in first post bottom.

Edited by Demonized
added info of new test

Share this post


Link to post
Share on other sites

I have a scripted solution where AI will use flares actively based on suspicion. However, as it's based on one running script per running AI unit with flares, it's not the best possible solution. But note the following:

1) If AI suspects something, then he will fire flares in order to see better so he can make that call better.

2) It's based on distance and some randomness, so they won't fire flares all over the place.

3) Last I checked, the actual flare object doesn't seem to have a valid #lightpoint associated with it. It's bright for the player, but it won't help the AI at all :( Earlier I solved this problem by doing some magical revealing, but now I attach a #lightpoint object to the actual flare while it's alive. And voila, the AI can now also spot you when they fire a flare :D

4) Although they will continue to shoot flares, they don't actually have to in order to see you once you've been made (they can see new enemies though that they didn't know of before). It's like grass and smoke - once you've been made there really is no hiding anymore.

5) Units are given equipment based on their class, grenadiers will have half of their HEs replaced with flares. Furthermore, they are magically restocked to keep the battlefield lit. Keep in mind I did it for an MP mission, so sometimes you have to cheat a little to ease the load.

6) AI doesn't know and/or couldn't care less what they are shooting. They may well try to hit you with a flare.

7) It's actually flare shooting (not magically created), so you can often hear the shot being fired, because they tend to be close.

So yes, I'm doing the same mistake as OP, by having one script running for each unit, instead of looping over units with the same script. But it works pretty good, and they start using them before they have a valid ID on the guy. I've posted this stuff before, but I consider it a bit outdated. Let me know if a refreshed version is useful. To test it in action, try Domino (not Domination, but based on it, the flare stuff is not in Domination) during night mission.

Share this post


Link to post
Share on other sites
Let me know if a refreshed version is useful.

Always is! Yes, please. :)

Share this post


Link to post
Share on other sites

Crap. Me and my big mouth :D Ehm, ok. Note that this is for east enemy AI only. I thought I had a more generalized version available, but I'm not sure how up to date that one is compared to how I use it in Domino, so I show this way.

When units are created, call this:

[_unit] call x_equipunit;

Where x_equipunit is:

x_equipunit = {
private ["_unit"];
_unit = _this select 0;
_muzzles = getArray(configFile>> "cfgWeapons" >> primaryWeapon _unit >> "muzzles");
if (count _muzzles == 2) then {
	_flaremagsw = ["FlareWhite_M203","FlareGreen_M203","FlareRed_M203","FlareYellow_M203"];
	_flaremagse = ["FlareWhite_GP25","FlareGreen_GP25","FlareRed_GP25","FlareYellow_GP25"];
	if ("M203Muzzle" in _muzzles) then {
		if (typeOf _unit in ["TK_Soldier_GL_EP1"]) then {
			{_unit removeMagazine "1Rnd_HE_M203"} forEach [1,2,3,4];
		};
		for "_i" from 0 to 3 do {
			_unit addMagazine (_flaremagsw select (_flaremagsw call XfRandomFloorArray));
		};
	};
	if ("GP25Muzzle" in _muzzles) then {
		_unit addMagazine (_flaremagse select (_flaremagse call XfRandomFloorArray));
	};
	_unit addEventHandler ["fired",{_this spawn DOM_EH_Fired}];
	[_unit] execVM "bat\EnemyFlares.sqf";
};
};

XfRandomFloorArray is a basic randomizer:

XfRandomFloorArray = {floor (random (count _this))};

The DOM_EH_Fired is precompiled via:

DOM_EH_Fired = compile preprocessFileLineNumbers "bat\EH-Fired.sqf";

which looks like this (tried to remove all additional stuff it does):

_unit = _this select 0;
_weapon = _this select 1;
_muzzle = _this select 2;
_mode = _this select 3;
_ammo = _this select 4;
_magazine = _this select 5; //Not in use yet.
_projectile = _this select 6; //_this expanded removed, now uses internal projectile support.
_flareammo = ["F_40mm_White","F_40mm_Green","F_40mm_Red","F_40mm_Yellow"];
_flaremagsw = ["FlareWhite_M203","FlareGreen_M203","FlareRed_M203","FlareYellow_M203"];
_flaremagse = ["FlareWhite_GP25","FlareGreen_GP25","FlareRed_GP25","FlareYellow_GP25"];

//For AI, add back ammo if shooting flares
if (_unit != player) then {
_restore = "";
if (_muzzle == "GP25Muzzle") then {
	switch (_ammo) do {
		case "F_40mm_White" : {_restore = "FlareWhite_GP25"};
		case "F_40mm_Green" : {_restore = "FlareGreen_GP25"};
		case "F_40mm_Red" : {_restore = "FlareRed_GP25"};
		case "F_40mm_Yellow" : {_restore = "FlareYellow_GP25"};
	};
} else {
	switch (_ammo) do {
		case "F_40mm_White" : {_restore = "FlareWhite_M203"};
		case "F_40mm_Green" : {_restore = "FlareGreen_M203"};
		case "F_40mm_Red" : {_restore = "FlareRed_M203"};
		case "F_40mm_Yellow" : {_restore = "FlareYellow_M203"};
	};
};
if (_restore != "") then {_unit addMagazine _restore};
};
if (_ammo in _flareammo) then { //[color="Red"]Forget these for now, I'll try to explain in detail later.[/color]
//	["[i][u][color="#2e8b57"][b]glflareclient[/b][/color][/u][/i]", [_projectile]] call XNetCallEvent;
//	["[i][u][color="#2e8b57"][b]glflareserver[/b][/color][/u][/i]", [_projectile]] call XNetCallEvent;
};

And finally, the actual script that does the shooting of the flares:

private ["_unit","_check","_leader","_flarechance","_mags","_one_flare","_one_flare_muzzle","_muzzles","_enemies"];
_unit = _this select 0;
_flarechance = 0.6;
_enemylist = [];
_flareammo = ["F_40mm_White","F_40mm_Green","F_40mm_Red","F_40mm_Yellow"];
_flaremagsw = ["FlareWhite_M203","FlareGreen_M203","FlareRed_M203","FlareYellow_M203"];
_flaremagse = ["FlareWhite_GP25","FlareGreen_GP25","FlareRed_GP25","FlareYellow_GP25"];
_flarefired = false;
_unit setVariable ["flarefired", false];
sleep 0.123;
while {alive _unit} do {
_flarefired = _unit getVariable "flarefired";
if (_flarefired) then {sleep 10.123 + (random 10)};
_leader = leader _unit;
_check = false;
_enemies = [];
_enemies = [color="Blue"]nearestObjects[/color] [_unit,["[color="#ff0000"]SoldierWB[/color]"],400];
{
	scopeName "xxxx1";
	if((_leader knowsAbout _x >= [color="#ff0000"]0.05[/color]) && (_unit distance _x < 300) && ((side _unit) getFriend (side _x)) < 0.6) then {
		_check = true;
		breakout "xxxx1";
		sleep 1.123;
	};
} forEach _enemies;

if (_check && !_flarefired && (random 1 < _flarechance) && !(call X_fnc_isDay)) then {
	_one_flare = "";
	_mags = magazines _unit;
	{
		scopeName "xxxx2";
		if (_x in _flaremagsw || _x in _flaremagse) then {
			_one_flare = _x;
			breakOut "xxxx2";
		};
	} forEach _mags;
	sleep 3.345;
	if (!_flarefired && alive _unit) then {
		if (_one_flare != "") then {
			sleep 1.234;
			_muzzles = getArray(configFile>> "cfgWeapons" >> primaryWeapon _unit >> "muzzles");
			_one_flare_muzzle = "";
			if ("GP25Muzzle" in _muzzles) then {_one_flare_muzzle = "GP25Muzzle"};
			if ("M203Muzzle" in _muzzles) then {_one_flare_muzzle = "M203Muzzle"};
			sleep (3 + random 6);
			_unit selectWeapon _one_flare_muzzle;
			if (count _enemies == 0) then {
				_unit doWatch [getPos _unit select 0, getPos _unit select 1, 200];
			} else {
				_unit doWatch [getPos (_enemies select 0) select 0, getPos (_enemies select 0) select 1, 150 + (300 - (_unit distance (_enemies select 0))/2)];
			};
			sleep 1.234;
			_unit fire [_one_flare_muzzle, _one_flare_muzzle, _one_flare];
			sleep 1.234;
			_flarefired = true;
			_unit setVariable ["flarefired", true];
			_unit doWatch objNull;
			sleep 31.234;
			if (random 1 < 0.7) then {
				if (_one_flare_muzzle == "GP25Muzzle") then {
					_unit addMagazine (_flaremagse select (_flaremagse call XfRandomFloorArray));
				} else {
					_unit addMagazine (_flaremagsw select (_flaremagsw call XfRandomFloorArray));
				};
			};
		};
	}
	else {
		_flarefired = false;
	};
	sleep 30;
};
sleep 10 + (random 10);
_flarefired = false;
_unit setVariable ["flarefired", false];
};

Note the low knowsAbout value in red. That's what trigger the unit to use flares in the first place. Adjust to suit. Also I'm using "SoldierWB", which isn't very generalized. Adjust to suit. The blue command nearestObjects would probably work even better with nearestEntities.

The script checks for night using a generalized function that looks like:

X_fnc_IsDay = {
private ["_ret"];
_ret = if (call X_fnc_SunElev > 0) then {true} else {false};
_ret
};

and (phew...)

X_fnc_SunElev = {
/*
	Author: CarlGustaffa

	Description:
	Returns the suns altitude for current day and hour of the year on any island (whos latitude may differ).

	Parameters:
	None needed.

	Returns:
	Suns altitude in degrees, positive values after sunrise, negative values before sunrise.
*/
private ["_lat", "_day", "_hour", "_angle", "_isday"];
_lat = -1 * getNumber(configFile >> "CfgWorlds" >> worldName >> "latitude");
_day = 360 * (dateToNumber date);
_hour = (daytime / 24) * 360;
_angle = ((12 * cos(_day) - 78) * cos(_lat) * cos(_hour)) - (24 * sin(_lat) * cos(_day));
_angle
};

but for a static mission on a static island you could pull it off with a normal time check instead.

Now, about those effect files, they are called in this weird looking way because that's the semantics that Domination uses. How you end up calling them are up to you, but they are split up into client and server scripts so you can easily see what's going on. In Domination there is a middle wrapper handling system that sits between everything, but I'm not going to add more confusion by using that here, so I'll just show the scripts that end up on clients and server:

client:

GL_Effects_Flare_Client = {
_projectile = _this select 0;
_delay = time + 3;
waitUntil {count getArray (configFile >> "CfgAmmo" >> typeOf _projectile >> "lightColor") > 1 || time > _delay};
if (time > _delay) exitWith {}; //Not a flare.
sleep 2;
if (!alive _projectile) exitWith {}; //Color will not have enough elements if dead.
_timetolive = getNumber (configFile >> "CfgAmmo" >> (typeOf _projectile) >> "timeToLive");
_color = getArray (configFile >> "CfgAmmo" >> typeOf _projectile >> "lightColor");
_r = _color select 0;
_g = _color select 1;
_b = _color select 2;
_a = _color select 3;
sleep 0.05;
_sm = "#particlesource" createVehicleLocal getPos _projectile;
_sm setParticleRandom [0.5, [0, 0, 0], [0, 0, 0], 0, 0.3, [0, 0, 0, 0], 0, 0, 360];
_sm setParticleParams [["\ca\Data\ParticleEffects\Universal\Universal", 16, 12, 8,0],
	"", "Billboard", 1, 3, [0, 0, 0],
	[0,0,0], 1, 1, 0.80, 0.5, [0.6,1.4],
	[[0.9,0.9,0.9,0.6], [1,1,1,0.3], [1,1,1,0]],[1],0.1,0.1,"","",_projectile];	
_sm setdropinterval 0.02;
_sp = "#particlesource" createVehicleLocal getPos _projectile;
_sp setParticleRandom [0.03, [0, 0, 0], [0, 0, 0], 0, 0.2, [0, 0, 0, 0], 0, 0, 360];
_sp setParticleParams [["\ca\Data\ParticleEffects\Universal\Universal", 16, 13, 2,0],
	"", "Billboard", 1, 0.1, [0, 0, 0],
	[0,0,0], 1, 1, 0.80, 0.5, [1.5,0],
	[[_r,_g,_b,-4], [_r,_g,_b,-4], [_r,_g,_b,-2],[_r,_g,_b,0]],[1000],0.1,0.1,"","",_projectile,360];	
_sp setdropinterval 0.001;
//	_projectile say3D "FlareBurnGL"; //Activate if you have a 30 second sound sample available.
_to_delete = [_sm, _sp];
sleep 0.1;
[_to_delete, _projectile] spawn {
	_to_delete = _this select 0;
	_projectile = _this select 1;
	waitUntil {!alive _projectile};
	{deleteVehicle _x} forEach (_to_delete);
};
};

server:

GL_Effects_Flare_Server = {
_projectile = _this select 0;
_delay = time + 3;
waitUntil {count getArray (configFile >> "CfgAmmo" >> typeOf _projectile >> "lightColor") > 1 || time > _delay};
if (time > _delay) exitWith {}; //Not a flare.
sleep 2;
if (!alive _projectile) exitWith {}; //Color will not have enough elements if dead.
_color = getArray (configFile >> "CfgAmmo" >> typeOf _projectile >> "lightColor");
_r = _color select 0;
_g = _color select 1;
_b = _color select 2;
_a = _color select 3;
_li = "#lightpoint" createVehicleLocal [0,0,0]; //getPos _projectile;
_li setLightBrightness 0.24; //2.44;
_li setLightAmbient[_r*0.8, _g*0.8, _b*0.8];
_li setLightColor[_r, _g, _b];
_li lightAttachObject [_projectile, [0,0,0]];
[_projectile] spawn {
	_projectile = _this select 0;
	while {alive _projectile} do {
		_projectile setPosASL [(getPosASL _projectile select 0) + 0.05 * (wind select 0), (getPosASL _projectile select 1) + 0.05 * (wind select 1), (getPosASL _projectile select 2) + 0.2];
		sleep 0.075;
	};
};
waitUntil {!alive _projectile};
deleteVehicle _li;
};

Client script adds a lightsource (really only needed if you have AIs on your team, since AI will see what you see, and the flare alone as I said will not actually give additional spotting capabilities to the AI) to the flare. It also adds a glowing orb, also visible in daylight, and some smoke effects. Burnt residue effect was removed (didn't like how it looked in the end).

Server script also adds a lightsource (highly needed in COOP games, or they won't be aided by the flare). It doesn't add glowing orb or smoke as AI could care less. But it does add wind drift, but you may have to adjust its effect and delay to suit. Due to how AI sometimes shoots flares by aiming at you, I decided not to include any simulation stopping just above ground (like in ACE), and I rather just call it "destroyed on impact" instead.

Feel free to enhance and fix, no permissions needed, and no credits required. It may look a bit complex, but it's actually quite straightforward - no rocket science going on here :p Remember, running scripts on a per unit basis is BAD stuff, so optimizing this to loop over all units instead might be a first optimization step. GL flares are a bit more straightforward to handle than arty flares, as there are no incoming sounds, delay, expel sound, delay, ignite sequence that needs to be maintained.

Hope this is useful, and not adding too much confusion to the mix. Alternatively, you can try to create it for yourself from scratch, and come back and check how I solved some of the error messages you might come across. Hope I managed to put it all in this time, instead of just fragments :)

Share this post


Link to post
Share on other sites

wow that was alot of info CarlGustaffa :)

Any chance i dont have to pick your scripts apart to find the create light on flare shot part??

Maybe an example script of how to attach light to my AI launched flare?

I understand the script, im just not seeing what you _this select 0; from to get projectile in the server script....??

I think that server script is only thing i need to compliment my own script with actual light for ai... right?

In testing of my own script i didnt actually notice AI being blind even with flare, tho my test subject was this setDammage false; and once bluefor ai with NVG spotted him they shot, him and he launched flare, and started to kill them all, then launched next flare if anyone still left, and so on..

If i understand correctly:

My players in COOP using NVG´s approaching enemy, enemy doesnt see them, and is on aware mode, players shoot at enemy, enemy switches to combat mode and launches flare, and starts shooting at any player that is shooting, wich probably is all of them by this point, enemy sees players because of their shooting and not flare itself?? flare is only eyecandy for players??

That seems like a silly thing for BIS to still have ingame..

Edit: i am trying to look at a while loop and integrate all flare AIs into an array in same script, but im getting nowhere with that, my problem is the while loop stops or never starts.. so its kindof on the shelf for now, still learning.

Edit2: Man i feel stupid, my while loops didnt work because of while () do { instead of the correct while {} do {

I have finished my script with while do, but with all the help lines in it its now 0.10kb bigger than my original script lol.

Script has countermeasure to prevent multiple ais spamming nightsky with flares.

Also have incorporated an ambush or attack on sight option.

I have updated my first post at beginning of thread with script.

---------- Post added at 05:26 PM ---------- Previous post was at 03:29 PM ----------

Script fully working and updated with combat, ambush option as well as AI spam sky with flares prevention, and check if ai in vehicle then dont shoot.

Edited by Demonized

Share this post


Link to post
Share on other sites

Indeed flares are only eyecandy for players (can also work against players though, by washing out their NVGs, and I'm using this as a valid arty flare tactics for AI), and indeed it is silly. Disappointing even. A flare doesn't aid AI vision or ability to spot things. A #lightpoint object does (didn't always).

The point of this mess is that they start shooting flares based on suspicion of enemy around them, instead of waiting until they have confirmation, in which the flares doesn't really do anything. At the same time the script prevents them from using flare at all unknowns, only unknowns that actually are enemies. Or they would keep shooting flares all the time which looked silly.

Even with reveal, you'll only obtain a value of 1, which is not enough to start shooting, but enough to send units out to observe. So when the #lightpoint illuminates their enemy, knowsAbout goes high enough so they actually open fire.

Not sure what you mean about _this = _projectile. It's the lines that are commented here that sends [_projectile] as a parameter to the wrapper function, which in turn (but now shown) sends _projectile as parameter to the server and client scripts. You could possibly use publicVariable and addPublicVariableEventHandler to cope with it instead. If you really want to know about how it works in Domination, check out this, but I guess it's kinda hard to wrap your head around unless you're able to follow the code.

Share this post


Link to post
Share on other sites

checking out your link now.

What i meant in previous post was:

From where or how do you call the "server" script that creates a light for the ai on the projectile"the flare"?

This from above scripts confuses me...

_projectile = _this select 6; //_this expanded removed, now uses internal projectile support.

when its not being used or is it??

basically i wanted to know how to get the unit or name of: (flare shot aka the projectile)

for then to create a light source on for the AI to spot enemy players due to more light, from the flare.

I am far from a good scripter, i usually learn by copying and modifying or looking at others scripts.

Your scripts posted above may be just to much for me to understand atm.

Edit: i see you use a firedeventhandler to launch the create light on projectile script, is that correct?

Never messed with evenhandlers before, time to research again. :)

Share this post


Link to post
Share on other sites

Ehm, never mind the //comment on that line. If you see the notes on fired EH, you'll see that after b1.54.73642, magazine and projectile is passed automatically to the script. Before we had to use some tricks to obtain the projectile.

It works like this: When an AI that qualifies for a grenadier (determined in the x_equip function) shoots his weapon, the fired EH is started, and all those parameters are obtained automatically. As it is here only for server AI, the server script can be started normally. But you have to make sure somehow that the client script is started as well, for clients, if you want the added visual effects and sound (if activated). I'm using the wrapper in Domination to do it, but you could use publicVariables for an easier approach.

Yeah that's how I learn myself, watching other peoples stuff. Domination is now not as easy to read as it once was, but that's pretty much how I started. Trying to read and learn the updated ways made me understand scripting better in general.

Eventhandlers is a very important aspect of scripting, get down to business :)

Share this post


Link to post
Share on other sites

Thank you for that info CarlGustaffa.

That explained alot, and after a look at that bis link i got a better understanding of the concept EH as well now.

Tomorrow i will make the changes needed to add light from server script, if all goes well i should be able to make client side as well, just for the practice :)

I know im kindof inventing the wheel allover again, but this is the way i learn it.

Im abit exited, all those EH opens up a whole lot of uses that i wasnt familiar with :)

Time to hit the sack, have a good night.

Share this post


Link to post
Share on other sites

Added Event handler to create actual light for AI when flare is lit based on Carl Gustafas scripts and helpful tips.

If you use both of the scripts, AI will also get vision same as players at night when AI shoots a flare.

Also added and optional line for init.sqf so that if any players would shoot a flare, then same effect will be added for AI, meaning if player shoot a flare, AI will see in the dark aswell.

If deleting line in lightsoldflare.sqf wich adds evenhandler, then script is standalone and AI will shoot flares so players can see (eyecandy for players), but AI will not be able to see any better in the dark, they will still be blind.

1st Post updated with scripts and info

Edit, @Carl Gustafa: Im curious, can you decribe the reasoning for the exact value in setLightBrightness 0.24;?

I asumed it was an value that made the light strong enough to cover a realistic area lit up by the flare, key word, i asumed...

Edited by Demonized
edited text

Share this post


Link to post
Share on other sites

Updated script to Version 1.2.

1st post updated and added demo mission wich should be usable in arma2 standalone, OA standalone and CO because i used baf and pmc units for demonstration on pmc map.

Share this post


Link to post
Share on other sites

Very, very cool.

I've been trying to implement this in Pogoman's Insurgency mission, to no avail. I'm new to the scripting. Although I can make sense of some of it, I can't seem to find and manipulate the OPFOR ai spawning options. Only the player ones in mission.sqm but that's not what has to be edited (I presume since the player selects an already spawned ai from the map to control).

Can someone shed some light on this issue (which could elevate Insurgency to be really interesting at night).

Thanks in advance.

Share this post


Link to post
Share on other sites
Very, very cool.

I've been trying to implement this in Pogoman's Insurgency mission, to no avail. I'm new to the scripting. Although I can make sense of some of it, I can't seem to find and manipulate the OPFOR ai spawning options. Only the player ones in mission.sqm but that's not what has to be edited (I presume since the player selects an already spawned ai from the map to control).

Can someone shed some light on this issue (which could elevate Insurgency to be really interesting at night).

Thanks in advance.

Im not familiar with how insurgency works in scripts, but there should be a script in the mission folder referring to the spawning of units, where you can add the eventhandler. if you could PM me a copy of the mission folder i can take a look when i got some time.

Share this post


Link to post
Share on other sites
Guest

Thanks for the script, I'll defo use it in my upcoming vietnam mission:)

Share this post


Link to post
Share on other sites
Thanks for the script, I'll defo use it in my upcoming vietnam mission:)

Yeah! id assume the Vietnam arena is the perfect place for flares, getting platoon flashbacks of charlie sheen entrenched at night.

Share this post


Link to post
Share on other sites

i am new to editing and have recently created a mission where seal teams try secure the airbase in Utes. Its in the dark and it kinda feels lonely without any flares going up as my men are spotted. i have used the sript provided but then as i go into the game it comes up with "script scripts\lightsoldflare.sqf; not found". any ideas on what im doing wrong? any advice would be grate,

thanks

Share this post


Link to post
Share on other sites

You have the script just inside your mission folder??

Precisely how and where are you calling it??

The game error is looking for the script inside a folder inside the mission folder.

Just change the reference when/ where the script is called or put inside a folder called 'scripts'.

Open up a few more missions to get idea of internal structure.

This is good practice anyways to seperate and keep stuff tidy in a busy mission.

Share this post


Link to post
Share on other sites

if i want ai unit to use flare gun instead of gl rifle... can this script do that? i hav try custom script (wep = [this,"custom","wx_flaregun"] execVM "scripts\lightsoldflare.sqf";) but, ai unit dont do anything... can someone help me?

Share this post


Link to post
Share on other sites

Would this script work for UNSUNG mod, with BLUEFOR being the enemy? They will use the script as they search out the player (OPFOR) in the jungle, at night.

Share this post


Link to post
Share on other sites

Hey,

 

awesome script.

 

I have a few problems tho.

I am using your script for different takistani soldiers.

Normal soldiers, special forces and militia.

According to the script, normal+special should get "AK_74_GL" and the militia should get "M16A2GL".

Plus east units should have red flares.

 

In my mission all flare units get either the AK or the M16 but totally random. Some special forces+normal soldiers  using the M16 and militia using the AK.

That's not really my problem, the problem is the color, it is not red!

All M16 units have white flares and all AK units have green flares.

I would like all units to either use red or even white flares.

I tried using custom and full custom, I managed to get red with this way but I am getting an annoying error message then: " no entry 'bin\config.binCFG.Magazines.'. "

Changing all weapons to the M16 to get white or all colors to white or red inside the script didn't work.

I just did this for example:

Spoiler

                case 0: {_wpArr = ["M16A2GL","AK_74_GL"]};
                case 1: {_wpArr = ["M16A2GL","AK_74_GL"]};
                case 2: {_wpArr = ["M16A2GL","AK_74_GL"]};
                case 3: {_wpArr = ["M16A2GL","AK_74_GL"]};
                case 4: {_wpArr = ["M16A2GL","AK_74_GL"]};
                case 5: {_wpArr = ["M16A2GL","AK_74_GL"]};
                case 6: {_wpArr = ["M16A2GL","AK_74_GL"]};
                case 7: {_wpArr = ["M16A2GL","AK_74_GL"]};

Or this:

Spoiler

            if (_side == west) then {_orgArr = ["white"]};
            if (_side == east) then {_orgArr = ["white"]};
            if (_side == resistance) then {_orgArr = ["white"]};
            if (_side == civilian) then {_orgArr = ["white"]};

 

I also tried to use 'full_custom' to use ace "ACE_SSRed_GP25" flares, like this:

wep = [this,"red","refill",180,3,"sunElev", ""beheaviour", "full_custom","AK_74_GL","30Rnd_545x39_AK","ACE_SSRed_GP25","GP25Muzzle"] execVM "scripts\AiLight\lightsoldflare.sqf";

But I am always getting this annoying error pop up when I load the mission for the first time after starting the game..

" no entry 'bin\config.binCFG.Magazines.'. "

Strangely I have an old mission save where it does work without the error but when I am adding it now I am getting it.

 

Thanks in advance.

Cheers

 

Edit:

I managed to do it error free and with white flares like this:

wep = [unit,"red","custom","M16A2GL"] execVM "scripts\AiLight\lightsoldflare.sqf";

Ignore the red .... flares are white, which works well for me.

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  

×