Jump to content

5133p39

How to lock a vehicle?

Recommended Posts

I need to lock a vehicle to prevent anybody from:
- getting in (not just as a driver, but anywhere)

- opening any doors
- accessing vehicle's inventory

- loading/unloading supplies (i need to get rid of this mechanics in general - my mission is not using it, so it makes no sense for these prompts to even be there)

 

What i need is the equivalent of the good old lock command from Arma 3.

Share this post


Link to post
Share on other sites

Never mind. Figured it out with the help of some very patient people on Discord.
Will come back here later to describe how to implement it, in case anybody is lost as i was.

Share this post


Link to post
Share on other sites

IMPORTANT:
I wouldn't expect this to work in MP environment as it is, because i don't know anything about that yet, and i had no time to test in MP at all. I only used the code in SP missions so far.

It is rough and needs to be tweaked to work with any vehicle - i only tested it with UAZ469.
The code can use some improvements, at the very least to make it more universal, supporting different vehicle types, but most importantly it may need properly implemented replication for MP, and maybe more (post your tips and opinions, especially on how to do things cleanly and properly).


First, let's summarize how we want it to work:

  • Each door, trunk, hood, etc., should be (un)lockable individually, and if locked, will prevent all related actions (opening door, entering, exiting, jumping out, inventory access, whatever).
    NOTE: None of the old cars would have central locking, but we should add such option so it can be used with any modern car mods, i just don't want to bother with that right now, maybe later.
  • The system will work for, and restrict, only players.
    Bots will behave same way as they did before, unaffected by the system.
  • To lock/unlock anything, players need to have a key (an item), which is paired with the vehicle.
    Except if players are already inside the vehicle - then they won't need a key to lock/unlock any door withing reach.
    The key-to-vehicle pairing will be based on 5 letter string codes ("ABCDE"), so if need be, we can show the code to player in a nice readable form, but internally we will rely on hashes.
    We will make am Inventory Item Component attached on the key item prefab, and a vehicle Script Component attached on the vehicle entities (or base prefabs) - each holding the string code, its hash (we'll need that only on the vehicle), and any minimal methods that we may need on one or the other.
  • To use a key, player will need to place it in some Quick Slot - no actions needed, just have it in a slot.
    When player closes inventory after placing a key in Quick Slot, we will check all slots and use code from the first key we find.
    We will store the code, that we found on the first key, in a static variable on a Game Component that we will make for this purpose (and to provide some needed methods) - that way we can have quick and easy access to the "cached" code from anywhere.
  • Starting the vehicle's engine will not need a key.
    As long as a player is inside a vehicle, they can start the engine freely (or at least unrestricted by this system) without a key.


 

The Game Component: YOUR_PROJECT/scripts/GameCode/Mors/Mors_VehicleLockGameComponent.c

To be added as a component to a GameMode.

  Reveal hidden contents



The Vehicle Component: YOUR_PROJECT/scripts/GameCode/Mors/Mors_VehicleLockingComponent.c

To be added as a component to a vehicle placed in World Editor directly (not in a "Slot.et", so you can access the component and manually can set the vehicle-to-key pairing code), or some vehicle base class (i added it to an override of Wheeled_base.et).

  Reveal hidden contents

 

 

The Inventory Item Component: YOUR_PROJECT/scripts/GameCode/Mors/Mors_VehicleKeyItem.c
To be added as a component to the vehicle key prefab.

For now, just make a duplicate of some bandage item (anything that you know is already configured as inventory item that can be placed in Quick Slot), and then attach this component to that prefab, and use that as the "vehicle key".

Also, you need to place this item in the World Editor directly, so you can have access to the component on it and manually set the vehicle code that is to be used for pairing with a vehicle (otherwise you'd need to do that using some script, which is not covered here).

  Reveal hidden contents

 

 

 

The next things you need, are overrides of various User Action classes/methods.
That is where you add conditions to check for locked door before allowing to proceed with opening it, etc.
To set these scripts up, use filter to find these files, create duplicates (keep same filename) into your project, move the created duplicates into a "modded" subfolder that you create in the location where each duplicate was created, then edit them accordingly:

SCR_GetInUserAction.c
Found in "ArmaReforger/scripts/Game/UserActions/", create duplicate into "YOUR_PROJECT/scripts/Game/UserActions/modded/".

  Reveal hidden contents

 

SCR_GetOutUserAction.c
Found in "ArmaReforger/scripts/Game/UserActions/", create duplicate into "YOUR_PROJECT/scripts/Game/UserActions/modded/".

  Reveal hidden contents

 

SCR_JumpOutUserAction.c
Found in "ArmaReforger/scripts/Game/UserActions/", create duplicate into "YOUR_PROJECT/scripts/Game/UserActions/modded/".

  Reveal hidden contents

 

SCR_OpenVehicleDoorUserAction.c

Found in "ArmaReforger/scripts/Game/UserActions/", create duplicate into "YOUR_PROJECT/scripts/Game/UserActions/modded/".

  Reveal hidden contents

 

SCR_OpenVehicleStorageAction.c

Found in "ArmaReforger/scripts/Game/UserActions/", create duplicate into "YOUR_PROJECT/scripts/Game/UserActions/modded/".

  Reveal hidden contents

 

SCR_RefuelAtSupportStationAction.c

Found in "ArmaReforger/scripts/Game/UserActions/SupportStations/", create duplicate into "YOUR_PROJECT/scripts/Game/UserActions/SupportStations/modded/".

  Reveal hidden contents

 

SCR_ResourceContainerVehicleLoadAction.c

Found in "ArmaReforger/scripts/Game/Sandbox/Resources/UserActions/", create duplicate into "YOUR_PROJECT/scripts/Game/Sandbox/Resources/UserActions/modded/".

  Reveal hidden contents

 

SCR_ResourceContainerVehicleUnloadAction.c

Found in "ArmaReforger/scripts/Game/Sandbox/Resources/UserActions/", create duplicate into "YOUR_PROJECT/scripts/Game/Sandbox/Resources/UserActions/modded/".

  Reveal hidden contents

 

 

 

Mors_LockUnlockVehicleAction.c
You need to CREATE this script. This is a new script for a custom Lock/Unlock user action.
Place into "YOUR_PROJECT/scripts/Game/UserActions/".
 

  Reveal hidden contents

 

 

 

That would be the scripts.
Now we need to... smash it all together. And because describing all this would be too much work 🙂 i'll just use screenshots.

This post is already WAY to long (god! i hope i won't need to edit it), so i will make a break here, and continue in another post below.

  • Thanks 2

Share this post


Link to post
Share on other sites

This is the continuation of the process started in my previous post.

I had to upload the images on IMGUR, and i don't know if they show up embedded in here - if not, use this link: https://imgur.com/a/MIcAFSh

 

 

1. Find this prefab called Wheeled_Base.et and create an override in your project, and add the VehicleLocking Component to it.

https://imgur.com/Qp2LKHK

 

2. Add 2 custom user actions to ActionsManagerComponent on the Wheel_Base override, configure them as they are on this image.

https://imgur.com/k57Lzvq

 

3. To create the Vehicle Key Inventory Item, find this prefab and duplicate into your project.

https://imgur.com/TNo1OHK

 

4. Vehicle Key Inventory Item - Rename it, and add the highlighted VehicleKeyItem Component to it.

https://imgur.com/GMwekmx

 

5. Add the VehicleLockGameComponent to your GameMode.

https://imgur.com/Oc2iUKa

 

That should be all, unless i forgot something.

Now you can test it.

 

Place some vehicle into the world (preferably the UAZ 469, on which i tested this), and the the "vehicle key" inventory item.

You need to manually set the pairing codes on both, and placing them in the world directly ensures that you will be able to access those attributes on the entities.

Of course you can use scripting to set the codes, but this will be quicker, just tor test the thing.

 

Make sure you set the code on the vehicle and on the key to the same value (example: ABCDE).

Stick to simple ASCII characters, and i recommend sticking to the length of 5 characters.

Then hit Play (assuming you have your test "mission" prepared - which i do not cover here at all), pickup the key you placed in the World Editor, put it in some Quick Slot, and mess with the vehicle to see how it works.

Then quit, rewrite everything properly into a proper mod that works universally with any vehicle, and drop me a link so i can save some time doing that myself 😉

  • Thanks 2

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

×