Jump to content
Sign in to follow this  
super-truite

flashbang config and script execution

Recommended Posts

Thanks to Messiah and Thromp I have a config file which allows me to throw my flashbang (see this: http://forums.bistudio.com/showthread.php?153858-Custom-Grenade-config). Now I am trying to execute my flashbang.sqf script when the grenade explode.

What I tried so far is create some new particle effects for the explosion and I created as well a dummy particle effect which allows me to launch my script (you can execute a script from the particlearray https://community.bistudio.com/wiki/ParticleArray).

The advantage of this is that I should be able to launch the script directly when the grenade explode and get its position (_this select 0 will be the particle source position), which is useful in the script.

The issue I have is to launch the script at the right time (when the grenade explode) and only once.

Full config:

class CfgPatches
{
class SUP_flash  
{
	units[] = {};
	weapons[] = {"SUP_flash_throw"};
	requiredAddons[] = { "A3_characters_F", "A3_Data_F"};	
};
};


class CfgCloudlets
{
class Default;
class SUP_flashExp: Default
{
	circleVelocity[] = {0,0,0};
	moveVelocity[] = {0,0,0};
	size[] = {"4 + 4 * intensity","6 + 4 * intensity"};
	color[] = {
		{ 0.45,1,0.83,0 },
		{ 0.45,1,0.25,0.03 },
		{ 0.45,1,0.25,0.03 },
		{ 0.45,1,0.25,0.03 },
		{ 0.45,1,0.83,0 }};
	animationSpeed[] = {1000};
	positionVar[] = {"3 * intensity","1.2 * intensity","3 * intensity"};
	MoveVelocityVar[] = {1.75,1.75,1.75};
	colorVar[] = {0,0,0,0.02};
	interval = "0.007 * interval + 0.007";
	circleRadius = "intensity";
	particleShape = "\A3\data_f\ParticleEffects\Universal\Universal";
	particleFSNtieth = 16;
	particleFSIndex = 13;
	particleFSFrameCount = 2;
	particleFSLoop = 0;
	angleVar = 1;
	animationName = "";
	particleType = "Billboard";
	timerPeriod = 1.5;
	lifeTime = "25 + 20 * intensity";
	rotationVelocity = 0;
	weight = 4;
	volume = 1;
	rubbing = 0;
	randomDirectionPeriod = 0.01;
	randomDirectionIntensity = 0.08;
	onTimerScript = ""; //put script here
	beforeDestroyScript = "";
	lifeTimeVar = 0.2;
	rotationVelocityVar = 1;
	sizeVar = 2;
	randomDirectionPeriodVar = 2;
	randomDirectionIntensityVar = 0.1;
};
class SUP_flashExp2: Default
{
	circleVelocity[] = {0,0,0};
	moveVelocity[] = {0,0,0};
	size[] = {"4 + 4 * intensity","6 + 4 * intensity"};
	color[] = {
		{ 0.45,1,0.83,0 },
		{ 0.45,1,0.25,0.03 },
		{ 0.45,1,0.25,0.03 },
		{ 0.45,1,0.25,0.03 },
		{ 0.45,1,0.83,0 }};
	animationSpeed[] = {1000};
	positionVar[] = {"3 * intensity","1.2 * intensity","3 * intensity"};
	MoveVelocityVar[] = {1.75,1.75,1.75};
	colorVar[] = {0,0,0,0.02};
	interval = 1;
	circleRadius = "intensity";
	particleShape = "\A3\data_f\ParticleEffects\Universal\Universal";
	particleFSNtieth = 16;
	particleFSIndex = 13;
	particleFSFrameCount = 2;
	particleFSLoop = 0;
	angleVar = 1;
	animationName = "";
	particleType = "Billboard";
	timerPeriod = 0.01;
	lifeTime = 1;
	rotationVelocity = 0;
	weight = 4;
	volume = 1;
	rubbing = 0;
	randomDirectionPeriod = 0.01;
	randomDirectionIntensity = 0.08;
	onTimerScript = "\SUP_flash\scripts\flashbang.sqf"; //put script here
	beforeDestroyScript = "";
	lifeTimeVar = 0.2;
	rotationVelocityVar = 1;
	sizeVar = 2;
	randomDirectionPeriodVar = 2;
	randomDirectionIntensityVar = 0.1;
};
class SUP_flashSmoke: Default
{
	circleVelocity[] = {0,0,0};
	moveVelocity[] = {0,1,0};
	size[] = {"1.013 * intensity + 3","1.0125 * intensity + 5","1.013 * intensity + 7","2.013 * intensity + 10"};
	color[] = {
		{ 0.9,1,0.83,0.2 },
		{ 0.9,1,0.83,0.6 },
		{ 0.9,1,0.83,0.2 },
		{ 0.9,1,0.83,0 }};
	animationSpeed[] = {0.2};
	positionVar[] = {1.2,0.6,1.2};
	MoveVelocityVar[] = {3,1.5,3};
	colorVar[] = {0,0,0,0.1};
	interval = "0.014 * interval + 0.014";
	circleRadius = 0;
	particleShape = "\A3\data_f\ParticleEffects\Universal\Universal";
	particleFSNtieth = 16;
	particleFSIndex = 12;
	particleFSFrameCount = 8;
	particleFSLoop = 0;
	angleVar = 1;
	animationName = "";
	particleType = "Billboard";
	timerPeriod = 1;
	lifeTime = "5 * intensity";
	rotationVelocity = 0;
	weight = 0.053;
	volume = 0.04;
	rubbing = 0.15;
	randomDirectionPeriod = 0.2;
	randomDirectionIntensity = 0.2;
	onTimerScript = "";
	beforeDestroyScript = "";
	lifeTimeVar = 2;
	rotationVelocityVar = 5;
	sizeVar = 0.4;
	randomDirectionPeriodVar = 0.5;
	randomDirectionIntensityVar = 0.02;
};
};
class CfgLights
{
class SUP_flashLight
{
	color[] = {10,10,9.37};
	ambient[] = {0.35,0.35,0.35};
	brightness = 1;
	diffuse[] = {0,0,0};
	position[] = {0,0,0};
};
};







class SUP_flashExplosion
{
class Light1
{
	position[] = {0,0,0};
	simulation = "light";
	type = "SUP_flashLight";
	intensity = 1;
	interval = 1;
	lifeTime = 1;
};
class GrenadeExp1
{
	position[] = {0,0,0};
	simulation = "particles";
	type = "SUP_flashExp";
	intensity = 0.5;
	interval = 1;
	lifeTime = 1;
};
class GrenadeExp2
{
	position[] = {0,0,0};
	simulation = "particles";
	type = "SUP_flashExp2";
	intensity = 0.5;
	interval = 0.01;
	lifeTime = 0.015;
};
class GrenadeSmoke1
{
	position[] = {0,0,0};
	simulation = "particles";
	type = "SUP_flashExp"; //SUP_flashSmoke
	intensity = 0.5;
	interval = 1;
	lifeTime = 1;
};
};
class CfgAmmo 
{
class Default;	// External class reference
class Grenade : Default {};
class GrenadeHand : Grenade {};
class SUP_flash_ammo  : GrenadeHand 
{
	scope = 1;
	hit = 0.001;
	indirectHit = 0.001;
	indirectHitRange = 0.01;
	model = "\A3\Weapons_f\ammo\smokegrenade_white"; //  mettre ça plus tard  \SUP_flash\flash.p3d
	//\A3\Weapons_f\ammo\smokegrenade_white
	visibleFire = 0.5;
	audibleFire = 0.05;
	visibleFireTime = 1;
	fuseDistance = 5;
	ExplosionEffects = "SUP_flashExplosion";
};
};

class cfgMagazines
{
class Default;	// External class reference
class CA_Magazine : Default {};
class HandGrenade : CA_Magazine {};
class SUP_flash :  HandGrenade
{
    model = "\A3\Weapons_f\ammo\smokegrenade_white";   //  mettre ça plus tard  \SUP_flash\flash.p3d
	displayName = "flashbang";
	picture = "\SUP_flash\flash.paa";
	displayNameShort = "flash";
	ammo = "SUP_flash_ammo";
};
};


class CfgWeapons 
{
class Default;
class GrenadeLauncher : Default {};
class Throw : GrenadeLauncher {};
class SUP_Flash_Throw : Throw 
{
	displayname = "Throw";
	muzzles[] = {"SUP_Flash_Muzzle"};
	class  ThrowMuzzle: GrenadeLauncher
	{
		aidispersioncoefx = 6;
		aidispersioncoefy = 6;
		autoreload = 1;
		cursor = "EmptyCursor";
		cursoraim = "throw";
		enableattack = 0;
		keepininventory = 1;
		magazinereloadtime = 0;
		maxrange = 60;
		maxrangeprobab = 0.03;
		midrange = 45;
		midrangeprobab = 0.9;
		minrange = 10;
		minrangeprobab = 0.2;
		modeloptics = "";
		reloadsound[] = {"", 0.000316228, 1};
		reloadtime = 0;
		showempty = 0;
		sound[] = {"", 0.000316228, 1};

	};

	class SUP_FLash_Muzzle: ThrowMuzzle
	{
		magazines[] = {"SUP_Flash"};
	};
};
};


class cfgvehicles
{
class B_Soldier_base_F;
class my_throwing_soldier: B_Soldier_base_F
{
	_generalMacro = "my_throwing_soldier";
	scope = 2;
	displayName = "Flash Grenadier";
	weapons[] = {"arifle_MX_GL_ACO_point_F","hgun_P07_F","SUP_Flash_Throw","Put","Binocular"};
	respawnWeapons[] = {"arifle_MX_GL_ACO_point_F","hgun_P07_F","SUP_Flash_Throw","Put","Binocular"};
	magazines[] = {"30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","16Rnd_9x21_Mag","16Rnd_9x21_Mag","SUP_flash","SUP_flash","SUP_flash"};
	respawnMagazines[] = {"30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","16Rnd_9x21_Mag","16Rnd_9x21_Mag","SUP_flash","SUP_flash","SUP_flash","SUP_flash"};
	cost = 60000;
	threat[] = {1,0.3,0.1};
	linkedItems[] = {"V_PlateCarrierGL_rgr","H_HelmetB_paint","NVGoggles","ItemMap","ItemCompass","ItemWatch","ItemRadio"};
	respawnLinkedItems[] = {"V_PlateCarrierGL_rgr","H_HelmetB_paint","NVGoggles","ItemMap","ItemCompass","ItemWatch","ItemRadio"};
};
};

To simplify the discussion: here is a simplified version of the code with only the part that's bothering me:

class CfgCloudlets
{
class Default;
...
class SUP_flashExp2: Default // My dummy particle effect class
{

	interval = 1; // interval between two particle emission ?
	timerPeriod = 0.01; // interval between two execution of the script?
	lifeTime = 0.001; // particle lifetime?
	onTimerScript = "\SUP_flash\scripts\flashbang.sqf"; //script executed every timerperiod?
	beforeDestroyScript = "";
	lifeTimeVar = 0.2; //???
};

class SUP_flashExplosion //my flashbag explosion class
{
...
class GrenadeExp2 //part of the explosion which uses the dummy particle effect
{
	position[] = {0,0,0};
	simulation = "particles";
	type = "SUP_flashExp2";
	intensity = 0.5;
	interval = 0.01; //???
	lifeTime = 0.015; //time before the source is destroyed?
};

};

If the comments in the code were right, it should work, because there would be no time to execute the script twice and the script should be executed quickly after the explosion effect is called (0.01 second).

But it doesn't work and it acts randomly (sometimes the script is not activated, sometimes it is but like 5 or 10 times instead of once).

Any help on how to read those "time" numbers or on how to launch a script differently (this method is a bit fishy :) ) would be much appreciated.

From one of Thromp's comments, I understand that I could modify alternatively the muzzle effect, which is perhaps a simpler idea. I'll look into that if this fails.

Share this post


Link to post
Share on other sites

If you can figure this out will you be releasing it to the public?

Share this post


Link to post
Share on other sites

Sure, but I'll test it a bit with my clan first.

edit: It's more or less working now. I don't really now how I fixed it though :eek: and the script is still not exactly executed when the grenade explode.

I would still welcome a better idea :rolleyes:

Edited by super-truite

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  

×