Ragemp-roleplay-skript/Environment/mobile.ts
2019-04-16 13:59:07 +02:00

138 lines
4 KiB
TypeScript

/// <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, () => {
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);
}
});
API.onUpdate.connect(function () {
Timer.handleTimers();
});
API.onKeyDown.connect(function (sender, args) {
if (args.KeyCode == Keys.I) {
API.triggerServerEvent("InventoryKeyPressed");
}
});
class Timer {
static Timers = [];
interval: number;
repeating: boolean;
createdAt: number;
repeatedIterations: number;
callback: () => void;
constructor(interval: number, repeating: boolean, callback: () => void) {
this.interval = interval;
this.repeating = repeating;
this.createdAt = API.getGlobalTime();
this.callback = callback;
this.repeatedIterations = 1;
Timer.Timers.push(this);
}
getNextTickTime() {
if (!this.repeating) {
return this.createdAt + this.interval;
} else {
return (this.createdAt + (this.interval * this.repeatedIterations));
}
}
stop() {
var index = Timer.Timers.indexOf(this);
Timer.Timers.splice(index, 1);
}
static handleTimers() {
/* 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);
}
}
}
}
}
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;
}
}
});