TWJESTER
Member
Im making a frisk mod from undertale and im trying to make a dive script but its not working can someone help?? (I labeled each category :D)
local lastJumpTime = 0 -- Tracks the last time the player pressed jump
local doubleTapTime = 0.5 -- Time window for double tap (in seconds)
local canDive = false -- Flag to track if dive is available
-- Function to start the dive
function StartDive(player)
if player.mo and player.mo.z > 0 then -- Ensure the player is in the air
-- Calculate forward movement based on the player's current momentum
local forwardSpeed = player.mo.vel.x * 1.5 -- Scale player's momentum for X-axis
local strafeSpeed = player.mo.vel.y * 1.5 -- Scale player's momentum for Y-axis
-- Debug output to check the velocities
print("Starting dive with X speed: ", forwardSpeed, " Y speed: ", strafeSpeed)
-- Apply forward momentum (move the player in the X and Y direction)
player.mo.vel.x = forwardSpeed
player.mo.vel.y = strafeSpeed
-- Apply a slight upward velocity to simulate a swoosh effect
player.mo.vel.z = 8 -- Slight vertical velocity to add momentum to the dive
-- Disable the dive ability until the player lands again
canDive = false
end
end
-- Function to check for double-tap
function CheckDoubleTap(player)
local currentTime = player.mo.time -- Get the current game time
-- Debug output to check jump presses
if player.cmd.buttons & BT_JUMP ~= 0 then
print("Jump button pressed")
if currentTime - lastJumpTime <= doubleTapTime then
print("Double tap detected!")
if canDive then
StartDive(player) -- Trigger the forward dive ability
end
else
lastJumpTime = currentTime -- Reset the time if it wasn't a double-tap
end
end
end
-- Function to reset dive ability when touching the ground
function ResetDive(player)
if player.mo.z == 0 then -- Check if the player is on the ground
print("Player is on the ground, resetting dive ability.")
canDive = true -- Re-enable the dive ability when the player touches the ground
end
end
-- Hook everything together
addHook("PlayerThink", function(player)
ResetDive(player) -- Reset dive if on the ground
CheckDoubleTap(player) -- Check for double tap to trigger dive
end)
local lastJumpTime = 0 -- Tracks the last time the player pressed jump
local doubleTapTime = 0.5 -- Time window for double tap (in seconds)
local canDive = false -- Flag to track if dive is available
-- Function to start the dive
function StartDive(player)
if player.mo and player.mo.z > 0 then -- Ensure the player is in the air
-- Calculate forward movement based on the player's current momentum
local forwardSpeed = player.mo.vel.x * 1.5 -- Scale player's momentum for X-axis
local strafeSpeed = player.mo.vel.y * 1.5 -- Scale player's momentum for Y-axis
-- Debug output to check the velocities
print("Starting dive with X speed: ", forwardSpeed, " Y speed: ", strafeSpeed)
-- Apply forward momentum (move the player in the X and Y direction)
player.mo.vel.x = forwardSpeed
player.mo.vel.y = strafeSpeed
-- Apply a slight upward velocity to simulate a swoosh effect
player.mo.vel.z = 8 -- Slight vertical velocity to add momentum to the dive
-- Disable the dive ability until the player lands again
canDive = false
end
end
-- Function to check for double-tap
function CheckDoubleTap(player)
local currentTime = player.mo.time -- Get the current game time
-- Debug output to check jump presses
if player.cmd.buttons & BT_JUMP ~= 0 then
print("Jump button pressed")
if currentTime - lastJumpTime <= doubleTapTime then
print("Double tap detected!")
if canDive then
StartDive(player) -- Trigger the forward dive ability
end
else
lastJumpTime = currentTime -- Reset the time if it wasn't a double-tap
end
end
end
-- Function to reset dive ability when touching the ground
function ResetDive(player)
if player.mo.z == 0 then -- Check if the player is on the ground
print("Player is on the ground, resetting dive ability.")
canDive = true -- Re-enable the dive ability when the player touches the ground
end
end
-- Hook everything together
addHook("PlayerThink", function(player)
ResetDive(player) -- Reset dive if on the ground
CheckDoubleTap(player) -- Check for double tap to trigger dive
end)