@nativewrappers/server 0.0.65 → 0.0.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +45 -0
  2. package/cfx/StateBagChangeHandler.d.ts +1 -3
  3. package/common/Command.d.ts +30 -0
  4. package/common/Convar.d.ts +13 -0
  5. package/common/GlobalData.d.ts +8 -0
  6. package/common/Kvp.d.ts +69 -0
  7. package/common/Resource.d.ts +14 -0
  8. package/common/decors/Events.d.ts +54 -0
  9. package/common/index.d.ts +8 -0
  10. package/common/net/NetworkedMap.d.ts +28 -0
  11. package/common/types.d.ts +5 -0
  12. package/common/utils/ClassTypes.d.ts +11 -0
  13. package/common/utils/Color.d.ts +14 -0
  14. package/common/utils/Maths.d.ts +4 -0
  15. package/common/utils/PointF.d.ts +12 -0
  16. package/common/utils/Quaternion.d.ts +10 -0
  17. package/common/utils/Vector.d.ts +429 -0
  18. package/common/utils/Vector2.d.ts +1 -0
  19. package/common/utils/Vector3.d.ts +1 -0
  20. package/common/utils/Vector4.d.ts +1 -0
  21. package/common/utils/cleanPlayerName.d.ts +6 -0
  22. package/common/utils/enumValues.d.ts +12 -0
  23. package/common/utils/getStringFromUInt8Array.d.ts +8 -0
  24. package/common/utils/getUInt32FromUint8Array.d.ts +8 -0
  25. package/common/utils/index.d.ts +12 -0
  26. package/entities/BaseEntity.d.ts +3 -3
  27. package/entities/Ped.d.ts +1 -1
  28. package/entities/Vehicle.d.ts +3 -3
  29. package/index.d.ts +1 -1
  30. package/index.js +1807 -7
  31. package/package.json +7 -5
  32. package/type/Anticheat.d.ts +1 -1
  33. package/utils/index.d.ts +1 -1
  34. package/Events.js +0 -79
  35. package/Game.js +0 -55
  36. package/cfx/StateBagChangeHandler.js +0 -1
  37. package/cfx/index.js +0 -1
  38. package/entities/BaseEntity.js +0 -135
  39. package/entities/Entity.js +0 -12
  40. package/entities/Ped.js +0 -81
  41. package/entities/Player.js +0 -136
  42. package/entities/Prop.js +0 -32
  43. package/entities/Vehicle.js +0 -175
  44. package/entities/index.js +0 -5
  45. package/enum/PopulationType.js +0 -14
  46. package/enum/VehicleLockStatus.js +0 -10
  47. package/enum/VehicleType.js +0 -11
  48. package/enum/eEntityType.js +0 -6
  49. package/enum/index.js +0 -4
  50. package/type/Anticheat.js +0 -1
  51. package/type/Hash.js +0 -1
  52. package/utils/index.js +0 -1
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@nativewrappers/server",
3
- "description": "Native wrappers and utilities for use with FxServer.",
3
+ "description": "Native wrappers and utilities for use with FXServer.",
4
+ "contributors": [
5
+ "Remco Troost <d0p3t>",
6
+ "Dillon Skaggs <AvarianKnight>",
7
+ "Linden <thelindat>"
8
+ ],
4
9
  "license": "MIT",
5
10
  "type": "module",
6
- "version": "0.0.65",
11
+ "version": "0.0.72",
7
12
  "repository": {
8
13
  "type": "git",
9
14
  "url": "https://github.com/nativewrappers/nativewrappers.git"
@@ -25,8 +30,5 @@
25
30
  ],
26
31
  "exports": {
27
32
  ".": "./index.js"
28
- },
29
- "dependencies": {
30
- "@nativewrappers/common": "0.0.65"
31
33
  }
32
34
  }
