I need help with this lua, and lua in general

Vestige

Member
This is my first time doing lua and I wanted the P_InstaThrust to recharge when the coolCounter >= 3*TICRATE yet it's no charging. Aswell I want the sound to play once yet the thrust to repeat until a collision happens.

Also codding in a proficient non jank way is difficult for me to learn.


local invulframes = true
local ghost = true
local c1 = BT_CUSTOM1
local skin = "vestige"
local cooldown = 6
local starttimer = 290
local candash = false

addHook("PlayerThink", function(player)

if player.mo.eflags & MFE_UNDERWATER then
player.mo.dashtime = $1 -2
end


if player.mo.dashing == nil then
player.mo.dashing = false
end
if player.mo.dashtime == nil then
player.mo.dashtime = 0
end

if candash == nil then
candash = false
end

local function SpeedBoost_Reset(player)
player.normalspeed = skins[skin].normalspeed
player.jumpfactor = skins[skin].jumpfactor
player.charflags = $1 & ~SF_RUNONWATER
player.camerascale = skins[skin].camerascale
player.acceleration = skins[skin].acceleration
player.mo.blendmode = AST_COPY
player.mo.colorized = false
end
local function SpeedBoost_start(player)
player.charflags = $1|SF_RUNONWATER
player.normalspeed = skins[skin].normalspeed+10
player.jumpfactor = skins[skin].jumpfactor*2
player.acceleration = skins[skin].acceleration+5
player.camerascale = skins[skin].camerascale*2
player.mo.blendmode = AST_OVERLAY
player.mo.colorized = true
end


if player.mo.dashtime <= 0 then
player.mo.dashtime = $1 * 0
end

if player.mo.dashtime < starttimer then

player.mo.dashtime = $1 +1
candash = false
SpeedBoost_Reset(player)
else
candash = true
SpeedBoost_start(player)
end



if (player.cmd.buttons & BT_CUSTOM1)
and player.mo and player.mo.skin == skin
and candash == true then
P_InstaThrust(player.mo, player.mo.angle, 60*FRACUNIT)
P_RadiusAttack(player.mo, player.mo, 128*FRACUNIT)
if invulframes == true then
player.powers[pw_invulnerability] = TICRATE / 2
local speedtrail = P_SpawnGhostMobj(player.mo)
speedtrail.colorized = true
speedtrail.color = player.mo.color
speedtrail.fuse = 10
speedtrail.blendmode = AST_ADD
player.mo.dashtime = $1 * 2
if P_IsObjectOnGround(player.mo) then
player.mo.state = S_PLAY_RUN
end

end
end
end)
 
Last edited:
Yeesh, the lack of formatting makes it really hard to read. Allow me to put this whole thing in a code block and add the proper indentation...
Lua:
local invulframes = true
local ghost = true
local c1 = BT_CUSTOM1
local skin = "vestige"
local cooldown = 6
local starttimer = 290
local candash = false

addHook("PlayerThink", function(player)

    if player.mo.eflags & MFE_UNDERWATER then
        player.mo.dashtime = $1 -2
    end


    if player.mo.dashing == nil then
        player.mo.dashing = false
    end
    if player.mo.dashtime == nil then
        player.mo.dashtime = 0
    end

    if candash == nil then
        candash = false
    end

    local function SpeedBoost_Reset(player)
        player.normalspeed = skins[skin].normalspeed
        player.jumpfactor = skins[skin].jumpfactor
        player.charflags = $1 & ~SF_RUNONWATER
        player.camerascale = skins[skin].camerascale
        player.acceleration = skins[skin].acceleration
        player.mo.blendmode = AST_COPY
        player.mo.colorized = false
    end
    local function SpeedBoost_start(player)
        player.charflags = $1|SF_RUNONWATER
        player.normalspeed = skins[skin].normalspeed+10
        player.jumpfactor = skins[skin].jumpfactor*2
        player.acceleration = skins[skin].acceleration+5
        player.camerascale = skins[skin].camerascale*2
        player.mo.blendmode = AST_OVERLAY
        player.mo.colorized = true
    end


    if player.mo.dashtime <= 0 then
        player.mo.dashtime = $1 * 0
    end

    if player.mo.dashtime < starttimer then

        player.mo.dashtime = $1 +1
        candash = false
        SpeedBoost_Reset(player)
    else
        candash = true
        SpeedBoost_start(player)
    end



    if (player.cmd.buttons & BT_CUSTOM1)
    and player.mo and player.mo.skin == skin
    and candash == true then
        P_InstaThrust(player.mo, player.mo.angle, 60*FRACUNIT)
        P_RadiusAttack(player.mo, player.mo, 128*FRACUNIT)
        if invulframes == true then
            player.powers[pw_invulnerability] = TICRATE / 2
            local speedtrail = P_SpawnGhostMobj(player.mo)
            speedtrail.colorized = true
            speedtrail.color = player.mo.color
            speedtrail.fuse = 10
            speedtrail.blendmode = AST_ADD
            player.mo.dashtime = $1 * 2
            if P_IsObjectOnGround(player.mo) then
                player.mo.state = S_PLAY_RUN
            end

        end
    end
end)

First things first, does the console spit out any errors or warnings at any point during the gameplay? That's, uh, pretty important to know, and usually should be your immediate first step to troubleshooting your code.
You can open the console with the ~ (tilde) key by default (it's configurable in the options), and scroll through it using PgUp and PgDn. Pay attention to any lines that start with a "WARNING:" in yellow.
 

Who is viewing this thread (Total: 0, Members: 0, Guests: 0)

Back
Top