Jump to content
Sign in to follow this  
eagledude4

Vehicle Unlocks/Locks itself

Recommended Posts

Resolved, see the top half of post #8 for solution

EDIT: Still another issue, see the bottom half of post #8 for details.

Edited by eagledude4

Share this post


Link to post
Share on other sites

Why even bother using setVehicleInit? lock's effects are global, so once locked it will be locked for everyone, even JIPed players.

Considering your examples one thing can be ascertained: the vehicle isn't executing the lock-requests you make.

Please make sure that the vehicle is local to the client the lock is executed on. If your server has created the vehicle for example, then the server will be the only one able to issuing the lock.

Share this post


Link to post
Share on other sites

With the "vehicle enter" you overtake "ownership", so to say -> commands like lock, setfuel, etc.

I've made the experience, that once you try to use an "execvm" or call or spawn, with one of these codes, a server-spawned vehicle will not respond -> it will be unlocked for 1 second, and then lock, or have fuel for 1 second, and then the server resyncs and its back to normal. A command that is always transferred globally is "setdamage", for example.

Without fading further away, a half-assed solution is spawning the vehicle local to the player, or use a loop that starts on Server init, and use publicvariable; that way, you send the code to the server and it processes it and delivers it to other players to update the state of the vehicle, I cant think of anything better ATM.

Share this post


Link to post
Share on other sites

@XxAnimusxX: Without the setvehicleinit, I was getting errors. Also, that last part is incorrect because I can manually lock and unlock the vehicle after it's spawned, like I said initially.

@Dementented: I'm already using a public variable for clients when locking/unlocking the vehicle after it's been spawned. Also, I can't spawn the vehicle local to the player as this is a multiplayer mission.

Edited by eagledude4

Share this post


Link to post
Share on other sites

You probably have it on code somewhere but as I'm not seeing it I'll mention it.

You need to use processInitCommands after setvehicleinit

_Vcl setVehicleInit "
this setVehicleVarName format[""%1"",_Var];
if (_Lock == ""true"") then {
	this lock true;
} else {
	this lock false;
};	
";
processInitCommands;

also I see _Lock and you can't use underscore/local variables in an INIT line.

Share this post


Link to post
Share on other sites

I'm not getting any errors for _Lock with the below code:

call compile format ['
	newvehicle = _Class createVehicle %3; 
	newvehicle setdir %4; 
	newvehicle setdamage _Damage;
	newvehicle setVehicleInit "
	this setVehicleVarName ""%1_%2""; 
	%1_%2 = this; 

	clearWeaponCargo this; 
	clearMagazineCargo this;
	if (typeOf this != ""MMT_USMC"") then {
		if (_Lock == ""true"") then {
			this lock true;
		} else {
			this lock false;
		};
	} else {
		this lock false;
	};

	if (count _Mags > 0) then {
		{
			this addMagazineCargo _x;
		} forEach _Mags;
	};
	if (count _Weaps > 0) then {
		{
			this addWeaponCargo _x;
		} forEach _Weaps;
	};

	this addMPEventHandler [""MPKilled"",{VclDelete = this; publicVariable ""VclDelete""}];
	this addEventHandler [""getIn"",{[""Add"", _this] call FNC_GetInOut}]; 
	this addEventHandler [""getOut"",{[""Remove"", _this] call FNC_GetInOut}];
	"; 
	processInitCommands;
	', _Class, _Count, _Pos, _Dir];

Edited by eagledude4

Share this post


Link to post
Share on other sites

I don't think you will get an error when doing it that way just as you don't get one when doing the same thing in a scripted trigger or using a function. It just won't work.

Share this post


Link to post
Share on other sites

But as I was trying to explain before, it does work. The vehicle locks or unlocks properly (without errors) when using:

if (_Lock == ""true"") then {
this lock true;
} else {
this lock false;
};

but this isn't the issue I'm trying to convey.

EDIT:

Using this code on the client:

if (not(locked _vcl)) then {
if (hostedServer) then {
	_vcl lock true;
} else {
	VclLock = [_vcl, true];
	publicVariable "VclLock";
};
  hint localize "STRS_inv_items_vehiclelock_locked";
} else {
if (hostedServer) then {
	_vcl lock false;
} else {
	VclLock = [_vcl, false];
	publicVariable "VclLock";
};
hint localize "STRS_inv_items_vehiclelock_unlocked";
};

And using this code on the server:

"VclLock" addPublicVariableEventHandler {
_Arr = _this select 1;
_Vcl = _Arr select 0;
_Lock = _Arr select 1;
_Vcl lock _Lock;
       diag_log format ["%1", _Arr];
}; 

fixes the issue with the automatically locking/locking by the server.

HOWEVER...

I am now experiencing an issue where after I enter the vehicle, I am unable to lock or unlock it using the above code.

EDIT:

The solution for the above issue is including the "VclLock" addPublicVariableEventHandler on the clients as well.

Edited by eagledude4

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×