New universal lock command

This commit is contained in:
Vortrex
2022-04-18 20:58:23 -05:00
parent 55b2c9e22c
commit c1d27f7fb6
4 changed files with 154 additions and 77 deletions

View File

@@ -622,41 +622,6 @@ function removeBusinessOwnerCommand(command, params, client) {
// ===========================================================================
/**
* This is a command handler function.
*
* @param {string} command - The command name used by the player
* @param {string} params - The parameters/args string used with the command by the player
* @param {Client} client - The client/player that used the command
* @return {bool} Whether or not the command was successful
*
*/
function lockUnlockBusinessCommand(command, params, client) {
let businessId = getPlayerBusiness(client);
if(!areParamsEmpty(params)) {
businessId = getBusinessFromParams(params);
}
if(!getBusinessData(businessId)) {
messagePlayerError(client, getLocaleString(client, "InvalidBusiness"));
return false;
}
if(!canPlayerManageBusiness(client, businessId)) {
messagePlayerError(client, getLocaleString(client, "CantModifyBusiness"));
return false;
}
getBusinessData(businessId).locked = !getBusinessData(businessId).locked;
setEntityData(getBusinessData(businessId).entrancePickup, "vrr.label.locked", getBusinessData(businessId).locked, true);
getBusinessData(businessId).needsSaved = true;
messagePlayerSuccess(client, `${getLockedUnlockedEmojiFromBool((getBusinessData(businessId).locked))} Business {businessBlue}${getBusinessData(businessId).name} {MAINCOLOUR}${getLockedUnlockedFromBool((getBusinessData(businessId).locked))}!`);
}
// ===========================================================================
/**
* This is a command handler function.
*

View File

@@ -75,8 +75,8 @@ function loadCommands() {
//new CommandData("delbizloc", deleteBusinessLocationCommand, "[id]", getStaffFlagValue("ManageBusinesses"), true, false),
new CommandData("bizreloadall", reloadAllBusinessesCommand, "", getStaffFlagValue("ManageBusinesses"), true, false, "Reloads all businesses from the database"),
new CommandData("bizlock", lockUnlockBusinessCommand, "", getStaffFlagValue("None"), true, true, "Locks a business"),
new CommandData("bizlights", toggleBusinessInteriorLightsCommand, "", getStaffFlagValue("None"), true, true, "Turns on/off a business's interior lights"),
//new CommandData("bizlock", lockUnlockBusinessCommand, "", getStaffFlagValue("None"), true, true, "Locks a business"),
//new CommandData("bizlights", toggleBusinessInteriorLightsCommand, "", getStaffFlagValue("None"), true, true, "Turns on/off a business's interior lights"),
new CommandData("bizbuy", buyBusinessCommand, "", getStaffFlagValue("None"), true, true, "Purchases a business"),
new CommandData("bizfee", setBusinessEntranceFeeCommand, "<amount>", getStaffFlagValue("None"), true, true, "Sets a fee to charge players when they enter the business."),
new CommandData("biztill", viewBusinessTillAmountCommand, "", getStaffFlagValue("None"), true, true, "Shows the business's till (cash register) amount"),
@@ -250,8 +250,8 @@ function loadCommands() {
new CommandData("housebuy", buyHouseCommand, "", getStaffFlagValue("None"), true, false, "Purchases a house"),
new CommandData("houseclan", setHouseClanCommand, "", getStaffFlagValue("None"), true, false, "Gives a house to your clan"),
new CommandData("housedesc", setHouseDescriptionCommand, "", getStaffFlagValue("ManageHouses"), true, false, "Sets a house's description"),
new CommandData("houselock", lockUnlockHouseCommand, "", getStaffFlagValue("None"), true, false, "Locks/unlocks a house door"),
new CommandData("houselights", toggleHouseInteriorLightsCommand, "", getStaffFlagValue("None"), true, false, "Turns on and off the lights inside a house"),
//new CommandData("houselock", lockUnlockHouseCommand, "", getStaffFlagValue("None"), true, false, "Locks/unlocks a house door"),
//new CommandData("houselights", toggleHouseInteriorLightsCommand, "", getStaffFlagValue("None"), true, false, "Turns on and off the lights inside a house"),
new CommandData("houseowner", setHouseOwnerCommand, "", getStaffFlagValue("None"), true, false, "Gives a house to a player"),
new CommandData("housebuyprice", setHouseBuyPriceCommand, "", getStaffFlagValue("None"), true, false, "Sets the purchase price of a house so people can buy it"),
new CommandData("houserentprice", setHouseRentPriceCommand, "", getStaffFlagValue("None"), true, false, "Sets the rent price of a house so people can rent it"),
@@ -384,6 +384,8 @@ function loadCommands() {
new CommandData("stuck", stuckPlayerCommand, "", getStaffFlagValue("None"), true, false, "Fixes your position and virtual world if bugged"),
new CommandData("gps", gpsCommand, "[item or place name]", getStaffFlagValue("None"), true, false, "Shows you locations for special places or where to buy items"),
new CommandData("speak", playerPedSpeakCommand, "<speech name>", getStaffFlagValue("None"), true, false, "Makes your ped say something in their game voice (IV only)"),
new CommandData("lock", lockCommand, "", getStaffFlagValue("None"), true, false, "Locks and unlocks your vehicle, house, or business"),
new CommandData("lights", lightsCommand, "", getStaffFlagValue("None"), true, false, "Turns on and off the lights for your vehicle, house, or business"),
],
npc: [
new CommandData("addnpc", createNPCCommand, "<skin id/name>", getStaffFlagValue("ManageNPCs"), true, false, "Creates an NPC with the specified skin"),
@@ -492,11 +494,9 @@ function loadCommands() {
new CommandData("oldcar", getLastVehicleInfoCommand, "", getStaffFlagValue("None"), true, false),
new CommandData("lastcar", getLastVehicleInfoCommand, "", getStaffFlagValue("None"), true, false),
new CommandData("lock", vehicleLockCommand, "", getStaffFlagValue("None"), true, false),
new CommandData("unlock", vehicleLockCommand, "", getStaffFlagValue("None"), true, false),
new CommandData("engine", vehicleEngineCommand, "", getStaffFlagValue("None"), true, false),
new CommandData("siren", vehicleSirenCommand, "", getStaffFlagValue("None"), true, false),
new CommandData("lights", vehicleLightsCommand, "", getStaffFlagValue("None"), true, false),
new CommandData("vehowner", setVehicleOwnerCommand, "<player id/name>", getStaffFlagValue("ManageVehicles"), true, true),
new CommandData("vehpublic", setVehiclePublicCommand, "", getStaffFlagValue("ManageVehicles"), true, true),

View File

@@ -99,39 +99,6 @@ function createHouseCommand(command, params, client) {
// ===========================================================================
/**
* This is a command handler function.
*
* @param {string} command - The command name used by the player
* @param {string} params - The parameters/args string used with the command by the player
* @param {Client} client - The client/player that used the command
* @return {bool} Whether or not the command was successful
*
*/
function lockUnlockHouseCommand(command, params, client) {
let houseId = getPlayerHouse(client);
if(!getHouseData(houseId)) {
messagePlayerError(client, getLocaleString(client, "InvalidHouse"));
return false;
}
getHouseData(houseId).locked = !getHouseData(houseId).locked;
//for(let i in getHouseData(houseId).locations) {
// if(getHouseData(houseId).locations[i].type == VRR_HOUSE_LOC_DOOR) {
// setEntityData(getHouseData(houseId).locations[i].entrancePickup, "vrr.label.locked", getHouseData(houseId).locked, true);
// }
//}
setEntityData(getHouseData(houseId).entrancePickup, "vrr.label.locked", getHouseData(houseId).locked, true);
getHouseData(houseId).needsSaved = true;
messagePlayerSuccess(client, `House {houseGreen}${getHouseData(houseId).description} {MAINCOLOUR}${getLockedUnlockedFromBool((getHouseData(houseId).locked))}!`);
}
// ===========================================================================
/**
* This is a command handler function.
*

View File

@@ -348,7 +348,7 @@ function checkPlayerSpawning() {
// ===========================================================================
function showPlayerPrompt(client, promptType, promptMessage, promptTitle) {
function showPlayerPrompt(client, promptType, promptMessage, promptTitle, yesButtonText, noButtonText) {
if(promptType == VRR_PROMPT_NONE) {
return false;
}
@@ -356,15 +356,24 @@ function showPlayerPrompt(client, promptType, promptMessage, promptTitle) {
getPlayerData(client).promptType = promptType;
if(canPlayerUseGUI(client)) {
showPlayerPromptGUI(client, promptMessage, promptTitle);
showPlayerPromptGUI(client, promptMessage, promptTitle, yesButtonText, noButtonText);
} else {
messagePlayerNormal(client, `${promptMessage}`);
messagePlayerInfo(client, `{MAINCOLOUR}Use {ALTCOLOUR}/yes or {ALTCOLOUR}/no`);
messagePlayerInfo(client, getLocaleString(client, "PromptResponseTip", `{ALTCOLOUR}/yes{MAINCOLOUR}`, `{ALTCOLOUR}/no{MAINCOLOUR}`));
}
}
// ===========================================================================
/**
* This is a command handler function.
*
* @param {string} command - The command name used by the player
* @param {string} params - The parameters/args string used with the command by the player
* @param {Client} client - The client/player that used the command
* @return {bool} Whether or not the command was successful
*
*/
function updateServerGameTime() {
if(isTimeSupported()) {
game.time.hour = getServerConfig().hour;
@@ -374,6 +383,15 @@ function updateServerGameTime() {
// ===========================================================================
/**
* This is a command handler function.
*
* @param {string} command - The command name used by the player
* @param {string} params - The parameters/args string used with the command by the player
* @param {Client} client - The client/player that used the command
* @return {bool} Whether or not the command was successful
*
*/
function listOnlineAdminsCommand(command, params, client) {
//== Admins ===================================
messagePlayerNormal(client, makeChatBoxSectionHeader(getLocaleString(client, "HeaderAdminsList")));
@@ -398,6 +416,15 @@ function listOnlineAdminsCommand(command, params, client) {
// ===========================================================================
/**
* This is a command handler function.
*
* @param {string} command - The command name used by the player
* @param {string} params - The parameters/args string used with the command by the player
* @param {Client} client - The client/player that used the command
* @return {bool} Whether or not the command was successful
*
*/
function gpsCommand(command, params, client) {
messagePlayerNormal(client, makeChatBoxSectionHeader(getLocaleString(client, "HeaderBusinessList")));
@@ -528,6 +555,15 @@ function gpsCommand(command, params, client) {
// ===========================================================================
/**
* This is a command handler function.
*
* @param {string} command - The command name used by the player
* @param {string} params - The parameters/args string used with the command by the player
* @param {Client} client - The client/player that used the command
* @return {bool} Whether or not the command was successful
*
*/
function stuckPlayerCommand(command, params, client) {
if((getCurrentUnixTimestamp()-getPlayerData(client).lastStuckCommand) < getGlobalConfig().stuckCommandInterval) {
messagePlayerError(client, "CantUseCommandYet");
@@ -598,6 +634,15 @@ function stuckPlayerCommand(command, params, client) {
// ===========================================================================
/**
* This is a command handler function.
*
* @param {string} command - The command name used by the player
* @param {string} params - The parameters/args string used with the command by the player
* @param {Client} client - The client/player that used the command
* @return {bool} Whether or not the command was successful
*
*/
function playerPedSpeakCommand(command, params, client) {
if(areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
@@ -607,4 +652,104 @@ function playerPedSpeakCommand(command, params, client) {
makePlayerPedSpeak(client, params);
}
// ===========================================================================
/**
* This is a command handler function.
*
* @param {string} command - The command name used by the player
* @param {string} params - The parameters/args string used with the command by the player
* @param {Client} client - The client/player that used the command
* @return {bool} Whether or not the command was successful
*
*/
function lockCommand(command, params, client) {
if(isPlayerInAnyVehicle(client)) {
let vehicle = getPlayerVehicle(client);
if(!getVehicleData(vehicle)) {
messagePlayerError(client, getLocaleString(client, "RandomVehicleCommandsDisabled"));
return false;
}
if(isPlayerInAnyVehicle(client)) {
vehicle = getPlayerVehicle(client);
if(!isPlayerInFrontVehicleSeat(client)) {
messagePlayerError(client, getLocaleString(client, "MustBeInVehicleFrontSeat"));
return false;
}
} else {
if(!doesPlayerHaveVehicleKeys(client, vehicle)) {
messagePlayerError(client, getLocaleString(client, "DontHaveVehicleKey"));
return false;
}
}
getVehicleData(vehicle).locked = !getVehicleData(vehicle).locked;
vehicle.locked = getVehicleData(vehicle).locked;
getVehicleData(vehicle).needsSaved = true;
meActionToNearbyPlayers(client, `${toLowerCase(getLockedUnlockedFromBool(getVehicleData(vehicle).locked))} the ${getVehicleName(vehicle)}`);
} else {
let businessId = getPlayerBusiness(client);
if(businessId != false) {
if(!canPlayerManageBusiness(client, businessId)) {
messagePlayerError(client, getLocaleString(client, "CantModifyBusiness"));
return false;
}
getBusinessData(businessId).locked = !getBusinessData(businessId).locked;
updateBusinessPickupLabelData(businessId);
getBusinessData(businessId).needsSaved = true;
messagePlayerSuccess(client, `${getLockedUnlockedEmojiFromBool((getBusinessData(businessId).locked))} Business {businessBlue}${getBusinessData(businessId).name} {MAINCOLOUR}${getLockedUnlockedFromBool((getBusinessData(businessId).locked))}!`);
return true;
}
let houseId = getPlayerHouse(client);
if(houseId != false) {
if(!canPlayerManageHouse(client, houseId)) {
messagePlayerError(client, getLocaleString(client, "CantModifyHouse"));
return false;
}
getHouseData(houseId).locked = !getHouseData(houseId).locked;
updateHousePickupLabelData(houseId);
getHouseData(houseId).needsSaved = true;
messagePlayerSuccess(client, `House {houseGreen}${getHouseData(houseId).description} {MAINCOLOUR}${getLockedUnlockedFromBool((getHouseData(houseId).locked))}!`);
return true;
}
let vehicle = getClosestVehicle(getPlayerPosition(client));
if(getDistance(getPlayerPosition(client), getVehiclePosition(vehicle) <= getGlobalConfig().vehicleLockDistance)) {
if(!getVehicleData(vehicle)) {
messagePlayerError(client, getLocaleString(client, "RandomVehicleCommandsDisabled"));
return false;
}
if(isPlayerInAnyVehicle(client)) {
vehicle = getPlayerVehicle(client);
if(!isPlayerInFrontVehicleSeat(client)) {
messagePlayerError(client, getLocaleString(client, "MustBeInVehicleFrontSeat"));
return false;
}
} else {
if(!doesPlayerHaveVehicleKeys(client, vehicle)) {
messagePlayerError(client, getLocaleString(client, "DontHaveVehicleKey"));
return false;
}
}
getVehicleData(vehicle).locked = !getVehicleData(vehicle).locked;
vehicle.locked = getVehicleData(vehicle).locked;
getVehicleData(vehicle).needsSaved = true;
meActionToNearbyPlayers(client, `${toLowerCase(getLockedUnlockedFromBool(getVehicleData(vehicle).locked))} the ${getVehicleName(vehicle)}`);
return false;
}
}
}
// ===========================================================================