Files
GTA4RP/scripts/server/misc.js
Vortrex 9c87ff950c Lots of fixes + clans
* Added clans
* Fixed interior exit labels
* Disabled nametags on games without 3D label support
* Fixed mouse cursor toggle command
* Fixed SA fight-style not being applied
* Added manageRanks clan permission bitflag
* Added interior lights toggle
* Fixed clan chat
* Added real-time support with optional timezone offset
* Added lots of JSDoc stuff
* Added command for managers to set server GUI colour
* Added GeoIP command for admins
* Added command for admins to force an immediate payday
* Added admins gotospawn command
* Added return player command for teleported players
* Added pizza delivery job const
* Fixed biz/house set pickup & interior type
* Fixed inventory showing ammo count for melee weapons
* Fixed SA using wrong pickup types
* Fixed char select screen breaking when in a clan
* Added +/- symbol util for number display
* Added get current timestamp for timezone offset util
* Fixed vehicle owner ID being set wrong for job veh
2021-09-09 01:37:04 -05:00

414 lines
15 KiB
JavaScript

// ===========================================================================
// Vortrex's Roleplay Resource
// https://github.com/VortrexFTW/gtac_roleplay
// ===========================================================================
// FILE: misc.js
// DESC: Provides any uncategorized functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
// ===========================================================================
function initMiscScript() {
logToConsole(LOG_INFO, "[VRR.Misc]: Initializing misc script ...");
logToConsole(LOG_INFO, "[VRR.Misc]: Misc script initialized successfully!");
return true;
}
// ===========================================================================
function getPositionCommand(command, params, client) {
let position = getPlayerPosition(client);
messagePlayerNormal(client, `Your position is: ${position.x.toFixed(2)}, ${position.y.toFixed(2)}, ${position.z.toFixed(2)}`);
logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s position is: ${position.x.toFixed(2)}, ${position.y.toFixed(2)}, ${position.z.toFixed(2)}`);
return true;
}
// ===========================================================================
function toggleMouseCursorCommand(command, params, client) {
sendPlayerMouseCursorToggle(client);
return true;
}
// ===========================================================================
function toggleMouseCameraCommand(command, params, client) {
sendPlayerMouseCameraToggle(client);
return true;
}
// ===========================================================================
function setNewCharacterSpawnPositionCommand(command, params, client) {
let position = client.player.position;
getServerConfig().newCharacter.spawnPosition = position;
getServerConfig().newCharacter.spawnHeading = client.player.heading;
getServerConfig().needsSaved = true;
messagePlayerNormal(client, `The new character spawn position has been set to ${position.x.toFixed(2)}, ${position.y.toFixed(2)}, ${position.z.toFixed(2)}`)
return true;
}
// ===========================================================================
function setNewCharacterMoneyCommand(command, params, client) {
if(areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
let splitParams = params.split();
let amount = toInteger(splitParams[0]) || 1000;
getServerConfig().newCharacter.cash = amount;
getServerConfig().needsSaved = true;
messagePlayerNormal(client, `The new character money has been set to $${amount}`);
return true;
}
// ===========================================================================
function setNewCharacterSkinCommand(command, params, client) {
if(areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
let skinId = 0;
if(areParamsEmpty(params)) {
skinId = client.player.modelIndex;
} else {
skinId = getSkinFromParams(params);
}
getServerConfig().newCharacter.skin = skinId;
getServerConfig().needsSaved = true;
messagePlayerNormal(client, `The new character skin has been set to ${getSkinNameFromId(skinId)} (ID ${skinId})`);
return true;
}
// ===========================================================================
function submitIdeaCommand(command, params, client) {
if(areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
submitIdea(client, params);
messagePlayerNormal(client, `Your suggestion/idea has been sent to the developers!`);
return true;
}
// ===========================================================================
function submitBugReportCommand(command, params, client) {
if(areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
submitBugReport(client, params);
messagePlayerNormal(client, `Your bug report has been sent to the developers!`);
return true;
}
// ===========================================================================
function enterExitPropertyCommand(command, params, client) {
if(isPlayerInAnyHouse(client)) {
let inHouse = getServerData().houses[getPlayerHouse(client)];
if(getDistance(inHouse.exitPosition, getPlayerPosition(client)) <= getGlobalConfig().exitPropertyDistance) {
if(inHouse.locked) {
meActionToNearbyPlayers(client, "tries to open the house door but fails because it's locked");
return false;
}
clearPlayerStateToEnterExitProperty(client);
getPlayerData(client).pedState = VRR_PEDSTATE_EXITINGPROPERTY;
meActionToNearbyPlayers(client, "opens the door and exits the house");
if(isFadeCameraSupported()) {
fadeCamera(client, false, 1.0);
}
disableCityAmbienceForPlayer(client, true);
setTimeout(function() {
setPlayerPosition(client, inHouse.entrancePosition);
setPlayerHeading(client, inHouse.entranceRotation);
setPlayerDimension(client, inHouse.entranceDimension);
setPlayerInterior(client, inHouse.entranceInterior);
setTimeout(function() {
if(isFadeCameraSupported()) {
fadeCamera(client, true, 1.0);
}
setTimeout(function() {
enableCityAmbienceForPlayer(client);
clearPlayerOwnedPeds(client);
clearPlayerHouseGameScripts(client, inHouse.index);
getPlayerData(client).pedState = VRR_PEDSTATE_READY;
}, 2000);
updateInteriorLightsForPlayer(client, true);
}, 1000);
}, 1100);
removeEntityData(client, "vrr.inHouse");
playRadioStreamForPlayer(client, "");
getPlayerData(client).streamingRadioStation = -1;
logToConsole(LOG_DEBUG, `[VRR.Misc] ${getPlayerDisplayForConsole(client)} exited house ${inHouse.description}[${inHouse.index}/${inHouse.databaseId}]`);
return true;
}
}
if(isPlayerInAnyBusiness(client)) {
let inBusiness = getServerData().businesses[getPlayerBusiness(client)];
if(getDistance(inBusiness.exitPosition, getPlayerPosition(client)) <= getGlobalConfig().exitPropertyDistance) {
if(inBusiness.locked) {
meActionToNearbyPlayers(client, "tries to open the business door but fails because it's locked");
return false;
}
getPlayerData(client).pedState = VRR_PEDSTATE_EXITINGPROPERTY;
clearPlayerStateToEnterExitProperty(client)
meActionToNearbyPlayers(client, "opens the door and exits the business");
if(isFadeCameraSupported()) {
fadeCamera(client, false, 1.0);
}
disableCityAmbienceForPlayer(client, true);
setTimeout(function() {
setPlayerPosition(client, inBusiness.entrancePosition);
setPlayerHeading(client, inBusiness.entranceRotation);
setPlayerDimension(client, inBusiness.entranceDimension);
setPlayerInterior(client, inBusiness.entranceInterior);
setTimeout(function() {
if(isFadeCameraSupported()) {
fadeCamera(client, true, 1.0);
}
setTimeout(function() {
enableCityAmbienceForPlayer(client);
clearPlayerOwnedPeds(client);
clearPlayerBusinessGameScripts(client, inBusiness.index);
getPlayerData(client).pedState = VRR_PEDSTATE_READY;
}, 2000);
updateInteriorLightsForPlayer(client, true);
}, 1000);
}, 1100);
removeEntityData(client, "vrr.inBusiness");
playRadioStreamForPlayer(client, "");
getPlayerData(client).streamingRadioStation = -1;
logToConsole(LOG_DEBUG, `[VRR.Misc] ${getPlayerDisplayForConsole(client)} exited business ${inBusiness.name}[${inBusiness.index}/${inBusiness.databaseId}]`);
return true;
}
}
if(getServerData().businesses.length > 0) {
let closestBusinessId = getClosestBusinessEntrance(getPlayerPosition(client));
let closestBusiness = getBusinessData(closestBusinessId);
if(getDistance(closestBusiness.entrancePosition, getPlayerPosition(client)) <= getGlobalConfig().enterPropertyDistance) {
if(!doesBusinessHaveInterior(closestBusinessId)) {
messagePlayerAlert(client, "This business does not have an interior.");
messagePlayerTip(client, "You can use business commands at the door.");
return false;
}
if(closestBusiness.locked) {
meActionToNearbyPlayers(client, "tries to open the business door but fails because it's locked");
return false;
}
clearPlayerStateToEnterExitProperty(client)
meActionToNearbyPlayers(client, "opens the door and enters the business");
getPlayerData(client).pedState = VRR_PEDSTATE_ENTERINGPROPERTY;
if(isFadeCameraSupported()) {
fadeCamera(client, false, 1.0);
}
disableCityAmbienceForPlayer(client);
setTimeout(function() {
setPlayerPosition(client, closestBusiness.exitPosition);
setPlayerHeading(client, closestBusiness.exitRotation);
setPlayerDimension(client, closestBusiness.exitDimension);
setPlayerInterior(client, closestBusiness.exitInterior);
sendPlayerBusinessGameScripts(client, closestBusiness.index);
setTimeout(function() {
if(isFadeCameraSupported()) {
fadeCamera(client, true, 1.0);
}
getPlayerData(client).pedState = VRR_PEDSTATE_READY;
if(doesBusinessHaveAnyItemsToBuy(closestBusinessId)) {
messagePlayerInfo(client, "Use /buy to purchase items from this business");
}
updateInteriorLightsForPlayer(client, closestBusiness.interiorLights);
setTimeout(function() {
if(closestBusiness.streamingRadioStation != -1) {
if(getPlayerData(client).streamingRadioStation != closestBusiness.streamingRadioStation) {
playRadioStreamForPlayer(client, radioStations[closestBusiness.streamingRadioStation].url, true, getPlayerStreamingRadioVolume(client));
}
}
}, 1250);
}, 1000);
}, 1100);
setEntityData(client, "vrr.inBusiness", closestBusinessId, true);
return true;
}
}
if(getServerData().houses.length > 0) {
let closestHouseId = getClosestHouseEntrance(getPlayerPosition(client));
let closestHouse = getHouseData(closestHouseId);
//let distance = getDistance(closestHouse.entrancePosition, getPlayerPosition(client));
if(getDistance(closestHouse.entrancePosition, getPlayerPosition(client)) <= getGlobalConfig().enterPropertyDistance) {
if(!doesHouseHaveInterior(closestHouseId)) {
messagePlayerAlert(client, "This house does not have an interior.");
messagePlayerTip(client, "You can use house commands at the door.");
return false;
}
if(closestHouse.locked) {
meActionToNearbyPlayers(client, "tries to open the house door but fails because it's locked");
return false;
}
clearPlayerStateToEnterExitProperty(client)
meActionToNearbyPlayers(client, "opens the door and enters the house");
getPlayerData(client).pedState = VRR_PEDSTATE_ENTERINGPROPERTY;
if(isFadeCameraSupported()) {
fadeCamera(client, false, 1.0);
}
disableCityAmbienceForPlayer(client);
setTimeout(function() {
setPlayerDimension(client, closestHouse.exitDimension);
setPlayerInterior(client, closestHouse.exitInterior);
setPlayerPosition(client, closestHouse.exitPosition);
setPlayerHeading(client, closestHouse.exitRotation);
sendPlayerHouseGameScripts(client, closestHouse.index);
setTimeout(function() {
if(isFadeCameraSupported()) {
fadeCamera(client, true, 1.0);
}
getPlayerData(client).pedState = VRR_PEDSTATE_READY;
updateInteriorLightsForPlayer(client, closestHouse.interiorLights);
setTimeout(function() {
if(closestHouse.streamingRadioStation != -1) {
if(getPlayerData(client).streamingRadioStation != closestHouse.streamingRadioStation) {
playRadioStreamForPlayer(client, radioStations[closestHouse.streamingRadioStation].url, true, getPlayerStreamingRadioVolume(client));
}
}
}, 1250);
}, 1000);
}, 1100);
setEntityData(client, "vrr.inHouse", closestHouseId, true)
return true;
}
}
return true;
}
// ===========================================================================
function loadGameFixesResource() {
//switch(getServerGame()) {
// case GAME_GTA_III:
// if(findResourceByName("asshat-gta3") != null) {
// findResourceByName("asshat-gta3").start();
// }
// break;
//
// default:
// break;
//}
return true;
}
// ===========================================================================
function getPlayerInfoCommand(command, params, client) {
if(areParamsEmpty(params)) {
return false;
}
let targetClient = getPlayerFromParams(params);
if(!getPlayerData(targetClient)) {
messagePlayerError(client, "Player not found!");
return false;
}
messagePlayerInfo(client, `${getInlineChatColourByName("lightGrey")}[Player Info] ${getInlineChatColourByName("white")}Account: ${getInlineChatColourByName("lightGrey")}${getPlayerData(targetClient).accountData.name}[${getPlayerData(targetClient).accountData.databaseId}], ${getInlineChatColourByName("white")}Character: ${getInlineChatColourByName("lightGrey")}${getCharacterFullName(client)}[${getPlayerCurrentSubAccount(client).databaseId}], ${getInlineChatColourByName("white")}Connected: ${getInlineChatColourByName("lightGrey")}${getTimeDifferenceDisplay(Math.ceil(sdl.tick/1000), getPlayerData(targetClient).connectTime)} ago, ${getInlineChatColourByName("white")}Game Version: ${getInlineChatColourByName("lightGrey")}${targetClient.gameVersion}, [#FFFFFFF]Client Version: ${getInlineChatColourByName("lightGrey")}${getPlayerData(targetClient).clientVersion}`);
}
// ===========================================================================
function playerChangeAFKState(client, afkState) {
if(afkState) {
setEntityData(client, "vrr.afk", true, true);
} else {
client.removeData("vrr.afk");
}
}
// ===========================================================================
function checkPlayerSpawning() {
let clients = getClients();
for(let i in clients) {
if(!isConsole(clients[i])) {
if(getPlayerData(clients[i])) {
if(getPlayerData(clients[i]).loggedIn) {
if(!getPlayerData(clients[i]).ped) {
if(clients[i].player != null) {
//getPlayerData(clients[i]).ped = clients[i].player;
onPlayerSpawn(clients[i].player);
}
}
}
}
}
}
}
// ===========================================================================
function showPlayerPrompt(client, promptType, promptMessage, promptTitle) {
if(promptType == VRR_PROMPT_NONE) {
return false;
}
getPlayerData(client).promptType = promptType;
if(canPlayerUseGUI(client)) {
showPlayerPromptGUI(client, promptMessage, promptTitle);
} else {
messagePlayerNormal(client, `${promptMessage}`);
messagePlayerInfo(client, `${getInlineChatColourByName("white")}Use ${getInlineChatColourByName("lightGrey")}/yes or ${getInlineChatColourByName("lightGrey")}/no`);
}
}
// ===========================================================================
function updateServerGameTime() {
if(isTimeSupported()) {
gta.time.hour = getServerConfig().hour;
gta.time.minute = getServerConfig().minute;
}
}
// ===========================================================================
function listOnlineAdminsCommand(command, params, client) {
let clients = getClients();
for(let i in clients) {
if(getPlayerData(clients[i])) {
if(getPlayerData(clients[i]).accountData.flags.admin > 0) {
messagePlayerNormal(client, `• [${getPlayerData(clients[i]).accountData.staffTitle}] ${getCharacterFullName(clients[i])}`);
}
}
}
}
// ===========================================================================