@@ -1,4 +1,4 @@
1
- import { Hash } from "./Hash";
1
+ import type { Hash } from "./Hash";
2
2
  export type AnticheatWeaponDamageEvent = {
3
3
  actionResultId: number;
4
4
  actionResultName: number;
package/utils/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { cleanPlayerName, Vector2, Vector3, Vector4, Maths, Quaternion, Color, Delay, enumValues, getStringFromUInt8Array, getUInt32FromUint8Array, } from "../../common/utils/index";
1
+ export { cleanPlayerName, Vector2, Vector3, Vector4, Maths, Quaternion, Color, Delay, enumValues, getStringFromUInt8Array, getUInt32FromUint8Array, } from "../common/utils/index";
package/Events.js DELETED
@@ -1,79 +0,0 @@
1
- import { Ped, Prop, Vehicle, Entity } from "./entities";
2
- import { Player } from "./entities/Player";
3
- import { ClassTypes } from "../common/utils/ClassTypes";
4
- import { Vector2, Vector3, Vector4 } from "./utils";
5
- const getClassFromArguments = (...args) => {
6
- const newArgs = [];
7
- for (const arg of args) {
8
- if (!arg.type) {
9
- newArgs.push(arg);
10
- continue;
11
- }
12
- switch (arg.type) {
13
- case ClassTypes.Vector2: {
14
- newArgs.push(Vector2.fromObject(arg));
15
- continue;
16
- }
17
- case ClassTypes.Vector3: {
18
- newArgs.push(Vector3.fromObject(arg));
19
- continue;
20
- }
21
- case ClassTypes.Vector4: {
22
- newArgs.push(Vector4.fromObject(arg));
23
- continue;
24
- }
25
- case ClassTypes.Ped: {
26
- newArgs.push(Ped.fromNetworkId(arg.handle));
27
- continue;
28
- }
29
- case ClassTypes.Player: {
30
- newArgs.push(new Player(arg.source));
31
- continue;
32
- }
33
- case ClassTypes.Prop: {
34
- newArgs.push(Prop.fromNetworkId(arg.handle));
35
- continue;
36
- }
37
- case ClassTypes.Vehicle: {
38
- newArgs.push(Vehicle.fromNetworkId(arg.netId));
39
- continue;
40
- }
41
- case ClassTypes.Entity: {
42
- newArgs.push(Entity.fromNetworkId(arg.netId));
43
- continue;
44
- }
45
- default: {
46
- newArgs.push(arg);
47
- }
48
- }
49
- }
50
- return newArgs;
51
- };
52
- export class Events {
53
- static cancel() {
54
- CancelEvent();
55
- }
56
- static wasCanceled() {
57
- return WasEventCanceled();
58
- }
59
- static get InvokingResource() {
60
- return GetInvokingResource();
61
- }
62
- /**
63
- * An onNet wrapper that properly converts the type into the correct type
64
- */
65
- static onNet = (eventName, event) => {
66
- onNet(eventName, (...args) => {
67
- const ply = new Player(source);
68
- event(ply, ...getClassFromArguments(...args));
69
- });
70
- };
71
- /**
72
- * An on wrapper that properly converts the classes
73
- */
74
- static on = (eventName, event) => {
75
- on(eventName, (...args) => {
76
- event(...getClassFromArguments(...args));
77
- });
78
- };
79
- }
package/Game.js DELETED
@@ -1,55 +0,0 @@
1
- import { Player } from "./entities/Player";
2
- export class Game {
3
- // A map containing generated hashes.
4
- static hashCache = new Map();
5
- /**
6
- * Calculate the Jenkins One At A Time (joaat) has from the given string.
7
- *
8
- * @param input The input string to calculate the hash
9
- */
10
- static generateHash(input) {
11
- if (typeof input === "undefined") {
12
- return 0;
13
- }
14
- const _hash = this.hashCache.get(input);
15
- if (_hash)
16
- return _hash;
17
- const hash = GetHashKey(input);
18
- this.hashCache.set(input, hash);
19
- return hash;
20
- }
21
- /**
22
- * Gets how many milliseconds the game has been open this session
23
- */
24
- static get GameTime() {
25
- return GetGameTimer();
26
- }
27
- static get GameBuild() {
28
- return GetGameBuildNumber();
29
- }
30
- static get GameName() {
31
- return GetGameName();
32
- }
33
- static registerCommand(name,
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- handler, restricted = false) {
36
- RegisterCommand(name,
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- (source, args) => {
39
- const player = new Player(parseInt(source));
40
- handler(player, args);
41
- }, restricted);
42
- }
43
- static get RegisteredCommands() {
44
- return GetRegisteredCommands();
45
- }
46
- /**
47
- * Get an iterable list of players currently on the server.
48
- * @returns Iterable list of Player objects.
49
- */
50
- static *PlayerList() {
51
- for (const id of getPlayers()) {
52
- yield new Player(id);
53
- }
54
- }
55
- }
@@ -1 +0,0 @@
1
- export {};
package/cfx/index.js DELETED
@@ -1 +0,0 @@
1
- export default { Entity, Player };
@@ -1,135 +0,0 @@
1
- import cfx from "../cfx";
2
- import { ClassTypes } from "../../common/utils/ClassTypes";
3
- import { Vector4 } from "../utils";
4
- import { Vector3 } from "../utils";
5
- export class BaseEntity {
6
- handle;
7
- type = ClassTypes.Entity;
8
- constructor(handle) {
9
- this.handle = handle;
10
- }
11
- // Replaces the current handle for the entity used on, this hsould be used sparringly, mainly
12
- // in situations where you're going to reuse an entity over and over and don't want to make a
13
- // new entity every time.
14
- //
15
- // **WARNING**: This does no checks, if you provide it an invalid entity it will use it
16
- //
17
- // ```ts
18
- // const REUSABLE_ENTITY = new Entity(entityHandle);
19
- //
20
- // onNet("entityHandler", (entNetId: number) => {
21
- // // if no net entity we should ignore
22
- // const entId = NetworkGetEntityFromNetworkId(entNetId);
23
- // if (entId === 0) return;
24
- //
25
- // // Reuse our entity so we don't have to initialize a new one
26
- // REUSABLE_ENTITY.replaceHandle(entId);
27
- // // Do something with REUSABLE_ENTITY entity
28
- // })
29
- // ```
30
- replaceHandle(newHandle) {
31
- this.handle = newHandle;
32
- }
33
- static fromNetworkId(networkId) {
34
- const ent = NetworkGetEntityFromNetworkId(networkId);
35
- if (ent === 0)
36
- return null;
37
- return new BaseEntity(ent);
38
- }
39
- static fromStateBagName(stateBagName) {
40
- const ent = GetEntityFromStateBagName(stateBagName);
41
- if (ent === 0)
42
- return null;
43
- return new BaseEntity(ent);
44
- }
45
- get State() {
46
- return cfx.Entity(this.handle).state;
47
- }
48
- get Handle() {
49
- return this.handle;
50
- }
51
- get Owner() {
52
- return NetworkGetEntityOwner(this.handle);
53
- }
54
- get FirstOwner() {
55
- return NetworkGetFirstEntityOwner(this.handle);
56
- }
57
- get Exists() {
58
- return this.handle !== 0 && DoesEntityExist(this.handle);
59
- }
60
- /**
61
- * @returns the entity that the calling entity is attached to, or null if
62
- * there is none
63
- */
64
- get AttachedTo() {
65
- const ent = GetEntityAttachedTo(this.handle);
66
- if (ent === 0)
67
- return null;
68
- return new BaseEntity(ent);
69
- }
70
- get Position() {
71
- return Vector3.fromArray(GetEntityCoords(this.handle));
72
- }
73
- get Heading() {
74
- return GetEntityHeading(this.handle);
75
- }
76
- get PositionAndHeading() {
77
- return Vector4.fromArray([
78
- ...GetEntityCoords(this.handle),
79
- GetEntityHeading(this.handle),
80
- ]);
81
- }
82
- get Health() {
83
- return GetEntityHealth(this.handle);
84
- }
85
- get MaxHealth() {
86
- return GetEntityMaxHealth(this.handle);
87
- }
88
- get Model() {
89
- return GetEntityModel(this.handle);
90
- }
91
- get PopulationType() {
92
- return GetEntityPopulationType(this.handle);
93
- }
94
- get Rotation() {
95
- return Vector3.fromArray(GetEntityRotation(this.handle));
96
- }
97
- get RotationVelocity() {
98
- return Vector3.fromArray(GetEntityRotationVelocity(this.handle));
99
- }
100
- get RoutingBucket() {
101
- return GetEntityRoutingBucket(this.handle);
102
- }
103
- /**
104
- * @returns The script that made the entity
105
- */
106
- get Script() {
107
- return GetEntityScript(this.handle);
108
- }
109
- get Speed() {
110
- return GetEntitySpeed(this.handle);
111
- }
112
- get Type() {
113
- return GetEntityType(this.handle);
114
- }
115
- /**
116
- * @returns the entitys velocity, if the entity is a ped it will return Vector3(0, 0, 0)
117
- */
118
- get Velocity() {
119
- return Vector3.fromArray(GetEntityVelocity(this.handle));
120
- }
121
- get IsVisible() {
122
- return IsEntityVisible(this.handle);
123
- }
124
- get NetworkId() {
125
- return NetworkGetNetworkIdFromEntity(this.handle);
126
- }
127
- get IsNoLongerNeeded() {
128
- return HasEntityBeenMarkedAsNoLongerNeeded(this.handle);
129
- }
130
- delete() {
131
- if (this.Exists) {
132
- DeleteEntity(this.handle);
133
- }
134
- }
135
- }
@@ -1,12 +0,0 @@
1
- import { BaseEntity } from "./BaseEntity";
2
- export class Entity extends BaseEntity {
3
- constructor(handle) {
4
- super(handle);
5
- }
6
- static fromNetworkId(netId) {
7
- return new Entity(NetworkGetEntityFromNetworkId(netId));
8
- }
9
- static fromHandle(handle) {
10
- return new Entity(handle);
11
- }
12
- }
package/entities/Ped.js DELETED
@@ -1,81 +0,0 @@
1
- import { ClassTypes } from "../../common/utils/ClassTypes";
2
- import { BaseEntity } from "./BaseEntity";
3
- import { Vehicle } from "./Vehicle";
4
- export class Ped extends BaseEntity {
5
- type = ClassTypes.Ped;
6
- constructor(handle) {
7
- super(handle);
8
- }
9
- /**
10
- * Get an interable list of peds currently on the server
11
- * @returns Iterable list of Peds.
12
- */
13
- static *AllPeds() {
14
- for (const pedId of GetAllPeds()) {
15
- yield new Ped(pedId);
16
- }
17
- }
18
- static fromNetworkId(netId) {
19
- const ent = NetworkGetEntityFromNetworkId(netId);
20
- if (ent === 0)
21
- return null;
22
- return new Ped(ent);
23
- }
24
- static fromStateBagName(stateBagName) {
25
- const handle = GetEntityFromStateBagName(stateBagName);
26
- if (handle === 0)
27
- return null;
28
- return new Ped(handle);
29
- }
30
- static fromSource(source) {
31
- return new Ped(GetPlayerPed(source));
32
- }
33
- get Armour() {
34
- return GetPedArmour(this.handle);
35
- }
36
- get CauseOfDeath() {
37
- return GetPedCauseOfDeath(this.handle);
38
- }
39
- get DesiredHeading() {
40
- return GetPedDesiredHeading(this.handle);
41
- }
42
- get MaxHealth() {
43
- return GetPedMaxHealth(this.handle);
44
- }
45
- get TaskCommand() {
46
- return GetPedScriptTaskCommand(this.handle);
47
- }
48
- get TaskStage() {
49
- return GetPedScriptTaskStage(this.handle);
50
- }
51
- get LastSourceOfDamage() {
52
- return GetPedSourceOfDamage(this.handle);
53
- }
54
- get DeathCause() {
55
- return GetPedCauseOfDeath(this.handle);
56
- }
57
- get Weapon() {
58
- return GetSelectedPedWeapon(this.handle);
59
- }
60
- /**
61
- * @returns the current vehicle the ped is in, or null if it doesn't exist
62
- */
63
- get CurrentVehicle() {
64
- const vehicle = GetVehiclePedIsIn(this.handle, false);
65
- if (vehicle === 0)
66
- return null;
67
- return new Vehicle(vehicle);
68
- }
69
- get LastVehicle() {
70
- const vehicle = GetVehiclePedIsIn(this.handle, false);
71
- if (vehicle === 0)
72
- return null;
73
- return new Vehicle(GetVehiclePedIsIn(this.handle, true));
74
- }
75
- get IsPlayer() {
76
- return IsPedAPlayer(this.handle);
77
- }
78
- getSpecificTaskType(index) {
79
- return GetPedSpecificTaskType(this.handle, index);
80
- }
81
- }
@@ -1,136 +0,0 @@
1
- import cfx from "../cfx";
2
- import { ClassTypes } from "../../common/utils/ClassTypes";
3
- import { cleanPlayerName } from "../utils";
4
- import { Vector3 } from "../utils";
5
- import { Ped } from "./Ped";
6
- export class Player {
7
- source;
8
- type = ClassTypes.Player;
9
- constructor(source) {
10
- this.source = source;
11
- }
12
- /**
13
- * Get an interable list of players currently on the server
14
- * @returns Iterable list of Players.
15
- */
16
- static *AllPlayers() {
17
- const num = GetNumPlayerIndices();
18
- for (let i = 0; i < num; i++) {
19
- yield new Player(parseInt(GetPlayerFromIndex(i)));
20
- }
21
- }
22
- get Exists() {
23
- return this.source !== 0;
24
- }
25
- get Source() {
26
- return this.source;
27
- }
28
- get State() {
29
- return cfx.Player(this.source).state;
30
- }
31
- /**
32
- * Returns the player source casted as a string
33
- */
34
- get Src() {
35
- return this.source;
36
- }
37
- get Ped() {
38
- return new Ped(GetPlayerPed(this.Src));
39
- }
40
- get Tokens() {
41
- return getPlayerTokens(this.source);
42
- }
43
- get Identifiers() {
44
- return getPlayerIdentifiers(this.source);
45
- }
46
- get Endpoint() {
47
- return GetPlayerEndpoint(this.Src);
48
- }
49
- get CamerRotation() {
50
- return Vector3.fromArray(GetPlayerCameraRotation(this.Src));
51
- }
52
- /**
53
- * Returns the time since the last player UDP message
54
- */
55
- get LastMessage() {
56
- return GetPlayerLastMsg(this.Src);
57
- }
58
- get MaxArmour() {
59
- return GetPlayerMaxArmour(this.Src);
60
- }
61
- get MaxHealth() {
62
- return GetPlayerMaxHealth(this.Src);
63
- }
64
- get MeleeModifier() {
65
- return GetPlayerMeleeWeaponDamageModifier(this.Src);
66
- }
67
- /**
68
- * @returns the players name
69
- */
70
- get Name() {
71
- return GetPlayerName(this.Src);
72
- }
73
- /**
74
- * @returns the players name with any color code unicode, etc removed, this can lead to there being no name at all
75
- */
76
- filteredName() {
77
- return cleanPlayerName(this.Name);
78
- }
79
- /**
80
- * @returns the players round trip ping
81
- */
82
- get Ping() {
83
- return GetPlayerPing(this.Src);
84
- }
85
- /**
86
- * @returns the current routhing bucket the player is in, default is 0
87
- */
88
- get RoutingBucket() {
89
- return GetPlayerRoutingBucket(this.Src);
90
- }
91
- get Team() {
92
- return GetPlayerTeam(this.Src);
93
- }
94
- get WantedPosition() {
95
- return Vector3.fromArray(GetPlayerWantedCentrePosition(this.Src));
96
- }
97
- get WantedLevel() {
98
- return GetPlayerWantedLevel(this.Src);
99
- }
100
- get IsEvadingWanted() {
101
- return IsPlayerEvadingWantedLevel(this.Src);
102
- }
103
- get WeaponDamageModifier() {
104
- return GetPlayerWeaponDamageModifier(this.Src);
105
- }
106
- get WeaponDefenseModifier() {
107
- return GetPlayerWeaponDefenseModifier(this.Src);
108
- }
109
- get WeaponDefenseModifier2() {
110
- return GetPlayerWeaponDefenseModifier_2(this.Src);
111
- }
112
- get AirDragMultiplier() {
113
- return GetAirDragMultiplierForPlayersVehicle(this.Src);
114
- }
115
- get IsUsingSuperJump() {
116
- return IsPlayerUsingSuperJump(this.Src);
117
- }
118
- get IsMuted() {
119
- return MumbleIsPlayerMuted(this.source);
120
- }
121
- set IsMuted(isMuted) {
122
- MumbleSetPlayerMuted(this.source, isMuted);
123
- }
124
- isAceAllowed(object) {
125
- return IsPlayerAceAllowed(this.Src, object);
126
- }
127
- timeInPersuit(lastPursuit = false) {
128
- return GetPlayerTimeInPursuit(this.Src, lastPursuit);
129
- }
130
- drop(reason = "No reason specified") {
131
- DropPlayer(this.Src, reason);
132
- }
133
- emit(eventName, ...args) {
134
- TriggerClientEvent(eventName, this.source, ...args);
135
- }
136
- }
package/entities/Prop.js DELETED
@@ -1,32 +0,0 @@
1
- import { ClassTypes } from "../../common/utils/ClassTypes";
2
- import { BaseEntity } from "./BaseEntity";
3
- export class Prop extends BaseEntity {
4
- type = ClassTypes.Prop;
5
- constructor(handle) {
6
- super(handle);
7
- }
8
- /**
9
- * Get an interable list of props currently on the server
10
- * @returns Iterable list of Props.
11
- */
12
- static *AllProps() {
13
- for (const prop of GetAllObjects()) {
14
- yield new Prop(prop);
15
- }
16
- }
17
- static fromNetworkId(networkId) {
18
- const ent = NetworkGetEntityFromNetworkId(networkId);
19
- if (ent === 0)
20
- return null;
21
- return new Prop(ent);
22
- }
23
- static fromStateBagName(stateBagName) {
24
- const ent = GetEntityFromStateBagName(stateBagName);
25
- if (ent === 0)
26
- return null;
27
- return new Prop(ent);
28
- }
29
- static fromHandle(handle) {
30
- return new Prop(handle);
31
- }
32
- }