Jump to content
gianni001

Please put me out of my scripting misery...

Recommended Posts

Im no great scripter, sometimes I wonder why I even try and it hurts my brain... bt please,I have searched high and low to try and get this to work, it may seem simple to some of you but I dont care, im spent!

 

All I want is the bottom part of the script to not fire until the chopper is dead (trigger activated)... everything else on the script works except the waituntil ive tried many different ways but Im all outa puff......................

 

As a side note but not nearly as important.. can anyone tell me, within this script hwo to make the chopper wreck smoke forever?

 

Thanks a bunch

 

 
_group = [getMarkerPos "helospawn1", EAST, ["O_Heli_Light_02_unarmed_F"],[],[],[],[],[],180] call BIS_fnc_spawngroup;
 
wp1 = _group addWaypoint [getMarkerPos "HC", 0];
wp2 = _group addWaypoint [getMarkerPos "MainDot", 0];
{
        _x setWaypointBehaviour "CARELESS"; 
_x setWaypointSpeed "FULL";
_x setWaypointType "MOVE";
 
} forEach [_wp1,_wp2];
 
_trg = createTrigger ["EmptyDetector", getMarkerPos "MainDot"];
_trg setTriggerArea [100, 100, 0, false];
_trg setTriggerActivation ["EAST", "PRESENT", true];
_trg setTriggerStatements ["this", "{_x setDamage 1} forEach thislist", ""];
 
^^^^^^^^^
Script works until here.
 
waitUntil {!alive _this}; // THIS IS THE BIT I CANT GET TO WORK I do not want the below to execute until the chopper is dead..
 
This bottom bit works when ran without the above...
 
_pos = getMarkerPos "DMS_MainDot";
while {alive player} do {
_smoke = createvehicle ["SmokeShellRed",_pos,[],0,"none"];
_smoke setpos _pos;
waitUntil {isNull _smoke};
};

Share this post


Link to post
Share on other sites

https://community.bistudio.com/wiki/this

 

 

waitUntil {!alive _this}; // THIS IS THE BIT I CANT GET TO WORK I do not want the below to execute until the chopper is dead..

 

 

The variable _this is not defined. Read the content of the link I've posted above.

 

Has the chopper a specific variable name? If so then do:

 

waitUntil {sleep 0.5; !alive heliName};

 

Also it's always good to add a sleep to waitUntil.

Share this post


Link to post
Share on other sites

The choper hasnt got a name, not sure how to give one?

 

I also tried {!alive _group} as I thought _group was the chopper?

Share this post


Link to post
Share on other sites

 In the editor click on your chopper and give it a name -the tab at the top right. Once you name it ie Helo1, that variable name will activate in any script as it is a global one.

 

 Then simple !alive Helo1 etc....

Share this post


Link to post
Share on other sites

Yeh.. I cant do that as this must be run through a script only (online mission)..

 

anything else?

Share this post


Link to post
Share on other sites

or

waitUntil {!alive (vehicle leader _group)};

Share this post


Link to post
Share on other sites

Thanks guys , at work but the trigger activated way seems to be likley to work (I hope) will let u know!

Share this post


Link to post
Share on other sites

Is the whole point of the trigger just to delete the helicopter and crew youve created and sent there? If so just use the waypoint statement..

_group = [getMarkerPos "helospawn1", EAST, ["O_Heli_Light_02_unarmed_F"],[],[],[],[],[],180] call BIS_fnc_spawngroup;
 
wp1 = _group addWaypoint [getMarkerPos "HC", 0];
wp2 = _group addWaypoint [getMarkerPos "MainDot", 0];
{
	_x setWaypointBehaviour "CARELESS"; 
	_x setWaypointSpeed "FULL";
	_x setWaypointType "MOVE";
 
} forEach [_wp1,_wp2];

_wp setWaypointStatements [ "true", "
	{ _x setdamage 1 } foreach ( thislist + [vehicle this] );
	nul = [] spawn {
		_pos = getMarkerPos 'DMS_MainDot';
		while {alive player} do {
			_smoke = createvehicle ['SmokeShellRed',_pos,[],0,'none'];
			_smoke setpos _pos;
			waitUntil {isNull _smoke};
		};
	};
" ];

Share this post


Link to post
Share on other sites

Is the whole point of the trigger just to delete the helicopter and crew youve created and sent there? If so just use the waypoint statement..

_group = [getMarkerPos "helospawn1", EAST, ["O_Heli_Light_02_unarmed_F"],[],[],[],[],[],180] call BIS_fnc_spawngroup;
 
wp1 = _group addWaypoint [getMarkerPos "HC", 0];
wp2 = _group addWaypoint [getMarkerPos "MainDot", 0];
{
	_x setWaypointBehaviour "CARELESS"; 
	_x setWaypointSpeed "FULL";
	_x setWaypointType "MOVE";
 
} forEach [_wp1,_wp2];

_wp setWaypointStatements [ "true", "
	{ _x setdamage 1 } foreach ( thislist + [vehicle this] );
	nul = [] spawn {
		_pos = getMarkerPos 'DMS_MainDot';
		while {alive player} do {
			_smoke = createvehicle ['SmokeShellRed',_pos,[],0,'none'];
			_smoke setpos _pos;
			waitUntil {isNull _smoke};
		};
	};
" ];

Yeh, the idea is the helicopter flys aorund to the waypoints, reaches the last waypoint and explodes. Where there is a crate that spawns. (different script).

 

Will your script above acheive the same thing?

 

Also. Can anyone tell me how to stop the smoke grenade? Ideally, Id want it to repeat for a timer, say 1800 seconds? Currently it keeps going forever on an endless loop, and if I delete the marker / grenade it self it just creates a new one :D

 

Thanks guys

Share this post


Link to post
Share on other sites

 

Im no great scripter [...]

waitUntil {!alive _this};
waitUntil {isNull _smoke};

 

Me neither, but with a little help from the community we can become good enough to realise our ideas. One thing I learned lately is, that in situations where time is rather uncritical, one should use a "while-do" loop over "waituntil" loop. At least one should add a sleep command, to reduce impact on processing power.

wailtUntil {!alive _this}; // Fast evaluation, but processor heavy
 
waitUntil {sleep 0.5; !alive _this}; // Slower evaluation (twice a second) but much less processor heavy

Reason: waitUntil is verified each frame, so on a server running at maybe 40 frames per second, the condition will get evaluated 40 times each second as well, if no additional sleep command is added. Therefore waitUntil should only be used without a sleep command in very time critical situations. Also note, that a waitUntil loop will automatically end after 10.000 cycles, no matter if the condition is met or not.

 

Most of the time it is possible (and preferable) to convert a "waitUntil" loop into a "while-do" loop, by simply reverting its conditions:

waitUntil {(!alive car1) && (soldier1 distance car1 < 10)}; // Evaluated each frame
 
while {(alive car1) && (soldier1 distance car1 > 10)} do {sleep 2}; // Same effect, evaluated only every 2 seconds

In a "while-do" loop you can define exactly how "urgent" you need the condition to be evaluated. Very often it is unnecessary to check conditions more than twice a second (like editor placed triggers will do).

Share this post


Link to post
Share on other sites

 

 

Also. Can anyone tell me how to stop the smoke grenade? Ideally, Id want it to repeat for a timer, say 1800 seconds? Currently it keeps going forever on an endless loop, and if I delete the marker / grenade it self it just creates a new one :D

 

Thanks guys

 

Well... currently the while-loop you started will repeat, as long as the condition (alive player) is true.

So you could either use a different condition (player distance _pos > 20) or just use a for-loop instead, to limit the amount of smoke grenade creation cycles:

for "_i" from 1 to 20 do // Will repeat the loop 20 times
{
_smoke = createvehicle ["SmokeShellRed",_pos,[],0,"none"];
_smoke setpos _pos;
while {!isNull _smoke} do {sleep 2}; // Better than waitUntil for this purpose
};

This will create a total of 20 smoke grenades, each after the one before burned out - provided your check for !isNull _smoke works. Didn't test it.

Share this post


Link to post
Share on other sites

Thanks grollig, I will try that tongiht when I get home from work.

 

Its not a "timer" but I could time the smoke grenade in the editor and repeat it as many times as needed to achieve my result. So my current script looks like this, I was also getting script errors on the waypoints so Ive fixed them up.

 

_group = [getMarkerPos "helospawn1", EAST, ["O_Heli_Light_02_unarmed_F"],[],[],[],[],[],180] call BIS_fnc_spawngroup;
 
_wp1 = _group addWaypoint [getMarkerPos "HC", 0];
_wp2 = _group addWaypoint [getMarkerPos "heloMainDot", 0];
{
    [_group, 2] setWaypointBehaviour "CARELESS"; 
    [_group, 2] setWaypointSpeed "FULL";
    [_group, 2] setWaypointType "MOVE";
 
} forEach [_wp1,_wp2];
 
_trg = createTrigger ["EmptyDetector", getMarkerPos "heloMainDot"];
_trg setTriggerArea [100, 100, 0, false];
_trg setTriggerActivation ["EAST", "PRESENT", true];
_trg setTriggerStatements ["this", "{_x setDamage 1} forEach thislist", ""];
 
waitUntil {triggerActivated _trg};
 
_pos = getMarkerPos "heloMainDot"; // Is this in the right spot? You didnt have this bit in your suggestion
for "_i" from 1 to 20 do // understand that this determines the amount of times the loop will occur, so I could increase to 25 for 25x etc?
{
_smoke = createvehicle ["SmokeShellRed",_pos,[],0,"none"];
_smoke setpos _pos;
while {!isNull _smoke} do {sleep 2}; 
};

Share this post


Link to post
Share on other sites

 

waitUntil {sleep 0.5; triggerActivated _trg}; // Add a sleep here to reduce processor load

 

 

 

 

_pos = getMarkerPos "heloMainDot"; // Yes, this is the right spot, and this line is definately needed

for "_i" from 1 to 20 do // Yes, you can change 20 to the times you want the loop to repeat, like 25 for 25x
{
_smoke = createvehicle ["SmokeShellRed",_pos,[],0,"none"];
_smoke setpos _pos;
while {!isNull _smoke} do {sleep 2}; 
};

 

 

However I did edit my last post a bit. I assume, that the purpose of the smoke grenades is to lead the player to its position.

In this case you could just change the condition in your while-loop from (alive player) to (player distance _pos > 20).

 

Like this:

_pos = getMarkerPos 'DMS_MainDot';
while {player distance _pos > 20} do
{
   _smoke = createvehicle ['SmokeShellRed',_pos,[],0,'none'];
   _smoke setpos _pos;
   while {!isNull _smoke && (player distance _pos > 20)} do {sleep 2};
};

This will keep spawning smoke grenades until the player is within 20 metre range of the smoke position. That is if your check for {isNull _smoke} is working. I didn't test that.

Of course the last smoke grenade will keep on smoking until it burns out, even if the player gets within 20 metres. The loop just prevents the spawning of further smoke grenades once the player got into range.

 

To delete the last "active" smokegrenade you could simply try adding

deleteVehicle _smoke;

as the next line after the loop I posted above.

 

Share this post


Link to post
Share on other sites

I have to be carefull with waiting for a player to be < 20 from the grenade. Because its entirely possible the player will never find the weapons crate and I dont want uncessary smoke litering my pretty server :D hence the timer, or loop you suggested.

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

×