Jan 1, 2026 at 4:45 PM
Join Date: Sep 10, 2025
Location: your mother's abode
Posts: 9
I was attempting to change the knife into a close range weapon that pushes the player back when they are hitting an enemy or entity. currently it just pushes the player, which is progress, but it just allows them to fly due to allowing the hit to be registered regardless of if it's hitting an enemy or not. here is the code:
Code:
ModCS.Bullet.Act[25] = function(bul)
-- count1 is just a general-purpose variable
-- Here it's being used to keep track of how long the bullet has lived
bul.count1 = bul.count1 + 1
if bul.count1 > bul.life_count then -- life_count is the "frames to live" in bullet properties
-- Delete when reaching the end of its range
ModCS.Bullet.Delete(bul)
ModCS.Caret.Spawn(3, bul.x, bul.y, 0) -- Spawn effect 3 (shoot effect)
return
end
-- This is atypical of bullets in general, but the vanilla Blade starts with the
-- "ignore solid" flag and only removes it after a few frames
if bul.count1 == 3 then
ModCS.Bullet.UnsetBit(bul, 3) -- 2 is the "ignore solid" bit
end
-- Play a sound every so often
if bul.count1 % 1 == 1 then
ModCS.Sound.Play(12)
end
-- Using act_no like this lets us run some initialization code only on the first frame
-- of the bullet's existence
if bul.act_no == 0 then
bul.act_no = 1
-- Set movement velocity
if bul.direct == 0
then-- left -- 4 px/frame
ModCS.Player.xm = 1112
ModCS.Player.ym = -812
elseif bul.direct == 1 then -- up
bul.ym = -1
elseif bul.direct == 2 then -- right
bul.xm = 1
elseif bul.direct == 3 then -- down
bul.ym = 1
ModCS.Player.ym = -1112
else
ModCS.Player.ym = 0 ModCS.Player.xm = 0
end
-- Move the bullet
if ModCS.Player.direct == 0 then
bul.x = -20 + ModCS.Player.x
bul.y = ModCS.Player.y
elseif ModCS.Player.direct == 2 then
bul.x = 20 + ModCS.Player.x
bul.y = ModCS.Player.y
end
local left_animation_frames = {
ModCS.Rect.Create(0, 48, 16, 64),
ModCS.Rect.Create(16, 48, 32, 64),
ModCS.Rect.Create(32, 48, 48, 64),
ModCS.Rect.Create(48, 48, 64, 64)
}
local right_animation_frames = {
ModCS.Rect.Create(64, 48, 80, 64),
ModCS.Rect.Create(80, 48, 96, 64),
ModCS.Rect.Create(96, 48, 112, 64),
ModCS.Rect.Create(112, 48, 128, 64)
}
-- Animate the bullet
bul.ani_wait = bul.ani_wait + 1
if bul.ani_wait > 1 then
bul.ani_wait = 0
bul.ani_no = bul.ani_no + 1
end
if bul.ani_no > 3 then
bul.ani_no = 0
end
if bul.direct == 0 then
ModCS.Bullet.SetRect(bul, left_animation_frames[bul.ani_no + 1])
else
ModCS.Bullet.SetRect(bul, right_animation_frames[bul.ani_no + 1])
end
end
end
