-- name: \\#FF4040\\Permadeath -- description: For Coopnet Only! \n\nIf you die, you stay dead for the rest of the session! If guests reconnect after dying, their death is remembered! \n\nWritten by Dan\nstring_without_hex() function by birdekek -- Enforce Server Settings gServerSettings.bubbleDeath = 0 gServerSettings.pauseAnywhere = 1 -- Global Values for Death List gGlobalSyncTable.deathList = "" gGlobalSyncTable.deathCount = 0 -- Local Variables local bannedList = {} local banned = false local rejoinCooldown = 30 local function update() -- Decrement Rejoin Cooldown (Prevents sending death message on rejoin) if rejoinCooldown > 0 then rejoinCooldown = rejoinCooldown - 1 end -- Set Player's Lives to 0 gMarioStates[0].numLives = 0 -- Force Health to 0 if Died Once if banned then gMarioStates[0].health = 255 end -- Enforce Death for Players on the Death List if network_is_server() then for i=1,(MAX_PLAYERS-1) do if #bannedList > 0 then for j=0, #bannedList do if gNetworkPlayers[i].connected and get_coopnet_id(i) == bannedList[j] then network_send_to(i, true, {packet = "ban"}) end end end end end end local function packet_receive(data) if data.packet == "ban" then if not banned and rejoinCooldown == 0 then -- Get Dead Player's Name local deadName = string_without_hex(gNetworkPlayers[0].name) -- Send Message to All Players packet_receive({packet = "message", name = deadName}) network_send(true, {packet = "message", name = deadName}) -- Add to Death List and Counter if gGlobalSyncTable.deathList == "" then gGlobalSyncTable.deathList = deadName else gGlobalSyncTable.deathList = gGlobalSyncTable.deathList .. ", " .. deadName end gGlobalSyncTable.deathCount = gGlobalSyncTable.deathCount + 1 end -- Enable Permadeath banned = true end -- Host Processes Guest Death if data.packet == "submit" then -- Make Sure Coopnet ID isn't already on the list. local noRepeat = true if #bannedList > 0 then for i = 0, #bannedList do if bannedList[i] == data.id then noRepeat = false end end end if noRepeat then -- Add Coopnet ID to Death List table.insert(bannedList, data.id) end end -- Death Message if data.packet == "message" then djui_chat_message_create("\\#FF8080\\" .. data.name .. " has died!") play_character_sound(gMarioStates[0], CHAR_SOUND_GAME_OVER) end end local function on_death() if not banned then if network_is_server() then -- Host Dies, Self Ban if not banned then packet_receive({packet = "ban"}) end else -- Send Guest Death Info to Host network_send_to(1, true, {packet = "submit", id = get_coopnet_id(0)}) end -- Death Fade return true end -- No Death Fade return false end -- Can't Exit Course While Airborne local function on_pause_exit() if gMarioStates[0].action & ACT_FLAG_AIR ~= 0 or gMarioStates[0].health < 256 then return false end return true end -- Remove Color Hex from Name (Code by birdekek) function string_without_hex(name) local s = '' local inSlash = false for i = 1, #name do local c = name:sub(i,i) if c == '\\' then inSlash = not inSlash elseif not inSlash then s = s .. c end end return s end -- Hooks hook_event(HOOK_UPDATE, update) hook_event(HOOK_ON_PACKET_RECEIVE, packet_receive) hook_event(HOOK_ON_DEATH, on_death) hook_event(HOOK_ON_PAUSE_EXIT, on_pause_exit) -- Death List Command local function view_list() if gGlobalSyncTable.deathCount > 0 then djui_chat_message_create("\\#FFFF40\\Dead Players: " .. gGlobalSyncTable.deathList) end djui_chat_message_create("\\#FFFF40\\Death Count: " .. gGlobalSyncTable.deathCount) return true end hook_chat_command("deaths", "- View all players who died.", view_list)