Home   Help Search Login Register  

Author Topic: Assigning new driver  (Read 1491 times)

0 Members and 1 Guest are viewing this topic.

Offline Cheetah

  • Former Staff
  • ****
Assigning new driver
« 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.

Code: [Select]
_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.
« Last Edit: 27 Jul 2006, 13:49:10 by Cheetah »
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline Seven

  • Members
  • *
  • Am I a llama?
Re: Assigning new driver
« Reply #1 on: 27 Jul 2006, 16:19:50 »
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  :)

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Assigning new driver
« Reply #2 on: 27 Jul 2006, 16:35:12 »
You must assignAsDriver your new driver before moving him in.
urp!

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: Assigning new driver
« Reply #3 on: 28 Jul 2006, 18:24:25 »
Quote
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

Code: [Select]
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
« Last Edit: 28 Jul 2006, 18:46:50 by THobson »

Offline Cheetah

  • Former Staff
  • ****
Re: Assigning new driver
« Reply #4 on: 28 Jul 2006, 22:29:09 »
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).

Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: Assigning new driver
« Reply #5 on: 29 Jul 2006, 00:21:47 »
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:

Code: [Select]
_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.
« Last Edit: 29 Jul 2006, 00:24:00 by THobson »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: Assigning new driver
« Reply #6 on: 13 Aug 2006, 07:09:35 »
Okay - I am now back from my holidays.  Did it work?

Offline Cheetah

  • Former Staff
  • ****
Re: Assigning new driver
« Reply #7 on: 14 Aug 2006, 09:16:30 »
Yes, problem solved thanks :).
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!