Download:
https://drive.google.com/file/d/1LzdV4x ... drive_link
EDIT: Seems that there's a problem in my drive. Anyway, here's the code. Just copy these into a lua file and then name it flung.lua
Spoiler: show
--A silly library if you want to see npcs tumbling down
--Rotation code based from Saturnyoshi & Emral's Grrrol
local flung = {}
local npcDrawn = nil
local npcManager = require("npcManager")
local npcutils = require("npcs/npcutils")
function flung.onInitAPI()
registerEvent(flung, "onDraw")
registerEvent(flung, "onTick")
end
function drawNPCFrame(id, frame, x, y, angle, direction)
local settings = npcManager.getNpcSettings(id)
local priority = -45
local myWidth = settings.gfxwidth
local myHeight = settings.gfxheight
if settings.gfxwidth == 0 then
myWidth = settings.width
end
if settings.gfxwidth == 0 then
myHeight = settings.height
end
if settings.foreground then
priority = -15
end
local img = Graphics.sprites.npc[id].img
imgHeight = img.height
imgWidth = img.width
local npcDrawn = Sprite.box({
texture = img,
width = myWidth,
height = myHeight,
x = x + settings.gfxoffsetx + (myWidth * 0.5),
y = y + settings.gfxoffsety + (myHeight * 0.5),
rotation = angle,
pivot = Sprite.align.CENTER,
frames = imgHeight / myHeight,
frame = frame,
})
npcDrawn.x = x + settings.gfxoffsetx + (myWidth * 0.5)
npcDrawn.y = y + settings.gfxoffsety + (myHeight * 0.5)
if direction > 0 then
npcDrawn.scale = vector.v2(-1, 1)
end
npcDrawn:draw({
align = Sprite.align.CENTER,
frame = frame,
sceneCoords = true,
priority = priority,
})
end
function flung.onDraw()
for _,fallingNPC in ipairs(NPC.get()) do
if fallingNPC.isProjectile then
local config = npcManager.getNpcSettings(fallingNPC.id)
local data = fallingNPC.data
local tid = fallingNPC.id
local tdir = fallingNPC.data._basegame.angle or 0
if tdir == nil then return end
local myWidth = config.gfxwidth
local myHeight = config.gfxheight
if config.gfxwidth == 0 then
myWidth = config.width
end
if config.gfxwidth == 0 then
myHeight = config.height
end
local drawX = fallingNPC.x + 0.5 * fallingNPC.width - 0.5 * myWidth
local drawY = fallingNPC.y + fallingNPC.height - myHeight
npcutils.hideNPC(fallingNPC)
drawNPCFrame(tid, fallingNPC.frame, drawX, drawY, tdir, fallingNPC.direction)
end
end
end
function flung.onTick()
for _,fallingNPC in ipairs(NPC.get()) do
if fallingNPC.isProjectile then
local data = fallingNPC.data._basegame
-- Rotation
local fallMagnitude = fallingNPC.speedX
if fallingNPC.speedX == 0 then
fallMagnitude = fallingNPC.direction
end
if fallingNPC:mem(0x12A, FIELD_WORD) > 0 and not fallingNPC.isHidden and fallingNPC:mem(0x124,FIELD_WORD) ~= 0 and fallingNPC:mem(0x12C,FIELD_WORD) == 0 then
if data.angle == nil then
data.angle = 0
data.timer = 0
else
data.angle = data.angle + (fallMagnitude / (0.5 * fallingNPC.height)) * 0.5 * 180 / math.pi
if fallingNPC:mem(0x12C, FIELD_WORD) > 0 then
data.angle = data.angle + 15
end
end
if fallingNPC:mem(0x12C, FIELD_WORD) ~= 0 then return end
data.timer = data.timer + fallingNPC.direction * fallingNPC.speedX
end
end
end
end
return flung
--Rotation code based from Saturnyoshi & Emral's Grrrol
local flung = {}
local npcDrawn = nil
local npcManager = require("npcManager")
local npcutils = require("npcs/npcutils")
function flung.onInitAPI()
registerEvent(flung, "onDraw")
registerEvent(flung, "onTick")
end
function drawNPCFrame(id, frame, x, y, angle, direction)
local settings = npcManager.getNpcSettings(id)
local priority = -45
local myWidth = settings.gfxwidth
local myHeight = settings.gfxheight
if settings.gfxwidth == 0 then
myWidth = settings.width
end
if settings.gfxwidth == 0 then
myHeight = settings.height
end
if settings.foreground then
priority = -15
end
local img = Graphics.sprites.npc[id].img
imgHeight = img.height
imgWidth = img.width
local npcDrawn = Sprite.box({
texture = img,
width = myWidth,
height = myHeight,
x = x + settings.gfxoffsetx + (myWidth * 0.5),
y = y + settings.gfxoffsety + (myHeight * 0.5),
rotation = angle,
pivot = Sprite.align.CENTER,
frames = imgHeight / myHeight,
frame = frame,
})
npcDrawn.x = x + settings.gfxoffsetx + (myWidth * 0.5)
npcDrawn.y = y + settings.gfxoffsety + (myHeight * 0.5)
if direction > 0 then
npcDrawn.scale = vector.v2(-1, 1)
end
npcDrawn:draw({
align = Sprite.align.CENTER,
frame = frame,
sceneCoords = true,
priority = priority,
})
end
function flung.onDraw()
for _,fallingNPC in ipairs(NPC.get()) do
if fallingNPC.isProjectile then
local config = npcManager.getNpcSettings(fallingNPC.id)
local data = fallingNPC.data
local tid = fallingNPC.id
local tdir = fallingNPC.data._basegame.angle or 0
if tdir == nil then return end
local myWidth = config.gfxwidth
local myHeight = config.gfxheight
if config.gfxwidth == 0 then
myWidth = config.width
end
if config.gfxwidth == 0 then
myHeight = config.height
end
local drawX = fallingNPC.x + 0.5 * fallingNPC.width - 0.5 * myWidth
local drawY = fallingNPC.y + fallingNPC.height - myHeight
npcutils.hideNPC(fallingNPC)
drawNPCFrame(tid, fallingNPC.frame, drawX, drawY, tdir, fallingNPC.direction)
end
end
end
function flung.onTick()
for _,fallingNPC in ipairs(NPC.get()) do
if fallingNPC.isProjectile then
local data = fallingNPC.data._basegame
-- Rotation
local fallMagnitude = fallingNPC.speedX
if fallingNPC.speedX == 0 then
fallMagnitude = fallingNPC.direction
end
if fallingNPC:mem(0x12A, FIELD_WORD) > 0 and not fallingNPC.isHidden and fallingNPC:mem(0x124,FIELD_WORD) ~= 0 and fallingNPC:mem(0x12C,FIELD_WORD) == 0 then
if data.angle == nil then
data.angle = 0
data.timer = 0
else
data.angle = data.angle + (fallMagnitude / (0.5 * fallingNPC.height)) * 0.5 * 180 / math.pi
if fallingNPC:mem(0x12C, FIELD_WORD) > 0 then
data.angle = data.angle + 15
end
end
if fallingNPC:mem(0x12C, FIELD_WORD) ~= 0 then return end
data.timer = data.timer + fallingNPC.direction * fallingNPC.speedX
end
end
end
end
return flung