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

Vehicle created by createVehicle array is locked - how to unlock?

Recommended Posts

Hey guys,

just noticed a bug in my mission, respawned vehicles are locked. Would have been quite a bummer when I play it with my clan, because you start on an island with only 3 boats :D

So that was the part of my script that respawned the vehicle:

if (_dead) then {	
deleteVehicle _unit;
sleep 2;
_unit = createVehicle [_type, _position, [], 0, "CAN_COLLIDE"];
_unit setDir _dir;
clearMagazineCargo _unit;
_dead = false;
};

After checking the Wiki I added lock false:

if (_dead) then {	
deleteVehicle _unit;
sleep 2;
_unit = createVehicle [_type, _position, [], 0, "CAN_COLLIDE"];
_unit setDir _dir;
clearMagazineCargo _unit;
_unit lock false;
_dead = false;
};

And that didn't change it. What's wrong here?

Cheers,

Thomas

Share this post


Link to post
Share on other sites

Not quite sure mate. I did a little test using this code.... even commented out the "lock" line and it still works. Tried with a few land vehicles and the RHIB with no problems. Could always get into them after respawn. Your code seems fine.

_veh = _this select 0;
_pos = _this select 1;

_type = typeOf _veh;
_dir = 180;

while {true} do {
while {alive _veh} do {
	sleep 1;
};

deleteVehicle _veh;
sleep 2;
_veh = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"];
_veh setDir _dir;
clearMagazineCargo _veh;
//_veh lock false;

};

Share this post


Link to post
Share on other sites

To be sure it's the issue, make a try with this code (not tested):

player sidechat format ["locked veh = %1", locked _veh];

And yes, your code seems fine for me too.

Share this post


Link to post
Share on other sites

Never heard about locked vehicles created by createVehicle command... if you test in multiplayer mode it is possible that your client don`t know about the new vehicle. Check it by targeting the vehicle and do a right click on it. Sometimes you will get the action menu entries after that procedure... :803:

Share this post


Link to post
Share on other sites

Thanks for trying that twirly, this really depresses me right now :)

So I will post my full script, even though I don't think there's the mistake:

// Respawns a vehicle at the position it was put in mission editor after it's been left for more than a specified time or is significantly damaged and empty. Cargo of the vehicle will be empty after respawn.

// Put following line in the init line of the vehicle: nul = [this, time_in_seconds] execVM "scripts\vehicle_respawn_damaged_or_left.sqf";

// Locality: Server only
if (!isServer) exitWith {};

// Variables
_unit = _this select 0;
_timealone = _this select 1;
_dir = getDir _unit;
_position = getPosASL _unit;
_type = typeOf _unit;
_dead = false;
_rnumber = round (random 15) + 5;

// Get started
while {true} do {
sleep (_rnumber);

if (getDammage _unit >= 0.8) then {
	if ({alive _x} count crew _unit == 0) then {
		_dead = true;
	};
};

if (getDammage _unit < 0.8) then {
	if (getPosASL _unit distance _position > 10) then {
		if ({alive _x} count crew _unit == 0) then {
			_timeout = time + _timealone;
			sleep 0.1;
			waitUntil {_timeout < time OR !alive _unit OR {alive _x} count crew _unit > 0};
			_dead = true;
			if ({alive _x} count crew _unit > 0) then {_dead = false};
		};
	};
};

if (_dead) then {	
	deleteVehicle _unit;
	_rnumber = round (random 15) + 5;
	sleep 2;
	_unit = createVehicle [_type, _position, [], 0, "NONE"];
	_unit setDir _dir;
	clearMagazineCargo _unit;
	_dead = false;
};
};

Edit: @Buliwyf, I can access its gear per mousewheel and the ace gear too. This is weird..

Share this post


Link to post
Share on other sites

I just ran it without any changes and while the RHIB I'm using spawned about 20m up in the air.... I could still get into it... once it landed :)

Maybe the spawn height has to do with getPosASL... not sure.

Try just running this script alone in a new test mission and see if it works. If it does then maybe there is some other script that is locking the vehicles.

Share this post


Link to post
Share on other sites

Ok, I found the problem apparently:

When testing in preview of the mission editor, the other playable units are controlled by AI. So the soldier I tested with, was in a group with AI and I was not the leader. And it seems the leader forbid me to get in the car?! When I made the soldier I test with the highest ranked, I could get in. <- Not the best english I ever wrote, it's late here.. hope you get the point ;)

Now I just need to test that on a dedicated server, where all soldiers are controlled by humans.

Thanks for your help guys :)

Share this post


Link to post
Share on other sites

Good detective work! Glad you found it man.

Share this post


Link to post
Share on other sites

Haha thanks, me too.. hopefully this will be different with human players on a dedicated server.

By the way, I just saw that I missed a few posts apparently. Thanks for trying to help me too :)

Share this post


Link to post
Share on other sites

Buliwyf is correct, vehicles that are createVehicle'd are not "known" of and cannot be interracted with. You can either reveal them using the reveal key (Hold right mouse button by default) or use the reveal command to do it automatically.

Share this post


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

×