OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Andurus on 01 Jul 2007, 14:33:53

Title: Vehicle Spawn Issue
Post by: Andurus on 01 Jul 2007, 14:33:53
I am trying to create a script  so that when a tank is destroyed it is replaced by another one at the position of a fire "fire1".

Currently I am trying two different methods

1. Using a trigger called 'trigger1' with condition "!alive tank1" and on act. "[] exec "tankdead.sqs""

tankdead.sqs:
Code: [Select]
?(!alive tank1):goto "dead"
?(alive tank1):goto "end"
#dead
_vcl= tank1
_vclname = name _vcl;
_dir= getdir fire1;
_pos= getpos fire1;
_type= typeof _vcl;
deletevehicle _vcl;
deletevehicle trigger1;
_vcl = _type createVehicle getpos fire1;
_vcl setVehicleVarName "tank1";
_vcl setDir _dir;
_vcl setPos _pos;
_vcl setVelocity [0,0,0];
deletevehicle trigger1;
trigger1 = createTrigger ["EmptyDetector", getpos fire1];
trigger1 setTriggerActivation ["NONE","PRESENT", true];
trigger1 setTriggerStatements ["!alive tank1","[] exec ""tankdead.sqs""",""];
exit
#end
exit

2. The second method is to put tank = [this, "fire1"] execVM "vehiclespawn.sqf" into the tanks init field

vehiclespawn.sqf
Code: [Select]
_vcl = _this select 0;
_fire = _this select 1;
_type = typeOf _vcl;
_pos = getPos _vcl;
_dir = getDir _vcl;
waitUntil (not alive _vcl) then
   {
      deleteVehicle _vcl;
sleep 20;
      _vcl = nil;
      _vcl = _type createVehicle _pos;
      _vcl setPos _pos;
      _vcl setDir _dir;
      _vcl setVehicleInit "tank = [this, "fire1"] execVM "vehiclespawn.sqf""
   };
exit;

Is either way correct currently with the first method it respawns once but will not do it a second time and method two seems to not find the sqf file after double checking everything. Help greatly appreciated (a small delay would be nice aswell)
Title: Re: Vehicle Spawn Issue
Post by: ArMaTeC on 01 Jul 2007, 15:07:23
might be this processInitCommands (http://community.bistudio.com/wiki/processInitCommands)
Title: Re: Vehicle Spawn Issue
Post by: Andurus on 05 Jul 2007, 13:20:44
Don't really understand what to do with that command ??? any other ideas appreciated
Title: Re: Vehicle Spawn Issue
Post by: Mandoble on 05 Jul 2007, 13:56:21
You may try this. If this is MP game, execute only in the server.

Code: [Select]
/*
SpawnTank.sqf

Arguments:
   type of unit
   spawn position
   initial direction
   seconds to wait after destruction before spawning it again
   Number of spawns allowed, once exceeded, the unit will not spawn again

   scr = ["T72", getPos fire1 ,getDir fire1, 10, 999]execVM "SpawnTank.sqf"
*/

_typeoftank = _this select 0;
_spawnpos = _this select 1;
_initialdir = _this select 2;
_wait = _this select 3;
_spawnsallowed = _this select 4;

_vcl = objNull;
_spanws = 0;
while {_spawns < _spawnsallowed} do
{
   _vcl = _typeoftank createVehicle _spawnpos;
   _vcl setPos _spawnpos;
   _vcl setDir _initialdir;
   _spawns =  _spawns + 1;

   while {alive _vcl} do
   {
      Sleep 4;
   };
   Sleep _wait;
   deleteVehicle _vcl;
};
Title: Re: Vehicle Spawn Issue
Post by: Andurus on 05 Jul 2007, 19:59:22
hmmm no luck i must be doing something fundamentally wrong do you have a small example mission? then I can see where to put what.
Title: Re: Vehicle Spawn Issue
Post by: LeeHunt on 05 Jul 2007, 21:32:38
This is probably not as good a solution as a well written function, but you could have the replacement tank (say Tank2) already made at a side island.  You could have a game logic (say logicA) and an event handler on the Tank1 so that when it dies this script runs:

logicA setpos getpos Tank1
deletevehicle Tank1
~1
Tank2 setpos getpos logicA
deletevehicle logicA

if you're concerned about bodies showing up too you could move the dead Tank1 to an off island and then delete it...
Title: Re: Vehicle Spawn Issue
Post by: Andurus on 05 Jul 2007, 21:38:09
The problem is that I want a replacement to be made everytime the tank gets killed so that it will always be usable and obviously I don't want to load the mission up with loads of tanks on a side island.
Title: Re: Vehicle Spawn Issue
Post by: Mandoble on 05 Jul 2007, 21:46:03
Example attached.
Title: Re: Vehicle Spawn Issue
Post by: Andurus on 05 Jul 2007, 22:25:46
Cheers Mandoble :good: I've got it working like a charm now.