141 lines
4.6 KiB
JavaScript
141 lines
4.6 KiB
JavaScript
"use strict";
|
|
/// <reference path="../types-gtanetwork/index.d.ts" />
|
|
API.onKeyDown.connect(function (sender, e) {
|
|
if (e.KeyCode === Keys.N) {
|
|
API.triggerServerEvent("openHandy");
|
|
}
|
|
});
|
|
var blip = null;
|
|
API.onServerEventTrigger.connect(function (eventName, args) {
|
|
if (eventName == "createClientSideBlipTime") {
|
|
var x = args[0];
|
|
var y = args[1];
|
|
var z = args[2];
|
|
var sprite = args[3];
|
|
var color = args[4];
|
|
var time = args[5];
|
|
blip = API.createBlip(new Vector3(x, y, z));
|
|
API.setBlipSprite(blip, sprite);
|
|
API.setBlipColor(blip, color);
|
|
var timer = new Timer(1000 * time, false, function () {
|
|
API.deleteEntity(blip);
|
|
});
|
|
}
|
|
else if (eventName == "createWayPoint") {
|
|
var x = args[0];
|
|
var y = args[1];
|
|
var z = args[2];
|
|
API.setWaypoint(x, y);
|
|
}
|
|
else if (eventName == "createClientBlip") {
|
|
var x = args[0];
|
|
var y = args[1];
|
|
var z = args[2];
|
|
var sprite = args[3];
|
|
var color = args[4];
|
|
blip = API.createBlip(new Vector3(x, y, z));
|
|
API.setBlipSprite(blip, sprite);
|
|
API.setBlipColor(blip, color);
|
|
}
|
|
else if (eventName == "deleteClientBlip") {
|
|
API.deleteEntity(blip);
|
|
blip = null;
|
|
} else if (eventName == "displayroute") {
|
|
var state = args[0];
|
|
API.showBlipRoute(blip,state);
|
|
} else if (eventName == "playMP3onPath") {
|
|
var path = args[0]; // String
|
|
var looped = args[1]; // Bool
|
|
API.startMusic(path,looped);
|
|
} else if(eventName == "stopMP3"){
|
|
API.stopMusic();
|
|
} else if(eventName == "loadingscreen"){
|
|
var time = args[0];
|
|
API.callNative("0x891B5B39AC6302AF", 0);
|
|
var timer = new Timer(1000 * time, false, function () {
|
|
API.callNative("0xD4E8E24955024033", 200);
|
|
});
|
|
} else if(eventName == "callSoundNative"){
|
|
API.callNative("0x67C540AA08E4A6F5",-1,args[0],args[1],0);
|
|
}
|
|
});
|
|
|
|
API.onUpdate.connect(function () {
|
|
Timer.handleTimers();
|
|
});
|
|
API.onKeyDown.connect(function (sender, args) {
|
|
if (args.KeyCode == Keys.I) {
|
|
API.triggerServerEvent("InventoryKeyPressed");
|
|
}
|
|
});
|
|
var Timer = (function () {
|
|
function Timer(interval, repeating, callback) {
|
|
this.interval = interval;
|
|
this.repeating = repeating;
|
|
this.createdAt = API.getGlobalTime();
|
|
this.callback = callback;
|
|
this.repeatedIterations = 1;
|
|
Timer.Timers.push(this);
|
|
}
|
|
Timer.prototype.getNextTickTime = function () {
|
|
if (!this.repeating) {
|
|
return this.createdAt + this.interval;
|
|
}
|
|
else {
|
|
return (this.createdAt + (this.interval * this.repeatedIterations));
|
|
}
|
|
};
|
|
Timer.prototype.stop = function () {
|
|
var index = Timer.Timers.indexOf(this);
|
|
Timer.Timers.splice(index, 1);
|
|
};
|
|
Timer.handleTimers = function () {
|
|
/* Handle all timers */
|
|
var currentGameTime = API.getGlobalTime();
|
|
for (var i = 0; i < Timer.Timers.length; i++) {
|
|
if (currentGameTime >= Timer.Timers[i].getNextTickTime()) {
|
|
Timer.Timers[i].callback();
|
|
if (Timer.Timers[i].repeating) {
|
|
Timer.Timers[i].repeatedIterations += 1;
|
|
}
|
|
else {
|
|
Timer.Timers.splice(i, 1);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
return Timer;
|
|
}());
|
|
Timer.Timers = [];
|
|
var clientapimarker = null;
|
|
API.onServerEventTrigger.connect(function (eventName, args) {
|
|
if (eventName == "display_subtitle") {
|
|
API.displaySubtitle(args[0], args[1]);
|
|
}
|
|
else if (eventName == "display_shard") {
|
|
API.showShard(args[0], args[1]);
|
|
}
|
|
else if (eventName == "set_marker_color") {
|
|
API.setMarkerColor(args[0], 30, args[1], args[2], args[3]);
|
|
}
|
|
else if (eventName == "set_blip_color") {
|
|
API.setBlipColor(args[0], args[1]);
|
|
}
|
|
else if (eventName == "play_sound") {
|
|
API.playSoundFrontEnd(args[0], args[1]);
|
|
} else if(eventName == "ClientAPICreateMarker"){
|
|
var markertype = args[0];
|
|
var posX = args[1];
|
|
var posY = args[2];
|
|
var posZ = args[3];
|
|
var size = args[4];
|
|
var r = args[5];
|
|
var g = args[6];
|
|
var b = args[7];
|
|
var a = args[8];
|
|
clientapimarker = API.createMarker(markertype,new Vector3(posX,posY,posZ), new Vector3(0,0,0), new Vector3(0,0,0),new Vector3(size,size,size),r,g,b,a);
|
|
} else if(eventName == "ClientAPIDeleteMarker"){
|
|
API.deleteEntity(clientapimarker);
|
|
clientapimarker = null;
|
|
}
|
|
});
|