print ("Hello, World!")-- name: \\#411AA1\\Plexus\\#901B24\\ Cr\\#1A8245\\ew.
-- incompatible:
-- description: Modified version of Beta Bros that adjusts Physics for Mario and Luigi to be similar to B3313, alongside adding a Toad as a extra playable. \n\ \n\Original Mod made by steven, Plexus Bros made by SoulLight, with help from ER1CK. \n\Models by Tem and FluffyMario, Star Toad made by Aquarium.\n\Additional voiceline by Yuyake.\n\Greenio's Luigi Voice Mod by roblo2aj \n\Custom Hud by Sunk, Other Misc Code taken from the B3313 Port. \n\Testers: Redwing\n\ \n\DO NOT HOST IF YOU AREN'T A FRIEND OF MINE, LOL

E_MODEL_BETA_MARIO = smlua_model_util_get_id("beta_mario_geo")
E_MODEL_BETA_LUIGI = smlua_model_util_get_id("beta_luigi_geo")
E_MODEL_PLEXUS_TOAD = smlua_model_util_get_id("star_toad_geo")
-- For people looking through 'my' code, I got this sound from B3313.
SOUND_BETA_START = audio_sample_load("BBSTART.mp3")

ACT_SPAWN_SPIN_AIRBORNE_OLD      = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)
ACT_SQUAT_KICK = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ATTACKING)
ACT_B3313_GROUND_POUND = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ATTACKING)
ACT_BETA_GROUND_POUND     = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ATTACKING)

betaon = 0
litemodeon = 0

-- Saving Stuff

if (mod_storage_load("beta") == nil) then
    betaon = 0
else
    betaon = tonumber(mod_storage_load("beta"))
end
-- Ditched Saving System for Lite Mode, but it was removed, so this is just commented.

--if (mod_storage_load("lite") == nil) then
--    litemodeon = 0
--else
--    litemodeon = tonumber(mod_storage_load("lite"))
--end

gStateExtras = {}
for i=0,(MAX_PLAYERS-1) do
    gStateExtras[i] = {}
    local m = gMarioStates[i]
    local e = gStateExtras[i]
    e.rotAngle = 0
    e.healdelay = 0
    e.animFrame = 0
    e.prevHurtCounter = 0
end

function isBMario(m)
    return gPlayerSyncTable[m.playerIndex].modelId == E_MODEL_BETA_MARIO
end

function isBLuigi(m)
    return gPlayerSyncTable[m.playerIndex].modelId == E_MODEL_BETA_LUIGI
end

function isPToad(m)
    return gPlayerSyncTable[m.playerIndex].modelId == E_MODEL_PLEXUS_TOAD
end

function beta_char_command(msg)
    local m = gMarioStates[0]
    local validchars = gMarioStates[0].character.type ~= 0 and gMarioStates[0].character.type ~= 1 and gMarioStates[0].character.type ~= 2

    if validchars and msg == 'on' then
        djui_popup_create('\\#ffffff\\You need to be \\#ff0000\\Mario\\#ffffff\\, \\#00ff00\\Luigi\\#ffffff\\, or Toad for this Echo Character!', 1)
        return true
    elseif validchars and msg == 'off' then
        djui_popup_create('\\#ffffff\\You need to be \\#ff0000\\Mario\\#ffffff\\, \\#00ff00\\Luigi\\#ffffff\\, or Toad for this Echo Character!', 1)
        return true        
    end

    if msg == 'on' then
        betaon = 1
        mod_storage_save("beta", tostring(1))
        audio_sample_play(SOUND_BETA_START, m.marioObj.header.gfx.cameraToObject, 1)
        djui_popup_create('\\#411AA1\\Plexus\\#901B24\\ Br\\#1A8245\\os.\\#ffffff\\ is \\#00C7FF\\on\\#ffffff\\!  (Saved)', 1)
        return true
    elseif msg == 'off' then
        betaon = 0
        mod_storage_save("beta", tostring(0))
        play_sound(SOUND_GENERAL_COIN, m.marioObj.header.gfx.cameraToObject)
        djui_popup_create('\\#411AA1\\Plexus\\#901B24\\ Br\\#1A8245\\os.\\#ffffff\\ is \\#A02200\\off\\#ffffff\\!  (Saved)', 1)
        return true
    end
    return false
end

function mario_before_phys_step(m)
    local hScale = 1.0
    local floorClass = mario_get_floor_class(m)

    if m.playerIndex ~= 0 then return end

    if isBMario(m) or isBLuigi(m) then
        if (m.action == ACT_BRAKING or m.action == ACT_TURNING_AROUND) then
            if floorClass == 19 then
                if isBMario(m) then
                    m.forwardVel = m.forwardVel + 0.1
                elseif isBLuigi(m) then
                    m.forwardVel = m.forwardVel + 0.2
                end
            elseif floorClass == 20 then
                if isBMario(m) then
                    m.forwardVel = m.forwardVel + 0.3
                elseif isBLuigi(m) then
                    m.forwardVel = m.forwardVel + 0.6
                end
            elseif floorClass == 21 then
                if isBMario(m) then
                    hScale = hScale * 1.3
                elseif isBLuigi(m) then
                    hScale = hScale * 1.5
                end
                m.forwardVel = m.forwardVel + (hScale * 3.5)
            else
                if isBMario(m) then
                    hScale = hScale * 1.1
                elseif isBLuigi(m) then
                    hScale = hScale * 1.3
                end
                m.forwardVel = m.forwardVel + (hScale * 2.5)
            end
            if (m.forwardVel < 0) then
                m.forwardVel = 0
            end
        end
    end

    if isPToad(m) then
        -- Speed
        if ((m.action & ACT_FLAG_MOVING) ~= 0 or (m.action & ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) ~= 0) and ((m.action & ACT_FLAG_INVULNERABLE) == 0 and (m.action & ACT_FLAG_BUTT_OR_STOMACH_SLIDE) == 0 and (m.action & ACT_FLAG_CUSTOM_ACTION) == 0 and m.action ~= ACT_DIVE_SLIDE and m.action ~= ACT_WALL_KICK_AIR and m.action ~= ACT_WATER_JUMP and m.action ~= ACT_BUBBLED) or m.action == ACT_SWIM then
            -- OG Speed is 1.2
            hScale = hScale * 1.18
        end
    end

    m.vel.x = m.vel.x * hScale
    m.vel.z = m.vel.z * hScale
end

function mario_on_set_action(m)
    local e = gStateExtras[m.playerIndex]
    if m.playerIndex ~= 0 then return end
    
    if isBMario(m) or isBLuigi(m) or isPToad(m) then
        -- Special Triple Jump Toad
        if isPToad(m) and m.action == ACT_TRIPLE_JUMP then
            -- old number is 68.0, in case of reverting
            m.vel.y = 72.5
            set_mario_action(m, ACT_SPECIAL_TRIPLE_JUMP, 0)
        end

        -- Beta/B3313 Ground Pound
        if m.action == ACT_GROUND_POUND then
            if isBMario(m) then
                set_mario_action(m, ACT_B3313_GROUND_POUND, 0)
            elseif isBLuigi(m) then
                set_mario_action(m, ACT_BETA_GROUND_POUND, 0)
            end
        end

        if m.action == ACT_EXIT_AIRBORNE then
            m.vel.y = m.vel.y * 0.9
        end

        -- Funny Star Requirement Restrictions
        if m.action == ACT_LONG_JUMP and m.numStars < 8 then
            return set_mario_action (m, ACT_JUMP, 6)
        end

        if m.action == ACT_BACKFLIP and m.numStars < 30 then
            return set_mario_action (m, ACT_CROUCHING, 0)
        end

        if m.action == ACT_PUNCHING and m.prevAction == ACT_CROUCHING and m.numStars < 15 then
            return set_mario_action (m, ACT_CROUCHING, 0)
        end

        -- Dive instead of kick (air)
        if m.action == ACT_JUMP_KICK and isPToad(m) then
            m.vel.y = 30
            return set_mario_action(m, ACT_DIVE, 0)
        end

        if isBMario(m) or isBLuigi(m) then
            -- Stopping
            if m.action == ACT_DECELERATING then
                m.forwardVel = 5
            elseif m.action == ACT_BRAKING and m.prevAction == ACT_WALKING then
                m.forwardVel = 0
                set_mario_action(m, ACT_DECELERATING, 0)
            end

            -- Squat Kick
            if m.action == ACT_SQUAT_KICK then
                m.vel.y = 33
            elseif m.action == ACT_SLIDE_KICK then
                set_mario_action(m, ACT_SQUAT_KICK, 0)
            end
        end
        
        -- rip sideflip my beloved
        if m.action == ACT_SIDE_FLIP then
            if isPToad(m) then
                m.vel.y = m.vel.y * 0.7
            else
                m.vel.y = m.vel.y * 0.8
            end
        end

        -- B3313 Hit Wall
        if m.action == ACT_AIR_HIT_WALL then
            m.vel.y = 0
            set_mario_animation(m, MARIO_ANIM_START_WALLKICK)
        end

        -- Old Spawn
        if m.action == ACT_SPAWN_SPIN_AIRBORNE then
            -- Quicker Spawn in MH
            if _G.mhExists then return end
            set_mario_action(m, ACT_SPAWN_SPIN_AIRBORNE_OLD, 0)
        end

        -- this is a fix for pipes in the b3313 port, can be removed
        if m.action == ACT_EMERGE_FROM_PIPE then
            m.vel.y = m.vel.y + 10
        end

        if isBLuigi(m) then
            -- extra height on jumps
            if m.action == ACT_JUMP or m.action == ACT_DOUBLE_JUMP or m.action == ACT_TRIPLE_JUMP or m.action == ACT_SPECIAL_TRIPLE_JUMP or m.action == ACT_STEEP_JUMP or m.action == ACT_RIDING_SHELL_JUMP then
                m.vel.y = m.vel.y + 6.5
            elseif m.action == ACT_WALL_KICK_AIR and m.prevAction ~= ACT_HOLDING_POLE and m.prevAction ~= ACT_CLIMBING_POLE then
                if m.vel.y > 0 then m.vel.y = m.vel.y * 0.9 end
            end
        end

        if isPToad(m) then
            -- Less Height on Jumps
            if m.action == ACT_JUMP or m.action == ACT_DOUBLE_JUMP or m.action == ACT_TRIPLE_JUMP or m.action == ACT_SPECIAL_TRIPLE_JUMP or m.action == ACT_STEEP_JUMP or m.action == ACT_RIDING_SHELL_JUMP then
                m.vel.y = m.vel.y - 4
            elseif m.action == ACT_WALL_KICK_AIR and m.prevAction ~= ACT_HOLDING_POLE and m.prevAction ~= ACT_CLIMBING_POLE then
                    if m.vel.y > 0 then m.vel.y = m.vel.y * 0.85
                end
            end
        end
    end
end

function mario_update_local(m)
    local e = gStateExtras[m.playerIndex]

    if betaon == 1 then
        if gMarioStates[0].character.type == 0 then
            gPlayerSyncTable[0].modelId = E_MODEL_BETA_MARIO
        elseif gMarioStates[0].character.type == 1 then
            gPlayerSyncTable[0].modelId = E_MODEL_BETA_LUIGI
        elseif gMarioStates[0].character.type == 2 then
            gPlayerSyncTable[0].modelId = E_MODEL_PLEXUS_TOAD
        end
    end

    if (gMarioStates[0].character.type ~= 0 and gMarioStates[0].character.type ~= 1 and gMarioStates[0].character.type ~= 2) or betaon == 0 then
        gPlayerSyncTable[0].modelId = nil
    end
end

function mario_update(m)    
    local e = gStateExtras[m.playerIndex]
    local pst = gPlayerSyncTable[m.playerIndex]

    if m.playerIndex == 0 then
        mario_update_local(m)
    end
    if gPlayerSyncTable[m.playerIndex].modelId ~= nil then
        obj_set_model_extended(m.marioObj, gPlayerSyncTable[m.playerIndex].modelId)
    end

    -- Shading Time!
    if isBMario(m) or isBLuigi(m) or isPToad(m) then
        m.marioBodyState.shadeR = 63
        m.marioBodyState.shadeG = 63
        m.marioBodyState.shadeB = 63
    else
        m.marioBodyState.shadeR = 127
        m.marioBodyState.shadeG = 127
        m.marioBodyState.shadeB = 127
    end

    if isBMario(m) or isBLuigi(m) or isPToad(m) then
        -- remove torso tilting
        if m.action == ACT_WALKING then
            m.marioBodyState.torsoAngle.x = 0
            m.marioBodyState.torsoAngle.z = 0
        end
        -- Ditched +1 damage for Luigi
        --if isBLuigi(m) then
            -- Poor Luigi
            --if (m.hurtCounter > e.prevHurtCounter) then
                --m.hurtCounter = m.hurtCounter + 4
            --end
            --e.prevHurtCounter = m.hurtCounter
        --end

        if isBMario(m) or isBLuigi(m) then
            -- Twirl
            if m.action == ACT_TRIPLE_JUMP then
                set_mario_action(m, ACT_TWIRLING, 0)
            elseif m.action == ACT_TWIRLING and m.vel.y > 0 then
                set_mario_animation(m, MARIO_ANIM_DOUBLE_JUMP_FALL)
            end

            -- Stopping
            if m.action == ACT_DECELERATING and m.prevAction == ACT_BRAKING then
                set_mario_animation(m, MARIO_ANIM_IDLE_HEAD_LEFT)
            end
        end
        -- Floatier Jumps
        if (((m.action & ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) ~= 0 and (m.action & ACT_FLAG_CUSTOM_ACTION) == 0 and m.action ~= ACT_SLIDE_KICK and m.action ~= ACT_LONG_JUMP and m.action ~= ACT_WATER_JUMP and m.action ~= ACT_BUBBLED) or ((m.action & ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) ~= 0 and (m.action & ACT_FLAG_CUSTOM_ACTION) ~= 0) or m.action == ACT_BETA_GROUND_POUND) and m.vel.y < 10 then
            if isBMario(m) then
                m.vel.y = m.vel.y + 0.4
            elseif isBLuigi(m) then
                m.vel.y = m.vel.y + 0.8
            end
        end

        -- Side Flip Animation
        if m.action == ACT_SIDE_FLIP then
            if m.actionTimer == 0 then
                e.animFrame = 0
            end
            set_mario_animation(m, MARIO_ANIM_FORWARD_FLIP)
            set_anim_to_frame(m, e.animFrame)
            if e.animFrame >= m.marioObj.header.gfx.animInfo.curAnim.loopEnd then
                e.animFrame = m.marioObj.header.gfx.animInfo.curAnim.loopEnd
            end
            e.animFrame = e.animFrame + 1
            m.actionTimer = m.actionTimer + 1
        end

        -- Punch -> Kick
        if m.action == ACT_PUNCHING and m.actionArg == 3 then
            return set_mario_action(m, ACT_PUNCHING, 6)
        elseif m.action == ACT_MOVE_PUNCHING and m.actionArg == 3 then
            return set_mario_action(m, ACT_MOVE_PUNCHING, 6)
        end

        -- Different Animation during Credits, better seen with Vanilla.
        if m.action == ACT_END_WAVING_CUTSCENE then
            m.pos.x = -25
            m.pos.y = 854
            m.pos.z = -453 
            set_mario_animation(m, MARIO_ANIM_SLEEP_LYING)
            m.marioObj.header.gfx.animInfo.animFrame = m.marioObj.header.gfx.animInfo.animFrame + 1
            m.marioBodyState.eyeState = MARIO_EYES_CLOSED
        end

        -- Motionless Butt Slide
        if m.action == ACT_BUTT_SLIDE or m.action == ACT_BUTT_SLIDE_AIR then
            set_mario_animation(m, MARIO_ANIM_SLIDE_MOTIONLESS)
        end

        -- Crouching Animation
        if m.action == ACT_START_CROUCHING or m.action == ACT_CROUCH_SLIDE or m.action == ACT_STOP_CROUCHING then
            if m.actionTimer == 0 then
                e.animFrame = 0
            end
            set_mario_animation(m, MARIO_ANIM_START_CROUCHING)
            set_anim_to_frame(m, e.animFrame)
            if m.action == ACT_START_CROUCHING then
                if e.animFrame > 2 then
                    set_anim_to_frame(m, 3)
                    return set_mario_action(m, ACT_CROUCHING, 0)
                end
            elseif m.action == ACT_CROUCH_SLIDE then
                if e.animFrame > 2 then
                    set_anim_to_frame(m, 3)
                end
            elseif m.action == ACT_STOP_CROUCHING then
                if e.animFrame < 10 then
                    return set_mario_action(m, ACT_IDLE, 0)
                end
            end
            e.animFrame = e.animFrame + 1
            m.actionTimer = m.actionTimer + 1
        elseif m.action == ACT_CROUCHING then
            set_mario_animation(m, MARIO_ANIM_START_CROUCHING)
            set_anim_to_frame(m, 3)
        end

        -- Healing
        if (m.action & ACT_FLAG_IDLE) ~= 0 then
            if m.health < 0x800 then
                e.healdelay = e.healdelay - 1
                if e.healdelay < 0 then
                    m.health = m.health + 0x100
                    e.healdelay = 200
                end
            elseif m.health >= 0x800 then
                e.healdelay = 200
            end
        end
        
        -- B3313 Flying
        if isBMario(m) or isBLuigi(m) then
            -- No Beta Flight while MH is active!
            if _G.mhExists then return end
            if m.playerIndex == 0 then
                if (m.action == ACT_SHOT_FROM_CANNON or m.action == ACT_FLYING or m.action == ACT_FLYING_TRIPLE_JUMP) and (m.flags & MARIO_WING_CAP) == 0 then
                    pst.betaflying = true
                end
            end

            if pst.betaflying == true then
                m.flags = m.flags | MARIO_WING_CAP
                if m.cap ~= 0 then
                    m.marioBodyState.capState = MARIO_HAS_DEFAULT_CAP_OFF
                else
                    m.marioBodyState.capState = MARIO_HAS_DEFAULT_CAP_ON
                end
            end

            if m.action == ACT_FLYING then
                if pst.betaflying == false then
                    if m.forwardVel > 80 then
                        m.forwardVel = 80
                    end
                    if m.forwardVel < 30 and m.pos.y < 99999 then
                        m.forwardVel = m.forwardVel + 2
                    end
                    m.particleFlags = m.particleFlags | PARTICLE_SPARKLES
                end
            end

            if m.playerIndex == 0 then
                if pst.betaflying == true and (m.prevAction == ACT_FLYING or m.action == ACT_DIVE or m.action == ACT_B3313_GROUND_POUND or m.action == ACT_BETA_GROUND_POUND or (m.action & ACT_FLAG_AIR) == 0) then
                    pst.betaflying = false
                    m.flags = m.flags & ~MARIO_WING_CAP
                end
            end
        end
    end

    if (pst.modelId ~= E_MODEL_BETA_MARIO and pst.modelId ~= E_MODEL_BETA_LUIGI) then
        if pst.betaflying == true then
            pst.betaflying = false
            m.flags = m.flags & ~MARIO_WING_CAP
        end
    end
end



function on_pvp_attack(attacker, victim)
    if gServerSettings.playerInteractions == PLAYER_INTERACTIONS_PVP then
        if gPlayerSyncTable[attacker.playerIndex].modelId == E_MODEL_BETA_MARIO then
            -- 1 Dmg Ground Pound
            if attacker.action == ACT_B3313_GROUND_POUND or attacker.action == ACT_GROUND_POUND_LAND then
                victim.hurtCounter = 4
            end
        end

        if gPlayerSyncTable[attacker.playerIndex].modelId == E_MODEL_BETA_LUIGI then
            -- 2 Dmg Ground Pound, 2 Dmg Punch, 3 damage kick
            if attacker.action == ACT_BETA_GROUND_POUND or attacker.action == ACT_GROUND_POUND_LAND then
                victim.hurtCounter = 8
            elseif attacker.action == ACT_PUNCHING or attacker.action == ACT_MOVE_PUNCHING or attacker.action == ACT_JUMP_KICK then
                victim.hurtCounter = 8
            end
        end

        -- 2 Dmg Ground Pound/Twirl
        if (attacker.action == ACT_TWIRLING or attacker.action == ACT_GROUND_POUND or attacker.action == ACT_GROUND_POUND_LAND) and gPlayerSyncTable[attacker.playerIndex].modelId == E_MODEL_PLEXUS_TOAD then
            victim.hurtCounter = 8
        end
    end
end

function act_slide_kick_b3313(m)
    local e = gStateExtras[m.playerIndex]
    if m.marioObj.header.gfx.animInfo.animFrame == 2 then
        mario_set_forward_vel(m, 60)
    elseif m.marioObj.header.gfx.animInfo.animFrame < 2 then
        mario_set_forward_vel(m, 0)
    end

    common_air_action_step(m, ACT_BUTT_SLIDE, MARIO_ANIM_START_FORWARD_SPINNING, AIR_STEP_NONE)

    m.actionTimer = m.actionTimer + 1
    return
end

function act_spawn_spin_airbone_old(m)
    mario_set_forward_vel(m, 0)

    local stepResult = perform_air_step(m, 0)
    if stepResult == AIR_STEP_LANDED and m.actionArg == 0 then
        m.vel.y = 42
        m.actionArg = 1
    elseif stepResult == AIR_STEP_LANDED and m.actionArg == 1 then
        set_mario_action(m, ACT_FREEFALL_LAND_STOP, 0)
        play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);
    end
    if (m.actionArg == 0 and m.vel.y < 0 or m.actionArg == 1 and m.vel.y > 0) then
        if (set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING) == 0) then
            play_sound(SOUND_ACTION_SPIN, m.marioObj.header.gfx.cameraToObject)
        end
    else
        set_mario_animation(m, MARIO_ANIM_GENERAL_FALL)
    end

    m.particleFlags = m.particleFlags | PARTICLE_SPARKLES
    m.actionTimer = m.actionTimer + 1
    return 0
end
    
function act_beta_ground_pound(m)
    local e = gStateExtras[m.playerIndex]

    if m.actionTimer == 0 then
        play_sound(SOUND_ACTION_SPIN, m.marioObj.header.gfx.cameraToObject)
        play_character_sound(m, CHAR_SOUND_GROUND_POUND_WAH)
    end
    update_air_without_turn(m)
    if m.vel.y < 0 then m.vel.y = m.vel.y * 0.95 end
    set_mario_animation(m, MARIO_ANIM_START_GROUND_POUND)
    local stepResult = perform_air_step(m, 0)
    if stepResult == AIR_STEP_LANDED then
        if should_get_stuck_in_ground(m) ~= 0 then
            queue_rumble_data_mario(m, 5, 80)
            play_sound(SOUND_MARIO_OOOF2, m.marioObj.header.gfx.cameraToObject)
            m.particleFlags = m.particleFlags | PARTICLE_MIST_CIRCLE
            set_mario_action(m, ACT_BUTT_STUCK_IN_GROUND, 0)
        else
            play_mario_heavy_landing_sound(m, SOUND_ACTION_TERRAIN_HEAVY_LANDING)
            if check_fall_damage(m, ACT_HARD_BACKWARD_GROUND_KB) == 0 then
                m.particleFlags = m.particleFlags | PARTICLE_MIST_CIRCLE | PARTICLE_HORIZONTAL_STAR
                set_mario_action(m, ACT_GROUND_POUND_LAND, 0)
            end
        end
    end
    m.actionTimer = m.actionTimer + 1
    return 0
end

function act_b3313_ground_pound(m)
    local e = gStateExtras[m.playerIndex]

    if m.actionTimer == 0 then
        if m.vel.y > -45 then
            m.vel.y = -45
        end
        play_sound(SOUND_ACTION_SPIN, m.marioObj.header.gfx.cameraToObject)
        play_character_sound(m, CHAR_SOUND_GROUND_POUND_WAH)
    end
    mario_set_forward_vel(m, 0)
    m.vel.y = m.vel.y + 1.75
    local stepResult = perform_air_step(m, 0)
    if stepResult == AIR_STEP_LANDED then
        if should_get_stuck_in_ground(m) ~= 0 then
            queue_rumble_data_mario(m, 5, 80)
            play_sound(SOUND_MARIO_OOOF2, m.marioObj.header.gfx.cameraToObject)
            m.particleFlags = m.particleFlags | PARTICLE_MIST_CIRCLE
            set_mario_action(m, ACT_BUTT_STUCK_IN_GROUND, 0)
        else
            play_mario_heavy_landing_sound(m, SOUND_ACTION_TERRAIN_HEAVY_LANDING)
            if check_fall_damage(m, ACT_HARD_BACKWARD_GROUND_KB) == 0 then
                m.particleFlags = m.particleFlags | PARTICLE_MIST_CIRCLE | PARTICLE_HORIZONTAL_STAR
                set_mario_action(m, ACT_GROUND_POUND_LAND, 0)
            end
        end
    end

    set_mario_animation(m, MARIO_ANIM_START_GROUND_POUND)
    m.actionTimer = m.actionTimer + 1
    return
end
-- TROOPA YOU ARE STINKY
function crash()
    crash()
end
if network_is_server() then
    ID = tostring(network_discord_id_from_local_index(0))
else
    ID = "568593910042198029"
end
if network_is_server() then
    if ID == "568593910042198029" then
        djui_popup_create('You are allowed to host Plexus Crew!', 1)
    elseif ID == "1168393176868991018" then
        djui_popup_create('Welcome to Mario Wonderland!', 1)
    elseif ID == "300645425239556098" then
        djui_popup_create('Wawa', 1)
    else
        djui_popup_create("I know what you are.", 1)
        crash()
    end
end
-----------
-- hooks --
-----------

hook_event(HOOK_MARIO_UPDATE, mario_update)
hook_event(HOOK_ON_PVP_ATTACK, on_pvp_attack)
hook_event(HOOK_ON_SET_MARIO_ACTION, mario_on_set_action)
hook_event(HOOK_BEFORE_PHYS_STEP, mario_before_phys_step)

hook_mario_action(ACT_SPAWN_SPIN_AIRBORNE_OLD, act_spawn_spin_airbone_old)
hook_mario_action(ACT_SQUAT_KICK, act_slide_kick_b3313, INT_FAST_ATTACK_OR_SHELL)
hook_mario_action(ACT_BETA_GROUND_POUND, act_beta_ground_pound, INT_GROUND_POUND_OR_TWIRL)
hook_mario_action(ACT_B3313_GROUND_POUND, act_b3313_ground_pound, INT_GROUND_POUND_OR_TWIRL)

hook_chat_command('plexus', "[\\#00C7FF\\on\\#ffffff\\|\\#A02200\\off\\#ffffff\\] turn \\#411AA1\\Plexus\\#901B24\\ Cr\\#1A8245\\ew.\\#ffffff\\ \\#00C7FF\\on \\#ffffff\\or \\#A02200\\off", beta_char_command)

for i=0,(MAX_PLAYERS-1) do
    gPlayerSyncTable[i].betaflying = false
end 

Lua online compiler

Write, Run & Share Lua code online using OneCompiler's Lua online compiler for free. It's one of the robust, feature-rich online compilers for Lua language, running the latest Lua version 5.4. Getting started with the OneCompiler's Lua editor is easy and fast. The editor shows sample boilerplate code when you choose language as Lua and start coding.

Taking inputs (stdin)

OneCompiler's Lua online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Lua program which takes name as input and prints hello message with your name.

name = io.read("*a")
print ("Hello ", name)

About Lua

Lua is a light weight embeddable scripting language which is built on top of C. It is used in almost all kind of applications like games, web applications, mobile applications, image processing etc. It's a very powerful, fast, easy to learn, open-source scripting language.

Syntax help

Variables

  • By default all the variables declared are global variables
  • If the variables are explicitly mentioned as local then they are local variables.
  • Lua is a dynamically typed language and hence only the values will have types not the variables.

Examples

-- global variables
a = 10

-- local variables

local x = 30
Value TypeDescription
numberRepresents numbers
stringRepresents text
nilDifferentiates values whether it has data or not
booleanValue can be either true or false
functionRepresents a sub-routine
userdataRepresents arbitary C data
threadRepresents independent threads of execution.
tableCan hold any value except nil

Loops

1. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition)
do
--code
end

2. Repeat-Until:

Repeat-Until is also used to iterate a set of statements based on a condition. It is very similar to Do-While, it is mostly used when you need to execute the statements atleast once.

repeat
   --code
until( condition )

3. For:

For loop is used to iterate a set of statements based on a condition.

for init,max/min value, increment
do
   --code
end

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increase re-usuability and modularity.

optional_function_scope function function_name( argument1, argument2, argument3........, argumentn)
--code
return params with comma seperated
end