Skip to content

Commit

Permalink
52 (#130)
Browse files Browse the repository at this point in the history
* docs: increment version

* feat: Pick database name from env (#127)

* Added disabling Wheel Radial Menu into serverConfig. (#129)

* Update serverConfig.ts

* Update serverConfig.ts

* Added disableWeaponRadial to docs

* feat: doors system (#128)

* WIP: doors system

* Added doors list to the docs

* Added events invocation, fixed webview synced meta change

* Few changes around confusing isUnlocked state

* Moved doors file on client from controllers to virtualEntities

* Removed junk

* fix: missing door invoke event

* revert previous changes

* Add new callback "hold" to useKeypress (#131)

* Add new callback "hold" to useKeypress

* Add new callback "hold" to useKeypress

* Add new callback "hold" to useKeypress

* Update src/main/client/system/serverKeypress.ts

Co-authored-by: Stuyk <trevorwessel@protonmail.com>

---------

Co-authored-by: Stuyk <trevorwessel@protonmail.com>

* feat: update useKeypress functionality, and make backwards compatible

* feat: change onHold functionality slightly

* docs: update useKeypress

---------

Co-authored-by: Vladyslav Halatskyi <xfloydya@gmail.com>
Co-authored-by: Liam Robinson <liamrobinson5@web.de>
Co-authored-by: KoronGIT <error@dragonspace.de>
  • Loading branch information
4 people authored Jul 26, 2024
1 parent 9f4b39c commit b431300
Show file tree
Hide file tree
Showing 23 changed files with 786 additions and 34 deletions.
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Connection string used to connect to a MongoDB database
MONGODB=mongodb://127.0.0.1:27017
MONGODB=mongodb://127.0.0.1:27017

# You can set database name here, so it will populate the config with the value.
# Don't forget to uncomment the line below if you want to change:
# DATABASE_NAME=Rebar
19 changes: 19 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ order: 95

# Changelog

## Version 52

### Code Changes

- Added ability to change database name through environment variables — @floydya
- Added door system controller — @floydya
- Added server config option for disabling weapon wheel menu — @mnkyarts
- Added onHold callback for `useKeypress` that invokes after `x` time has passed while holding a key — @koron
- Updated `useKeypress` to include `onHold`, which is invoked after `2s` of holding

### Docs Changes

- Added door system docs @floydya
- Added `env` options for database name to useConfig page
- Updated server config docs @mnkyarts
- Updated `useKeypress` docs to include `onHold`

---

## Version 51

### Code Changes
Expand Down
106 changes: 106 additions & 0 deletions docs/data/doors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Doors

List of doors that could be used with useDoor controller.

| Description | Model | Position |
| ------------------------------------------------------- | ------------- | ------------------------------------------------ |
| Pacific Standard Bank Main Right Door | `110411286` | `new alt.Vector3(232.6054, 214.1584, 106.4049` |
| Pacific Standard Bank Main Left Door | `110411286` | `new alt.Vector3(231.5123, 216.5177, 106.4049` |
| Pacific Standard Bank Back Right Door | `110411286` | `new alt.Vector3(260.6432, 203.2052, 106.4049` |
| Pacific Standard Bank Back Left Door | `110411286` | `new alt.Vector3(258.2022, 204.1005, 106.4049` |
| Pacific Standard Bank Door To Upstair | `1956494919` | `new alt.Vector3(237.7704, 227.87, 106.426` |
| Pacific Standard Bank Upstair Door | `1956494919` | `new alt.Vector3(236.5488, 228.3147, 110.4328` |
| Pacific Standard Bank Back To Hall Right Door | `110411286` | `new alt.Vector3(259.9831, 215.2468, 106.4049` |
| Pacific Standard Bank Back To Hall Left Door | `110411286` | `new alt.Vector3(259.0879, 212.8062, 106.4049` |
| Pacific Standard Bank Upstair Door To Offices | `1956494919` | `new alt.Vector3(256.6172, 206.1522, 110.4328` |
| Pacific Standard Bank Big Office Door | `964838196` | `new alt.Vector3(260.8579, 210.4453, 110.4328` |
| Pacific Standard Bank Small Office Door | `964838196` | `new alt.Vector3(262.5366, 215.0576, 110.4328` |
| Discount Store South Enter Right Door | `-1148826190` | `new alt.Vector3(82.38156, -1390.476, 29.52609` |
| Discount Store South Enter Left Door | `868499217` | `new alt.Vector3(82.38156, -1390.752, 29.52609` |
| Los Santos Customs Popular Street Door | `270330101` | `new alt.Vector3(723.116, -1088.831, 23.23201` |
| Los Santos Customs Carcer Way Door | `-550347177` | `new alt.Vector3(-356.0905, -134.7714, 40.01295` |
| Los Santos Customs Greenwich Parkway Door | `-550347177` | `new alt.Vector3(-1145.898, -1991.144, 14.18357` |
| Los Santos Customs Route 68 Right Garage Door | `-822900180` | `new alt.Vector3(1174.656, 2644.159, 40.50673` |
| Los Santos Customs Route 68 Left Garage Door | `-822900180` | `new alt.Vector3(1182.307, 2644.166, 40.50784` |
| Los Santos Customs Route 68 Office Door | `1335311341` | `new alt.Vector3(1187.202, 2644.95, 38.55176` |
| Los Santos Customs Route 68 Interior Door | `1544229216` | `new alt.Vector3(1182.646, 2641.182, 39.31031` |
| Beeker's Garage Paleto Bay Right Garage Door | `-822900180` | `new alt.Vector3(114.3135, 6623.233, 32.67305` |
| Beeker's Garage Paleto Bay Left Garage Door | `-822900180` | `new alt.Vector3(108.8502, 6617.877, 32.67305` |
| Beeker's Garage Paleto Bay Office Door | `1335311341` | `new alt.Vector3(105.1518, 6614.655, 32.58521` |
| Beeker's Garage Paleto Bay Interior Door | `1544229216` | `new alt.Vector3(105.7772, 6620.532, 33.34266` |
| Ammu Nation Vespucci Boulevard Right Door | `-8873588` | `new alt.Vector3(842.7685, -1024.539, 28.34478` |
| Ammu Nation Vespucci Boulevard Left Door | `97297972` | `new alt.Vector3(845.3694, -1024.539, 28.34478` |
| Ammu Nation Lindsay Circus Right Door | `-8873588` | `new alt.Vector3(-662.6415, -944.3256, 21.97915` |
| Ammu Nation Lindsay Circus Left Door | `97297972` | `new alt.Vector3(-665.2424, -944.3256, 21.97915` |
| Ammu Nation Popular Street Right Door | `-8873588` | `new alt.Vector3(810.5769, -2148.27, 29.76892` |
| Ammu Nation Popular Street Left Door | `97297972` | `new alt.Vector3(813.1779, -2148.27, 29.76892` |
| Ammu Nation Popular Street Shooting Range Door | `452874391` | `new alt.Vector3(827.5342, -2160.493, 29.76884` |
| Ammu Nation Adam's Apple Boulevard Right Door | `-8873588` | `new alt.Vector3(18.572, -1115.495, 29.94694` |
| Ammu Nation Adam's Apple Boulevard Left Door | `97297972` | `new alt.Vector3(16.12787, -1114.606, 29.94694` |
| Ammu Nation Adam's Apple Boulevard Shooting Range Door | `452874391` | `new alt.Vector3(6.81789, -1098.209, 29.94685` |
| Ammu Nation Vinewood Plaza Right Door | `-8873588` | `new alt.Vector3(243.8379, -46.52324, 70.09098` |
| Ammu Nation Vinewood Plaza Left Door | `97297972` | `new alt.Vector3(244.7275, -44.07911, 70.09098` |
| Ponsonbys Portola Drive Right Door | `-1922281023` | `new alt.Vector3(-715.6154, -157.2561, 37.67493` |
| Ponsonbys Portola Drive Left Door | `-1922281023` | `new alt.Vector3(-716.6755, -155.42, 37.67493` |
| Ponsonbys Cougar Avenue Right Door | `-1922281023` | `new alt.Vector3(-1456.201, -233.3682, 50.05648` |
| Ponsonbys Cougar Avenue Left Door | `-1922281023` | `new alt.Vector3(-1454.782, -231.7927, 50.05649` |
| Ponsonbys Rockford Plaza Right Door | `-1922281023` | `new alt.Vector3(-156.439, -304.4294, 39.99308` |
| Ponsonbys Rockford Plaza Left Door | `-1922281023` | `new alt.Vector3(-157.1293, -306.4341, 39.99308` |
| Sub Urban Prosperity Street Promenade Door | `1780022985` | `new alt.Vector3(-1201.435, -776.8566, 17.99184` |
| Sub Urban Hawick Avenue Door | `1780022985` | `new alt.Vector3(127.8201, -211.8274, 55.22751` |
| Sub Urban Route 68 Door | `1780022985` | `new alt.Vector3(617.2458, 2751.022, 42.75777` |
| Sub Urban Chumash Plaza Door | `1780022985` | `new alt.Vector3(-3167.75, 1055.536, 21.53288` |
| Rob's Liquor Route 1 Main Enter Door | `-1212951353` | `new alt.Vector3(-2973.535, 390.1414, 15.18735` |
| Rob's Liquor Route 1 Personnal Door | `1173348778` | `new alt.Vector3(-2965.648, 386.7928, 15.18735` |
| Rob's Liquor Route 1 Back Door | `1173348778` | `new alt.Vector3(-2961.749, 390.2573, 15.19322` |
| Rob's Liquor Prosperity Street Main Enter Door | `-1212951353` | `new alt.Vector3(-1490.411, -383.8453, 40.30745` |
| Rob's Liquor Prosperity Street Personnal Door | `1173348778` | `new alt.Vector3(-1482.679, -380.153, 40.30745` |
| Rob's Liquor Prosperity Street Back Door | `1173348778` | `new alt.Vector3(-1482.693, -374.9365, 40.31332` |
| Rob's Liquor San Andreas Avenue Main Enter Door | `-1212951353` | `new alt.Vector3(-1226.894, -903.1218, 12.47039` |
| Rob's Liquor San Andreas Avenue Personnal Door | `1173348778` | `new alt.Vector3(-1224.755, -911.4182, 12.47039` |
| Rob's Liquor San Andreas Avenue Back Door | `1173348778` | `new alt.Vector3(-1219.633, -912.406, 12.47626` |
| Rob's Liquor El Rancho Boulevard Main Enter Door | `-1212951353` | `new alt.Vector3(1141.038, -980.3225, 46.55986` |
| Rob's Liquor El Rancho Boulevard Personnal Door | `1173348778` | `new alt.Vector3(1132.645, -978.6059, 46.55986` |
| Rob's Liquor El Rancho Boulevard Back Door | `1173348778` | `new alt.Vector3(1129.51, -982.7756, 46.56573` |
| Bob Mulét Barber Shop Right Door | `145369505` | `new alt.Vector3(-822.4442, -188.3924, 37.81895` |
| Bob Mulét Barber Shop Left Door | `-1663512092` | `new alt.Vector3(-823.2001, -187.0831, 37.81895` |
| Hair on Hawick Barber Shop Door | `-1844444717` | `new alt.Vector3(-29.86917, -148.1571, 57.22648` |
| O'Sheas Barber Shop Door | `-1844444717` | `new alt.Vector3(1932.952, 3725.154, 32.9944` |
| Premium Deluxe Motorsport Parking Right Door | `1417577297` | `new alt.Vector3(-37.33113, -1108.873, 26.7198` |
| Premium Deluxe Motorsport Parking Left Door | `2059227086` | `new alt.Vector3(-39.13366, -1108.218, 26.7198` |
| Premium Deluxe Motorsport Main Right Door | `1417577297` | `new alt.Vector3(-60.54582, -1094.749, 26.88872` |
| Premium Deluxe Motorsport Main Left Door | `2059227086` | `new alt.Vector3(-59.89302, -1092.952, 26.88362` |
| Premium Deluxe Motorsport Right Office Door | `-2051651622` | `new alt.Vector3(-33.80989, -1107.579, 26.57225` |
| Premium Deluxe Motorsport Left Office Door | `-2051651622` | `new alt.Vector3(-31.72353, -1101.847, 26.57225` |
| Franklin House Enter Door | `520341586` | `new alt.Vector3(-14.86892, -1441.182, 31.19323` |
| Franklin House Garage Door | `703855057` | `new alt.Vector3(-25.2784, -1431.061, 30.83955` |
| Vanilla Unicorn Main Enter Door | `-1116041313` | `new alt.Vector3(127.9552, -1298.503, 29.41962` |
| Vanilla Unicorn Back Enter Door | `668467214` | `new alt.Vector3(96.09197, -1284.854, 29.43878` |
| Vanilla Unicorn Office Door | `-626684119` | `new alt.Vector3(99.08321, -1293.701, 29.41868` |
| Vanilla Unicorn Dress Door | `-495720969` | `new alt.Vector3(113.9822, -1297.43, 29.41868` |
| Vanilla Unicorn Private Rooms Door | `-1881825907` | `new alt.Vector3(116.0046, -1294.692, 29.41947` |
| Bolingbroke Penitentiary Main Enter First Door | `741314661` | `new alt.Vector3(1844.998, 2597.482, 44.63626` |
| Bolingbroke Penitentiary Main Enter Second Door | `741314661` | `new alt.Vector3(1818.543, 2597.482, 44.60749` |
| Bolingbroke Penitentiary Main Enter Third Door | `741314661` | `new alt.Vector3(1806.939, 2616.975, 44.60093` |
| Mission Row Police Station Main Enter Right Door | `320433149` | `new alt.Vector3(434.7479, -983.2151, 30.83926` |
| Mission Row Police Station Main Enter Left Door | `-1215222675` | `new alt.Vector3(434.7479, -980.6184, 30.83926` |
| Mission Row Police Station Back Enter Right Door | `-2023754432` | `new alt.Vector3(469.9679, -1014.452, 26.53623` |
| Mission Row Police Station Back Enter Left Door | `-2023754432` | `new alt.Vector3(467.3716, -1014.452, 26.53623` |
| Mission Row Police Station Back To Cells Door | `-1033001619` | `new alt.Vector3(463.4782, -1003.538, 25.00599` |
| Mission Row Police Station Cell Door 1 | `631614199` | `new alt.Vector3(461.8065, -994.4086, 25.06443` |
| Mission Row Police Station Cell Door 2 | `631614199` | `new alt.Vector3(461.8065, -997.6583, 25.06443` |
| Mission Row Police Station Cell Door 3 | `631614199` | `new alt.Vector3(461.8065, -1001.302, 25.06443` |
| Mission Row Police Station Door To Cells Door | `631614199` | `new alt.Vector3(464.5701, -992.6641, 25.06443` |
| Mission Row Police Station Captan's Office Door | `-1320876379` | `new alt.Vector3(446.5728, -980.0106, 30.8393` |
| Mission Row Police Station Armory Double Door Right | `185711165` | `new alt.Vector3(450.1041, -984.0915, 30.8393` |
| Mission Row Police Station Armory Double Door Left | `185711165` | `new alt.Vector3(450.1041, -981.4915, 30.8393` |
| Mission Row Police Station Armory Secure Door | `749848321` | `new alt.Vector3(453.0793, -983.1895, 30.83926` |
| Mission Row Police Station Locker Rooms Door | `1557126584` | `new alt.Vector3(450.1041, -985.7384, 30.8393` |
| Mission Row Police Station Locker Room 1 Door | `-2023754432` | `new alt.Vector3(452.6248, -987.3626, 30.8393` |
| Mission Row Police Station Roof Access Door | `749848321` | `new alt.Vector3(461.2865, -985.3206, 30.83926` |
| Mission Row Police Station Roof Door | `-340230128` | `new alt.Vector3(464.3613, -984.678, 43.83443` |
| Mission Row Police Station Cell And Briefing Right Door | `185711165` | `new alt.Vector3(443.4078, -989.4454, 30.8393` |
| Mission Row Police Station Cell And Briefing Left Door | `185711165` | `new alt.Vector3(446.0079, -989.4454, 30.8393` |
| Mission Row Police Station Briefing Right Door | `-131296141` | `new alt.Vector3(443.0298, -991.941, 30.8393` |
| Mission Row Police Station Briefing Left Door | `-131296141` | `new alt.Vector3(443.0298, -994.5412, 30.8393` |
| Mission Row Police Station Back Gate Door | `-1603817716` | `new alt.Vector3(488.8923, -1011.67, 27.14583` |
57 changes: 57 additions & 0 deletions docs/useRebar/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Controllers pretty much make your gamemode tick by displaying a lot information
- Interactable Positions
- Menus
- Text Labels
- Doors
- etc.

---
Expand Down Expand Up @@ -686,3 +687,59 @@ async function showSomeMenu(player: alt.Player) {
console.log(result);
}
```

## Doors

Doors are objects that can be opened and closed. When they are locked, no one can bypass them.

### useDoor

```ts
import { useRebar } from '@Server/index.js';
import { DoorState } from '@Shared/types/index.js';

const Rebar = useRebar();
const doorController = Rebar.controllers.useDoor();

// Register a door
doorController.register({
uid: 'pacific-standard-bank-main-right-door',
state: DoorState.LOCKED,
model: 110411286,
pos: { x: 232.6054, y: 214.1584, z: 106.4049 },
permissions: ['admin', 'bankOperator'],
});


// Then we can add few interactions, that will be applied for all doors in the game:

const keybinder = Rebar.systems.useKeybinder();
// Toggle the door state when the player presses 'K'.
// If player has permission to toggle lock state of the door, it will toggle it.
keybinder.on(75, async (player: alt.Player) => {
const nearestDoor = await doorController.getNearestDoor(player);
if (!nearestDoor) return;
doorController.toggleLockState(player, nearestDoor.uid);
});


const { commands, message } = Rebar.systems.useMessenger();
// Register a command to lock/unlock the door for testing purposes.
// /lockdoor [uid]
commands.register({
name: 'lockdoor',
desc: '[uid] – Locks the door.',
callback: (player: alt.Player, doorUid: string) => {
doorController.forceSetLockState(doorUid, DoorState.LOCKED);
}
})

// /unlockdoor [uid]
commands.register({
name: 'unlockdoor',
desc: '[uid] – Unlocks the door.',
callback: (player: alt.Player, doorUid: string) => {
doorController.forceSetLockState(doorUid, DoorState.UNLOCKED);
}
})
```
59 changes: 51 additions & 8 deletions docs/useRebar/systems/useKeypress.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,59 @@

Keypress lets you handle key up and key down from server-side. It completely ignores if a `page` is open.

```ts
const keypress = Rebar.useKeypress();
## on

Each callback is called when the key is pressed down, and when the key is let go after being held down.

keypress.on(
118,
(player: alt.Player) => {
console.log('up!');
```ts
// Uses the 'F3' key
Rebar.systems.useKeypress().on(
114,
// on key up
(player) => {
alt.log('they let go of the key');
},
(player: alt.Player) => {
console.log('down!');
// on key down
(player) => {
alt.log('they pressed the key down');
},
);
```

## onHold

The `onHold` callback is invoked after `2s` on client-side.

Additionally, the callback time is verified server-side as well to ensure callback times are accurate and can't be invoked manually.

### Simple Usage

If you only want it to be invoked if the player holds a key long enough, then here's the short form.

```ts
// Uses the 'F4' key
Rebar.systems.useKeypress().onHold(115, {
hold: (player) => {
console.log('player held the key long enough');
},
});
```

### Advanced Usage

```ts
function handleHoldUp(player: alt.Player) {
alt.log('just let go of held key');
}

function handleHoldDown(player: alt.Player) {
alt.log('just pressed held key down');
}

function handleHoldKey(player: alt.Player) {
alt.log('player held the key for a long time');
}

// Uses the 'F4' key
Rebar.systems.useKeypress().onHold(115, { hold: handleHoldKey, up: handleHoldUp, down: handleHoldDown });
```
3 changes: 3 additions & 0 deletions docs/useRebar/systems/useServerConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ serverConfig.set('disableDriveBys', true);

// Disables ambient noises around the map
serverConfig.set('disableAmbientNoise', true);

// Disables the Weapon Radial Menu
serverConfig.set('disableWeaponRadial', true);
```
9 changes: 7 additions & 2 deletions docs/useRebar/useConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ This document provides an overview of the configuration management for a Rebar s
- Setting a default value if env variable was not defined.
- Basic type validation - number, boolean, string (by default).

## Usage
## Defaults

| Config Variable | Env Variable | Type | Default |
|-----------------|---------------|--------|---------------------------|
| `mongodb` | `MONGODB` | `string` | `mongodb://127.0.0.1:27017` |
| `database_name` | `DATABASE_NAME` | `string` | `Rebar` |

By default, `mongodb` is initialized automatically. It is required and has default value of local mongodb instance.
## Usage

Config defined as an interface, all methods covered with type hints, so you will see all variables and correct types on each method call.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "stuyk",
"type": "module",
"version": "51",
"version": "52",
"scripts": {
"dev": "nodemon --config ./nodemon-dev.json -x pnpm start",
"dev:linux": "nodemon --config ./nodemon-dev.json -x pnpm start:linux",
Expand Down
4 changes: 4 additions & 0 deletions src/main/client/system/serverConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ function tick() {
native.setPlayerCanUseCover(alt.Player.local, false);
}

if(config.disableWeaponRadial) {
native.disableControlAction(0, 37, true);
}

let finalRadarState = true;

if (config.hideMinimapOnFoot) {
Expand Down
Loading

0 comments on commit b431300

Please sign in to comment.