Skip to content

Instantly share code, notes, and snippets.

@Stuyk
Created March 23, 2020 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stuyk/eaf4c9aa908d069c74a8ee24b36a55e8 to your computer and use it in GitHub Desktop.
Save Stuyk/eaf4c9aa908d069c74a8ee24b36a55e8 to your computer and use it in GitHub Desktop.
Shooting Range Job Framework
import * as alt from 'alt';
import { Interaction } from '../systems/interaction.js';
import { Job, Objectives, ObjectiveFlags } from '../systems/job.js';
import { PedStream } from '../systems/pedstream.js';
import { distance } from '../utility/vector.js';
import { addXP } from '../systems/skills.js';
import { shuffle } from '../utility/array.js';
let bestTime = null;
let bestTimeOwner = null;
const jobIdentifier = 'job:ShootingRange1';
alt.onClient(jobIdentifier, startJob);
alt.on('job:Complete', completedJob);
alt.on('job:ObjectiveComplete', completedObjective);
const positions = [
{
x: 20.004396438598633,
y: -1090.6549072265625,
z: 29.785400390625
},
{
x: 16.483516693115234,
y: -1089.217529296875,
z: 29.785400390625
},
{
x: 12.98901081085205,
y: -1088.08349609375,
z: 29.785400390625
},
{
x: 11.472527503967285,
y: -1090.892333984375,
z: 29.785400390625
},
{
x: 14.756044387817383,
y: -1092.11865234375,
z: 29.785400390625
},
{
x: 19.85934066772461,
y: -1093.96484375,
z: 29.785400390625
},
{
x: 22.101099014282227,
y: -1086.25048828125,
z: 29.785400390625
},
{
x: 19.925275802612305,
y: -1085.3538818359375,
z: 29.785400390625
},
{
x: 17.538461685180664,
y: -1084.4571533203125,
z: 29.785400390625
},
{
x: 13.978022575378418,
y: -1083.3099365234375,
z: 29.785400390625
},
{
x: 15.283516883850098,
y: -1079.024169921875,
z: 29.785400390625
},
{
x: 19.120880126953125,
y: -1080.052734375,
z: 29.785400390625
},
{
x: 22.285715103149414,
y: -1081.3319091796875,
z: 29.785400390625
},
{
x: 24.55384635925293,
y: -1082.18896484375,
z: 29.785400390625
},
{
x: 25.516483306884766,
y: -1079.221923828125,
z: 29.785400390625
},
{
x: 22.5230770111084,
y: -1077.164794921875,
z: 29.785400390625
},
{
x: 18.58022117614746,
y: -1075.8330078125,
z: 29.785400390625
},
{
x: 16.074726104736328,
y: -1074.896728515625,
z: 29.785400390625
},
{
x: 16.826374053955078,
y: -1071.9296875,
z: 29.785400390625
},
{
x: 19.96483612060547,
y: -1072.3780517578125,
z: 29.785400390625
},
{
x: 22.44395637512207,
y: -1073.3802490234375,
z: 29.785400390625
},
{
x: 24.949451446533203,
y: -1074.2637939453125,
z: 29.785400390625
},
{
x: 28.02198028564453,
y: -1075.120849609375,
z: 29.785400390625
},
{
x: 28.153846740722656,
y: -1071.8505859375,
z: 29.785400390625
},
{
x: 23.789011001586914,
y: -1070.756103515625,
z: 29.785400390625
},
{
x: 21.309890747070312,
y: -1069.8330078125,
z: 29.785400390625
},
{
x: 18.870330810546875,
y: -1068.962646484375,
z: 29.785400390625
}
];
const startPoint = { x: 17.665916442871094, y: -1100.62744140625, z: 29.796998977661133 };
const pedStream = new PedStream('u_m_y_chip', startPoint, 85.15, 'Shooting Range');
pedStream.addInteraction({
name: 'Train Shooting',
isServer: true,
eventName: jobIdentifier,
data: {}
});
pedStream.addGreeting('Train your shooting?');
function startJob(player) {
if (distance(player.pos, startPoint) >= 5) {
return;
}
if (!player.equipment[11]) {
player.send('You must have a weapon to use the shooting range.');
return;
}
if (!player.equipment[11].base.includes('weapon')) {
player.send('You must have a weapon to use the shooting range.');
return;
}
const objectives = [];
const newPositions = shuffle([...positions]);
newPositions.forEach(pos => {
const shootObjective = new Objectives.DestroyObject(pos, 50, 1, {
r: 255,
g: 255,
b: 255,
a: 75
});
shootObjective.setOptions({
description: 'Shoot the target.',
blip: { sprite: 1, color: 1, description: 'Shoot the target.' },
maxProgress: 1,
objectType: 'gr_prop_gr_target_02a',
objectAlpha: 255
});
objectives.push(shootObjective);
});
new Job(player, jobIdentifier, [...objectives]);
player.job.start();
player.shootingRangeStartTime = Date.now();
}
function completedJob(identifier, player) {
if (jobIdentifier !== identifier) {
return;
}
addXP(player, 'shooting', 65);
player.send('{FFFF00} Round Complete!');
const totalTime = new Date(Date.now() - player.shootingRangeStartTime);
player.shootingRangeStartTime = null;
if (!bestTime) {
bestTime = totalTime;
bestTimeOwner = `${player.data.name}`;
player.send('Congratulations you have the best shooting range time today!');
player.send(`${totalTime.getMinutes()} minutes ${totalTime.getSeconds()} seconds`);
return;
}
if (totalTime < bestTime) {
bestTime = totalTime;
bestTimeOwner = `${player.data.name}`;
player.send('Congratulations you have the beat the best time today!');
player.send(`${totalTime.getMinutes()} minutes ${totalTime.getSeconds()} seconds`);
return;
}
const timeData = `${totalTime.getMinutes()} minutes ${totalTime.getSeconds()} seconds`;
player.send(`Best Time Owner: ${bestTimeOwner} @ ${timeData}`);
}
function completedObjective(identifier, objective, player) {
if (jobIdentifier !== identifier) {
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment