Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
clydefrog

Stopping vehicles from moving

Recommended Posts

Hi, I'm making a "mission" (basically just a practice map) for my squad to practice with mando missiles on, but I'm having a problem with keeping vehicles in the same place I've put them. I'm using this disableAI "MOVE" and this disableAI "TARGET" but the vehicles still move around. What I've also tried is putting invisible barriers around them all with "this allowdamage false" in their init fields to stop them being destroyed, but it seems they still are after being hit by bombs meaning the vehicle can escape. I've tried removing all of the fuel but this means they don't show up as targets for AGM-65 mavericks or GBU's unless they are lased, it won't pick them up with the remote radar. Is there a better way to do this?

Another problem I'm having is I'm using a vehicle respawn script on the armoured targets for Javelins but when they respawn they seem to not have any crew in them as you can no longer lock onto them, is there a simple fix for this?

Thanks.

Share this post


Link to post
Share on other sites

try this enableSimulation false; in the vehicles init field

Share this post


Link to post
Share on other sites

Thanks I'll give it a go, what is it supposed to do exactly? Also I see this needs to be run on all clients to work on multiplayer, how do I do that?

Edited by clydefrog

Share this post


Link to post
Share on other sites

One workaround is to use attachto statements with an immobile object. That way the vehicle can be fully manned and fueled up, but it will not be able to move away. Another simple one is to remove the driver of the target vehicles.

Regards,

Sander

Share this post


Link to post
Share on other sites
One workaround is to use attachto statements with an immobile object. That way the vehicle can be fully manned and fueled up, but it will not be able to move away. Another simple one is to remove the driver of the target vehicles.

Regards,

Sander

Hmm, a problem I might have with that is if the invisible barriers are being destroyed despite having them set to not allow damage, the object the vehicle is attached to may also be destroyed.

Edited by clydefrog

Share this post


Link to post
Share on other sites

To avoid any trouble with an immobile object having an unwanted side effect when it gets destroyed (for example a destructible ammo crate that is destroyed and sinks into the ground along with the attached vehicle) one should pick the right type. Try out an invisible helipad on the ground, that is an object that does not get destroyed and that should not present a barrier to an engagement with projectiles.

The least trouble is naming the target vehicles, eg target1 and putting in the init line astatement to remove the driver, in the example deleteVehicle target1D;. That would save figuring out setting the appropriate height for attachto statements. That should be allright during day time settings, though it may result in the headlights being turned on at night, in which case one should ensure that the vehicle crew's behaviour is set to combat or stealth.

Regards,

Sander

Edited by sander

Share this post


Link to post
Share on other sites

Couple of things you can prevent most objects from being destroyed by placing an eventhandler in the init box of the object

this addEventHandler ["HandleDamage", {}];

You can also just attach an object to something that can't be destroyed such as gamelogic and it won't matter where on the map the gl is placed.

This will attach an object relative to it's position so x,y,z is not an issue.

vehname attachto [glname];

Share this post


Link to post
Share on other sites
To avoid any trouble with an immobile object having an unwanted side effect when it gets destroyed (for example a destructible ammo crate that is destroyed and sinks into the ground along with the attached vehicle) one should pick the right type. Try out an invisible helipad on the ground, that is an object that does not get destroyed and that should not present a barrier to an engagement with projectiles.

The least trouble is naming the target vehicles, eg target1 and putting in the init line astatement to remove the driver, in the example deleteVehicle target1D;. That would save figuring out setting the appropriate height for attachto statements. That should be allright during day time settings, though it may result in the headlights being turned on at night, in which case one should ensure that the vehicle crew's behaviour is set to combat or stealth.

Regards,

Sander

Thanks for the information, I'll try the invisible helipads and attaching the vehicles to them. I don't want to remove the crew from vehicles as if I do that then they won't show up as targets for missiles/bombs as their engines won't be on. One thing, if the vehicle that is attached to a helipad is destroyed, when it respawns will it again attach to the helipad?

---------- Post added at 13:21 ---------- Previous post was at 13:18 ----------

Couple of things you can prevent most objects from being destroyed by placing an eventhandler in the init box of the object

this addEventHandler ["HandleDamage", {}];

You can also just attach an object to something that can't be destroyed such as gamelogic and it won't matter where on the map the gl is placed.

This will attach an object relative to it's position so x,y,z is not an issue.

vehname attachto [glname];

So I can have 1 game logic and attach say, 20 vehicles to it just with that piece of code in each of their init fields? and they'll all stay where I put them and not move to the position of the game logic? Also I heard those eventhandlers can cause lag and I'd need to use loads of them as I have "this allowdamage false" on every invisible barrier object that make up perimeters around the target vehicles, and I'd have to replace them all with that eventhandler code. Does it work better than allowdamage and is it true they can cause lag/high traffic or something (can't remember exactly what it was I read). Also again the same question to you, if I attach something to a gamelogic and it is destroyed, when it respawns will it still be attached or will that break the link?

Edited by clydefrog

Share this post


Link to post
Share on other sites

if i read your question right you want to have some vehicles that cant be destroyed so you can use as target practice , if so

add this to the vehicles init field...

this enableSimulation false;this allowdamage false;{_x allowdamage false} foreach crew this;

this should also be fine for MP

if not then add this to the vehicles init

_nil = [this] execVM "target.sqf";

target.sqf

_veh = _this select 0;
_veh setVehicleInit "this enableSimulation false;this allowdamage false;{_x allowdamage false} foreach crew this;";
processInitCommands;
clearVehicleInit _veh;

enableSimulation will stop it moving - if you add that to a chopper even the rotors will freeze

allowdamage false = no damage will happen to the vehicle

{_x allowdamage false} foreach crew this; ---- will stop the crew from being damaged

setVehicleInit is how you can set commands to be global in MP - maybe not the most efficient way but it is effective and for what you want to do you it wont lag anything at all

for a simple vehicle & crew respawn script add this to the init of the vehicle

_nil = [this] execVM "Veh_Respawn.sqf";

Veh_Respawn.sqf


sleep .5;

if !(isServer) exitwith {};

private ["_delay","_car","_pos","_dir","_typeveh","_hgt","_grp","_vel","_speed","_sld","_x","_AIcrew","_AIcrew1","_AIcrew2"];

_delay = 10;       // set this for the delay to respawn a new vehicle after the old one is to damaged;

_car = _this select 0;
_pos = position _car;
_dir = direction _car;
_hgt = _pos select 2;
_vel = velocity _car;

sleep 2;

_AIcrew = [];
_AIcrew1 = [];
_AIcrew2 = [];
{_AIcrew = _AIcrew + [typeOf _x]} foreach crew _car;
{_AIcrew1 = _AIcrew1 + [(assignedVehicleRole _x select 0)];
_AIcrew2 = _AIcrew2 + [(assignedVehicleRole _x select 1)];
} foreach crew _car;

_typeveh = typeOf _car;
_grp = group _car;

while {true} do
{
sleep 1;

waituntil {!(canmove vehicle _car)};

sleep _delay;  

deleteVehicle _car;
_grp = creategroup east;


if (vehicle _car isKindOf "AIR") then {_pos set [2,500];_car = createVehicle [_typeveh, _pos, [],0,"fly"]} else {_car = _typeveh createVehicle _pos;};
_car setdir _dir;
_car setdamage 0;
_car setFuel 1;
_car setVehicleAmmo 1;
_car setpos _pos;


_sld = objnull;
_ii = 0;
{_sld = _grp createUnit [_x,_pos,[],0,"NONE"];
if (isnil{(_AIcrew2 select _ii)}) then {_sld action ["getin" + (_AIcrew1 select _ii),_car]}else{_sld action ["Getin" + (_AIcrew1 select _ii),_car,(_AIcrew2 select _ii)]};
_ii = _ii + 1;
} foreach _AIcrew;

_speed = 0;
_car setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+(cos _dir*_speed),(_vel select 2)];
};

this will put the vehicle and crew even cargo positions where it started and will go on and on

so if you have a group of 8 units moveincargo to a truck at mission start , every time the truck respawns it will have 8 units in the back

this also works on every vehicle , in the air or on the ground

Edited by Zonekiller

Share this post


Link to post
Share on other sites
if i read your question right you want to have some vehicles that cant be destroyed so you can use as target practice , if so

add this to the vehicles init field...

this enableSimulation false;this allowdamage false;{_x allowdamage false} foreach crew this;

this should also be fine for MP

if not then add this to the vehicles init

_nil = [this] execVM "target.sqf";

target.sqf

_veh = _this select 0;
_veh setVehicleInit "this enableSimulation false;this allowdamage false;{_x allowdamage false} foreach crew this;";
processInitCommands;
clearVehicleInit _veh;

enableSimulation will stop it moving - if you add that to a chopper even the rotors will freeze

allowdamage false = no damage will happen to the vehicle

{_x allowdamage false} foreach crew this; ---- will stop the crew from being damaged

setVehicleInit is how you can set commands to be global in MP - maybe not the most efficient way but it is effective and for what you want to do you it wont lag anything at all

for a simple vehicle & crew respawn script add this to the init of the vehicle

_nil = [this] execVM "Veh_Respawn.sqf";

Veh_Respawn.sqf


sleep .5;

if !(isServer) exitwith {};

private ["_delay","_car","_pos","_dir","_typeveh","_hgt","_grp","_vel","_speed","_sld","_x","_AIcrew","_AIcrew1","_AIcrew2"];

_delay = 10;       // set this for the delay to respawn a new vehicle after the old one is to damaged;

_car = _this select 0;
_pos = position _car;
_dir = direction _car;
_hgt = _pos select 2;
_vel = velocity _car;

sleep 2;

_AIcrew = [];
_AIcrew1 = [];
_AIcrew2 = [];
{_AIcrew = _AIcrew + [typeOf _x]} foreach crew _car;
{_AIcrew1 = _AIcrew1 + [(assignedVehicleRole _x select 0)];
_AIcrew2 = _AIcrew2 + [(assignedVehicleRole _x select 1)];
} foreach crew _car;

_typeveh = typeOf _car;
_grp = group _car;

while {true} do
{
sleep 1;

waituntil {!(canmove vehicle _car)};

sleep _delay;  

deleteVehicle _car;
_grp = creategroup east;


if (vehicle _car isKindOf "AIR") then {_pos set [2,500];_car = createVehicle [_typeveh, _pos, [],0,"fly"]} else {_car = _typeveh createVehicle _pos;};
_car setdir _dir;
_car setdamage 0;
_car setFuel 1;
_car setVehicleAmmo 1;
_car setpos _pos;


_sld = objnull;
_ii = 0;
{_sld = _grp createUnit [_x,_pos,[],0,"NONE"];
if (isnil{(_AIcrew2 select _ii)}) then {_sld action ["getin" + (_AIcrew1 select _ii),_car]}else{_sld action ["Getin" + (_AIcrew1 select _ii),_car,(_AIcrew2 select _ii)]};
_ii = _ii + 1;
} foreach _AIcrew;

_speed = 0;
_car setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+(cos _dir*_speed),(_vel select 2)];
};

this will put the vehicle and crew even cargo positions where it started and will go on and on

so if you have a group of 8 units moveincargo to a truck at mission start , every time the truck respawns it will have 8 units in the back

this also works on every vehicle , in the air or on the ground

Thanks a lot, I want vehicles that can be destroyed but respawn with crew and also not move so I'll try using both those scripts but just leave out the damage stuff.

Share this post


Link to post
Share on other sites

in that case use both as you suggested but change Veh_Respawn.sqf to this to rerun the enableSimulation false for the new vehicle that is created

sleep .5;

if !(isServer) exitwith {};

private ["_delay","_car","_pos","_dir","_typeveh","_hgt","_grp","_vel","_speed","_sld","_x","_AIcrew","_AIcrew1","_AIcrew2"];

_delay = 10;       // set this for the delay to respawn a new vehicle after the old one is to damaged;

_car = _this select 0;
_pos = position _car;
_dir = direction _car;
_hgt = _pos select 2;
_vel = velocity _car;

