Advertisement
glitchdetector

PlayRustIO Map Modification

Apr 6th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var socket;
  2. var dropCount = 0;
  3. var clanHomes = "http://pastebin.com/raw/X368aBh3";
  4.  
  5. function newConnect() {
  6.    
  7.     if (typeof WebSocket == "undefined") {
  8.         alert(_("Sorry, your browser does not support WebSockets. Please consider an upgrade to use RustWeb!"));
  9.         return;
  10.     }
  11.     console.log("[RLRC] connecting to websocket ...");
  12.     socket = connect.socket = new WebSocket("ws://" + endpoint + "/ms");
  13.     socket.onopen = function() {
  14.         console.log("[RLRC] connected to websocket");
  15.     }
  16.     socket.onmessage = function(e) {
  17.         var msg = e.data,
  18.             cmd, data;
  19.         var p = msg.indexOf(" ");
  20.         if (p < 0) {
  21.             cmd = msg;
  22.             data = null;
  23.         } else {
  24.             cmd = msg.substring(0, p);
  25.             data = JSON.parse(msg.substring(p + 1));
  26.         }
  27.         console.log("[RLRC Command] " + cmd + "");
  28.        
  29.         switch (cmd) {
  30.             case "plane.drop":
  31.                 console.log("[RLRC] Plane Drop at " + data);
  32.                 updateDropLocation(cmd, data);
  33.                 break;
  34.             case "ping":
  35.                 console.log("[RLRC] ping");
  36.                 break;
  37.             default:
  38.                 break;
  39.         }
  40.     }
  41. }
  42.  
  43. newConnect();
  44.  
  45.  
  46.  
  47. function updateDropLocation(type, data) {
  48.     var loc, pos = worldToMap(data),
  49.         rot, elem;
  50.     var key, name, img;
  51.     key = "loot";
  52.     name = _("Drop");
  53.     img = "http://i.imgur.com/EAebaHz.png";
  54.     rot = 0;
  55.     data.id = 54461337 + dropCount;
  56.     dropCount += 1;
  57.     if (!locations.hasOwnProperty(data.id)) {
  58.         if (data.k)
  59.             return;
  60.         if (inBounds(pos)) {
  61.             console.log("[RLRC] Creating " + key + ": " + data.id);
  62.             sound("drop");
  63.             $landmarks.append(elem = $('<img class="' + key + '" alt="" id="' + key + '-' + data.id + '" />'));
  64.             elem.prop("title", name);
  65.             elem.prop("src", img);
  66.             elem.css({
  67.                 width: iconSize + "px",
  68.                 left: (pos.x - iconSize / 2) + "px",
  69.                 top: (pos.y - iconSize / 2) + "px",
  70.                 transform: "rotate(" + rot + "deg)",
  71.                 zIndex: 200
  72.             });
  73.             elem.bind("mousedown", function(evt) {
  74.                 evt.stopPropagation();
  75.             });
  76.             loc = locations[data.id] = {};
  77.             loc.type = key;
  78.             loc.id = data.id;
  79.             loc.pos = pos;
  80.             loc.rot = rot;
  81.             loc.time = Date.now();
  82.             loc.elem = elem;
  83.             setTimeout(function(){
  84.                 console.log("[RLRC] Removing " + key + ": " + data.id);
  85.                 loc.elem.remove();
  86.                 delete locations[data.id];
  87.                 }, 15 * (60 * 1000));
  88.         }
  89.     } else {
  90.         loc = locations[data.id];
  91.         if (inBounds(pos) && !data.k) {
  92.             loc.time = Date.now();
  93.             var realRot = rot;
  94.             var diff = loc.rot - rot;
  95.             if (diff > 180)
  96.                 rot += 360;
  97.             else if (diff < -180)
  98.                 rot -= 360;
  99.             loc.elem.transition({
  100.                 "left": (pos.x - iconSize / 2) + "px",
  101.                 "top": (pos.y - iconSize / 2) + "px",
  102.                 "rotate": rot + "deg"
  103.             }, 990, "linear", function() {
  104.                 loc.elem.css({
  105.                     "transform": "rotate(" + realRot + "deg)"
  106.                 });
  107.             });
  108.             loc.pos = pos;
  109.             loc.rot = realRot;
  110.         } else {
  111.             console.log("[RLRC] Removing " + key + ": " + data.id);
  112.             loc.elem.remove();
  113.             delete locations[data.id];
  114.         }
  115.     }
  116. }
  117.  
  118. function updateSpecialLocation(type, data) {
  119.     var loc, pos = worldToMap(data),
  120.         rot = data.r,
  121.         elem;
  122.     var key, name, img;
  123.     if (type === "p") {
  124.         key = "plane";
  125.         name = _("Plane");
  126.         img = "img/plane.png";
  127.     } else {
  128.         key = "helicopter";
  129.         name = _("Helicopter");
  130.         img = "img/heli.gif";
  131.         rot += 180;
  132.     }
  133.     if (!locations.hasOwnProperty(data.id)) {
  134.         if (data.k)
  135.             return;
  136.         if (inBounds(pos)) {
  137.             console.log("[RLRC] Creating " + key + ": " + data.id);
  138.             switch (type) {
  139.                 case "p":
  140.                     sound("plane");
  141.                     break;
  142.                 case "h":
  143.                     sound("heli");
  144.                     break;
  145.             }
  146.             $landmarks.append(elem = $('<img class="' + key + '" alt="" id="' + key + '-' + data.id + '" />'));
  147.             elem.prop("title", name);
  148.             elem.prop("src", img);
  149.             elem.css({
  150.                 width: iconSize + "px",
  151.                 left: (pos.x - iconSize / 2) + "px",
  152.                 top: (pos.y - iconSize / 2) + "px",
  153.                 transform: "rotate(" + rot + "deg)",
  154.                 zIndex: 200
  155.             });
  156.             elem.bind("mousedown", function(evt) {
  157.                 evt.stopPropagation();
  158.             });
  159.             loc = locations[data.id] = {};
  160.             loc.type = key;
  161.             loc.id = data.id;
  162.             loc.pos = pos;
  163.             loc.rot = rot;
  164.             loc.time = Date.now();
  165.             loc.elem = elem;
  166.         }
  167.     } else {
  168.         loc = locations[data.id];
  169.         if (inBounds(pos) && !data.k) {
  170.             loc.time = Date.now();
  171.             var realRot = rot;
  172.             var diff = loc.rot - rot;
  173.             if (diff > 180)
  174.                 rot += 360;
  175.             else if (diff < -180)
  176.                 rot -= 360;
  177.             loc.elem.transition({
  178.                 "left": (pos.x - iconSize / 2) + "px",
  179.                 "top": (pos.y - iconSize / 2) + "px",
  180.                 "rotate": rot + "deg"
  181.             }, 990, "linear", function() {
  182.                 loc.elem.css({
  183.                     "transform": "rotate(" + realRot + "deg)"
  184.                 });
  185.             });
  186.             loc.pos = pos;
  187.             loc.rot = realRot;
  188.         } else {
  189.             console.log("[RLRC] Removing " + key + ": " + data.id);
  190.             loc.elem.remove();
  191.             delete locations[data.id];
  192.         }
  193.     }
  194. }
  195.  
  196. function sound(type) {
  197.     var file = "";
  198.     switch (type) {
  199.         case "info":
  200.             file = "http://soundbible.com/mp3/Industrial%20Alarm-SoundBible.com-1012301296.mp3";
  201.             break;
  202.         case "warning":
  203.             file = "http://static1.grsites.com/archive/sounds/emergency/emergency029.mp3";
  204.             break;
  205.         case "heli":
  206.             file = "http://static1.grsites.com/archive/sounds/emergency/emergency029.mp3";
  207.             break;
  208.         case "plane":
  209.             file = "http://soundbible.com/mp3/Industrial%20Alarm-SoundBible.com-1012301296.mp3";
  210.             break;
  211.         case "drop":
  212.             file = "http://www.flashkit.com/imagesvr_ce/flashkit/soundfx/Electronic/Arcade/Arcade_S-wwwbeat-8530/Arcade_S-wwwbeat-8530_hifi.mp3";
  213.             break;
  214.         default:
  215.             file = "http://soundbible.com/mp3/Industrial%20Alarm-SoundBible.com-1012301296.mp3";
  216.             break;
  217.     }
  218.     var audio = new Audio(file);
  219.     audio.play();
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement