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.
Special mechanism design for custom maps.
Advanced gameplay: Combine with events and other actions to create customized maps and features.
local playerCanJump = {}
The playerCanJump variable is a table used to track each player's jump status, identified by their unique user ID.
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)
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)