OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Cheetah on 27 Jul 2006, 11:31:36
-
I'm making a script for a mission that you can use to create a group of units and a truck with createUnit and let them move to a position on the map.
The problem is that this is not working properly. My problem is replacing the driver when he gets killed and getting everyone out when the vehicle is under attack. After this getting them back in and let them move out towards their destination.
Once at their destination they remain there for a few minutes and will get back in the truck to drive back to their starting position. During this ride back dead drivers should be replaced too and if the enemy gets near and attacks the truck everyone should get out. After the fight the truck should move again.
The code I wrote could do the simple thing of letting get into the truck and let them drive towards the destination. Get them out, wait, get them back in and drive back.
But, the code I made failed when I shot the driver.
_moveTo = _this select 0;
_aantalMan = 8;
_o = 1;
nummerVracht = nummerVracht + 1;
_truck1 = "TruckV3SCivil" createVehicle getpos out_gate;
_i = 1;
#make
?(_i == 1): "Civilian11" createUnit [getpos policeSpawn,truckMaster,format["vracht%1_%2 = this;",nummerVracht,_i],0.6,"captain"]; _unit = call format["vracht%1_%2",nummerVracht,_i]; ;_unit moveInDriver _truck1;
?(_i == 1): [_unit] join GrpNull; _Group1 = group _unit;
?(_i != 1): "Civilian8" createUnit [getpos policeSpawn,truckMaster,format["vracht%1_%2 = this;",nummerVracht,_i],0.6,"private"]; _unit = call format["vracht%1_%2",nummerVracht,_i]; [_unit] join GrpNull; ;_unit moveInCargo _truck1;
_unit removeWeapon "binocular";
if (_i <= _aantalMan-1) then { _i = _i + 1; goto "make" }
_unitArray = [call format["vracht%1_1",nummerVracht],call format["vracht%1_2",nummerVracht],call format["vracht%1_3",nummerVracht],call format["vracht%1_4",nummerVracht],call format ["vracht%1_5",nummerVracht],call format["vracht%1_6",nummerVracht],call format["vracht%1_7",nummerVracht],call format["vracht%1_8",nummerVracht]]
(call format["vracht%1_1",nummerVracht]) moveInDriver _truck1;
_unitArray doMove getpos _moveTo;
"_x setBehaviour {AWARE}" foreach _unitArray;
"_x allowFleeing 0" foreach _unitArray;
"_x setCombatMode {RED}" foreach _unitArray;
~5
#loop
?!(alive (driver _truck1)): goto "newDriver"
goto "loop"
#newDriver
_unit = call format["vracht%1_%2",nummerVracht,_o];
~2
hint format ["%1",_unit];
if(alive _unit) then { _unit moveInDriver _truck1; } else { _o = _o + 1; goto "newDriver" }
@(_unit == driver _truck1)
#GetIn
if(_o <= count _unitArray) then { _o = _o + 1; } else { _unitArray doMove getPos _moveTo; _o = 1; goto "loop" }
_unit = call format["vracht%1_%2",nummerVracht,_o];
_unit AssignAsCargo _truck1;
goto "GetIn"EDIT: sorry for any dutch text in the code
The script I use is the following. Although I have about four versions of it, none of them work. This is my latest one. Can anyone help me. The problems I have right now, is that I know no way of letting everyone get out when the enemy is present. And that replacing the driver takes too long (about 15 seconds or so) and it will only work once, whereas I thought that it should work every time.
EDIT: Another problem, how to remove dead units from an array. I might have a solution for my problem if I know how to do this. My other big problem remains, how to check if there's enemy units in the vicinity.
-
Could you not make a list of all enemy on map and then do a distance check between an enemy and the driver so you can order them all out from certain distance?
Furthermore maybe have an eventhandler that keeps the drivers condition(health) above certain point?
Just thinking :)
-
You must assignAsDriver your new driver before moving him in.
-
to check if there's enemy units in the vicinity.
Create a repeating trigger that detects the enemy. Give it a name: say trig_enemy. Have a loop say 2 to 3 seconds that moves the trigger to the location of the vehicle. The activation field should set a variable that is reset on deactivation:
EG:
Activation: EnemyDetected = true
Deactivation: EnemyDetected = false
EnemyDetected =false
#loop
~3
trig_enemy setPos getPos vehiclename
if EnemyDetected then {goto"detected"}
goto "loop"
#detected
Put the code here you want to happen when the enemy have been detected
eventually when EnemyDetected is false:
goto"loop"
Or some such
-
Thanks thobson, it works well. But the script can be called X times where I don't know the X. So is there a way to create a trigger on the run? Don't think so, think that I'll have to place enough triggers on the map. And if a script is ended use the trigger that's 'free' again for a new script that might be activated.
My problem with the array still remains. I have this array with unitnames in it, is there a way to delete them from the array. Like a command so that I can delete the fifth element of the array (I think I can do the rest of the code myself).
-
The script should only be run once at the start of the mission. The trigger should be a repeating trigger so that it can fire (and un-fire) as many times as it likes. You only need one trigger and the thing will run for ever and fire an infinite number of times if you wait long enough
Not sure why you want to remove dead units from your array, but something like this might do it:
_newarray = []
{if (alive _x) then {_newarray = _newarray + [_x]}} forEach oldarray
oldarray = +_newarray
I am not being rude if I don't respond to any further questions - I am going away for a few weeks.
-
Okay - I am now back from my holidays. Did it work?
-
Yes, problem solved thanks :).