MegoZ_

Fast Fireballs

Jun 29th, 2022 (edited)
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.92 KB | None | 0 0
  1. local fastFireballs = {}
  2. --v1.1
  3.  
  4. local textplus = require("textplus")
  5.  
  6. function fastFireballs.onInitAPI()
  7.     registerEvent(fastFireballs, "onTick")
  8.     registerEvent(fastFireballs, "onNPCKill")
  9. end
  10. fastFireballs.limit = 2
  11. fastFireballs.showMeDebug = false
  12. local cam = Camera.get()[1] --for debug
  13.  
  14.  
  15. local playerBallCount = {0,0}
  16.  
  17. function fastFireballs.onTick()
  18.     for kp, p in ipairs(Player.get()) do
  19.         if p:mem(0x50, FIELD_BOOL) then return end
  20.         --Assosiate Fireball to Player
  21.         for kn, n in ipairs(NPC.getIntersecting(p.x-3, p.y-3, p.x+p.width+3, p.y+p.height+3)) do
  22.             if (n.id == 13 or n.id == 265 or n.id == 171) and n.ai3 == 0 then --This checks if ai3 is 0, which means it's ownerless.
  23.                 n.ai3 = kp
  24.                 playerBallCount[kp] = playerBallCount[kp] + 1
  25.             end
  26.         end
  27.  
  28.         if playerBallCount[kp] < fastFireballs.limit then
  29.             p:mem(0x160,FIELD_WORD,0) -- Allow Shooting
  30.         else
  31.             p:mem(0x160,FIELD_WORD,1) -- Disable Shooting
  32.         end
  33.  
  34.         --Reset Fireball counting to 0 when there are no fireballs (In case it bugs out)
  35.         if #NPC.get({13,265,171}) == 0 then
  36.             playerBallCount[kp] = 0
  37.         end
  38.  
  39.         for kn, n in ipairs(NPC.get({13,265,171})) do
  40.             if n.ai3 == kp then
  41.                 if n.despawnTimer == 179 then
  42.                     playerBallCount[kp] = playerBallCount[kp] - 1
  43.                     n.ai3 = 0
  44.                 end
  45.             end
  46.         end
  47.  
  48. -------------------------------------DEBUG-------------------------------------------------------------------------------------------------------------------
  49.         if fastFireballs.showMeDebug then
  50.             function print(line, text, variable,color,x,y)
  51.                 debugFont = textplus.loadFont("scripts/textplus/font/11.ini")
  52.                 if x == nil or y == nil then
  53.                     textplus.print{font=debugFont,xscale=1.5,yscale=1.5,x=20^kp*1.02,y=(6+line)*15,text=text..": "..tostring(variable),color=color}
  54.                 else
  55.                     textplus.print{font=debugFont,xscale=1.5,yscale=1.5,x=x,y=y,text=tostring(variable),color=color}
  56.                 end
  57.             end
  58.             --print(2,  "Pressing Run Button",          (p.keys.run or p.keys.altRun)   )
  59.            
  60.             --print(3,  "0x160 (WORD)",                     p:mem(0x160,FIELD_WORD)         )
  61.             --print(4,  "0x160 (BOOL)",                     p:mem(0x160,FIELD_BOOL)         )
  62.             print(5,    "Fireball Count (P"..kp..")",   playerBallCount[kp]                 )
  63.             print(6,    "Total Fireball Count",         #NPC.get({13,265,171})                  )
  64.             for kn, n in ipairs(NPC.get({13,265,171})) do
  65.                 print(nil,  nil,        "Owner: P"..(n.ai3)     ,nil                ,n.x-Camera.get()[kp].x-32,     n.y-Camera.get()[kp].y-12   )
  66.                 print(7+kn,     "0x126 (Owner:"..n.ai3..")",            (n.despawnTimer)                    )
  67.                 print(7+kn,     "0x128 (Owner:"..n.ai3..")",            (n.despawnTimer)                    )
  68.             end
  69.         end
  70. -------------------------------------------------------------------------------------------------------------------------------------------------------------
  71.     end
  72. end
  73.  
  74.  
  75. function fastFireballs.onNPCKill(eventObj, npc, harmtype)
  76.     for kp, p in ipairs(Player.get()) do
  77.         if npc.ai3 == kp then
  78.             playerBallCount[kp] = playerBallCount[kp] - 1
  79.         end
  80.     end
  81. end
  82.  
  83. return fastFireballs
  84.  
  85.  
Add Comment
Please, Sign In to add comment