COM_AddCommand("lifeshare", function(p, arg, arg2, arg3) if not p or not p.valid return end if not multiplayer or not (maptol & TOL_COOP) CONS_Printf(p, "\x04 This command can only be used during multiplayer mode inside co-op maps.") return end if not (p.mo and p.mo.valid) or (p.playerstate != PST_LIVE) or (p.spectator) CONS_Printf(p, "\x04 You need to be alive and playing the game to use this command.") return end if CV_FindVar("cooplives").value == 3 CONS_Printf(p, "\x04 The server must not have shared life pool mode enabled.") return end if not p.lives or p.lives == 1 CONS_Printf(p, "\x04 You need at least 2 lives to use this command.") return end if arg if arg:lower() == p.name:lower() CONS_Printf(p, "\x04 You can't donate lives to yourself.") return end if not arg2 CONS_Printf(p, "\x04 The number of lives to share has not been specified.") return end local donation = tonumber(arg2, 10) if not donation CONS_Printf(p, "\x04 The number of lives specified is invalid.") return end if donation <= 0 CONS_Printf(p, "\x04 Your life donation can't be lower than 1.") return end if p.lives - arg2 <= 0 CONS_Printf(p, "\x04 This life donation would leave you at 0 lives or less.") return end arg = $:lower() local target = nil for receiver in players.iterate() do if receiver.valid and receiver.name:lower() == arg then target = receiver end end if target == nil CONS_Printf(p, "\x04 The player named \"" .. arg .. "\" does not exist.") if arg3 then CONS_Printf(p, "\x82 If the player's name has spaces in it, make sure to write it between quotation marks.") end return end if target.lives == INFLIVES CONS_Printf(p, "\x04 The specified player already has infinite lives.") return end if target.lives == 99 CONS_Printf(p, "\x04 The specified player has already maxed out their lives.") return end local lifeReturn = (target.lives + arg2) - 99 P_GivePlayerLives(target, arg2) P_GivePlayerLives(p, -arg2) CONS_Printf(target, "\x04 You received " .. arg2 .. " lives from " .. p.name .. "!") CONS_Printf(p, "\x04 You gave away " .. arg2 .. " lives to " .. target.name .. "!") P_PlayLivesJingle(target) if lifeReturn > 0 CONS_Printf(p, "\x04 The player now has more than 99 lives. Any lives that exceed the maximum have been given back to you.") P_GivePlayerLives(target, lifeReturn) end else CONS_Printf(p, "\x04 Give away one or more of your lives to a different player.") CONS_Printf(p, "\x82 Usage: ") CONS_Printf(p, "\x88 lifeshare [player receiving lives] [lives to donate]") end end) addHook("PlayerMsg", function(p, msgtype, pto, msg) if not p.valid return end if msgtype return end msg = msg:lower() if msg:sub(0, 10) ~= "!lifeshare" return end local quote1 = nil local quotes = {} local i = 1 local args = {} for arg in msg:gmatch("%S+") do if arg:sub(1,1) == "\"" and (not quote1) quote1 = arg:sub( 2, arg:len() ) elseif quote1 and arg:sub( arg:len(), arg:len() ) ~= "\"" table.insert(quotes, " " .. arg .. " ") elseif quote1 and arg:sub( arg:len(), arg:len() ) == "\"" if #quotes > 0 local finalName = quote1 for k, namePart in ipairs(quotes) do finalName = $ .. namePart end finalName = $ .. arg:sub(1, arg:len()-1) table.insert(args,finalName) else table.insert(args, quote1 .. " " .. arg:sub(1, arg:len()-1)) end quote1 = nil else table.insert(args,arg) end end if #args < 3 CONS_Printf(p, "\x04 Invalid chat command received. Not enough arguments were given.") return true elseif #args >= 4 CONS_Printf(p, "\x04 Invalid chat command received. Did the player's name have spaces in it?") CONS_Printf(p, "\x82 If so, make sure it was written between quotation marks.") return true end COM_BufInsertText(p, "lifeshare" .. " " .. "\"" .. args[2] .. "\"" .. " " .. args[3]) return true end)