Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var socket;
- var dropCount = 0;
- var clanHomes = "http://pastebin.com/raw/X368aBh3";
- function newConnect() {
- if (typeof WebSocket == "undefined") {
- alert(_("Sorry, your browser does not support WebSockets. Please consider an upgrade to use RustWeb!"));
- return;
- }
- console.log("[RLRC] connecting to websocket ...");
- socket = connect.socket = new WebSocket("ws://" + endpoint + "/ms");
- socket.onopen = function() {
- console.log("[RLRC] connected to websocket");
- }
- socket.onmessage = function(e) {
- var msg = e.data,
- cmd, data;
- var p = msg.indexOf(" ");
- if (p < 0) {
- cmd = msg;
- data = null;
- } else {
- cmd = msg.substring(0, p);
- data = JSON.parse(msg.substring(p + 1));
- }
- console.log("[RLRC Command] " + cmd + "");
- switch (cmd) {
- case "plane.drop":
- console.log("[RLRC] Plane Drop at " + data);
- updateDropLocation(cmd, data);
- break;
- case "ping":
- console.log("[RLRC] ping");
- break;
- default:
- break;
- }
- }
- }
- newConnect();
- function updateDropLocation(type, data) {
- var loc, pos = worldToMap(data),
- rot, elem;
- var key, name, img;
- key = "loot";
- name = _("Drop");
- img = "http://i.imgur.com/EAebaHz.png";
- rot = 0;
- data.id = 54461337 + dropCount;
- dropCount += 1;
- if (!locations.hasOwnProperty(data.id)) {
- if (data.k)
- return;
- if (inBounds(pos)) {
- console.log("[RLRC] Creating " + key + ": " + data.id);
- sound("drop");
- $landmarks.append(elem = $('<img class="' + key + '" alt="" id="' + key + '-' + data.id + '" />'));
- elem.prop("title", name);
- elem.prop("src", img);
- elem.css({
- width: iconSize + "px",
- left: (pos.x - iconSize / 2) + "px",
- top: (pos.y - iconSize / 2) + "px",
- transform: "rotate(" + rot + "deg)",
- zIndex: 200
- });
- elem.bind("mousedown", function(evt) {
- evt.stopPropagation();
- });
- loc = locations[data.id] = {};
- loc.type = key;
- loc.id = data.id;
- loc.pos = pos;
- loc.rot = rot;
- loc.time = Date.now();
- loc.elem = elem;
- setTimeout(function(){
- console.log("[RLRC] Removing " + key + ": " + data.id);
- loc.elem.remove();
- delete locations[data.id];
- }, 15 * (60 * 1000));
- }
- } else {
- loc = locations[data.id];
- if (inBounds(pos) && !data.k) {
- loc.time = Date.now();
- var realRot = rot;
- var diff = loc.rot - rot;
- if (diff > 180)
- rot += 360;
- else if (diff < -180)
- rot -= 360;
- loc.elem.transition({
- "left": (pos.x - iconSize / 2) + "px",
- "top": (pos.y - iconSize / 2) + "px",
- "rotate": rot + "deg"
- }, 990, "linear", function() {
- loc.elem.css({
- "transform": "rotate(" + realRot + "deg)"
- });
- });
- loc.pos = pos;
- loc.rot = realRot;
- } else {
- console.log("[RLRC] Removing " + key + ": " + data.id);
- loc.elem.remove();
- delete locations[data.id];
- }
- }
- }
- function updateSpecialLocation(type, data) {
- var loc, pos = worldToMap(data),
- rot = data.r,
- elem;
- var key, name, img;
- if (type === "p") {
- key = "plane";
- name = _("Plane");
- img = "img/plane.png";
- } else {
- key = "helicopter";
- name = _("Helicopter");
- img = "img/heli.gif";
- rot += 180;
- }
- if (!locations.hasOwnProperty(data.id)) {
- if (data.k)
- return;
- if (inBounds(pos)) {
- console.log("[RLRC] Creating " + key + ": " + data.id);
- switch (type) {
- case "p":
- sound("plane");
- break;
- case "h":
- sound("heli");
- break;
- }
- $landmarks.append(elem = $('<img class="' + key + '" alt="" id="' + key + '-' + data.id + '" />'));
- elem.prop("title", name);
- elem.prop("src", img);
- elem.css({
- width: iconSize + "px",
- left: (pos.x - iconSize / 2) + "px",
- top: (pos.y - iconSize / 2) + "px",
- transform: "rotate(" + rot + "deg)",
- zIndex: 200
- });
- elem.bind("mousedown", function(evt) {
- evt.stopPropagation();
- });
- loc = locations[data.id] = {};
- loc.type = key;
- loc.id = data.id;
- loc.pos = pos;
- loc.rot = rot;
- loc.time = Date.now();
- loc.elem = elem;
- }
- } else {
- loc = locations[data.id];
- if (inBounds(pos) && !data.k) {
- loc.time = Date.now();
- var realRot = rot;
- var diff = loc.rot - rot;
- if (diff > 180)
- rot += 360;
- else if (diff < -180)
- rot -= 360;
- loc.elem.transition({
- "left": (pos.x - iconSize / 2) + "px",
- "top": (pos.y - iconSize / 2) + "px",
- "rotate": rot + "deg"
- }, 990, "linear", function() {
- loc.elem.css({
- "transform": "rotate(" + realRot + "deg)"
- });
- });
- loc.pos = pos;
- loc.rot = realRot;
- } else {
- console.log("[RLRC] Removing " + key + ": " + data.id);
- loc.elem.remove();
- delete locations[data.id];
- }
- }
- }
- function sound(type) {
- var file = "";
- switch (type) {
- case "info":
- file = "http://soundbible.com/mp3/Industrial%20Alarm-SoundBible.com-1012301296.mp3";
- break;
- case "warning":
- file = "http://static1.grsites.com/archive/sounds/emergency/emergency029.mp3";
- break;
- case "heli":
- file = "http://static1.grsites.com/archive/sounds/emergency/emergency029.mp3";
- break;
- case "plane":
- file = "http://soundbible.com/mp3/Industrial%20Alarm-SoundBible.com-1012301296.mp3";
- break;
- case "drop":
- file = "http://www.flashkit.com/imagesvr_ce/flashkit/soundfx/Electronic/Arcade/Arcade_S-wwwbeat-8530/Arcade_S-wwwbeat-8530_hifi.mp3";
- break;
- default:
- file = "http://soundbible.com/mp3/Industrial%20Alarm-SoundBible.com-1012301296.mp3";
- break;
- }
- var audio = new Audio(file);
- audio.play();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement