Add some natives wrapping
This commit is contained in:
35
scripts/native/gtac/client.js
Normal file
35
scripts/native/gtac/client.js
Normal file
@@ -0,0 +1,35 @@
|
||||
// ===========================================================================
|
||||
// Asshat-Gaming Roleplay
|
||||
// https://github.com/VortrexFTW/gtac_asshat_rp
|
||||
// Copyright (c) 2021 Asshat-Gaming (https://asshatgaming.com)
|
||||
// ---------------------------------------------------------------------------
|
||||
// FILE: client.js
|
||||
// DESC: Provides wrapped client natives for GTAC
|
||||
// TYPE: Natives (JavaScript)
|
||||
// ===========================================================================
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getClientGame() {
|
||||
return gta.game;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function sendToServer(eventName, ...args) {
|
||||
triggerNetworkEvent.call(eventName, args);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function receiveFromServer(eventName, handlerFunction) {
|
||||
addNetworkHandler(eventName, handlerFunction);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function listenFromServer(eventName, handlerFunction) {
|
||||
addNetworkHandler(eventName, handlerFunction);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
264
scripts/native/gtac/server.js
Normal file
264
scripts/native/gtac/server.js
Normal file
@@ -0,0 +1,264 @@
|
||||
// ===========================================================================
|
||||
// Asshat-Gaming Roleplay
|
||||
// https://github.com/VortrexFTW/gtac_asshat_rp
|
||||
// Copyright (c) 2021 Asshat-Gaming (https://asshatgaming.com)
|
||||
// ---------------------------------------------------------------------------
|
||||
// FILE: native.js
|
||||
// DESC: Provides util function to wrap mod-specific stuff
|
||||
// TYPE: Server (JavaScript)
|
||||
// ===========================================================================
|
||||
|
||||
// Use data for each because args are probably gonna be way different for each mod
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getServerGame() {
|
||||
return server.game;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerPosition(client) {
|
||||
if(getServerGame() == GAME_GTA_IV) {
|
||||
return getPlayerData(client).syncPosition;
|
||||
} else {
|
||||
if(client.player != null) {
|
||||
return client.player.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setPlayerPosition(client, position) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s position to ${position.x}, ${position.y}, ${position.z}`);
|
||||
sendPlayerSetPosition(client, position);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerHeading(client) {
|
||||
if(getServerGame() == GAME_GTA_IV) {
|
||||
return getPlayerData(client).syncHeading;
|
||||
} else {
|
||||
if(client.player != null) {
|
||||
return client.player.heading;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setPlayerHeading(client, heading) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s heading to ${heading}`);
|
||||
sendPlayerSetHeading(client, heading);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerVehicle(client) {
|
||||
if(getServerGame() == GAME_GTA_IV) {
|
||||
return getPlayerData().syncVehicle;
|
||||
} else {
|
||||
if(client.player.vehicle) {
|
||||
return client.player.vehicle;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerDimension(client) {
|
||||
return client.player.dimension;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerInterior(client) {
|
||||
if(getPlayerData(client)) {
|
||||
if(getPlayerCurrentSubAccount(client)) {
|
||||
return getPlayerCurrentSubAccount(client).interior;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setPlayerDimension(client, dimension) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s dimension to ${dimension}`);
|
||||
client.player.dimension = dimension;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setPlayerInterior(client, interior) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s interior to ${interior}`);
|
||||
sendPlayerSetInterior(client, interior);
|
||||
getPlayerCurrentSubAccount(client).interior = interior;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isPlayerInAnyVehicle(client) {
|
||||
if(getServerGame() == GAME_GTA_IV) {
|
||||
return (getPlayerData().syncVehicle != null);
|
||||
} else {
|
||||
return (client.player.vehicle != null);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerVehicleSeat(client) {
|
||||
if(!isPlayerInAnyVehicle(client)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(let i = 0 ; i <= 8 ; i++) {
|
||||
if(getPlayerVehicle(client).getOccupant(i) == client.player) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isPlayerSpawned(client) {
|
||||
return (client.player != null);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getVehiclePosition(vehicle) {
|
||||
return vehicle.position;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getVehicleHeading(vehicle) {
|
||||
return vehicle.heading;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getVehicleSyncer(vehicle) {
|
||||
return getElementSyncer(vehicle);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getVehicleForNetworkEvent(vehicle) {
|
||||
return vehicle;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function deleteGameElement(element) {
|
||||
logToConsole(LOG_DEBUG, `Destroying game element ${element.id} (Type: ${element.type})`);
|
||||
if(element != null) {
|
||||
destroyElement(element);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isPlayerInFrontVehicleSeat(client) {
|
||||
return (getPlayerVehicleSeat(client) == 0 || getPlayerVehicleSeat(client) == 1);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function removePlayerFromVehicle(client) {
|
||||
logToConsole(LOG_DEBUG, `Removing ${getPlayerDisplayForConsole(client)} from their vehicle`);
|
||||
sendPlayerRemoveFromVehicle(client);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setPlayerSkin(client, skin) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s skin to ${skin} (${getSkinNameFromId(skin)})`);
|
||||
client.player.modelIndex = skin;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerSkin(client) {
|
||||
return client.player.modelIndex;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function disconnectPlayer(client) {
|
||||
logToConsole(LOG_DEBUG, `Disconnecting (kicking) ${getPlayerDisplayForConsole(client)}`);
|
||||
client.disconnect();
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getElementSyncer(element) {
|
||||
return getClients()[element.syncer];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerWeaponAmmo(client) {
|
||||
return client.player.weaponAmmunition;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setPlayerVelocity(client, velocity) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s velocity to ${velocity.x}, ${velocity.y}, ${velocity.z}`);
|
||||
client.player.velocity = velocity;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerVelocity(client, velocity) {
|
||||
return client.player.velocity;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getElementDimension(element) {
|
||||
return element.dimension;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setElementDimension(element, dimension) {
|
||||
return element.dimension = dimension;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function givePlayerHealth(client, amount) {
|
||||
if(getPlayerHealth(client)+amount > 100) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to 100`);
|
||||
setPlayerHealth(client, 100);
|
||||
} else {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to ${getPlayerHealth(client)+amount}`);
|
||||
setPlayerHealth(client, getPlayerHealth(client)+amount);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function givePlayerArmour(client, amount) {
|
||||
if(getPlayerArmour(client)+amount > 100) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to 100`);
|
||||
setPlayerArmour(client, 100);
|
||||
} else {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to ${getPlayerArmour(client)+amount}`);
|
||||
setPlayerArmour(client, getPlayerArmour(client)+amount);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
333
scripts/native/gtac/shared.js
Normal file
333
scripts/native/gtac/shared.js
Normal file
@@ -0,0 +1,333 @@
|
||||
// ===========================================================================
|
||||
// Asshat-Gaming Roleplay
|
||||
// https://github.com/VortrexFTW/gtac_asshat_rp
|
||||
// Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com)
|
||||
// ---------------------------------------------------------------------------
|
||||
// FILE: native.js
|
||||
// DESC: Provides util funcs for native wrapping
|
||||
// TYPE: Shared (JavaScript)
|
||||
// ===========================================================================
|
||||
|
||||
"use strict";
|
||||
setErrorMode(RESOURCEERRORMODE_STRICT);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function and(var1, var2) {
|
||||
return (var1 && var2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function or(var1, var2) {
|
||||
return (var1 || var2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function not(var1) {
|
||||
return !var1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function bitAnd(var1, var2) {
|
||||
return var1 & var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function bitOr(var1, var2) {
|
||||
return var1 | var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function bitXor(var1, var2) {
|
||||
return var1 ^ var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function bitNot(var1) {
|
||||
return ~var1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function bitLeftShift(var1, var2) {
|
||||
return var1 << var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function bitRightShift(var1, var2) {
|
||||
return var1 >> var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function greaterThan(var1, var2) {
|
||||
return var1 > var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function lessThan(var1, var2) {
|
||||
return (var1 < var2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function greaterThanOrEqualTo(var1, var2) {
|
||||
return (var1 >= var2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function lessThanOrEqualTo(var1, var2) {
|
||||
return (var1 <= var2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function equals(var1, var2) {
|
||||
return (var1 == var2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function modulo(var1, var2) {
|
||||
return var1 % var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function add(...args) {
|
||||
return args.reduce((acc, a) => {
|
||||
return acc + a;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function subtract(...args) {
|
||||
return args.reduce((acc, a) => {
|
||||
return acc - a;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function multiply(...args) {
|
||||
return args.reduce((acc, a) => {
|
||||
return acc * a;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function divide(...args) {
|
||||
return args.reduce((acc, a) => {
|
||||
return acc / a;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toArray(...args) {
|
||||
return args;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toInteger(val) {
|
||||
return Number(val);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toFloat(val, fixed = 2) {
|
||||
return parseFloat((val).toFixed(fixed));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toString(val) {
|
||||
return String(val);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toVector3(x, y, z) {
|
||||
return new Vec3(x, y, z);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toVector2(x, y) {
|
||||
return new Vec2(x, y);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toUpperCase(val) {
|
||||
return String(val).toUpperCase();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toLowerCase(val) {
|
||||
return String(val).toLowerCase();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isNull(val) {
|
||||
if(val == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(typeof val === "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getEntityData(entity, dataName) {
|
||||
if(entity != null) {
|
||||
if(entity.getData != null) {
|
||||
return entity.getData(dataName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setEntityData(entity, dataName, dataValue, syncToClients = true) {
|
||||
if(entity != null) {
|
||||
if(!isNull(server)) {
|
||||
return entity.setData(dataName, dataValue, syncToClients);
|
||||
} else {
|
||||
return entity.setData(dataName, dataValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function removeEntityData(entity, dataName) {
|
||||
if(entity != null) {
|
||||
return entity.removeData(dataName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function doesEntityDataExist(entity, dataName) {
|
||||
if(entity != null) {
|
||||
return (entity.getData(dataName) != null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getDistance(vec1, vec2) {
|
||||
if(isNull(vec1) || isNull(vec2)) {
|
||||
return false;
|
||||
}
|
||||
return vec1.distance(vec2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isConsole(client) {
|
||||
if(client == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return client.console;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function logToConsole(tempLogLevel, text) {
|
||||
if((logLevel & tempLogLevel) || logLevel == LOG_ALL) {
|
||||
if(tempLogLevel == LOG_ERROR) {
|
||||
console.error(text);
|
||||
return true;
|
||||
} else if(tempLogLevel == LOG_WARN) {
|
||||
console.warn(text);
|
||||
return true;
|
||||
} else {
|
||||
console.log(text);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isSamePlayer(client1, client2) {
|
||||
return (client1 == client2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getClientFromIndex(index) {
|
||||
let clients = getClients();
|
||||
for(let i in clients) {
|
||||
if(clients[i].index == index) {
|
||||
return clients[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getConsoleClient() {
|
||||
let clients = getClients();
|
||||
for(let i in clients) {
|
||||
if(isConsole(clients[i])) {
|
||||
return clients[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerFromParams(params) {
|
||||
let clients = getPlayers();
|
||||
if(isNaN(params)) {
|
||||
for(let i in clients) {
|
||||
if(!isConsole(clients[i])) {
|
||||
if(toLowerCase(clients[i].name).indexOf(toLowerCase(params)) != -1) {
|
||||
return clients[i];
|
||||
}
|
||||
|
||||
if(toLowerCase(getCharacterFullName(clients[i])).indexOf(toLowerCase(params)) != -1) {
|
||||
return clients[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(typeof clients[toInteger(params)] != "undefined") {
|
||||
return clients[toInteger(params)];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayers() {
|
||||
return getClients();
|
||||
}
|
||||
29
scripts/native/ragemp/client.js
Normal file
29
scripts/native/ragemp/client.js
Normal file
@@ -0,0 +1,29 @@
|
||||
// ===========================================================================
|
||||
// Asshat-Gaming Roleplay
|
||||
// https://github.com/VortrexFTW/gtac_asshat_rp
|
||||
// Copyright (c) 2021 Asshat-Gaming (https://asshatgaming.com)
|
||||
// ---------------------------------------------------------------------------
|
||||
// FILE: client.js
|
||||
// DESC: Provides wrapped client natives for RAGEMP
|
||||
// TYPE: Natives (JavaScript)
|
||||
// ===========================================================================
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getClientGame() {
|
||||
return AG_GAME_GTA_V;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function sendToServer(eventName, ...args) {
|
||||
mp.events.call(eventName, args);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function receiveFromServer(eventName, handlerFunction) {
|
||||
mp.events.add(eventName, handlerFunction);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
256
scripts/native/ragemp/server.js
Normal file
256
scripts/native/ragemp/server.js
Normal file
@@ -0,0 +1,256 @@
|
||||
// ===========================================================================
|
||||
// Asshat-Gaming Roleplay
|
||||
// https://github.com/VortrexFTW/gtac_asshat_rp
|
||||
// Copyright (c) 2021 Asshat-Gaming (https://asshatgaming.com)
|
||||
// ---------------------------------------------------------------------------
|
||||
// FILE: server.js
|
||||
// DESC: Provides wrapped server natives for RAGEMP
|
||||
// TYPE: Natives (JavaScript)
|
||||
// ===========================================================================
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getServerGame() {
|
||||
return AG_GAME_GTA_V;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerPosition(client) {
|
||||
return client.player.position;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setPlayerPosition(client, position) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s position to ${position.x}, ${position.y}, ${position.z}`);
|
||||
client.position = position;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerHeading(client) {
|
||||
if(getServerGame() == GAME_GTA_IV) {
|
||||
return getPlayerData(client).syncHeading;
|
||||
} else {
|
||||
if(client.player != null) {
|
||||
return client.player.heading;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setPlayerHeading(client, heading) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s heading to ${heading}`);
|
||||
sendPlayerSetHeading(client, heading);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerVehicle(client) {
|
||||
if(getServerGame() == GAME_GTA_IV) {
|
||||
return getPlayerData().syncVehicle;
|
||||
} else {
|
||||
if(client.player.vehicle) {
|
||||
return client.player.vehicle;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerDimension(client) {
|
||||
return client.player.dimension;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerInterior(client) {
|
||||
if(getPlayerData(client)) {
|
||||
if(getPlayerCurrentSubAccount(client)) {
|
||||
return getPlayerCurrentSubAccount(client).interior;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setPlayerDimension(client, dimension) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s dimension to ${dimension}`);
|
||||
client.player.dimension = dimension;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setPlayerInterior(client, interior) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s interior to ${interior}`);
|
||||
sendPlayerSetInterior(client, interior);
|
||||
getPlayerCurrentSubAccount(client).interior = interior;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isPlayerInAnyVehicle(client) {
|
||||
if(getServerGame() == GAME_GTA_IV) {
|
||||
return (getPlayerData().syncVehicle != null);
|
||||
} else {
|
||||
return (client.player.vehicle != null);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerVehicleSeat(client) {
|
||||
if(!isPlayerInAnyVehicle(client)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(let i = 0 ; i <= 8 ; i++) {
|
||||
if(getPlayerVehicle(client).getOccupant(i) == client.player) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isPlayerSpawned(client) {
|
||||
return (client.player != null);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getVehiclePosition(vehicle) {
|
||||
return vehicle.position;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getVehicleHeading(vehicle) {
|
||||
return vehicle.heading;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getVehicleSyncer(vehicle) {
|
||||
return getElementSyncer(vehicle);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getVehicleForNetworkEvent(vehicle) {
|
||||
return vehicle;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function deleteGameElement(element) {
|
||||
logToConsole(LOG_DEBUG, `Destroying game element ${element.id} (Type: ${element.type})`);
|
||||
if(element != null) {
|
||||
destroyElement(element);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isPlayerInFrontVehicleSeat(client) {
|
||||
return (getPlayerVehicleSeat(client) == 0 || getPlayerVehicleSeat(client) == 1);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function removePlayerFromVehicle(client) {
|
||||
logToConsole(LOG_DEBUG, `Removing ${getPlayerDisplayForConsole(client)} from their vehicle`);
|
||||
sendPlayerRemoveFromVehicle(client);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setPlayerSkin(client, skin) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s skin to ${skin} (${getSkinNameFromId(skin)})`);
|
||||
client.player.modelIndex = skin;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerSkin(client) {
|
||||
return client.player.modelIndex;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function disconnectPlayer(client) {
|
||||
logToConsole(LOG_DEBUG, `Disconnecting (kicking) ${getPlayerDisplayForConsole(client)}`);
|
||||
client.disconnect();
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getElementSyncer(element) {
|
||||
return getClients()[element.syncer];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerWeaponAmmo(client) {
|
||||
return client.player.weaponAmmunition;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setPlayerVelocity(client, velocity) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s velocity to ${velocity.x}, ${velocity.y}, ${velocity.z}`);
|
||||
client.player.velocity = velocity;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerVelocity(client, velocity) {
|
||||
return client.player.velocity;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getElementDimension(element) {
|
||||
return element.dimension;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setElementDimension(element, dimension) {
|
||||
return element.dimension = dimension;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function givePlayerHealth(client, amount) {
|
||||
if(getPlayerHealth(client)+amount > 100) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to 100`);
|
||||
setPlayerHealth(client, 100);
|
||||
} else {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to ${getPlayerHealth(client)+amount}`);
|
||||
setPlayerHealth(client, getPlayerHealth(client)+amount);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function givePlayerArmour(client, amount) {
|
||||
if(getPlayerArmour(client)+amount > 100) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to 100`);
|
||||
setPlayerArmour(client, 100);
|
||||
} else {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to ${getPlayerArmour(client)+amount}`);
|
||||
setPlayerArmour(client, getPlayerArmour(client)+amount);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
335
scripts/native/ragemp/shared.js
Normal file
335
scripts/native/ragemp/shared.js
Normal file
@@ -0,0 +1,335 @@
|
||||
// ===========================================================================
|
||||
// Asshat-Gaming Roleplay
|
||||
// https://github.com/VortrexFTW/gtac_asshat_rp
|
||||
// Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com)
|
||||
// ---------------------------------------------------------------------------
|
||||
// FILE: native.js
|
||||
// DESC: Provides util funcs for native wrapping
|
||||
// TYPE: Shared (JavaScript)
|
||||
// ===========================================================================
|
||||
|
||||
"use strict";
|
||||
setErrorMode(RESOURCEERRORMODE_STRICT);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function and(var1, var2) {
|
||||
return (var1 && var2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function or(var1, var2) {
|
||||
return (var1 || var2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function not(var1) {
|
||||
return !var1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function bitAnd(var1, var2) {
|
||||
return var1 & var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function bitOr(var1, var2) {
|
||||
return var1 | var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function bitXor(var1, var2) {
|
||||
return var1 ^ var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function bitNot(var1) {
|
||||
return ~var1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function bitLeftShift(var1, var2) {
|
||||
return var1 << var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function bitRightShift(var1, var2) {
|
||||
return var1 >> var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function greaterThan(var1, var2) {
|
||||
return var1 > var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function lessThan(var1, var2) {
|
||||
return (var1 < var2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function greaterThanOrEqualTo(var1, var2) {
|
||||
return (var1 >= var2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function lessThanOrEqualTo(var1, var2) {
|
||||
return (var1 <= var2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function equals(var1, var2) {
|
||||
return (var1 == var2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function modulo(var1, var2) {
|
||||
return var1 % var2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function add(...args) {
|
||||
return args.reduce((acc, a) => {
|
||||
return acc + a;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function subtract(...args) {
|
||||
return args.reduce((acc, a) => {
|
||||
return acc - a;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function multiply(...args) {
|
||||
return args.reduce((acc, a) => {
|
||||
return acc * a;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function divide(...args) {
|
||||
return args.reduce((acc, a) => {
|
||||
return acc / a;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toArray(...args) {
|
||||
return args;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toInteger(val) {
|
||||
return Number(val);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toFloat(val, fixed = 2) {
|
||||
return parseFloat((val).toFixed(fixed));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toString(val) {
|
||||
return String(val);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toVector3(x, y, z) {
|
||||
return new Vec3(x, y, z);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toVector2(x, y) {
|
||||
return new Vec2(x, y);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toUpperCase(val) {
|
||||
return String(val).toUpperCase();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function toLowerCase(val) {
|
||||
return String(val).toLowerCase();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isNull(val) {
|
||||
if(val == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(typeof val === "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getEntityData(entity, dataName) {
|
||||
if(entity != null) {
|
||||
if(entity.getData != null) {
|
||||
return entity.getData(dataName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setEntityData(entity, dataName, dataValue, syncToClients = true) {
|
||||
if(entity != null) {
|
||||
if(!isNull(server)) {
|
||||
return entity.setData(dataName, dataValue, syncToClients);
|
||||
} else {
|
||||
return entity.setData(dataName, dataValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function removeEntityData(entity, dataName) {
|
||||
if(entity != null) {
|
||||
return entity.removeData(dataName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function doesEntityDataExist(entity, dataName) {
|
||||
if(entity != null) {
|
||||
return (entity.getData(dataName) != null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getDistance(vec1, vec2) {
|
||||
if(isNull(vec1) || isNull(vec2)) {
|
||||
return false;
|
||||
}
|
||||
return vec1.distance(vec2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isConsole(client) {
|
||||
if(client == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return client.console;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function logToConsole(tempLogLevel, text) {
|
||||
if((logLevel & tempLogLevel) || logLevel == LOG_ALL) {
|
||||
if(tempLogLevel == LOG_ERROR) {
|
||||
console.error(text);
|
||||
return true;
|
||||
} else if(tempLogLevel == LOG_WARN) {
|
||||
console.warn(text);
|
||||
return true;
|
||||
} else {
|
||||
console.log(text);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isSamePlayer(client1, client2) {
|
||||
return (client1 == client2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getClientFromIndex(index) {
|
||||
let clients = getClients();
|
||||
for(let i in clients) {
|
||||
if(clients[i].index == index) {
|
||||
return clients[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getConsoleClient() {
|
||||
let clients = getClients();
|
||||
for(let i in clients) {
|
||||
if(isConsole(clients[i])) {
|
||||
return clients[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerFromParams(params) {
|
||||
let clients = getClients();
|
||||
if(isNaN(params)) {
|
||||
for(let i in clients) {
|
||||
if(!clients[i].console) {
|
||||
if(toLowerCase(clients[i].name).indexOf(toLowerCase(params)) != -1) {
|
||||
return clients[i];
|
||||
}
|
||||
|
||||
if(toLowerCase(getCharacterFullName(clients[i])).indexOf(toLowerCase(params)) != -1) {
|
||||
return clients[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(typeof clients[toInteger(params)] != "undefined") {
|
||||
return clients[toInteger(params)];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayers() {
|
||||
return getClients();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user