sleep 2;

_AIcrew = [];
_AIcrew1 = [];
_AIcrew2 = [];
{_AIcrew = _AIcrew + [typeOf _x]} foreach crew _car;
{_AIcrew1 = _AIcrew1 + [(assignedVehicleRole _x select 0)];
_AIcrew2 = _AIcrew2 + [(assignedVehicleRole _x select 1)];
} foreach crew _car;

_typeveh = typeOf _car;
_grp = group _car;

while {true} do
{
sleep 1;

waituntil {!(canmove vehicle _car)};

sleep _delay;  

deleteVehicle _car;
_grp = creategroup east;


if (vehicle _car isKindOf "AIR") then {_pos set [2,500];_car = createVehicle [_typeveh, _pos, [],0,"fly"]} else {_car = _typeveh createVehicle _pos;};
_car setdir _dir;
_car setdamage 0;
_car setFuel 1;
_car setVehicleAmmo 1;
_car setpos _pos;


_sld = objnull;
_ii = 0;
{_sld = _grp createUnit [_x,_pos,[],0,"NONE"];
if (isnil{(_AIcrew2 select _ii)}) then {_sld action ["getin" + (_AIcrew1 select _ii),_car]}else{_sld action ["Getin" + (_AIcrew1 select _ii),_car,(_AIcrew2 select _ii)]};
_ii = _ii + 1;
} foreach _AIcrew;

_car setVehicleInit "this enableSimulation false;";
processInitCommands;
clearVehicleInit _car;
//_speed = 0;
//_car setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+(cos _dir*_speed),(_vel select 2)];
};

Share this post


Link to post
Share on other sites

Thanks I'll use that. One thing though, I heard that enablesimulation doesn't work in multiplayer so you have to run it on all clients. Do you know anything about that or how I would set it to run it on all clients?

Also is _car in that script the name of the vehicle or something else? If it is should I change them all to _this so I can run it for different vehicles?

Edited by clydefrog

Share this post


Link to post
Share on other sites

setVehicleInit is how you can set commands to be global in MP - maybe not the most efficient way but it is effective and for what you want to do you it wont lag anything at all

it will work as it is

there is no need to change anything

Edited by Zonekiller

Share this post


Link to post
Share on other sites

Ok thanks a lot for your help, I'll try it out soon.

---------- Post added at 19:48 ---------- Previous post was at 18:35 ----------

Ok a problem, I think that enablesimulation thing is stopping the AI from turning on the engine. I have put a crewman by an empty vehicle named "t55" with "this moveindriver t55" in its init field. He gets in but doesn't start the engine up and because of that you can't lock onto it with a Javelin (and probably also air to ground missiles) which is something I need to work. Any ideas?

Share this post


Link to post
Share on other sites

That's what enablesimulation false does it freezes them including their turrets and shooting. They can be destroyed but you wont see any effect because that's frozen as well.

If you want them too fire but not move you'll have to try attchto again or disableAI "MOVE" maybe a hold waypoint for AI.

Share this post


Link to post
Share on other sites

No I need them to not fire so I removed all their ammunition. I don't want them to move but I do need their engines to be on so they show up as targets, if I use that attachto gamelogic thing you mentioned should they still have their engines on even though they can't move?

Share this post


Link to post
Share on other sites

They're fully functional they just can't move from their position.

Share this post


Link to post
Share on other sites
No I need them to not fire so I removed all their ammunition. I don't want them to move but I do need their engines to be on so they show up as targets, if I use that attachto gamelogic thing you mentioned should they still have their engines on even though they can't move?

heres what you can do:

tank setCombatMode "BLUE" - will never fire - EVER!

tank engineOn true

tank setBehaviour "CARELESS" - will ignore enemy contact and will not move

see if this works. To make things easier for you:

FNC_DisableVeh = {
private ["_veh"];
_veh setCombatMode "BLUE";
_veh engineOn true;
_veh setBehaviour "CARELESS";
};

run that in init.sqf (or you can preprocess it) then

{0 = _x call FNC_DisableVeh} foreach allMyVehicles;

Share this post


Link to post
Share on other sites
I removed all their ammunition

wont that stop them showing up as a threat also ?

FNC_DisableVeh = {

private ["_veh"];

_veh setCombatMode "BLUE";

_veh engineOn true;

_veh setBehaviour "CARELESS";

};

i think the reaction fsm will override this.

have you tried using a fully crewed vehicle placed in the editor instead of moving a unit into an empty vehicle.

welcome to the fun of AI scripting :)

i will have a play with this today and see what i can work out

Share this post


Link to post
Share on other sites

Hi, no removing ammo doesn't stop them showing as a target (i.e. green box with name that can be locked onto in AGM or GBU cameras) or in the case of the Javelin the little red name and then you get a red box that gets smaller until it locks on. It's only if the engine is off that these targets are disabled so either with no crew, or with crew and using that "this enablesimulation false" thing (and also if there is no fuel in them).

Yes until I read your post yesterday all my vehicles were already crewed and still are except for one empty one with a separate driver who moves into it (this moveInDriver t55), to test what you told me to do. The guy gets in it but enablesimulation false seems to prevent the engine being active. Should I stick with already crewed vehicles or should I change them all to empty and give them a driver each just so their engines will be on (without using enablesimulation), then after they are destroyed that vehicle respawn script you gave me will re-crew the new vehicles that spawn. Does it make any difference to your respawn script whether the original vehicles are already crewed or if you've moved separate AI into an empty one?

Edited by clydefrog

Share this post


Link to post
Share on other sites

from the tests i did today , tried quite a few tricks , unfortunatly no go , i could not stop them and keep them as a target using scripting commands

once the bis reaction fsm kicks in it overrides everything,

all i can think of is place an object where you want the vehicle and attach it to it, then in the Veh_Respawn.sqf attach the new vehicle to that object

add the object to the scrip as such

[this,object] execVM "Veh_Respawn.sqf";

_car = _this select 0;

_object = _this select 1;

ect

Share this post


Link to post
Share on other sites
from the tests i did today , tried quite a few tricks , unfortunatly no go , i could not stop them and keep them as a target using scripting commands

once the bis reaction fsm kicks in it overrides everything,

all i can think of is place an object where you want the vehicle and attach it to it, then in the Veh_Respawn.sqf attach the new vehicle to that object

add the object to the scrip as such

[this,object] execVM "Veh_Respawn.sqf";

_car = _this select 0;

_object = _this select 1;

ect

or can I just attach them all to the same gamelogic like F2k Sel said?

so I add

[this,object] execVM "Veh_Respawn.sqf";

_car = _this select 0;

_object = _this select 1;

anywhere into the Veh_Respawn.sqf? with object being the name of the gamelogic? Is that all there is to it or is there anything else I need to add?

I take it if I didn't do this then when the new vehicle spawned it would be no longer attached to the object/gamelogic?

Share this post


Link to post
Share on other sites
I take it if I didn't do this then when the new vehicle spawned it would be no longer attached to the object/gamelogic?

correct

so you have to attach the new vehicle to the logic again

or can I just attach them all to the same gamelogic like F2k Sel said?

if they are close enough yes

Share this post


Link to post
Share on other sites
correct

so you have to attach the new vehicle to the logic again

if they are close enough yes

Hmm, he said I could use one gamelogic and attach all my vehicles to it, and it wouldn't matter where the gamelogic was on the map, the vehicles would be attached to it but still be in the places you put them on the map by using "vehname attachto [glname];". So it won't work like that? Sorry for all the questions btw, I'm pretty new to editing as you can tell so I don't have a good understanding of how a lot of stuff works yet.

And just to confirm is that last bit of code you posted all I need to reattach the vehicle to an object on respawn and I can put that anywhere in the vehicle respawn script and it will work? You typed "ect" when you posted it that made me think there might be more to it than what you posted. Would I type for example:

[this,mygamelogicname] execVM "Veh_Respawn.sqf";

_car = _this select 0;

_object = _this select 1;

?

Edited by clydefrog

Share this post


Link to post
Share on other sites
Sign in to follow this  

×