Jump to content
Yolo Joe

Need help with addAction...

Recommended Posts

Hey all!

I'm creating a script that adds smoke trails on planes, but I'm having some issues. This is what I have so far:

 

Plane init:

this addAction ["Release Smoke Trails", "SpawnSmoke.sqf", "", 0, false, false, "", "_this in plane2"];

SpawnSmoke.sqf:

_smoke1 = "SmokeShellRed" createVehicle position plane2; _smoke1 attachTo [plane2, [-4, 0, 0] ];
_smoke2 = "SmokeShellRed" createVehicle position plane2; _smoke2 attachTo [plane2, [4, 0, 0] ];
_smoke3 = "SmokeShellBlue" createVehicle position plane2; _smoke3 attachTo [plane2, [-5, 0, 0] ];
_smoke4 = "SmokeShellBlue" createVehicle position plane2; _smoke4 attachTo [plane2, [5, 0, 0] ];

I want to add a new action after pressing that action so I tried:

 

SpawnSmoke.sqf

_smoke1 = "SmokeShellRed" createVehicle position plane2; _smoke1 attachTo [plane2, [-4, 0, 0] ];
_smoke2 = "SmokeShellRed" createVehicle position plane2; _smoke2 attachTo [plane2, [4, 0, 0] ];
_smoke3 = "SmokeShellBlue" createVehicle position plane2; _smoke3 attachTo [plane2, [-5, 0, 0] ];
_smoke4 = "SmokeShellBlue" createVehicle position plane2; _smoke4 attachTo [plane2, [5, 0, 0] ];
 
plane2 addAction ["Stop Smoke Trails", "StopSmoke.sqf", "", 0, false, false, "", "_this in plane2"];

and in StopSmoke.sqf:

deleteVehicle _smoke1; deleteVehicle _smoke2; deleteVehicle _smoke3; deleteVehicle _smoke4;

However when I press "Stop Smoke Trails", I get the error "Undefined variable in expression: _smoke1"

Also, if I press the "Release Smoke Trails" action there will be stacked more "Stop Smoke Trail" actions.

Any help is greatly appreciated!

Share this post


Link to post
Share on other sites

A variable with a preceding _ is called a local variable.  That means that it's only available within the script in which it was created.  So since you created those objects in SpawnSmoke script StopSmoke doesn't know what they are since they were local to the SpawnSmoke script.  That's why you're getting that error.

 

You can get around this a few ways, the easiest is to simple remove the _ from those variables which makes them global and both scripts would know about them assuming no issues with locality, which is yet another entire headache to deal with), but a different way might be to track those variables in a slightly different way.

this setVariable ["YOLO_SmokeOn", [], true];  
this addAction ["Release Smoke Trails", "SpawnSmoke.sqf", [true], 0, false, true, "", "driver _target == _this && count (_target getVariable 'YOLO_SmokeOn') < 1"];  
this addAction ["Stop Smoke Trails", "SpawnSmoke.sqf", [false], 0, false, true, "", "driver _target == _this && count (_target getVariable 'YOLO_SmokeOn') > 0"];

SpawnSmoke.sqf:

// SpawnSmoke.sqf
//this setVariable ["YOLO_SmokeOn", [], true];  
//this addAction ["Release Smoke Trails", "SpawnSmoke.sqf", [true], 0, false, true, "", "driver _target == _this && count (_target getVariable 'YOLO_SmokeOn') < 1"];  
//this addAction ["Stop Smoke Trails", "SpawnSmoke.sqf", [false], 0, false, true, "", "driver _target == _this && count (_target getVariable 'YOLO_SmokeOn') > 0"];

params ["_plane", "_pilot", "_action", "_args"];
_smokeStart = _args param [0, false];
_smokes = [];

if (_smokeStart) then {
	{
		_smokeTrail = (_x select 0) createVehicle [0, 0, 1000]; 
		_smokeTrail attachTo [_plane, [(_x select 1), 0, 0]];
		_smokes pushBack _smokeTrail; 
	} forEach [["SmokeShellRed", -4], ["SmokeShellRed", 4], ["SmokeShellBlue", -5], ["SmokeShellBlue", 5]];
} else {
	{
		deleteVehicle _x;
	} forEach (_plane getVariable "YOLO_SmokeOn");
};

_plane setVariable ["YOLO_SmokeOn", _smokes, true];

  • Like 2

Share this post


Link to post
Share on other sites

Lovingly stolen borrowed from smoke effect module 🙂

plane addAction [ "Release Smoke Trails", {
		params [
			"_target",
			"_caller",
			"_id"
		];
		
		_smokeOn = _target getVariable [ "smokeTrailsOn", false ];
		
		switch ( _smokeOn ) do {
			case true : {
				_target setUserActionText [ _id, "Release Smoke Trails" ];
				{
					deleteVehicle _x;
				}forEach ( _target getVariable [ "emitters", [] ] );
			};
			case false : {
				_target setUserActionText [ _id, "Stop Smoke Trails" ];
				_emitters = [];
				{
					_x params[ "_color", "_pos" ];
					_color params[ "_colorRed", "_colorGreen", "_colorBlue" ];
					
					_emitter = "#particlesource" createVehicle ( _target modelToWorld _pos );
					_emitter attachTo [ _target, _pos ];
					
					_colorAlpha = 0.5;
					_timeout = 0;
					_particleLifeTime = 50;
					_particleDensity = 10;
					_particleSize = 1;
					_particleSpeed = 1;
					_particleLifting = 1;
					_windEffect = 1;
					_effectSize = 1;
					_expansion = 1;
					
					_emitter setParticleParams [
						["\A3\data_f\ParticleEffects\Universal\Universal_02",8,0,40,1],"","billboard",1,_particleLifeTime,[0,0,0],[0,0,2*_particleSpeed],0,0.05,0.04*_particleLifting,0.05*_windEffect,[1 *_particleSize + 1,1.8 * _particleSize + 15],
					[[0.7*_colorRed,0.7*_colorGreen,0.7*_colorBlue,0.7*_colorAlpha],[0.7*_colorRed,0.7*_colorGreen,0.7*_colorBlue,0.6*_colorAlpha],[0.7*_colorRed,0.7*_colorGreen,0.7*_colorBlue,0.45*_colorAlpha],
					[0.84*_colorRed,0.84*_colorGreen,0.84*_colorBlue,0.28*_colorAlpha],[0.84*_colorRed,0.84*_colorGreen,0.84*_colorBlue,0.16*_colorAlpha],[0.84*_colorRed,0.84*_colorGreen,0.84*_colorBlue,0.09*_colorAlpha],
					[0.84*_colorRed,0.84*_colorGreen,0.84*_colorBlue,0.06*_colorAlpha],[1*_colorRed,1*_colorGreen,1*_colorBlue,0.02*_colorAlpha],[1*_colorRed,1*_colorGreen,1*_colorBlue,0*_colorAlpha]],
					[1,0.55,0.35], 0.1, 0.08*_expansion, "", "", ""];
					
					_emitter setParticleRandom [_particleLifeTime/2, [0.5*_effectSize,0.5*_effectSize,0.2*_effectSize], [0.3,0.3,0.5], 1, 0, [0,0,0,0.06], 0, 0];
					_emitter setDropInterval (1/_particleDensity);
					
					_nul = _emitters pushBack _emitter;
				}forEach [
					//[ smoke color[RGB], offset position[x,y,z] ]
					[ [ 1, 0, 0 ], [-4, 0, 0] ],
					[ [ 1, 0, 0 ], [4, 0, 0] ],
					[ [ 0, 0, 1 ], [-5, 0, 0] ],
					[ [ 0, 0, 1 ], [5, 0, 0] ]
				];
				_target setVariable [ "emitters", _emitters ];
			};
		};
		
		_target setVariable [ "smokeTrailsOn", !_smokeOn ];
	},
	[],
	1,
	false,
	true,
	"",
	"_this in crew _target"
];
  • Like 4
  • Thanks 1

Share this post


Link to post
Share on other sites

 

A variable with a preceding _ is called a local variable.  That means that it's only available within the script in which it was created.  So since you created those objects in SpawnSmoke script StopSmoke doesn't know what they are since they were local to the SpawnSmoke script.  That's why you're getting that error.

 

You can get around this a few ways, the easiest is to simple remove the _ from those variables which makes them global and both scripts would know about them assuming no issues with locality, which is yet another entire headache to deal with), but a different way might be to track those variables in a slightly different way.

this setVariable ["YOLO_SmokeOn", [], true];  
this addAction ["Release Smoke Trails", "SpawnSmoke.sqf", [true], 0, false, true, "", "driver _target == _this && count (_target getVariable 'YOLO_SmokeOn') < 1"];  
this addAction ["Stop Smoke Trails", "SpawnSmoke.sqf", [false], 0, false, true, "", "driver _target == _this && count (_target getVariable 'YOLO_SmokeOn') > 0"];

SpawnSmoke.sqf:

// SpawnSmoke.sqf
//this setVariable ["YOLO_SmokeOn", [], true];  
//this addAction ["Release Smoke Trails", "SpawnSmoke.sqf", [true], 0, false, true, "", "driver _target == _this && count (_target getVariable 'YOLO_SmokeOn') < 1"];  
//this addAction ["Stop Smoke Trails", "SpawnSmoke.sqf", [false], 0, false, true, "", "driver _target == _this && count (_target getVariable 'YOLO_SmokeOn') > 0"];

params ["_plane", "_pilot", "_action", "_args"];
_smokeStart = _args param [0, false];
_smokes = [];

if (_smokeStart) then {
	{
		_smokeTrail = (_x select 0) createVehicle [0, 0, 1000]; 
		_smokeTrail attachTo [_plane, [(_x select 1), 0, 0]];
		_smokes pushBack _smokeTrail; 
	} forEach [["SmokeShellRed", -4], ["SmokeShellRed", 4], ["SmokeShellBlue", -5], ["SmokeShellBlue", 5]];
} else {
	{
		deleteVehicle _x;
	} forEach (_plane getVariable "YOLO_SmokeOn");
};

_plane setVariable ["YOLO_SmokeOn", _smokes, true];

Thanks, this works, but the smoke grenades stop after 1 minute. Any way to change this? Or at least make the action say "Release Smoke Trails" again after 1 minute? :)

Share this post


Link to post
Share on other sites

And also, I want more than one plane to have this feature. Any easy way to do this without having one script per plane? 

Share this post


Link to post
Share on other sites

Yes, but you should use Larrow's code.  That smoke looks much better (larger and easier to see) and it's not limited by the smoke grenade timeout.  It's also a single line of code, which is pretty awesome! heh

Share this post


Link to post
Share on other sites

And also, I want more than one plane to have this feature. Any easy way to do this without having one script per plane? 

Just change the very first plane in Larrow's example to say this and slap that in each plane's init field.

Share this post


Link to post
Share on other sites

Or change plane for _this. Put it in a planeTrails.sqf. Then in each planes init..

nul = this execvm "planeTrails.sqf"
  • Thanks 1

Share this post


Link to post
Share on other sites

Yes, but you should use Larrow's code. That smoke looks much better (larger and easier to see) and it's not limited by the smoke grenade timeout. It's also a single line of code, which is pretty awesome! heh

The only problem with Larrow's script is the size and color of the smoke :P I want the color to be brighter, like the smoke grenades ingame. Its just too big and dark the way it is now :P

Share this post


Link to post
Share on other sites

Or change plane for _this. Put it in a planeTrails.sqf. Then in each planes init..

nul = this execvm "planeTrails.sqf"

Awesome, Thanks!

Share this post


Link to post
Share on other sites

Everything is working how I want it now, except for one small thing. I want to slightly reposition the smoke. To -4, 0.5, -0.2 instead of -4, 0, 0. I tried putting

...forEach [["SmokeShellRed", -4, 0.5, -0.2], ["SmokeShellRed", 4, 0.5, -0.2]...

but it did nothing. Am I missing something? 

Share this post


Link to post
Share on other sites

If you're using my code you'd need to change it like this:

		_smokeTrail attachTo [_plane, _x];
		_smokes pushBack _smokeTrail; 
	} forEach [["SmokeShellRed", [-4, 0.5, -0.2]], ["SmokeShellRed", [4, 0.5, -0.2]], ["SmokeShellBlue", [-5, 0.5, -0.2]], ["SmokeShellBlue", [5, 0.5, -0.2]]];

