Advertisement
Guest User

Untitled

a guest
Nov 16th, 2016
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. "use strict";
  2.  
  3. // functions to translate string array into hashes array (not default)
  4. // функция для преобразования массива строк в массив хешей игры. Она не является стандартной для RAGE Multiplayer, но она весьма полезна
  5. mp.hashify = hashes =>
  6. {
  7. var dst = [];
  8. hashes.forEach(hash => { dst.push(mp.joaat(hash)); });
  9. return dst;
  10. };
  11.  
  12. var game =
  13. {
  14. spawns: [new mp.Vector3(2140.15454, 4783.173, 40.4812241), new mp.Vector3(2133.27148, 4777.55, 40.4814262),
  15. new mp.Vector3(2019.19739, 4763.39746, 40.62057), new mp.Vector3(2027.80859, 4749.584, 40.7290535)],
  16.  
  17. models: mp.hashify(["mp_m_weed_01", "mp_m_forgery_01", "mp_f_weed_01", "mp_f_chbar_01", "ig_johnnyklebitz",
  18. "player_two", "ig_nervousron", "ig_wade", "ig_floyd", "ig_chef"]),
  19.  
  20. weapons: mp.hashify(["WEAPON_PISTOL", "WEAPON_ASSAULTRIFLE","WEAPON_SAWNOFFSHOTGUN","WEAPON_COMPACTRIFLE"])
  21. };
  22.  
  23. mp.environment.weather = 'HALLOWEEN';
  24. mp.environment.time.hour = 23;
  25.  
  26. // добавим словарь причин смертей, чтобы преобразовывать хеши в строки
  27. var g_reasons = {};
  28.  
  29. function InitReasons(arr)
  30. {
  31. arr.forEach(reason => { g_reasons[mp.joaat(reason)] = reason.substr(7); });
  32. }
  33.  
  34. InitReasons(["WEAPON_PISTOL", "WEAPON_ASSAULTRIFLE","WEAPON_SAWNOFFSHOTGUN","WEAPON_COMPACTRIFLE"]);
  35.  
  36. // Добавим события
  37. mp.events.add(
  38. {
  39. "playerJoin" : player =>
  40. {
  41. // присвоим игроку случайную модель
  42. player.model = game.models[Math.floor(Math.random() * game.models.length)]
  43.  
  44. // выдадим все оружие, которое указано в массиве game.weapons
  45. game.weapons.forEach(weapon => { player.giveWeapon(weapon, 10000); });
  46.  
  47. // заспавним в одной из точек, указанных в game.spawns
  48. player.spawn(game.spawns[Math.floor(Math.random() * game.spawns.length)]);
  49.  
  50. player.kills = 0;
  51. },
  52.  
  53. "playerDeath" : (player, reason, killer) =>
  54. {
  55. if(killer != null)
  56. {
  57. killer.kills++;
  58.  
  59. // узнаем причину, так как reason - хеш причины
  60. var str = g_reasons[reason];
  61.  
  62. if(str != undefined)
  63. {
  64. str = player.name + "(" + player.kills + ")" + " [" + str + "] " + killer.name + "(" + killer.kills + ")";
  65. mp.players.forEach(_player => { _player.outputChatBox(str); });
  66. }
  67. }
  68.  
  69. player.spawn(game.spawns[Math.floor(Math.random() * game.spawns.length)]);
  70. },
  71.  
  72. "playerQuit" : (player, reason, kickReason) =>
  73. {
  74. const str = player.name + " quit";
  75. mp.players.forEach(_player => { _player.outputChatBox(str); });
  76. },
  77.  
  78. "playerChat": (player, text) =>
  79. {
  80. // мы можем использовать html-теги в чате, так как он сделан на HTML (cef),
  81. // используем тег выделения для выделения количества убийств у каждого
  82. const str = player.name + "<b>(" + player.kills + ")</b>: " + text;
  83.  
  84. // отправим сообщение всем игрокам
  85. mp.players.forEach(_player => { _player.outputChatBox(str); });
  86. },
  87.  
  88. "playerCommand": (player, cmd) =>
  89. {
  90. if(cmd == "pos")
  91. {
  92. var pos = player.position;
  93. player.outputChatBox("X: <b>" + pos.x + "</b>, Y: <b>" + pos.y + "</b>, Z: <b>" + pos.z + "</b>");
  94. }
  95. else if(cmd.search("veh") != -1)
  96. {
  97. var pos = player.position;
  98. pos.x += 2.0;
  99.  
  100. // добавим созданную машину в массив createdVehs, чтобы контролировать в дальнейшем количество
  101. // созданных игроками машин
  102. createdVehs.push(new mp.Vehicle(mp.joaat(cmd.substr(4)), pos));
  103. }
  104. else if(cmd.search("setweather") != -1)
  105. {
  106. mp.environment.weather = cmd.substr(11);
  107. }
  108. else if(cmd.search("settime") != -1)
  109. {
  110. mp.environment.time.hour = parseInt(cmd.substr(8));
  111. }
  112. }
  113. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement