===== Double Jump Mechanism Script ===== ==== Function ==== This script manages the jumping mechanism of players in the game. It monitors the player’s motion state to determine when they can perform an additional jump while in the air and executes the jump when a key is pressed. ==== Application ==== Special mechanism design for custom maps. Advanced gameplay: Combine with events and other actions to create customized maps and features. === Managing Player Jump State === local playerCanJump = {} The playerCanJump variable is a table used to track each player's jump status, identified by their unique user ID. == Handling Player Motion State Changes == local function onPlayerMotionChange(event) if event.playermotion == 4 then playerCanJump[event.eventobjid] = true elseif event.playermotion == 32 then playerCanJump[event.eventobjid] = false end end ScriptSupportEvent:registerEvent("Player.MotionStateChange", onPlayerMotionChange) * The onPlayerMotionChange function listens to motion state changes: * If playermotion is 4 (the player jumps), the player is allowed to perform one more jump (true). * If playermotion is 32 (the player lands), the player is no longer allowed to double jump (false). == Handling Key Press Events == local function onPlayerKeyDown(event) local uid = event.eventobjid if event.vkey == "SPACE" and playerCanJump[uid] then Actor:appendSpeed(uid, 0, 0.8, 0) playerCanJump[uid] = false end end ScriptSupportEvent:registerEvent("Player.InputKeyDown", onPlayerKeyDown) * The onPlayerKeyDown function handles key press events: * If the SPACE key is pressed and the player is eligible to jump, the script adds upward velocity (0.8 units on the Y-axis — customizable). * After jumping, the player's ability to jump again is disabled (false) to prevent infinite jumping.