Advertisement
Shamba

Ability Manager

Nov 27th, 2022
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.22 KB | Gaming | 0 0
  1. -- Abilities
  2. local function Mirage(player)
  3.     print("Enabling Mirage by : ", player.EntityId)
  4.     YaDisplayObjectAPI.SetVisibility(player, false)
  5.     local timer = YaTime:WaitFor(5)
  6.     EventHelper.AddListener(timer, "TimeEvent", function ()
  7.         YaDisplayObjectAPI.SetVisibility(player, true)
  8.     end)
  9. end
  10.  
  11. local function Octane(player)
  12.     print("Enabling Octane by : ", player.EntityId)
  13.     local walk_speed = YaCharacterAPI.Instance(player):GetWalkMaxSpeed()
  14.     local run_speed = YaCharacterAPI.Instance(player):GetRunMaxSpeed()
  15.  
  16.     YaCharacterAPI.Instance(player):SetWalkMaxSpeed(8)
  17.     YaCharacterAPI.Instance(player):SetRunMaxSpeed(8)
  18.  
  19.     local timer = YaTime:WaitFor(5)
  20.     EventHelper.AddListener(timer, "TimeEvent", function ()
  21.         YaCharacterAPI.Instance(player):SetWalkMaxSpeed(walk_speed)
  22.         YaCharacterAPI.Instance(player):SetRunMaxSpeed(run_speed)
  23.     end)
  24. end
  25.  
  26. local function Tracer(player)
  27.     print("Enabling Tracer by : ", player.EntityId)
  28.     local walk_speed = YaCharacterAPI.Instance(player):GetWalkMaxSpeed()
  29.     local run_speed = YaCharacterAPI.Instance(player):GetRunMaxSpeed()
  30.  
  31.     YaCharacterAPI.Instance(player):SetWalkMaxSpeed(100)
  32.     YaCharacterAPI.Instance(player):SetRunMaxSpeed(100)
  33.  
  34.     local timer = YaTime:WaitFor(0.1)
  35.     EventHelper.AddListener(timer, "TimeEvent", function ()
  36.         YaCharacterAPI.Instance(player):SetWalkMaxSpeed(walk_speed)
  37.         YaCharacterAPI.Instance(player):SetRunMaxSpeed(run_speed)
  38.     end)
  39. end
  40.  
  41. -- Ability assignment
  42. local PlayerNums = 0
  43.  
  44. local AbilityTable = {}
  45. for i = 1, 6 do
  46.     AbilityTable[i] = {}
  47. end
  48.  
  49. AbilityTable[1][1] = "Mirage"
  50. AbilityTable[2][1] = "Octane"
  51. AbilityTable[3][1] = "Tracer"
  52. AbilityTable[4][1] = "Mirage"
  53. AbilityTable[5][1] = "Octane"
  54. AbilityTable[6][1] = "Tracer"
  55.  
  56. local AssignArray = {}
  57. for i = 1, 6 do
  58.     AssignArray[i] = i
  59. end
  60.  
  61. local function Assign(avatar_ent)
  62.     math.randomseed(os.time())
  63. ---@diagnostic disable-next-line: deprecated
  64.     local arSize = table.getn(AssignArray)
  65.     local rand = math.random(1, arSize)
  66.     local assignPos = table.remove(AssignArray, rand)
  67.     AbilityTable[assignPos][2] = avatar_ent.EntityId
  68.     print("Assigned ability to player ", avatar_ent.EntityId, " with ", AbilityTable[assignPos][1])
  69. end
  70.  
  71. -- Ability activating
  72. local OnCoolDownA = false
  73. local OnCoolDownB = false
  74. local OnCoolDownC = false
  75. local OnCoolDownD = false
  76. local OnCoolDownE = false
  77. local OnCoolDownF = false
  78.  
  79. local function PlayerA(player, key)
  80.     if key == 102 then
  81.         print("Pressed F by ", player.EntityId)
  82.         if not OnCoolDownA then
  83.             for i = 1, 6 do
  84.                 if AbilityTable[i][2] == player.EntityId then
  85.                     local ability = AbilityTable[i][1]
  86.                     print("Ability of ", player.EntityId, "is ", ability)
  87.                     if ability == "Mirage" then
  88.                         Mirage(player)
  89.                     elseif ability == "Octane" then
  90.                         Octane(player)
  91.                     elseif ability == "Tracer" then
  92.                         Tracer(player)
  93.                     end
  94.  
  95.                     OnCoolDownA = true
  96.                     local timer = YaTime:WaitFor(10)
  97.                     EventHelper.AddListener(timer, "TimeEvent", function ()
  98.                         OnCoolDownA = false
  99.                     end)
  100.                 end
  101.             end
  102.         end
  103.     end
  104. end
  105.  
  106. local function PlayerB(player, key)
  107.     if key == 102 then
  108.         print("Pressed F by ", player.EntityId)
  109.         if not OnCoolDownB then
  110.             for i = 1, 6 do
  111.                 if AbilityTable[i][2] == player.EntityId then
  112.                     local ability = AbilityTable[i][1]
  113.                     print("Ability of ", player.EntityId, "is ", ability)
  114.                     if ability == "Mirage" then
  115.                         Mirage(player)
  116.                     elseif ability == "Octane" then
  117.                         Octane(player)
  118.                     elseif ability == "Tracer" then
  119.                         Tracer(player)
  120.                     end
  121.  
  122.                     OnCoolDownB = true
  123.                     local timer = YaTime:WaitFor(10)
  124.                     EventHelper.AddListener(timer, "TimeEvent", function ()
  125.                         OnCoolDownB = false
  126.                     end)
  127.                 end
  128.             end
  129.         end
  130.     end
  131. end
  132.  
  133. local function PlayerC(player, key)
  134.     if key == 102 then
  135.         print("Pressed F by ", player.EntityId)
  136.         if not OnCoolDownC then
  137.             for i = 1, 6 do
  138.                 if AbilityTable[i][2] == player.EntityId then
  139.                     local ability = AbilityTable[i][1]
  140.                     print("Ability of ", player.EntityId, "is ", ability)
  141.                     if ability == "Mirage" then
  142.                         Mirage(player)
  143.                     elseif ability == "Octane" then
  144.                         Octane(player)
  145.                     elseif ability == "Tracer" then
  146.                         Tracer(player)
  147.                     end
  148.  
  149.                     OnCoolDownC = true
  150.                     local timer = YaTime:WaitFor(10)
  151.                     EventHelper.AddListener(timer, "TimeEvent", function ()
  152.                         OnCoolDownC = false
  153.                     end)
  154.                 end
  155.             end
  156.         end
  157.     end
  158. end
  159.  
  160. local function PlayerD(player, key)
  161.     if key == 102 then
  162.         print("Pressed F by ", player.EntityId)
  163.         if not OnCoolDownD then
  164.             for i = 1, 6 do
  165.                 if AbilityTable[i][2] == player.EntityId then
  166.                     local ability = AbilityTable[i][1]
  167.                     print("Ability of ", player.EntityId, "is ", ability)
  168.                     if ability == "Mirage" then
  169.                         Mirage(player)
  170.                     elseif ability == "Octane" then
  171.                         Octane(player)
  172.                     elseif ability == "Tracer" then
  173.                         Tracer(player)
  174.                     end
  175.  
  176.                     OnCoolDownD = true
  177.                     local timer = YaTime:WaitFor(10)
  178.                     EventHelper.AddListener(timer, "TimeEvent", function ()
  179.                         OnCoolDownD = false
  180.                     end)
  181.                 end
  182.             end
  183.         end
  184.     end
  185. end
  186.  
  187. local function PlayerE(player, key)
  188.     if key == 102 then
  189.         print("Pressed F by ", player.EntityId)
  190.         if not OnCoolDownE then
  191.             for i = 1, 6 do
  192.                 if AbilityTable[i][2] == player.EntityId then
  193.                     local ability = AbilityTable[i][1]
  194.                     print("Ability of ", player.EntityId, "is ", ability)
  195.                     if ability == "Mirage" then
  196.                         Mirage(player)
  197.                     elseif ability == "Octane" then
  198.                         Octane(player)
  199.                     elseif ability == "Tracer" then
  200.                         Tracer(player)
  201.                     end
  202.  
  203.                     OnCoolDownE = true
  204.                     local timer = YaTime:WaitFor(10)
  205.                     EventHelper.AddListener(timer, "TimeEvent", function ()
  206.                         OnCoolDownE = false
  207.                     end)
  208.                 end
  209.             end
  210.         end
  211.     end
  212. end
  213.  
  214. local function PlayerF(player, key)
  215.     if key == 102 then
  216.         print("Pressed F by ", player.EntityId)
  217.         if not OnCoolDownF then
  218.             for i = 1, 6 do
  219.                 if AbilityTable[i][2] == player.EntityId then
  220.                     local ability = AbilityTable[i][1]
  221.                     print("Ability of ", player.EntityId, "is ", ability)
  222.                     if ability == "Mirage" then
  223.                         Mirage(player)
  224.                     elseif ability == "Octane" then
  225.                         Octane(player)
  226.                     elseif ability == "Tracer" then
  227.                         Tracer(player)
  228.                     end
  229.  
  230.                     OnCoolDownF = true
  231.                     local timer = YaTime:WaitFor(10)
  232.                     EventHelper.AddListener(timer, "TimeEvent", function ()
  233.                         OnCoolDownF = false
  234.                     end)
  235.                 end
  236.             end
  237.         end
  238.     end
  239. end
  240.  
  241. local function OnSpawned(playerID, player, pointEntity)
  242.     print("Player spawned")
  243.     local spawnedPlayer = YaGame:GetPlayer(playerID)
  244.     print(spawnedPlayer:GetName())
  245.     local avatar = spawnedPlayer:GetAvatarEntity()
  246.     Assign(avatar)
  247.     print("Avatar : ", avatar.EntityId)
  248.  
  249.     PlayerNums = PlayerNums + 1
  250.     if PlayerNums == 1 then
  251.         YaInputAPI.OnKeyDown(avatar, PlayerA)
  252.     elseif PlayerNums == 2 then
  253.         YaInputAPI.OnKeyDown(avatar, PlayerB)
  254.     elseif PlayerNums == 3 then
  255.         YaInputAPI.OnKeyDown(avatar, PlayerC)
  256.     elseif PlayerNums == 4 then
  257.         YaInputAPI.OnKeyDown(avatar, PlayerD)
  258.     elseif PlayerNums == 5 then
  259.         YaInputAPI.OnKeyDown(avatar, PlayerE)
  260.     elseif PlayerNums == 6 then
  261.         YaInputAPI.OnKeyDown(avatar, PlayerF)
  262.     end
  263. end
  264.  
  265. local function OnJoined(playerID)
  266.     local player = YaGame:GetPlayer(playerID)
  267.     print("Player Joined")
  268.     EventHelper.AddListener(player, "SpawnedEvent", OnSpawned)
  269. end
  270.  
  271. -- Event Listeners
  272. EventHelper.AddListener(YaGame, "PlayerJoinedEvent", OnJoined)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement