Jump to content
Sign in to follow this  
NGagedFX

Clusterbomb

Recommended Posts

I'm working on a clusterbomb script and I nearly got it finished. Here is the code:

airplane init:

_plane addWeapon "AirBombLauncher";
_plane addMagazine "4Rnd_FAB_250";
nul = [this] execVM "CBU.sqf";

CBU.sqf

_plane = _this select 0;
hintSilent "starting script";

while {true} do {
_weaponClass = currentWeapon _plane;
if (_weaponClass == "AirBombLauncher") then {
	0 = _plane addEventHandler ["Fired", {[_plane] execVM "CBU2.sqf"}];
}
else {
	_plane removeEventHandler ["Fired", 0];
};
sleep 0.5;
};

CBU2.sqf

_plane = vehicle player;
_weaponClass = currentWeapon _plane;
_explode = false;
private ["_pos", "_dir", "_vel"];

if (_weaponClass == "AirBombLauncher") then {
_bomb = nearestobject [_plane, "Bo_FAB_250"];
sleep 1;
waitUntil {((getPos _bomb select 2) < 30)};
_pos = getPos _bomb;
_dir = getDir _bomb;
_vel = velocity _bomb;
deleteVehicle _bomb;
_explode = true;
}
else {
_plane removeEventHandler ["Fired", 0];
};

if (_explode) then {
_submun = 300;
_spread = 100;
_smarray = [];
for [{_i=0}, {_i<_submun}, {_i=_i+1}] do {
	_bomblet = "B_30mmA10_AP" createVehicle [2000,2000,2000];
	_bomblet setPos [(_pos select 0) + ((_spread / 2) - Random _spread), (_pos select 1) + ((_spread / 2) - Random _spread), _pos select 2];
	_bomblet setVelocity _vel;
	_smarray = _smarray + [_bomblet];
	_cnt = count _smarray;
	hintSilent format ["%1 bomblets", _cnt];
};
};

It kinda works pretty good. When I load the editor, the first bomb will do exactly what I want it to do. It creates the exact amount of bomblets and it does so smoothly.

However, when I drop a 2nd CBU, it creates double the amount of bomblets, even though _cnt displays there are only 300. This causes the sim speed to drop and there is a noticable slowdown.

When I drop the 3rd bomb, it creates double that of the first! 1 ingame second takes 4 RL seconds which is unacceptable. Eventually the game just crashes.

I made sure to reset _smarray and I've also tried setting every other variable to null/0 but that didn't work? I have no idea what to do here. :confused:

Edited by NGagedFX

Share this post


Link to post
Share on other sites

I think your problem is that it's adding multiple eventhandlers each loop.

I've popped in waituntil {_weaponClass != "AirBombLauncher"}; to stop it looping until the launcher is no longer selected.

_plane = _this select 0;
hintSilent "starting script";

while {true} do {
_weaponClass = currentWeapon _plane;
if (_weaponClass == "AirBombLauncher") then {
	0 = _plane addEventHandler ["Fired", {[_plane]execvm "CBU2.sqf";}];
	waituntil {_weaponClass != "AirBombLauncher"};
}
else {
	_plane removeEventHandler ["Fired", 0];
};
sleep 0.5;
};

Share this post


Link to post
Share on other sites

Well that fixes the problem. :) However, it spreads like a perfect square aligned to the x and y axis. Do you have any idea of how I could make it more roundly shaped?

This is the CBU.sqf as I have it right now, it executes itself with a different number of variables so I don't need 2 seperate files:

_cnt = count _this;

if (_cnt == 1) then {
_plane = _this select 0;
while {true} do {
	_weaponClass = currentWeapon _plane;
	if (_weaponClass == "AirBombLauncher") then {
		null = _plane addEventHandler ["Fired", {[] execVM "CBU.sqf";}];
		waituntil {_weaponClass != "AirBombLauncher"};
	}
	else {
		_plane removeEventHandler ["Fired", 0];
	};
	sleep 0.1;
};
};

if (_cnt == 0) then {
_plane = vehicle player;
_weaponClass = currentWeapon _plane;
_detoheight = 30;
_explode = false;
private ["_pos", "_dir", "_vel"];

if (_weaponClass == "AirBombLauncher") then {
	_bomb = nearestobject [_plane, "Bo_FAB_250"];
	sleep 1;
	waitUntil {((getPos _bomb select 2) < _detoheight)};
	_pos = getPos _bomb;
	_dir = getDir _bomb;
	_vel = velocity _bomb;
	deleteVehicle _bomb;
	_explode = true;

} else {
	_plane removeEventHandler ["Fired", 0];
};

if (_explode) then {
	_ammo = "B_30mmA10_AP";
	_submun = 250;
	_spread = 100;
	_spread2 = (_spread / 2);
	_speed = (sqrt ((_vel select 0)^2 + (_vel select 0)^2));

	for [{_i=0}, {_i<_submun}, {_i=_i+1}] do {
		_bomblet = _ammo createVehicle [2000,2000,2000];
		_bomblet setPos [(_pos select 0) + (_spread2 - Random _spread), (_pos select 1) + (_spread2 - Random _spread), _pos select 2];
		_bomblet setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+(cos _dir*_speed),(_vel select 2)*3];
	};
};
};

Right now I'll try to add a some kind of 'pop' effect/sound to the FAB_250 so it doesn't just disappaer mid-air. :)

Share this post


Link to post
Share on other sites

Yes I also reduced it to one script, I changed the way the velocity was working as my bombs were falling short.

I also added a slight random delay between each bomb which spreads the load on the CPU and GPU this also seems to make it look less square and a little simpler.

I reduced Bombs 200 and used grenades to give sounds but that's just a personal choice.

//
//Place the following three lines in the planes init
//this addWeapon "AirBombLauncher"; 
//this addMagazine "4Rnd_FAB_250";  
//this addEventHandler ["fired",{_this execvm "cluster_bomb.sqf"}]

_plane = _this Select 0; 
//_weaponclass = _this select 1;
_ammotype = _this Select 4;
//_round  = _this select 5;
_bomb = _this select 6;

if (_ammotype != "Bo_FAB_250") exitwith {};

_explode = false;
private ["_pos", "_dir", "_vel","_incvel"];

sleep 1;
waitUntil {((getPosatl _bomb select 2) < 30)};
_pos = getPosatl _bomb;
_dir = getDir _bomb;
_vel = velocity _bomb;
_incvel= 75;
deleteVehicle _bomb;
_explode = true;

if (_explode) then {
_submun = 200;
_spread = 100;
_smarray = [];
for [{_i=0}, {_i<_submun}, {_i=_i+1}] do {
	_bomblet = "grenade" createVehicle [2000,2000,2000];
	_bomblet setPosatl [(_pos select 0) + ((_spread / 2) - Random _spread), (_pos select 1) + ((_spread / 2) - Random _spread), _pos select 2];

	_bomblet setvelocity [
			((_vel select 0) + _incvel * (sin _dir)) ,
			((_vel select 1) + _incvel * (cos _dir)),
			(_vel select 2)
		];


	_smarray = _smarray + [_bomblet];
	_cnt = count _smarray;
	hintSilent format ["%1 bomblets", _cnt];
	sleep random 0.05;
};
};

Edited by F2k Sel

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  

×