-- name: The Toad Infection -- description: Don't touch Toad.\nYou've been warned.\n\nBy \\#d6c899\\eros\\#6fb900\\71\\#ffffff\\. gServerSettings.pauseAnywhere = true local becameToad = false local exploded = false local timer = 3 * 30 -- 2 seconds * 30 frames per second -- Array of objects to loop though which are considered NPCs local npcs = { id_bhvBobombBuddy, id_bhvBobombBuddyOpensCannon, id_bhvSmallPenguin, id_bhvHauntedChair, id_bhvCoffin, id_bhvTuxiesMother, id_bhvYoshi, id_bhvMessagePanel, id_bhvUkiki, id_bhvTree } local nearestObject = nil local spawnedToad = nil ---@param m MarioState function mario_update_local(m) if m.playerIndex ~= 0 then return end -- Only run for the local player controller = m.controller nearestObject = obj_get_nearest_object_with_behavior_id(m.marioObj, id_bhvToadMessage) if nearestObject == nil then nearestObject = obj_get_nearest_object_with_behavior_id(m.marioObj, id_bhvEndToad) end -- If Mario's position is close enough to a Toad, set Mario's model and behavior to that of the Toad if not becameToad and nearestObject ~= nil and dist_between_objects(m.marioObj, nearestObject) < 120 then stop_background_music(get_current_background_music()) stop_sounds_from_source(m.pos) play_sound(SOUND_ACTION_TELEPORT, m.marioObj.header.gfx.cameraToObject) spawn_mist_particles() spawnedToad = spawn_sync_object(id_bhvToadMessage, E_MODEL_TOAD, m.pos.x, m.pos.y, m.pos.z, nil) vec3s_set(spawnedToad.header.gfx.angle, 0, m.faceAngle.y, 0) set_mario_action(m, ACT_DISAPPEARED, 0) becameToad = true end if becameToad and not exploded and controller.buttonDown & A_BUTTON ~= 0 then --obj_explode_and_spawn_coins(80, 1) spawn_sync_object(id_bhvExplosion, E_MODEL_EXPLOSION, m.pos.x, m.pos.y, m.pos.z, nil) obj_spawn_yellow_coins(spawnedToad, 1) stop_sounds_from_source(m.pos) --obj_spawn_yellow_coins(m.marioObj, 1) --play_sound(SOUND_GENERAL2_BOBOMB_EXPLOSION, m.marioObj.header.gfx.cameraToObject) obj_mark_for_deletion(spawnedToad) exploded = true end if exploded then -- wait for 2 seconds then restart the level timer = timer - 1 --djui_chat_message_create("timer: " .. tostring(timer)) if timer <= 0 then timer = 3 * 30 exploded = false becameToad = false warp_restart_level() end end end function on_sync_valid() local m = gMarioStates[0] -- Make sure there's not already a Toad in the level nearestObject = obj_get_nearest_object_with_behavior_id(m.marioObj, id_bhvToadMessage) if nearestObject == nil then nearestObject = obj_get_nearest_object_with_behavior_id(m.marioObj, id_bhvEndToad) end if nearestObject ~= nil then log_to_console("Toad already exists in the level at " .. nearestObject.header.gfx.pos.x .. ", " .. nearestObject.header.gfx.pos.y .. ", " .. nearestObject.header.gfx.pos.z) return else check_for_npcs(m) end end ---@param m MarioState function check_for_npcs(m) for i = 1, #npcs do nearestObject = obj_get_nearest_object_with_behavior_id(m.marioObj, npcs[i]) if nearestObject ~= nil then log_to_console("Found " .. get_behavior_name_from_id(get_id_from_behavior(nearestObject.behavior)) .. " at " .. nearestObject.header.gfx.pos.x .. ", " .. nearestObject.header.gfx.pos.y .. ", " .. nearestObject.header.gfx.pos.z) local angleArray = { nearestObject.header.gfx.angle.x, nearestObject.header.gfx.angle.y, nearestObject.header.gfx.angle.z } local posArray = { nearestObject.header.gfx.pos.x, nearestObject.header.gfx.pos.y, nearestObject.header.gfx.pos.z } local newToad = spawn_sync_object(id_bhvToadMessage, E_MODEL_TOAD, posArray[1], posArray[2], posArray[3], nil) if newToad ~= nil then vec3s_set(newToad.header.gfx.angle, angleArray[1], angleArray[2], angleArray[3]) log_to_console("Replaced " .. get_behavior_name_from_id(get_id_from_behavior(nearestObject.behavior)) .. " at " .. posArray[1] .. ", " .. posArray[2] .. ", " .. posArray[3] .. " with Toad.") obj_mark_for_deletion(nearestObject) break else log_to_console("Failed to replace " .. get_behavior_name_from_id(get_id_from_behavior(nearestObject.behavior)) .. " with Toad.") break end end end end hook_event(HOOK_ON_SYNC_VALID, on_sync_valid) hook_event(HOOK_MARIO_UPDATE, mario_update_local)