From 72562688e72a08088b638b7aff9eff4e1ed5ae50 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Thu, 30 Jun 2022 16:32:28 -0500 Subject: [PATCH] Move get anim utils to shared --- scripts/client/animation.js | 48 +++++++++++++++---------------------- scripts/server/animation.js | 47 +++++++----------------------------- scripts/shared/utilities.js | 29 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 67 deletions(-) diff --git a/scripts/client/animation.js b/scripts/client/animation.js index f62db4f7..0540b992 100644 --- a/scripts/client/animation.js +++ b/scripts/client/animation.js @@ -10,7 +10,7 @@ function makePedPlayAnimation(pedId, animationSlot, positionOffset) { let ped = getElementFromId(pedId); - if(ped == null) { + if (ped == null) { return false; } @@ -18,10 +18,10 @@ function makePedPlayAnimation(pedId, animationSlot, positionOffset) { logToConsole(LOG_DEBUG, `[VRR.Animation] Playing animation ${animationData[0]} for ped ${pedId}`); let freezePlayer = false; - switch(animationData.moveType) { + switch (animationData.moveType) { case VRR_ANIMMOVE_FORWARD: { setElementCollisionsEnabled(ped, false); - if(ped.isSyncer) { + if (ped.isSyncer) { setElementPosition(ped, getPosInFrontOfPos(getElementPosition(pedId), fixAngle(getElementHeading(pedId)), positionOffset)); } freezePlayer = true; @@ -30,7 +30,7 @@ function makePedPlayAnimation(pedId, animationSlot, positionOffset) { case VRR_ANIMMOVE_BACK: { setElementCollisionsEnabled(pedId, false); - if(ped.isSyncer) { + if (ped.isSyncer) { setElementPosition(pedId, getPosBehindPos(getElementPosition(pedId), fixAngle(getElementHeading(pedId)), positionOffset)); } freezePlayer = true; @@ -39,7 +39,7 @@ function makePedPlayAnimation(pedId, animationSlot, positionOffset) { case VRR_ANIMMOVE_LEFT: { setElementCollisionsEnabled(pedId, false); - if(ped.isSyncer) { + if (ped.isSyncer) { setElementPosition(pedId, getPosToLeftOfPos(getElementPosition(pedId), fixAngle(getElementHeading(pedId)), positionOffset)); } freezePlayer = true; @@ -48,7 +48,7 @@ function makePedPlayAnimation(pedId, animationSlot, positionOffset) { case VRR_ANIMMOVE_RIGHT: { setElementCollisionsEnabled(pedId, false); - if(ped.isSyncer) { + if (ped.isSyncer) { setElementPosition(pedId, getPosToRightOfPos(getElementPosition(pedId), fixAngle(getElementHeading(pedId)), positionOffset)); } freezePlayer = true; @@ -60,21 +60,21 @@ function makePedPlayAnimation(pedId, animationSlot, positionOffset) { } } - if(getGame() < VRR_GAME_GTA_IV) { - if(animationData.animType == VRR_ANIMTYPE_NORMAL || animationData.animType == VRR_ANIMTYPE_SURRENDER) { - if(getGame() == VRR_GAME_GTA_VC || getGame() == VRR_GAME_GTA_SA) { + if (getGame() < VRR_GAME_GTA_IV) { + if (animationData.animType == VRR_ANIMTYPE_NORMAL || animationData.animType == VRR_ANIMTYPE_SURRENDER) { + if (getGame() == VRR_GAME_GTA_VC || getGame() == VRR_GAME_GTA_SA) { ped.clearAnimations(); } else { ped.clearObjective(); } ped.addAnimation(animationData.groupId, animationData.animId); - if(ped == localPlayer && freezePlayer == true) { + if (ped == localPlayer && freezePlayer == true) { inAnimation = true; setLocalPlayerControlState(false, false); localPlayer.collisionsEnabled = false; } - } else if(animationData.animType == VRR_ANIMTYPE_BLEND) { + } else if (animationData.animType == VRR_ANIMTYPE_BLEND) { ped.position = ped.position; ped.blendAnimation(animationData.groupId, animationData.animId, animationData.animSpeed); } @@ -89,17 +89,17 @@ function makePedPlayAnimation(pedId, animationSlot, positionOffset) { function forcePedAnimation(pedId, animSlot) { let ped = getElementFromId(pedId); - if(ped == null) { + if (ped == null) { return false; } let animationData = getAnimationData(animSlot); - if(getGame() < VRR_GAME_GTA_IV) { + if (getGame() < VRR_GAME_GTA_IV) { ped.position = ped.position; ped.addAnimation(animationData.groupId, animationData.animId); - if(ped == localPlayer) { + if (ped == localPlayer) { inAnimation = true; setLocalPlayerControlState(false, false); localPlayer.collisionsEnabled = false; @@ -115,34 +115,24 @@ function forcePedAnimation(pedId, animSlot) { function makePedStopAnimation(pedId) { let ped = getElementFromId(pedId); - if(ped == null) { + if (ped == null) { return false; } - if(getGame() != VRR_GAME_GTA_IV) { - if(getGame() == VRR_GAME_GTA_VC || getGame() == VRR_GAME_GTA_SA) { + if (getGame() != VRR_GAME_GTA_IV) { + if (getGame() == VRR_GAME_GTA_VC || getGame() == VRR_GAME_GTA_SA) { ped.clearAnimations(); } else { ped.clearObjective(); } } - if(ped == localPlayer) { - if(getGame() != VRR_GAME_GTA_IV) { + if (ped == localPlayer) { + if (getGame() != VRR_GAME_GTA_IV) { localPlayer.collisionsEnabled = true; } setLocalPlayerControlState(true, false); } } -// =========================================================================== - -/** - * @param {number} animationSlot - The slot index of the animation - * @return {AnimationData} The animation's data (array) - */ - function getAnimationData(animationSlot, gameId = getGame()) { - return getGameConfig().animations[gameId][animationSlot]; -} - // =========================================================================== \ No newline at end of file diff --git a/scripts/server/animation.js b/scripts/server/animation.js index 6d722ef9..320ef086 100644 --- a/scripts/server/animation.js +++ b/scripts/server/animation.js @@ -15,7 +15,7 @@ function initAnimationScript() { // =========================================================================== function playPlayerAnimationCommand(command, params, client) { - if(areParamsEmpty(params)) { + if (areParamsEmpty(params)) { messagePlayerSyntax(client, getCommandSyntaxText(command)); return false; } @@ -23,22 +23,22 @@ function playPlayerAnimationCommand(command, params, client) { let animationSlot = getAnimationFromParams(getParam(params, " ", 1)); let animationPositionOffset = 1; - if(!animationSlot) { + if (!animationSlot) { messagePlayerError(client, getLocaleString(client, "InvalidAnimation")); messagePlayerInfo(client, getLocaleString(client, "AnimationCommandTip", `{ALTCOLOUR}/animlist{MAINCOLOUR}`)); return false; } - if(toInteger(animationPositionOffset) < 0 || toInteger(animationPositionOffset) > 3) { + if (toInteger(animationPositionOffset) < 0 || toInteger(animationPositionOffset) > 3) { messagePlayerError(client, getLocaleString(client, "InvalidAnimationDistance")); return false; } - if(getAnimationData(animationSlot)[3] == VRR_ANIMTYPE_SURRENDER) { + if (getAnimationData(animationSlot)[3] == VRR_ANIMTYPE_SURRENDER) { getPlayerData(client).pedState = VRR_PEDSTATE_HANDSUP; } - if(isPlayerHandCuffed(client) || isPlayerTazed(client) || isPlayerInForcedAnimation(client)) { + if (isPlayerHandCuffed(client) || isPlayerTazed(client) || isPlayerInForcedAnimation(client)) { messagePlayerError(client, getLocaleString(client, "UnableToDoThat")); return false; } @@ -50,7 +50,7 @@ function playPlayerAnimationCommand(command, params, client) { // =========================================================================== function stopPlayerAnimationCommand(command, params, client) { - if(isPlayerHandCuffed(client) || isPlayerTazed(client) || isPlayerInForcedAnimation(client)) { + if (isPlayerHandCuffed(client) || isPlayerTazed(client) || isPlayerInForcedAnimation(client)) { messagePlayerError(client, getLocaleString(client, "UnableToDoThat")); return false; } @@ -70,29 +70,19 @@ function stopPlayerAnimationCommand(command, params, client) { // =========================================================================== function showAnimationListCommand(command, params, client) { - let animList = getGameConfig().animations[getGame()].map(function(x) { return x.name; }); + let animList = getGameConfig().animations[getGame()].map(function (x) { return x.name; }); let chunkedList = splitArrayIntoChunks(animList, 10); messagePlayerInfo(client, makeChatBoxSectionHeader(getLocaleString(client, "HeaderAnimationsList"))); - for(let i in chunkedList) { + for (let i in chunkedList) { messagePlayerNormal(client, chunkedList[i].join(", ")); } } // =========================================================================== -/** - * @param {number} animationSlot - The slot index of the animation - * @return {Array} The animation's data (array) - */ -function getAnimationData(animationSlot, gameId = getGame()) { - return getGameConfig().animations[gameId][animationSlot]; -} - -// =========================================================================== - function isPlayerInForcedAnimation(client) { return getPlayerData(client).animationForced; } @@ -125,7 +115,7 @@ function forcePlayerPlayAnimation(client, animationSlot, offsetPosition = 1) { getPlayerData(client).animationForced = true; setPlayerControlState(client, false); - forcePedAnimation(getPlayerPed(client), animationSlot, offsetPosition); + forcePedAnimation(getPlayerPed(client), animationSlot, offsetPosition); } // =========================================================================== @@ -141,23 +131,4 @@ function makePlayerStopAnimation(client) { getPlayerData(client).animationForced = false; } -// =========================================================================== - -function getAnimationFromParams(params) { - let animations = getGameConfig().animations[getGame()]; - if(isNaN(params)) { - for(let i in animations) { - if(toLowerCase(animations[i].name).indexOf(toLowerCase(params)) != -1) { - return i; - } - } - } else { - if(typeof getGameConfig().animations[getGame()][params] != "undefined") { - return toInteger(params); - } - } - - return false; -} - // =========================================================================== \ No newline at end of file diff --git a/scripts/shared/utilities.js b/scripts/shared/utilities.js index e5a19daf..6b7fb705 100644 --- a/scripts/shared/utilities.js +++ b/scripts/shared/utilities.js @@ -2857,4 +2857,33 @@ function removeBitFlag(allFlags, flagValue) { return allFlags ^ flagValue; } +// =========================================================================== + +function getAnimationFromParams(params) { + let animations = getGameConfig().animations[getGame()]; + if (isNaN(params)) { + for (let i in animations) { + if (toLowerCase(animations[i].name).indexOf(toLowerCase(params)) != -1) { + return i; + } + } + } else { + if (typeof getGameConfig().animations[getGame()][params] != "undefined") { + return toInteger(params); + } + } + + return -1; +} + +// =========================================================================== + +/** + * @param {number} animationSlot - The slot index of the animation + * @return {AnimationData} The animation's data (array) + */ +function getAnimationData(animationSlot, gameId = getGame()) { + return getGameConfig().animations[gameId][animationSlot]; +} + // =========================================================================== \ No newline at end of file