1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-07-14 17:42:45 +02:00
parent 32ff2b34b2
commit 71d3cde454
7 changed files with 577 additions and 0 deletions

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 BagusCodeStudio
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,33 @@
# Lockpick UI Minigame
![image](https://user-images.githubusercontent.com/60974759/161067952-d0acf8ef-ab1e-4540-bf83-b96268196b9c.png)
An easy lockpick export for FiveM.
I know this was in a lot of leaked resource and has been made similarly.
But this one I edited it myself from the codepen mentioned below.
Credits to [antoxa-kms](https://codepen.io/antoxa-kms/).
## Installation
1. Download the resource.
2. Drag and drop to resources folder.
3. Ensure or start the resource in server.cfg and you are done.
## Usage
Use `startLockpick` export to start lockpicking.
```lua
RegisterCommand('lockpicktry', function()
local result = exports['lockpick']:startLockpick()
print(result, 'lockpicking result')
end)
```
## Contribution
Suggestions and pull request are welcome!
## Acknowledgements
I do not take any credits from the UI code, credits to [antoxa-kms](https://codepen.io/antoxa-kms/pen/qbqoMy) codepen.

View file

@ -0,0 +1,36 @@
local Promise = nil
RegisterNUICallback('close', function()
SetNuiFocus(false, false)
if Promise then
Promise:resolve(false)
end
end)
RegisterNUICallback('succeed', function()
SetNuiFocus(false, false)
Promise:resolve(true)
end)
RegisterNUICallback('failed', function()
SetNuiFocus(false, false)
Promise:resolve(false)
end)
RegisterCommand('lockpicktry', function()
local result = exports['lockpick']:startLockpick()
print(result, 'lockpicking result')
end)
exports('startLockpick', function(tries)
SendNUIMessage({
start = true,
tries = tries
})
SetNuiFocus(true, true)
Promise = promise.new()
local result = Citizen.Await(Promise)
return result
end)

View file

@ -0,0 +1,12 @@
fx_version 'cerulean'
game 'gta5'
ui_page 'html/index.html'
files {
'html/index.html',
'html/styles.css',
'html/script.js'
}
client_script 'client.lua'

View file

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenMax.min.js"></script>
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<!-- <script type="text/javascript" src="jquery-3.6.0.min.js"></script> -->
<script type="text/javascript" src="script.js"></script>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="wrap">
<img
src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/95637/collar.png"
alt=""
id="collar"
/>
<div id="cylinder"></div>
<div id="driver"></div>
<div id="pin">
<div class="top"></div>
<div class="bott"></div>
</div>
</div>
<div id="text">
<p>WASD and Move cursor to pick lock</p>
<p><span>5</span> Lockpick Remaining</p>
</div>
</body>
</html>

View file

@ -0,0 +1,309 @@
let minRot = -90,
maxRot = 90,
solveDeg = Math.random() * 180 - 90,
solvePadding = 4,
maxDistFromSolve = 45,
pinRot = 0,
cylRot = 0,
lastMousePos = 0,
mouseSmoothing = 2,
keyRepeatRate = 25,
cylRotSpeed = 3,
pinDamage = 20,
pinHealth = 100,
pinDamageInterval = 150,
numPins = 5,
userPushingCyl = false,
gameOver = false,
gamePaused = false,
pin,
cyl,
driver,
cylRotationInterval,
pinLastDamaged;
$(function () {
//pop vars
pin = $('#pin');
cyl = $('#cylinder');
driver = $('#driver');
$('body').on('mousemove', function (e) {
if (lastMousePos && !gameOver && !gamePaused) {
var pinRotChange = (e.clientX - lastMousePos) / mouseSmoothing;
pinRot += pinRotChange;
pinRot = Util.clamp(pinRot, maxRot, minRot);
pin.css({
transform: 'rotateZ(' + pinRot + 'deg)',
});
}
lastMousePos = e.clientX;
});
$('body').on('mouseleave', function (e) {
lastMousePos = 0;
});
$('body').on('keydown', function (e) {
if (
(e.keyCode == 87 ||
e.keyCode == 65 ||
e.keyCode == 83 ||
e.keyCode == 68 ||
e.keyCode == 37 ||
e.keyCode == 39) &&
!userPushingCyl &&
!gameOver &&
!gamePaused
) {
pushCyl();
}
});
$('body').on('keyup', function (e) {
if (
(e.keyCode == 87 ||
e.keyCode == 65 ||
e.keyCode == 83 ||
e.keyCode == 68 ||
e.keyCode == 37 ||
e.keyCode == 39) &&
!gameOver
) {
unpushCyl();
}
});
//TOUCH HANDLERS
$('body').on('touchstart', function (e) {
// console.log('touchStart', e);
if (!e.touchList) {
} else if (e.touchList) {
}
});
}); //docready
//CYL INTERACTIVITY EVENTS
function pushCyl() {
var distFromSolve, cylRotationAllowance;
clearInterval(cylRotationInterval);
userPushingCyl = true;
//set an interval based on keyrepeat that will rotate the cyl forward, and if cyl is at or past maxCylRotation based on pick distance from solve, display "bounce" anim and do damage to pick. If pick is within sweet spot params, allow pick to rotate to maxRot and trigger solve functionality
//SO...to calculate max rotation, we need to create a linear scale from solveDeg+padding to maxDistFromSolve - if the user is more than X degrees away from solve zone, they are maximally distant and the cylinder cannot travel at all. Let's start with 45deg. So...we need to create a scale and do a linear conversion. If user is at or beyond max, return 0. If user is within padding zone, return 100. Cyl may travel that percentage of maxRot before hitting the damage zone.
distFromSolve = Math.abs(pinRot - solveDeg) - solvePadding;
distFromSolve = Util.clamp(distFromSolve, maxDistFromSolve, 0);
cylRotationAllowance = Util.convertRanges(
distFromSolve,
0,
maxDistFromSolve,
1,
0.02
); //oldval is distfromsolve, oldmin is....0? oldMax is maxDistFromSolve, newMin is 100 (we are at solve, so cyl may travel 100% of maxRot), newMax is 0 (we are at or beyond max dist from solve, so cyl may not travel at all - UPDATE - must give cyl just a teensy bit of travel so user isn't hammered);
cylRotationAllowance = cylRotationAllowance * maxRot;
cylRotationInterval = setInterval(function () {
cylRot += cylRotSpeed;
if (cylRot >= maxRot) {
cylRot = maxRot;
// do happy solvey stuff
clearInterval(cylRotationInterval);
unlock();
} else if (cylRot >= cylRotationAllowance) {
cylRot = cylRotationAllowance;
// do sad pin-hurty stuff
damagePin();
}
cyl.css({
transform: 'rotateZ(' + cylRot + 'deg)',
});
driver.css({
transform: 'rotateZ(' + cylRot + 'deg)',
});
}, keyRepeatRate);
}
function unpushCyl() {
userPushingCyl = false;
//set an interval based on keyrepeat that will rotate the cyl backward, and if cyl is at or past origin, set to origin and stop.
clearInterval(cylRotationInterval);
cylRotationInterval = setInterval(function () {
cylRot -= cylRotSpeed;
cylRot = Math.max(cylRot, 0);
cyl.css({
transform: 'rotateZ(' + cylRot + 'deg)',
});
driver.css({
transform: 'rotateZ(' + cylRot + 'deg)',
});
if (cylRot <= 0) {
cylRot = 0;
clearInterval(cylRotationInterval);
}
}, keyRepeatRate);
}
//PIN AND SOLVE EVENTS
function damagePin() {
if (!pinLastDamaged || Date.now() - pinLastDamaged > pinDamageInterval) {
var tl = new TimelineLite();
pinHealth -= pinDamage;
// console.log('damagePin, pinHealth=', pinHealth);
pinLastDamaged = Date.now();
//pin damage/lock jiggle animation
tl.to(pin, pinDamageInterval / 4 / 1000, {
rotationZ: pinRot - 2,
});
tl.to(pin, pinDamageInterval / 4 / 1000, {
rotationZ: pinRot,
});
if (pinHealth <= 0) {
breakPin();
}
}
}
function breakPin() {
var tl, pinTop, pinBott;
gamePaused = true;
clearInterval(cylRotationInterval);
numPins--;
$('span').text(numPins);
pinTop = pin.find('.top');
pinBott = pin.find('.bott');
tl = new TimelineLite();
tl.to(pinTop, 0.7, {
rotationZ: -400,
x: -200,
y: -100,
opacity: 0,
});
tl.to(
pinBott,
0.7,
{
rotationZ: 400,
x: 200,
y: 100,
opacity: 0,
onComplete: function () {
if (numPins > 0) {
gamePaused = false;
reset();
} else {
outOfPins();
}
},
},
0
);
tl.play();
}
function reset() {
//solveDeg = ( Math.random() * 180 ) - 90;
cylRot = 0;
pinHealth = 100;
pinRot = 0;
pin.css({
transform: 'rotateZ(' + pinRot + 'deg)',
});
cyl.css({
transform: 'rotateZ(' + cylRot + 'deg)',
});
driver.css({
transform: 'rotateZ(' + cylRot + 'deg)',
});
TweenLite.to(pin.find('.top'), 0, {
rotationZ: 0,
x: 0,
y: 0,
opacity: 1,
});
TweenLite.to(pin.find('.bott'), 0, {
rotationZ: 0,
x: 0,
y: 0,
opacity: 1,
});
}
function outOfPins() {
gameOver = true;
// $('#lose').css('display', 'inline-block');
finish(false);
}
function unlock() {
gameOver = true;
// $('#win').css('display', 'inline-block');
finish(true);
}
//UTIL
Util = {};
Util.clamp = function (val, max, min) {
return Math.min(Math.max(val, min), max);
};
Util.convertRanges = function (OldValue, OldMin, OldMax, NewMin, NewMax) {
return ((OldValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin) + NewMin;
};
window.addEventListener('message', function (event) {
let data = event.data;
if (data.start) {
$('#wrap').show();
$('#text').show();
minRot = -90;
maxRot = 90;
solveDeg = Math.random() * 180 - 90;
solvePadding = 4;
maxDistFromSolve = 45;
pinRot = 0;
cylRot = 0;
lastMousePos = 0;
mouseSmoothing = 2;
keyRepeatRate = 25;
cylRotSpeed = 3;
pinDamage = 20;
pinHealth = 100;
pinDamageInterval = 150;
numPins = 5;
userPushingCyl = false;
gameOver = false;
gamePaused = false;
pin = $('#pin');
cyl = $('#cylinder');
driver = $('#driver');
cylRotationInterval = null;
pinLastDamaged = null;
$('span').text(numPins);
reset();
}
});
function finish(success) {
$('#wrap').hide();
$('#text').hide();
if (success) {
$.post('https://' + GetParentResourceName() + '/succeed', JSON.stringify({}));
} else {
$.post('https://' + GetParentResourceName() + '/failed', JSON.stringify({}));
}
}
document.addEventListener('keyup', keyUpHandler);
function keyUpHandler(e) {
if (e.code == 'Escape') {
$('#wrap').hide();
$('#text').hide();
$.post('https://' + GetParentResourceName() + '/close', JSON.stringify({}));
}
}

View file

@ -0,0 +1,137 @@
@import url(https://fonts.googleapis.com/css?family=Lato:400,700,300,900);
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
font-family: 'Lato', helvetica, arial, sans-serif;
}
body {
display: inline-block;
overflow: hidden;
}
#text {
display: none;
}
#wrap {
display: none;
position: relative;
width: 12%;
margin: 15% auto 5%;
overflow: visible;
}
p {
color: #fde470;
color: #2f2;
text-align: center;
font-weight: 400;
font-size: 1.2em;
padding: 0;
margin: 0.5em;
}
p.disclaimer {
position: absolute;
bottom: 0;
left: 0;
opacity: 0.5;
font-size: 0.9em;
color: #000;
font-weight: 300;
}
#collar {
display: block;
position: relative;
width: 100%;
height: 100%;
}
#cylinder {
display: block;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/95637/cylinder.png');
background-size: cover;
width: 69.914%;
height: 69.914%;
position: absolute;
top: 14.9%;
left: 15%;
}
#driver {
display: block;
width: 172.1739%;
height: 84%;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/95637/driver.png');
background-size: cover;
position: absolute;
top: 57%;
left: 46%;
transform-origin: 3% -3%;
}
#pin {
display: block;
background-size: cover;
width: 7.1304%;
height: 146.4347%;
position: absolute;
left: 47.4%;
top: -98%;
transform-origin: 50% 99%;
}
#pin .top {
display: block;
width: 100%;
height: 50%;
position: absolute;
top: 0;
left: 0;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/95637/pinTop.png');
background-size: cover;
}
#pin .bott {
display: block;
width: 100%;
height: 50%;
position: absolute;
top: 50%;
left: 0;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/95637/pinBott.png');
background-size: cover;
}
#modal {
display: none;
overflow: auto;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
text-align: center;
}
#modal div {
margin-top: 5%;
display: inline-block;
background: #fff;
border-radius: 20px;
box-sizing: border-box;
padding: 1%;
}
#modal div h1 {
margin-bottom: 0.22em;
}
#modal div h2 {
margin-top: 0;
margin-bottom: 1.5em;
font-size: 1.4em;
}
#modal div h3 {
font-size: 1.1em;
}
#modal div h4 {
font-size: 0.8em;
}
#modal #win {
display: none;
}
#modal #lose {
display: none;
}