-- name: ~backup star warps -- description: spawn a star copy that other players can use to follow you when collecting a star or key by wereyoshi local spawnedfakestar = false local version = "1.1.0" local lastfakestartouched local servermodsync = false local staractions = {[ACT_STAR_DANCE_WATER] = true,[ACT_FALL_AFTER_STAR_GRAB] = true,[ACT_STAR_DANCE_NO_EXIT] = true,[ACT_STAR_DANCE_EXIT] = true,[ACT_JUMBO_STAR_CUTSCENE] = true} local staridcheck --- @param o Object --this sets up a fake star local function bhv_fakestar_init(o) cur_obj_init_animation(0) o.oFlags = OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE o.oInteractType = INTERACT_STAR_OR_KEY o.hitboxDownOffset = 0 o.oDamageOrCoinValue = 0 o.oHealth = 0 o.oNumLootCoins = 0 cur_obj_set_hitbox_radius_and_height(80, 50) cur_obj_set_hurtbox_radius_and_height(0, 0) spawn_star_number() end --- @param o Object --this is the fake star loop local function bhv_fakestar_loop(o) o.oFaceAngleYaw = o.oFaceAngleYaw + 0x800 cur_obj_become_tangible() if (o.oInteractStatus & INT_STATUS_INTERACTED)then o.oInteractStatus = 0 end spawn_star_number() end ---@param m MarioState ---@param o Object ---@param interactType InteractionType ---@param interactValue boolean --this function is for mario interacting with objects. local function on_interact(m,o,interactType,interactValue) if m.playerIndex ~= 0 then return end local oBeh local interactsub local newobj local newobjmodel if interactType == INTERACT_STAR_OR_KEY and (obj_has_behavior_id(o,id_bhvfakestar) == 0 ) and (spawnedfakestar ~= true) then oBeh = o.oBehParams interactsub = o.oInteractionSubtype if (staridcheck ~= nil) and staridcheck[oBeh] ~= true then --don't spawn a backup star if the star's id is not in the list return elseif (obj_has_behavior_id(o,id_bhvBowserKey) ~= 0 ) then newobjmodel = E_MODEL_BOWSER_KEY else newobjmodel = E_MODEL_TRANSPARENT_STAR end newobj = spawn_sync_object(id_bhvfakestar,newobjmodel,o.oPosX, o.oPosY,o.oPosZ,function (obj) obj.oInteractionSubtype = interactsub obj.oBehParams = oBeh end) if newobj ~= nil then spawnedfakestar = true lastfakestartouched = newobj end elseif (obj_has_behavior_id(o,id_bhvfakestar) ~= 0 ) then lastfakestartouched = o end end ---@param m MarioState ---@param o Object ---@param interactType InteractionType --this function is for allowing mario to interact with objects. local function allow_interact(m, o, interactType) if m.playerIndex ~= 0 then return end if (obj_has_behavior_id(o,id_bhvfakestar) ~= 0 ) and ((staractions[m.action] == true) or (staractions[m.prevAction] == true) or (gServerSettings.stayInLevelAfterStar ~= 0) or (lastfakestartouched == o)) then return false end end -- Called when the level is initialized local function on_level_init() spawnedfakestar = false lastfakestartouched = nil end --function used for built in support for some external mods local function modsupport() if _G.OmmApi ~= nil then _G.backupstarwarp.addactioncheck(_G.OmmApi["ACT_OMM_STAR_DANCE"])--adding omm's star dance end hook_event(HOOK_ALLOW_INTERACT, allow_interact) --Called before mario interacts with an object, return true to allow the interaction end --- @param m MarioState --Called when a player connects local function on_player_connected(m) -- only run on server if not network_is_server() then return end if servermodsync == false then modsupport() servermodsync = true end end --Called when the local player finishes the join process (if the player isn't the host) local function on_join() modsupport() end id_bhvfakestar = hook_behavior(nil, OBJ_LIST_LEVEL, true, bhv_fakestar_init, bhv_fakestar_loop) hook_event(HOOK_ON_INTERACT, on_interact) --Called when mario interacts with an object hook_event(HOOK_ON_LEVEL_INIT, on_level_init) -- Called when the level is initialized hook_event(HOOK_ON_PLAYER_CONNECTED, on_player_connected) -- hook for player joining hook_event(HOOK_JOINED_GAME, on_join) -- Called when the local player finishes the join process (if the player isn't the host) _G.backupstarwarp = { getversion = function()--this function returns the back up star warp version return version end, get_backupstarwarpbehaviorid = function() -- function that returns the behavior id of the fake star return id_bhvfakestar end, ---@param move number addactioncheck = function(move)--this function is for adding actions that you want backup star warps to have ignore backup stars if move ~= nil then staractions[move] = true end end, ---@param starparam number the oBehParams of the star you want to limit backup warps to addtostaridcheck = function(starparam)--this function is for if you want backup star warps to only work for certain stars staridcheck[starparam] = true end }