@nativewrappers/server 0.0.78 → 0.0.79
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.
- package/index.d.ts +1 -2
- package/index.js +408 -130
- package/package.json +1 -1
- package/Events.d.ts +0 -16
package/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from "./utils";
|
|
2
|
-
export * from "./Events";
|
|
3
2
|
export * from "./Game";
|
|
4
|
-
export
|
|
3
|
+
export * from "./common/index";
|
|
5
4
|
export * from "./enum/index";
|
|
6
5
|
export * from "./utils/index";
|
|
7
6
|
export * from "./entities/index";
|
package/index.js
CHANGED
|
@@ -584,6 +584,21 @@ var Vector4 = class _Vector4 extends Vector {
|
|
|
584
584
|
}
|
|
585
585
|
};
|
|
586
586
|
|
|
587
|
+
// src/common/utils/PointF.ts
|
|
588
|
+
var PointF = class _PointF {
|
|
589
|
+
constructor(x, y, z) {
|
|
590
|
+
this.x = x;
|
|
591
|
+
this.y = y;
|
|
592
|
+
this.z = z;
|
|
593
|
+
}
|
|
594
|
+
static {
|
|
595
|
+
__name(this, "PointF");
|
|
596
|
+
}
|
|
597
|
+
static empty() {
|
|
598
|
+
return new _PointF(0, 0, 0);
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
|
|
587
602
|
// src/common/utils/Maths.ts
|
|
588
603
|
var Maths = class {
|
|
589
604
|
static {
|
|
@@ -836,22 +851,6 @@ var BaseEntity = class _BaseEntity {
|
|
|
836
851
|
}
|
|
837
852
|
};
|
|
838
853
|
|
|
839
|
-
// src/server/entities/Entity.ts
|
|
840
|
-
var Entity2 = class _Entity extends BaseEntity {
|
|
841
|
-
static {
|
|
842
|
-
__name(this, "Entity");
|
|
843
|
-
}
|
|
844
|
-
constructor(handle) {
|
|
845
|
-
super(handle);
|
|
846
|
-
}
|
|
847
|
-
static fromNetworkId(netId) {
|
|
848
|
-
return new _Entity(NetworkGetEntityFromNetworkId(netId));
|
|
849
|
-
}
|
|
850
|
-
static fromHandle(handle) {
|
|
851
|
-
return new _Entity(handle);
|
|
852
|
-
}
|
|
853
|
-
};
|
|
854
|
-
|
|
855
854
|
// src/server/entities/Vehicle.ts
|
|
856
855
|
var Vehicle = class _Vehicle extends BaseEntity {
|
|
857
856
|
static {
|
|
@@ -1241,119 +1240,6 @@ var Player2 = class _Player {
|
|
|
1241
1240
|
}
|
|
1242
1241
|
};
|
|
1243
1242
|
|
|
1244
|
-
// src/server/entities/Prop.ts
|
|
1245
|
-
var Prop = class _Prop extends BaseEntity {
|
|
1246
|
-
static {
|
|
1247
|
-
__name(this, "Prop");
|
|
1248
|
-
}
|
|
1249
|
-
type = 1 /* Prop */;
|
|
1250
|
-
constructor(handle) {
|
|
1251
|
-
super(handle);
|
|
1252
|
-
}
|
|
1253
|
-
/**
|
|
1254
|
-
* Get an interable list of props currently on the server
|
|
1255
|
-
* @returns Iterable list of Props.
|
|
1256
|
-
*/
|
|
1257
|
-
static *AllProps() {
|
|
1258
|
-
for (const prop of GetAllObjects()) {
|
|
1259
|
-
yield new _Prop(prop);
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
static fromNetworkId(networkId) {
|
|
1263
|
-
const ent = NetworkGetEntityFromNetworkId(networkId);
|
|
1264
|
-
if (ent === 0) return null;
|
|
1265
|
-
return new _Prop(ent);
|
|
1266
|
-
}
|
|
1267
|
-
static fromStateBagName(stateBagName) {
|
|
1268
|
-
const ent = GetEntityFromStateBagName(stateBagName);
|
|
1269
|
-
if (ent === 0) return null;
|
|
1270
|
-
return new _Prop(ent);
|
|
1271
|
-
}
|
|
1272
|
-
static fromHandle(handle) {
|
|
1273
|
-
return new _Prop(handle);
|
|
1274
|
-
}
|
|
1275
|
-
};
|
|
1276
|
-
|
|
1277
|
-
// src/server/Events.ts
|
|
1278
|
-
var getClassFromArguments = /* @__PURE__ */ __name((...args) => {
|
|
1279
|
-
const newArgs = [];
|
|
1280
|
-
for (const arg of args) {
|
|
1281
|
-
if (!arg.type) {
|
|
1282
|
-
newArgs.push(arg);
|
|
1283
|
-
continue;
|
|
1284
|
-
}
|
|
1285
|
-
switch (arg.type) {
|
|
1286
|
-
case 5 /* Vector2 */: {
|
|
1287
|
-
newArgs.push(Vector2.fromObject(arg));
|
|
1288
|
-
continue;
|
|
1289
|
-
}
|
|
1290
|
-
case 6 /* Vector3 */: {
|
|
1291
|
-
newArgs.push(Vector3.fromObject(arg));
|
|
1292
|
-
continue;
|
|
1293
|
-
}
|
|
1294
|
-
case 7 /* Vector4 */: {
|
|
1295
|
-
newArgs.push(Vector4.fromObject(arg));
|
|
1296
|
-
continue;
|
|
1297
|
-
}
|
|
1298
|
-
case 0 /* Ped */: {
|
|
1299
|
-
newArgs.push(Ped.fromNetworkId(arg.handle));
|
|
1300
|
-
continue;
|
|
1301
|
-
}
|
|
1302
|
-
case 4 /* Player */: {
|
|
1303
|
-
newArgs.push(new Player2(arg.source));
|
|
1304
|
-
continue;
|
|
1305
|
-
}
|
|
1306
|
-
case 1 /* Prop */: {
|
|
1307
|
-
newArgs.push(Prop.fromNetworkId(arg.handle));
|
|
1308
|
-
continue;
|
|
1309
|
-
}
|
|
1310
|
-
case 2 /* Vehicle */: {
|
|
1311
|
-
newArgs.push(Vehicle.fromNetworkId(arg.netId));
|
|
1312
|
-
continue;
|
|
1313
|
-
}
|
|
1314
|
-
case 3 /* Entity */: {
|
|
1315
|
-
newArgs.push(Entity2.fromNetworkId(arg.netId));
|
|
1316
|
-
continue;
|
|
1317
|
-
}
|
|
1318
|
-
default: {
|
|
1319
|
-
newArgs.push(arg);
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
return newArgs;
|
|
1324
|
-
}, "getClassFromArguments");
|
|
1325
|
-
var Events = class {
|
|
1326
|
-
static {
|
|
1327
|
-
__name(this, "Events");
|
|
1328
|
-
}
|
|
1329
|
-
static cancel() {
|
|
1330
|
-
CancelEvent();
|
|
1331
|
-
}
|
|
1332
|
-
static wasCanceled() {
|
|
1333
|
-
return WasEventCanceled();
|
|
1334
|
-
}
|
|
1335
|
-
static get InvokingResource() {
|
|
1336
|
-
return GetInvokingResource();
|
|
1337
|
-
}
|
|
1338
|
-
/**
|
|
1339
|
-
* An onNet wrapper that properly converts the type into the correct type
|
|
1340
|
-
*/
|
|
1341
|
-
static onNet = /* @__PURE__ */ __name((eventName, event) => {
|
|
1342
|
-
onNet(eventName, (...args) => {
|
|
1343
|
-
const ply = new Player2(source);
|
|
1344
|
-
event(ply, ...getClassFromArguments(...args));
|
|
1345
|
-
});
|
|
1346
|
-
}, "onNet");
|
|
1347
|
-
/**
|
|
1348
|
-
* An on wrapper that properly converts the classes
|
|
1349
|
-
*/
|
|
1350
|
-
static on = /* @__PURE__ */ __name((eventName, event) => {
|
|
1351
|
-
on(eventName, (...args) => {
|
|
1352
|
-
event(...getClassFromArguments(...args));
|
|
1353
|
-
});
|
|
1354
|
-
}, "on");
|
|
1355
|
-
};
|
|
1356
|
-
|
|
1357
1243
|
// src/server/Game.ts
|
|
1358
1244
|
var Game = class {
|
|
1359
1245
|
static {
|
|
@@ -1450,6 +1336,340 @@ var NetworkedMapEventManager = class {
|
|
|
1450
1336
|
}
|
|
1451
1337
|
};
|
|
1452
1338
|
var netManager = new NetworkedMapEventManager();
|
|
1339
|
+
var NetworkedMap = class extends Map {
|
|
1340
|
+
static {
|
|
1341
|
+
__name(this, "NetworkedMap");
|
|
1342
|
+
}
|
|
1343
|
+
#syncName;
|
|
1344
|
+
#queuedChanges = [];
|
|
1345
|
+
#changeListeners = /* @__PURE__ */ new Map();
|
|
1346
|
+
#subscribers = /* @__PURE__ */ new Set();
|
|
1347
|
+
constructor(syncName, initialValue) {
|
|
1348
|
+
super(initialValue);
|
|
1349
|
+
this.#syncName = syncName;
|
|
1350
|
+
GlobalData.NetworkedTicks.push(this);
|
|
1351
|
+
netManager.addNetworkedMap(this);
|
|
1352
|
+
$SERVER: {
|
|
1353
|
+
if (!GlobalData.NetworkTick && GlobalData.IS_SERVER) {
|
|
1354
|
+
GlobalData.NetworkTick = setTick(() => {
|
|
1355
|
+
for (const networkedThis of GlobalData.NetworkedTicks) {
|
|
1356
|
+
networkedThis.networkTick();
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
get SyncName() {
|
|
1363
|
+
return this.#syncName;
|
|
1364
|
+
}
|
|
1365
|
+
// handles removing the player from the map whenever they're dropped
|
|
1366
|
+
onPlayerDropped() {
|
|
1367
|
+
this.removeSubscriber(source);
|
|
1368
|
+
}
|
|
1369
|
+
/*
|
|
1370
|
+
* Resyncs the entire map to the client, useful for if there's a mismatch in the clients map (when multiple players change things, in cases like inventories)
|
|
1371
|
+
*
|
|
1372
|
+
* NOTE: This doesn't check that the player is already subscribed to the map, you should do your own due-diligence to only call this for players already subscribed
|
|
1373
|
+
*/
|
|
1374
|
+
resync(source2) {
|
|
1375
|
+
const packed_data = msgpack_pack([this.#syncName, [[4 /* Init */, this.size === 0 ? [] : Array.from(this)]]]);
|
|
1376
|
+
TriggerClientEventInternal(
|
|
1377
|
+
`${GlobalData.CurrentResource}:syncChanges`,
|
|
1378
|
+
source2,
|
|
1379
|
+
packed_data,
|
|
1380
|
+
packed_data.length
|
|
1381
|
+
);
|
|
1382
|
+
}
|
|
1383
|
+
/*
|
|
1384
|
+
* Adds a new subscriber to the map
|
|
1385
|
+
*/
|
|
1386
|
+
addSubscriber(source2) {
|
|
1387
|
+
this.#subscribers.add(source2);
|
|
1388
|
+
this.resync(source2);
|
|
1389
|
+
}
|
|
1390
|
+
removeSubscriber(sub) {
|
|
1391
|
+
return this.#subscribers.delete(sub);
|
|
1392
|
+
}
|
|
1393
|
+
hasSubscriber(sub) {
|
|
1394
|
+
return this.#subscribers.has(sub);
|
|
1395
|
+
}
|
|
1396
|
+
subscriberCount() {
|
|
1397
|
+
return this.#subscribers.size;
|
|
1398
|
+
}
|
|
1399
|
+
handleSync(data) {
|
|
1400
|
+
for (const [change_type, key, value, possibly_undefined_subvalue] of data) {
|
|
1401
|
+
switch (change_type) {
|
|
1402
|
+
case 1 /* Add */: {
|
|
1403
|
+
this.set(key, value);
|
|
1404
|
+
continue;
|
|
1405
|
+
}
|
|
1406
|
+
case 2 /* Remove */: {
|
|
1407
|
+
super.delete(key);
|
|
1408
|
+
continue;
|
|
1409
|
+
}
|
|
1410
|
+
case 3 /* Reset */: {
|
|
1411
|
+
super.clear();
|
|
1412
|
+
continue;
|
|
1413
|
+
}
|
|
1414
|
+
case 4 /* Init */: {
|
|
1415
|
+
super.clear();
|
|
1416
|
+
const key_value = key;
|
|
1417
|
+
for (const [k, v] of key_value) {
|
|
1418
|
+
this.set(k, v);
|
|
1419
|
+
}
|
|
1420
|
+
continue;
|
|
1421
|
+
}
|
|
1422
|
+
case 0 /* SubValueChanged */: {
|
|
1423
|
+
const data2 = this.get(key);
|
|
1424
|
+
data2[value] = possibly_undefined_subvalue;
|
|
1425
|
+
continue;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
/*
|
|
1431
|
+
* Listens for the change on the specified key, it will get the resulting
|
|
1432
|
+
* value on the change
|
|
1433
|
+
*/
|
|
1434
|
+
listenForChange(key, fn) {
|
|
1435
|
+
const listener = this.#changeListeners.get(key);
|
|
1436
|
+
listener ? listener.push(fn) : this.#changeListeners.set(key, [fn]);
|
|
1437
|
+
}
|
|
1438
|
+
#triggerEventForSubscribers(data) {
|
|
1439
|
+
const packed_data = msgpack_pack([this.#syncName, data]);
|
|
1440
|
+
for (const sub of this.#subscribers) {
|
|
1441
|
+
TriggerClientEventInternal(
|
|
1442
|
+
`${GlobalData.CurrentResource}:syncChanges`,
|
|
1443
|
+
sub,
|
|
1444
|
+
packed_data,
|
|
1445
|
+
packed_data.length
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
#pushChangeForListener(key, value) {
|
|
1450
|
+
const listener = this.#changeListeners.get(key);
|
|
1451
|
+
if (!listener) return;
|
|
1452
|
+
for (const ln of listener) {
|
|
1453
|
+
ln(value);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
set(key, value) {
|
|
1457
|
+
let v = value;
|
|
1458
|
+
if (value instanceof Object) {
|
|
1459
|
+
const curMap = this;
|
|
1460
|
+
const objectChangeHandler = {
|
|
1461
|
+
get(target, prop, reciever) {
|
|
1462
|
+
return Reflect.get(target, prop, reciever);
|
|
1463
|
+
},
|
|
1464
|
+
set(target, p, newValue, receiver) {
|
|
1465
|
+
const success = Reflect.set(target, p, newValue, receiver);
|
|
1466
|
+
if (success) {
|
|
1467
|
+
curMap.#pushChangeForListener(key, target);
|
|
1468
|
+
$SERVER: {
|
|
1469
|
+
curMap.#queuedChanges.push([0 /* SubValueChanged */, key, p, newValue]);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
return success;
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
v = new Proxy(v, objectChangeHandler);
|
|
1476
|
+
}
|
|
1477
|
+
super.set(key, v);
|
|
1478
|
+
this.#pushChangeForListener(key, v);
|
|
1479
|
+
$SERVER: {
|
|
1480
|
+
this.#queuedChanges.push([1 /* Add */, key, v]);
|
|
1481
|
+
}
|
|
1482
|
+
return this;
|
|
1483
|
+
}
|
|
1484
|
+
/*
|
|
1485
|
+
* Resets the map to its default state
|
|
1486
|
+
*/
|
|
1487
|
+
clear() {
|
|
1488
|
+
this.#queuedChanges = [];
|
|
1489
|
+
this.#queuedChanges.push([3 /* Reset */]);
|
|
1490
|
+
super.clear();
|
|
1491
|
+
}
|
|
1492
|
+
delete(key) {
|
|
1493
|
+
this.#queuedChanges.push([2 /* Remove */, key]);
|
|
1494
|
+
return super.delete(key);
|
|
1495
|
+
}
|
|
1496
|
+
networkTick() {
|
|
1497
|
+
if (this.#queuedChanges.length !== 0) {
|
|
1498
|
+
this.#triggerEventForSubscribers(this.#queuedChanges);
|
|
1499
|
+
this.#queuedChanges = [];
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
[Symbol.dispose]() {
|
|
1503
|
+
this.#subscribers.clear();
|
|
1504
|
+
this.#changeListeners.clear();
|
|
1505
|
+
this.#queuedChanges = [];
|
|
1506
|
+
netManager.removeNetworkedMap(this.#syncName);
|
|
1507
|
+
GlobalData.NetworkedTicks.filter((v) => v !== this);
|
|
1508
|
+
}
|
|
1509
|
+
/**
|
|
1510
|
+
* Unregisters from the tick handler and removes the event listener
|
|
1511
|
+
*/
|
|
1512
|
+
dispose() {
|
|
1513
|
+
this[Symbol.dispose]();
|
|
1514
|
+
}
|
|
1515
|
+
get [Symbol.toStringTag]() {
|
|
1516
|
+
return "NetworkedMap";
|
|
1517
|
+
}
|
|
1518
|
+
};
|
|
1519
|
+
|
|
1520
|
+
// src/common/decors/Events.ts
|
|
1521
|
+
var ConVarType = /* @__PURE__ */ ((ConVarType2) => {
|
|
1522
|
+
ConVarType2[ConVarType2["String"] = 0] = "String";
|
|
1523
|
+
ConVarType2[ConVarType2["Integer"] = 1] = "Integer";
|
|
1524
|
+
ConVarType2[ConVarType2["Float"] = 2] = "Float";
|
|
1525
|
+
ConVarType2[ConVarType2["Boolean"] = 3] = "Boolean";
|
|
1526
|
+
return ConVarType2;
|
|
1527
|
+
})(ConVarType || {});
|
|
1528
|
+
var DisablePrettyPrint = /* @__PURE__ */ __name(() => GlobalData.EnablePrettyPrint = false, "DisablePrettyPrint");
|
|
1529
|
+
function Exports(exportName) {
|
|
1530
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
1531
|
+
if (context.private) {
|
|
1532
|
+
throw new Error("Exports does not work on private methods, please mark the method as public");
|
|
1533
|
+
}
|
|
1534
|
+
context.addInitializer(function() {
|
|
1535
|
+
exports(exportName, (...args) => {
|
|
1536
|
+
return originalMethod.call(this, ...args);
|
|
1537
|
+
});
|
|
1538
|
+
});
|
|
1539
|
+
}, "actualDecorator");
|
|
1540
|
+
}
|
|
1541
|
+
__name(Exports, "Exports");
|
|
1542
|
+
function Event(eventName) {
|
|
1543
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
1544
|
+
if (context.private) {
|
|
1545
|
+
throw new Error("Event does not work on private methods, please mark the method as public");
|
|
1546
|
+
}
|
|
1547
|
+
context.addInitializer(function() {
|
|
1548
|
+
on(eventName, (...args) => {
|
|
1549
|
+
try {
|
|
1550
|
+
return originalMethod.call(this, ...args);
|
|
1551
|
+
} catch (e) {
|
|
1552
|
+
REMOVE_EVENT_LOG: {
|
|
1553
|
+
if (!GlobalData.EnablePrettyPrint) return;
|
|
1554
|
+
console.error("------- EVENT ERROR --------");
|
|
1555
|
+
console.error(`Call to ${eventName} errored`);
|
|
1556
|
+
console.error(`Data: ${JSON.stringify(args)}`);
|
|
1557
|
+
console.error(`Error: ${e}`);
|
|
1558
|
+
console.error("------- END EVENT ERROR --------");
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
});
|
|
1562
|
+
});
|
|
1563
|
+
}, "actualDecorator");
|
|
1564
|
+
}
|
|
1565
|
+
__name(Event, "Event");
|
|
1566
|
+
function NetEvent(eventName, remoteOnly = true) {
|
|
1567
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
1568
|
+
if (context.private) {
|
|
1569
|
+
throw new Error("NetEvent does not work on private methods, please mark the method as public");
|
|
1570
|
+
}
|
|
1571
|
+
context.addInitializer(function() {
|
|
1572
|
+
onNet(eventName, (...args) => {
|
|
1573
|
+
const src = source;
|
|
1574
|
+
try {
|
|
1575
|
+
return originalMethod.call(this, ...args);
|
|
1576
|
+
} catch (e) {
|
|
1577
|
+
REMOVE_NET_EVENT_LOG: {
|
|
1578
|
+
if (!GlobalData.EnablePrettyPrint) return;
|
|
1579
|
+
console.error("------- NET EVENT ERROR --------");
|
|
1580
|
+
console.error(`Call to ${eventName} errored`);
|
|
1581
|
+
console.error(`Caller: ${src}`);
|
|
1582
|
+
console.error(`Data: ${JSON.stringify(args)}`);
|
|
1583
|
+
console.error(`Error: ${e}`);
|
|
1584
|
+
console.error("------- END NET EVENT ERROR --------");
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
});
|
|
1588
|
+
});
|
|
1589
|
+
}, "actualDecorator");
|
|
1590
|
+
}
|
|
1591
|
+
__name(NetEvent, "NetEvent");
|
|
1592
|
+
function NuiEvent(eventName) {
|
|
1593
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
1594
|
+
if (context.private) {
|
|
1595
|
+
throw new Error("NuiEvent does not work on private methods, please mark the method as public");
|
|
1596
|
+
}
|
|
1597
|
+
context.addInitializer(function() {
|
|
1598
|
+
RegisterNuiCallback(eventName, (...args) => {
|
|
1599
|
+
return originalMethod.call(this, ...args);
|
|
1600
|
+
});
|
|
1601
|
+
});
|
|
1602
|
+
}, "actualDecorator");
|
|
1603
|
+
}
|
|
1604
|
+
__name(NuiEvent, "NuiEvent");
|
|
1605
|
+
var get_convar_fn = /* @__PURE__ */ __name((con_var_type) => {
|
|
1606
|
+
switch (con_var_type) {
|
|
1607
|
+
case 0 /* String */:
|
|
1608
|
+
return GetConvar;
|
|
1609
|
+
case 1 /* Integer */:
|
|
1610
|
+
return GetConvarInt;
|
|
1611
|
+
case 2 /* Float */:
|
|
1612
|
+
return GetConvarFloat;
|
|
1613
|
+
case 3 /* Boolean */:
|
|
1614
|
+
return GetConvarBool;
|
|
1615
|
+
// needed so typescript wont complain about "unreachable code" for the error below
|
|
1616
|
+
default:
|
|
1617
|
+
}
|
|
1618
|
+
throw new Error("Got invalid ConVarType");
|
|
1619
|
+
}, "get_convar_fn");
|
|
1620
|
+
function ConVar(name, is_floating_point, deserialize) {
|
|
1621
|
+
return /* @__PURE__ */ __name(function actualDecorator(_initialValue, context, ..._args) {
|
|
1622
|
+
if (context.private) {
|
|
1623
|
+
throw new Error("ConVar does not work on private types, please mark the field as public");
|
|
1624
|
+
}
|
|
1625
|
+
context.addInitializer(function() {
|
|
1626
|
+
const t = this;
|
|
1627
|
+
const default_value = Reflect.get(t, context.name);
|
|
1628
|
+
const default_type = typeof default_value;
|
|
1629
|
+
let con_var_type = null;
|
|
1630
|
+
if (default_type === "number") {
|
|
1631
|
+
if (is_floating_point || !Number.isInteger(default_value)) {
|
|
1632
|
+
con_var_type = 2 /* Float */;
|
|
1633
|
+
} else {
|
|
1634
|
+
con_var_type = 1 /* Integer */;
|
|
1635
|
+
}
|
|
1636
|
+
} else if (default_type === "boolean") {
|
|
1637
|
+
con_var_type = 3 /* Boolean */;
|
|
1638
|
+
} else if (default_value === "string") {
|
|
1639
|
+
con_var_type = 0 /* String */;
|
|
1640
|
+
}
|
|
1641
|
+
if (!deserialize && con_var_type === null) {
|
|
1642
|
+
throw new Error("You should provide a deserialize function if you want to convert this to an object type");
|
|
1643
|
+
}
|
|
1644
|
+
if (con_var_type === null) {
|
|
1645
|
+
con_var_type = 0 /* String */;
|
|
1646
|
+
}
|
|
1647
|
+
const con_var_fn = get_convar_fn(con_var_type);
|
|
1648
|
+
const get_convar_value = /* @__PURE__ */ __name(() => {
|
|
1649
|
+
const data = con_var_fn(name, default_value);
|
|
1650
|
+
return deserialize ? deserialize(data) : data;
|
|
1651
|
+
}, "get_convar_value");
|
|
1652
|
+
Reflect.set(t, context.name, get_convar_value());
|
|
1653
|
+
AddConvarChangeListener(name, () => {
|
|
1654
|
+
Reflect.set(t, context.name, get_convar_value());
|
|
1655
|
+
});
|
|
1656
|
+
});
|
|
1657
|
+
}, "actualDecorator");
|
|
1658
|
+
}
|
|
1659
|
+
__name(ConVar, "ConVar");
|
|
1660
|
+
function SetTick() {
|
|
1661
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
1662
|
+
if (context.private) {
|
|
1663
|
+
throw new Error("SetTick does not work on private types, please mark the field as public");
|
|
1664
|
+
}
|
|
1665
|
+
context.addInitializer(function() {
|
|
1666
|
+
setTick(async () => {
|
|
1667
|
+
await originalMethod.call(this);
|
|
1668
|
+
});
|
|
1669
|
+
});
|
|
1670
|
+
}, "actualDecorator");
|
|
1671
|
+
}
|
|
1672
|
+
__name(SetTick, "SetTick");
|
|
1453
1673
|
|
|
1454
1674
|
// src/common/Convar.ts
|
|
1455
1675
|
var Convar = class {
|
|
@@ -1816,23 +2036,81 @@ var OrphanMode = /* @__PURE__ */ ((OrphanMode2) => {
|
|
|
1816
2036
|
OrphanMode2[OrphanMode2["KeepEntity"] = 2] = "KeepEntity";
|
|
1817
2037
|
return OrphanMode2;
|
|
1818
2038
|
})(OrphanMode || {});
|
|
2039
|
+
|
|
2040
|
+
// src/server/entities/Entity.ts
|
|
2041
|
+
var Entity2 = class _Entity extends BaseEntity {
|
|
2042
|
+
static {
|
|
2043
|
+
__name(this, "Entity");
|
|
2044
|
+
}
|
|
2045
|
+
constructor(handle) {
|
|
2046
|
+
super(handle);
|
|
2047
|
+
}
|
|
2048
|
+
static fromNetworkId(netId) {
|
|
2049
|
+
return new _Entity(NetworkGetEntityFromNetworkId(netId));
|
|
2050
|
+
}
|
|
2051
|
+
static fromHandle(handle) {
|
|
2052
|
+
return new _Entity(handle);
|
|
2053
|
+
}
|
|
2054
|
+
};
|
|
2055
|
+
|
|
2056
|
+
// src/server/entities/Prop.ts
|
|
2057
|
+
var Prop = class _Prop extends BaseEntity {
|
|
2058
|
+
static {
|
|
2059
|
+
__name(this, "Prop");
|
|
2060
|
+
}
|
|
2061
|
+
type = 1 /* Prop */;
|
|
2062
|
+
constructor(handle) {
|
|
2063
|
+
super(handle);
|
|
2064
|
+
}
|
|
2065
|
+
/**
|
|
2066
|
+
* Get an interable list of props currently on the server
|
|
2067
|
+
* @returns Iterable list of Props.
|
|
2068
|
+
*/
|
|
2069
|
+
static *AllProps() {
|
|
2070
|
+
for (const prop of GetAllObjects()) {
|
|
2071
|
+
yield new _Prop(prop);
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
static fromNetworkId(networkId) {
|
|
2075
|
+
const ent = NetworkGetEntityFromNetworkId(networkId);
|
|
2076
|
+
if (ent === 0) return null;
|
|
2077
|
+
return new _Prop(ent);
|
|
2078
|
+
}
|
|
2079
|
+
static fromStateBagName(stateBagName) {
|
|
2080
|
+
const ent = GetEntityFromStateBagName(stateBagName);
|
|
2081
|
+
if (ent === 0) return null;
|
|
2082
|
+
return new _Prop(ent);
|
|
2083
|
+
}
|
|
2084
|
+
static fromHandle(handle) {
|
|
2085
|
+
return new _Prop(handle);
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
1819
2088
|
export {
|
|
1820
2089
|
Color,
|
|
1821
2090
|
Command,
|
|
2091
|
+
ConVar,
|
|
2092
|
+
ConVarType,
|
|
1822
2093
|
Convar,
|
|
1823
2094
|
Delay,
|
|
2095
|
+
DisablePrettyPrint,
|
|
1824
2096
|
Entity2 as Entity,
|
|
1825
|
-
|
|
2097
|
+
Event,
|
|
2098
|
+
Exports,
|
|
1826
2099
|
Game,
|
|
1827
2100
|
Kvp,
|
|
1828
2101
|
Maths,
|
|
2102
|
+
NetEvent,
|
|
2103
|
+
NetworkedMap,
|
|
2104
|
+
NuiEvent,
|
|
1829
2105
|
OrphanMode,
|
|
1830
2106
|
Ped,
|
|
1831
2107
|
Player2 as Player,
|
|
2108
|
+
PointF,
|
|
1832
2109
|
PopulationType,
|
|
1833
2110
|
Prop,
|
|
1834
2111
|
Quaternion,
|
|
1835
2112
|
Resource,
|
|
2113
|
+
SetTick,
|
|
1836
2114
|
Vector2,
|
|
1837
2115
|
Vector3,
|
|
1838
2116
|
Vector4,
|
package/package.json
CHANGED
package/Events.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Player } from "./entities/Player";
|
|
2
|
-
export type NetEvent = (player: Player, ...args: any[]) => void;
|
|
3
|
-
export type LocalEvent = (...args: any[]) => void;
|
|
4
|
-
export declare class Events {
|
|
5
|
-
static cancel(): void;
|
|
6
|
-
static wasCanceled(): boolean;
|
|
7
|
-
static get InvokingResource(): string;
|
|
8
|
-
/**
|
|
9
|
-
* An onNet wrapper that properly converts the type into the correct type
|
|
10
|
-
*/
|
|
11
|
-
static onNet: (eventName: string, event: NetEvent) => void;
|
|
12
|
-
/**
|
|
13
|
-
* An on wrapper that properly converts the classes
|
|
14
|
-
*/
|
|
15
|
-
static on: (eventName: string, event: LocalEvent) => void;
|
|
16
|
-
}
|