OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: ArMaTeC on 23 Jun 2007, 14:46:18

Title: Chopper Air lift script *WIP*
Post by: ArMaTeC on 23 Jun 2007, 14:46:18
Hi im working on a script so that i can transport units around the map via a airlift script i have the airlift working 100% if i have it set to a preplaced chopper called transportchop1 my problem is that once this chopper is killed and respawns its no longer called transportchop1 therefor the script it always returning chopper is dead how would i rename the spawned chopper back to transportchop1?

CarryOn.sqf
Code: [Select]
_Unit = _this select 0;
_id = _this select 2;
_Unit removeAction _id;
incargo = _Unit;
endCargoSession = false;
publicVariable "endCargoSession";
publicVariable "incargo";

CarryOff.sqf
Code: [Select]
_Unit = _this select 0;
_id = _this select 2;
_Unit removeAction _id;
endCargoSession= false;
if(_Unit == transportchop1)then
{
}else{
_unit addAction ["Call Pickup","carry.sqf"];
};
incargo = _Unit;
publicVariable "incargo";
publicVariable "endCargoSession";

Carry.sqf
Code: [Select]
_Vehicle = transportchop1;
_Unit=_this select 0;
_id = _this select 2;
_Unit removeAction _id;
_StrComp = compile LoadFile "functions\StrComp.sqf";
_dirtoobj = compile LoadFile "functions\DirToObj.sqf";
_xa = 0.5;
_ya = 8;
_za = 8;
_Offset = [0,0,-8.26];
_engaged = false;
if(endCargoSession)ExitWith
{
Hint "Chopper in use"
};
_Display =
{
private ["_distocargopre","_distocargo","_realposssz","_zz1","_zz","_dirtoobjcal","_dirfromcargo","_message","_messagechopper","_compdirchopper","_compdir"];
_distocargopre= (_this select 1) Distance (position (_this select 0));
_distocargo = round _distocargopre;
_realposssz = getpos (_this select 1);
_zz1 = (_realposssz select 2);
_zz = round _zz1;
_dirtoobjcal = [(_this select 0),(_this select 1)] call _dirtoobj;
_dirfromcargo = [(_this select 1),(_this select 0)] call _dirtoobj;
_compdir = [_dirtoobjcal,.1,7] call _StrComp;
_compdirchopper = [_dirfromcargo,.1,7] call _StrComp;
_message = format["Distance:%1 Height:%2 Headding:%3",_distocargo,_zz,_compdir];
_messagechopper = format["Distance:%1 Headding:%2",_distocargo,_compdirchopper];
(_this select 1) vehicleChat _messagechopper;
(_this select 0) vehicleChat _message;
};
_Alive =
{
if(not alive (_this select 0))ExitWith
{
hint "Carryed is dead";
endCargoSession = false;
publicVariable "endCargoSession";
};
if(not alive (_this select 1))ExitWith
{
hint "Transport is dead";
endCargoSession = false;
publicVariable "endCargoSession";
};
};
_vectors =
{
(_this select 0) SetVelocity (Velocity (_this select 1));
(_this select 0) SetPos ((_this select 1) ModelToWorld _Offset);
_VUp=VectorUp (_this select 1);
_VDir=VectorDir (_this select 1);
(_this select 0) SetvectorDir _VDir;
(_this select 0) SetvectorUp _VUp;
};

[_unit,_Vehicle] call _Alive;
_act1 = _unit addAction ["Cancel Airlift","CarryOff.sqf"];
endCargoSession = true;
publicVariable "endCargoSession";
while {endCargoSession} do
{
sleep 0.001;
[_unit,_Vehicle] call _Alive;
[_unit,_Vehicle] call _Display;
_realposss = getpos _Vehicle;
_z = _realposss select 2;
_distocargopre= _Vehicle Distance (position _unit);
_distocargo = round _distocargopre;
if((_z <= 10) && (_distocargo <= 10))then
{
_Vehicle vehicleChat "Engaged";
_unit vehicleChat "Lock Engaged";
_act2 = _Vehicle addAction ["Uncouple Cargo","CarryOff.sqf"];
while{endCargoSession} do
{
_realposss = getpos _Vehicle;
_z = _realposss select 2;
if(_z > 15)then{_engaged = true};
if((_z <= 6)&& (_engaged))then {endCargoSession = flase};


sleep 0.001;
[_unit,_Vehicle] call _Alive;
[_unit,_Vehicle] call _vectors;
[_unit,_Vehicle] call _Display;
if(not endCargoSession)ExitWith
{
_Vehicle vehicleChat "Disengaged";
_unit vehicleChat "Lock Disengaged";
_Unit removeAction _act1;
_Vehicle removeAction _act2;
};
};
};
};
Title: Re: Chopper Air lift script *WIP*
Post by: Mandoble on 23 Jun 2007, 17:13:56
Use vehicleVarName instead of just transportwhatever
Title: Re: Chopper Air lift script *WIP*
Post by: ArMaTeC on 23 Jun 2007, 17:45:00
So would i use it like this

Code: [Select]
//Respawn sample
_thing = _this select 0;
_thingname = vehicleVarName _thing;
//create unit part
_vcl setVehicleVarName _thingname;
Title: Re: Chopper Air lift script *WIP*
Post by: Mandoble on 23 Jun 2007, 18:19:29
f(_Unit == transportchop1)then
->
if (_Unit vehicleVarName == "WHATEVERHERE") then

nad set it in the spawn.
Title: Re: Chopper Air lift script *WIP*
Post by: ArMaTeC on 24 Jun 2007, 14:48:10
my way would work if i wonted to keep all the names the same as when placed in the editor correct?
Title: Re: Chopper Air lift script *WIP*
Post by: Mandoble on 24 Jun 2007, 15:22:11
Yep, but you may also spawn these units directly (not placed in the editor) as long as you use setVehicleVarname there where you spawn them.
Title: Re: Chopper Air lift script *WIP*
Post by: ArMaTeC on 24 Jun 2007, 18:34:00
rgr that i think ill do just that would this cause more or less lag?
As the models will be not be loaded from the sqm
Title: Re: Chopper Air lift script *WIP*
Post by: Mandoble on 24 Jun 2007, 19:48:45
Do it and try it, best way to test lag.
Title: Re: Chopper Air lift script *WIP*
Post by: ArMaTeC on 25 Jun 2007, 01:32:29
ko got around to testing and it dont  seem to work as when its dead and respawns it still shows as a dead chopper

Code: [Select]
_vcl = _this select 0;
_oldpos = _this select 3;
_dir = direction _vcl;
while {true} do {if ((count crew _vcl) == 0 and (not alive _vcl))then
{
_thingname = vehicleVarName _vcl;
_vcl setdammage 0;
_vcl setpos _oldpos;
_vcl setdir _dir;
_vcl setVehicleVarName _thingname;
};
sleep 10;
};
Title: Re: Chopper Air lift script *WIP*
Post by: Mandoble on 25 Jun 2007, 01:41:18
Seems you are trying to revive a destroyed unit instead of just deleting the destroyed one and spawning a new one with createVehicle.
Title: Re: Chopper Air lift script *WIP*
Post by: ArMaTeC on 25 Jun 2007, 20:06:42
ok fixed this issue

Code: [Select]
if (not (local server)) exitwith {};

_time = 1+(random 1);
sleep _time;
_vcl = _this select 0;
_class = typeOf _vcl;
_oldpos = getpos _vcl;
_dir = direction _vcl;
while {true} do
{
if(not alive _vcl)ExitWith
{
_thingname = _vcl;
_vcl setdammage 0.01;
_vcl removealleventhandlers "killed";
_vcl removealleventhandlers "getout";
_vcl removealleventhandlers "getin";
_vcl removealleventhandlers "IncomingMissile";
deleteVehicle _vcl;
_vcl = _class createVehicle [10000+(random 1000),10000+(random 1000),0];
_vcl setdir _dir;
_vcl setpos _oldpos;
if (_thingname == transportchop1)then
{
transportchop1 = _vcl;
publicVariable "transportchop1";
};
_vcl setVehicleInit "handle = [this] execVM ""vecrespawn.sqf""";
processInitCommands;
};
sleep 10;
};