Jump to content
  • 0

Private Vehicles


thekaboobie

Question

So I saw something like this once and thought it was really cool, looked around and didn't find anything like this on any of the usual mod sites, so I have decided to try and create my own version. So what exactly am I trying to do?

 

Basically I am trying to create a vehicle that respawns every server restart. <-- This part is easy and I have done already. The catch and what I think makes it really cool is that the vehicle would be assigned an owner, based on a player uid, if you try to enter as someone who doesn't own the vehicle you are kicked out and given a message along the lines of "you don't have permission to enter this vehicle". <--- This I am finding much more difficult.

 

So Let me share what I have so far and hopefully some of you much more talented people can tell me where I have gone wrong and if I am even doing this halfway correctly.

 

first I have a file called privatevehicles.sqf which is called server side through the server_monitor.sqf like so:

// Private Vehicles
call compile preProcessFileLineNumbers "\z\addons\dayz_server\PV\privatevehicle.sqf";

the privatevehicle.sqf which works fine with spawning in a vehicle:

// This spawns the vehicles.

_vec = createVehicle ["UH1H_TK_EP1", [14110.31, 2782.1448, 0], [], 0, "CAN_COLLIDE"] 
_vec setVariable ["Sarge",1,true];
_vec setVariable ["owner",123,true]; //trying this to see if I can set an owner variable but this is over my head right now as to how to really do this and the values are placeholders.
_vec = execVM "z/addons/dayz_code/PV/privatechopper.sqf";

_vec2 = createVehicle ["LandRover_Special_CZ_EP1_DZ", [14210.31, 2782.1448, 0], [], 0, "CAN_COLLIDE"];
_vec2 setVariable ["Sarge",1,true];
_vec2 = execVM "z/addons/dayz_code/PV/privatelandrover.sqf"; //tried adding this to then end of the createvehicle line like I'm sure it should be but the sarge variable would not set when I did this so I'm not certain it's actually even using the script on the vehicle or not at this point.

This spawns in the vehicles and the sarge variable keeps them from exploding or disappearing when you enter them.

 

Now all that is very basic and easy to achieve however, now I have this which I was hoping would do all of the more interesting portions but so far has not worked.

private["_owner","_vec","_crew","_dontmove"];


if (vehicle player != player) then {

_vec = (vehicle player);

if (_vec isKindOf "UH1H_TK_EP1") then {

_owner = []; // this is filled with "123154123" in landrover.sqf
				
_owner = _vec getVariable "owner"; //this is removed in the landrover.sqf 
		
if ((count _owner) > 0) then {

if (!((getPlayerUID player) in _owner)) then {

_crew = crew _vec;

_dontmove = false;

{ if ((getPlayerUID _x) in _owner) then { _dontmove = true;}; } forEach _crew;

if (!_dontmove) then {

	cutText ["You are not allowed to enter this vehicle","PLAIN",3];

moveOut player;

};
}; 
};
};	
};
}; 

 So either that code is not functional or I am not actually calling it when I am spawning the vehicle. I hope that you guys will find this interesting and help me get this working. 

 

Just realized what I was trying to do with the setVariable isn't going to work without some additional scripting to define what those variables are and could be a solution to assigning an owner possibly. 

 

I assume if I use a setVariable solution to define the owner then I would have to define the variable itself somewhere with something like the example I found here: http://community.bistudio.com/wiki/setVariable but honestly this is over my head a bit still.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I would make it an Epoch Event so it triggers for the duration of the server being up.

 

You can get a list of playableUnits http://community.bistudio.com/wiki/playableUnits

 

Then use BIS_fnc_selectRandom https://community.bistudio.com/wiki/BIS_fnc_selectRandom to choose a player from the server (some checking may be required as playableUnits will return AI units too I believe)

 

Then getPlayerUID https://community.bistudio.com/wiki/getPlayerUID on the randomly selected player.

 

Then assign that UID to your owner variable. setVariable is a good way to go, consider adding the extra true on the end to broadcast the variable if running that bit on the server. Maybe use a custom owner var as I am not sure if that is used already..Call it kabOwner or something..?

 

In the player bit of code (last block) you want to add a loop so it keeps checking (key problem I think - look at the usage of while {alive player}do{ <your stuff in here with a sleep>};), with a decent pause so as not to overload the player. There is one too many }; in that code also. Personally I prefer 

player action ["eject", vehicle player];

 to boot a player from a vehicle.

 

Use -showScriptErrors in your start up parameter for your player http://community.bistudio.com/wiki/Arma2:_Startup_Parameters to see any syntax problems, I also strongly recommend running it past Squint before loading up the server http://www.armaholic.com/page.php?id=11817

 

Sorry it's taken so long to get back to you, been a bit snowed under, hope that is the sort of thing you are looking for.. gl. wasn't ignoring your PM :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...