Share this post


Link to post
Share on other sites
On 6/16/2016 at 4:30 PM, Larrow said:

Lovingly stolen borrowed from smoke effect module :)

 


plane addAction [ "Release Smoke Trails", {
		params [
			"_target",
			"_caller",
			"_id"
		];
		
		_smokeOn = _target getVariable [ "smokeTrailsOn", false ];
		
		switch ( _smokeOn ) do {
			case true : {
				_target setUserActionText [ _id, "Release Smoke Trails" ];
				{
					deleteVehicle _x;
				}forEach ( _target getVariable [ "emitters", [] ] );
			};
			case false : {
				_target setUserActionText [ _id, "Stop Smoke Trails" ];
				_emitters = [];
				{
					_x params[ "_color", "_pos" ];
					_color params[ "_colorRed", "_colorGreen", "_colorBlue" ];
					
					_emitter = "#particlesource" createVehicle ( _target modelToWorld _pos );
					_emitter attachTo [ _target, _pos ];
					
					_colorAlpha = 0.5;
					_timeout = 0;
					_particleLifeTime = 50;
					_particleDensity = 10;
					_particleSize = 1;
					_particleSpeed = 1;
					_particleLifting = 1;
					_windEffect = 1;
					_effectSize = 1;
					_expansion = 1;
					
					_emitter setParticleParams [
						["\A3\data_f\ParticleEffects\Universal\Universal_02",8,0,40,1],"","billboard",1,_particleLifeTime,[0,0,0],[0,0,2*_particleSpeed],0,0.05,0.04*_particleLifting,0.05*_windEffect,[1 *_particleSize + 1,1.8 * _particleSize + 15],
					[[0.7*_colorRed,0.7*_colorGreen,0.7*_colorBlue,0.7*_colorAlpha],[0.7*_colorRed,0.7*_colorGreen,0.7*_colorBlue,0.6*_colorAlpha],[0.7*_colorRed,0.7*_colorGreen,0.7*_colorBlue,0.45*_colorAlpha],
					[0.84*_colorRed,0.84*_colorGreen,0.84*_colorBlue,0.28*_colorAlpha],[0.84*_colorRed,0.84*_colorGreen,0.84*_colorBlue,0.16*_colorAlpha],[0.84*_colorRed,0.84*_colorGreen,0.84*_colorBlue,0.09*_colorAlpha],
					[0.84*_colorRed,0.84*_colorGreen,0.84*_colorBlue,0.06*_colorAlpha],[1*_colorRed,1*_colorGreen,1*_colorBlue,0.02*_colorAlpha],[1*_colorRed,1*_colorGreen,1*_colorBlue,0*_colorAlpha]],
					[1,0.55,0.35], 0.1, 0.08*_expansion, "", "", ""];
					
					_emitter setParticleRandom [_particleLifeTime/2, [0.5*_effectSize,0.5*_effectSize,0.2*_effectSize], [0.3,0.3,0.5], 1, 0, [0,0,0,0.06], 0, 0];
					_emitter setDropInterval (1/_particleDensity);
					
					_nul = _emitters pushBack _emitter;
				}forEach [
					[ [ 1, 0, 0 ], [-4, 0, 0] ],
					[ [ 1, 0, 0 ], [4, 0, 0] ],
					[ [ 0, 0, 1 ], [-5, 0, 0] ],
					[ [ 0, 0, 1 ], [5, 0, 0] ]
				];
				_target setVariable [ "emitters", _emitters ];
			};
		};
		
		_target setVariable [ "smokeTrailsOn", !_smokeOn ];
	},
	[],
	1,
	false,
	true,
	"",
	"_this in crew _target"
];

How can i change the color?

 

Share this post


Link to post
Share on other sites
2 hours ago, Chevere said:

How can i change the color?

 

looks like altering from here

0.7*_colorRed

  • Like 1

Share this post


Link to post
Share on other sites

I ha

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

×