Advertisement
dimden

Portal script

Dec 31st, 2019
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // make me a new year gift
  2.  
  3. if(!window.Players) {
  4.     Players = {};
  5.    
  6.     OWOP.on(26, up => {
  7.         for(let p in up) Players[p] = {
  8.                 id: p,
  9.                 x: (up[p].x >> 4) | 0,
  10.                 y: (up[p].y >> 4) | 0,
  11.                 color: up[p].rgb,
  12.                 tool: up[p].tool
  13.             }
  14.     });
  15.     OWOP.on(27, up => {
  16.         for(let p of up) delete Players[p];
  17.     })
  18. };
  19. teleporting = {};
  20. teleported  = {};
  21.  
  22. function makePortal(x, y, r, x2, y2) {
  23.     OWOP.chat.local(`Created portal at ${x}, ${y} and ${x2}, ${y2} with size of ${r}x${r}`);
  24.     OWOP.on(26, up => {
  25.         for(let p in up) {
  26.             if(teleporting[p]) continue;
  27.             let pl = Players[p];
  28.             if(x-r <= pl.x && x+r >= pl.x && y-r <= pl.y && y+r >= pl.y) {
  29.                 setTimeout(() => {
  30.                     pl = Players[p];
  31.                     if(x-r <= pl.x && x+r >= pl.x && y-r <= pl.y && y+r >= pl.y) {
  32.                         if(teleported[p]) return;
  33.                         OWOP.chat.send(`/tp ${pl.id} ${x2} ${y2}`);
  34.                         teleported[p] = 1;
  35.                     } else delete teleported[p];
  36.                     delete teleporting[p];
  37.                 }, 1000);
  38.                 teleporting[p] = 1;
  39.             };
  40.             if(x2-r <= pl.x && x2+r >= pl.x && y2-r <= pl.y && y2+r >= pl.y) {
  41.                 setTimeout(() => {
  42.                     pl = Players[p];
  43.                     if(x2-r <= pl.x && x2+r >= pl.x && y2-r <= pl.y && y2+r >= pl.y) {
  44.                         if(teleported[p]) return;
  45.                         OWOP.chat.send(`/tp ${pl.id} ${x} ${y}`);
  46.                         teleported[p] = 1;
  47.                     } else delete teleported[p];
  48.                     delete teleporting[p];
  49.                 }, 1000);
  50.                 teleporting[p] = 1;
  51.             };
  52.             // ik bug
  53.             if(!(x-r <= pl.x && x+r >= pl.x && y-r <= pl.y && y+r >= pl.y) || !(x2-r <= pl.x && x2+r >= pl.x && y2-r <= pl.y && y2+r >= pl.y)) delete teleported[p];
  54.         };
  55.     });
  56. };
  57.  
  58. oldCh = OWOP.chat.sendModifier;
  59. OWOP.chat.sendModifier = msg => {
  60.     msg = oldCh(msg);
  61.     if(msg.startsWith("/portal")) {
  62.         let args = msg.split(" ").slice(1);
  63.         if(args.length < 5) OWOP.chat.local("Command usage: /portal x y size x_dest y_dest");
  64.         else makePortal(...args.map(i => +i));
  65.         msg = "/";
  66.     };
  67.     return msg;
  68. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement