From f43a080a84cf93dc07d87e4a382b3ee264181d0b Mon Sep 17 00:00:00 2001 From: VortrexFTW Date: Sun, 6 Sep 2020 11:27:19 -0500 Subject: [PATCH] Handle blips sent to client --- scripts/client/main.js | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/scripts/client/main.js b/scripts/client/main.js index 5d3a0142..b939995c 100644 --- a/scripts/client/main.js +++ b/scripts/client/main.js @@ -8,6 +8,9 @@ // TYPE: Client (JavaScript) // =========================================================================== +let allServerBlips = []; +let currentServerBlips = []; + addNetworkHandler("ag.connectCamera", function(cameraPosition, cameraLookat) { gta.fadeCamera(true); gta.setCameraLookAt(cameraPosition, cameraLookat, true); @@ -86,3 +89,56 @@ addEventHandler("onElementStreamIn", function(event, element) { // --------------------------------------------------------------------------- +addNetworkHandler("ag.blips", function(blipData) { + for(let i in blipData) { + allServerBlips.push(blipData); + } +}); + +// --------------------------------------------------------------------------- + +function showIslandBlips() { + for(let i in allServerBlips) { + let position = new Vec3(allServerBlips[i][1], allServerBlips[i][2], allServerBlips[i][3]); + if(getIslandFromPosition(position) == getIslandFromPosition(localPlayer.position)) { + let tempBlip = createBlip(position, allServerBlips[i][0], allServerBlips[i][4], allServerBlips[i][5]); + currentServerBlips.push(tempBlip); + } + } +} + +// --------------------------------------------------------------------------- + +function getIslandFromPosition(position) { + switch(gta.game) { + case GAME_GTA_III: + if(position.x > 616) { + return 1; + } else if(position.x < -283) { + return 3; + } + return 2; + + default: + return 0; + } +} + +// --------------------------------------------------------------------------- + +addEventHandler("onPedSpawn", function(event, ped) { + console.log("localPlayer: " + localPlayer); + + // Nasty workaround since localPlayer is null as the player spawns (reported as client bug #194) + setTimeout(attemptToShowBlipsOnSpawn, 500, ped); +}); + +// --------------------------------------------------------------------------- + +function attemptToShowBlipsOnSpawn(ped) { + if(ped == localPlayer) { + showIslandBlips(); + } +} + +// --------------------------------------------------------------------------- \ No newline at end of file