Skip to content

Instantly share code, notes, and snippets.

@xDeda
Last active March 8, 2025 13:03
Show Gist options
  • Save xDeda/20679bf10a0a5a2dc05be8f333da5144 to your computer and use it in GitHub Desktop.
Save xDeda/20679bf10a0a5a2dc05be8f333da5144 to your computer and use it in GitHub Desktop.
monobridge grav 0 module for Transformice
-- #monobridge by Tactcat#0000
-- 2 minutes of no gravity, 30 seconds of gravity
-- !go to turn on gravity early
-- shift+click to tp on
-- Command system by Shinsetsu: https://gitlab.com/shinsetsu-projects/tfm-modules
players={}
KEYS={
SHIFT=16,
CTRL=17,
U=85
}
frozen = false
roundshaman = "Tigrounette#0001"
mapInfo={
lastLoad=os.time()-5000,
queue={},
}
admins = {"Tactcat#0000"}
commands = {}
tfm.exec.disableAutoNewGame(true)
tfm.exec.disableAllShamanSkills(true)
tfm.exec.disableAfkDeath(true)
tfm.exec.disablePhysicalConsumables(true)
tfm.exec.disableAutoScore(true)
tfm.exec.disableAutoShaman(true)
-- tfm.exec.newGame("@7870693") -- @7870692
Command = {}
function Command:new(admin, handler)
local command_object = {admin = admin, handler = handler}
setmetatable(command_object, self)
self.__index = self
return command_object
end
function getTableSize(t)
local count = 0
for _, _ in pairs(t) do
count = count + 1
end
return count
end
function isPresentInArray(tbl, x)
found = false
for _, v in pairs(tbl) do
if v == x then
found = true
end
end
return found
end
function getRandomPlayer()
local rplayers = {}
for playerName in next, tfm.get.room.playerList do
table.insert(rplayers,playerName)
end
return rplayers[math.random(#rplayers)]
end
function getRandomMap()
local mapcats = {"#4","#8"}
return mapcats[math.random(2)]
end
function getMaxScorePlayer()
local playerMax = "Tigrounette#0001"
local maxScore = -1
for playerName in next, tfm.get.room.playerList do
if tfm.get.room.playerList[playerName].score > maxScore then
playerMax = playerName
maxScore = tfm.get.room.playerList[playerName].score
end
end
return playerMax
end
function addAdmin(handler, args)
name = args[2]
name = findName(name)
if (isPresentInArray(admins, name)) then
print(name.." is already admin.")
else
table.insert(admins,name)
print("Added "..name.." to admins.")
end
end
function playMap(name,args)
if (args[2]) then map = args[2] else map = args end
for playerName in next, tfm.get.room.playerList do
tfm.exec.setPlayerScore(playerName, 1, true)
end
tfm.exec.setPlayerScore(roundshaman, 0, false)
local timeSinceLastLoad=os.time()-mapInfo.lastLoad
if timeSinceLastLoad<=3000 then
--tfm.exec.chatMessage("Error. Map trying to reload: "..map)
local timeUntilNextLoad=3000-timeSinceLastLoad
if timeUntilNextLoad<1000 then timeUntilNextLoad=1000 end
if mapInfo.timer then system.removeTimer(mapInfo.timer) mapInfo.timer=nil end
mapInfo.timer=system.newTimer(function(...)
local arg={...}
--tfm.exec.chatMessage("Reloading "..tostring(arg[2]))
playMap(arg[2])
end,timeUntilNextLoad,false,map,map)
else
--tfm.exec.chatMessage("Map "..map.." loaded!")
tfm.exec.newGame(map,mirrored)
mapInfo.lastLoad=os.time()
end
end
function findName(name)
if (name == nil) then name = getRandomPlayer() end
local name = string.lower(name)
for playerName in next, tfm.get.room.playerList do
local lowerName = string.lower(playerName)
if string.find(lowerName,name) ~= nil then
return playerName
end
end
end
function setMaxPoints(handler, args)
local name = findName(args[2])
local maxScore = 0
for playerName in next, tfm.get.room.playerList do
if tfm.get.room.playerList[playerName].score > maxScore then
maxScore = tfm.get.room.playerList[playerName].score
end
end
tfm.exec.setPlayerScore(name, maxScore+1, false)
end
function returnGravity(playerName)
frozen = false
tfm.exec.setWorldGravity(0, 10)
for playerName in next, tfm.get.room.playerList do
tfm.exec.freezePlayer(playerName,false)
if tfm.get.room.playerList[playerName].isShaman then
tfm.exec.setShaman(playerName,false)
tfm.exec.disableAutoTimeLeft(true)
tfm.exec.killPlayer(playerName)
tfm.exec.respawnPlayer(playerName)
tfm.exec.disableAutoTimeLeft(false)
end
end
end
function skipMap(playerName)
playMap("Tigrounette#0001",getRandomMap())
end
commands["admin"] = Command:new(1, addAdmin)
commands["map"] = Command:new(1, playMap)
commands["s"] = Command:new(1, setMaxPoints)
commands["go"] = Command:new(0, returnGravity)
commands["skip"] = Command:new(0, skipMap)
function eventLoop(time,remaining)
if remaining<=0 then
playMap("Tigrounette#0001",getRandomMap())
end
if remaining<=30000 and frozen==true then
returnGravity()
end
end
function eventNewGame()
tfm.exec.setGameTime(150, true)
tfm.exec.setWorldGravity(nil, 0)
frozen = true
for playerName in next, tfm.get.room.playerList do
if tfm.get.room.playerList[playerName].isShaman == false then
tfm.exec.freezePlayer(playerName,true)
end
end
local playerMax = getMaxScorePlayer()
roundshaman = playerMax
ui.setShamanName(playerMax)
tfm.exec.disableAutoTimeLeft(true)
tfm.exec.setShaman(playerMax,true)
tfm.exec.killPlayer(playerMax)
tfm.exec.respawnPlayer(playerMax)
tfm.exec.disableAutoTimeLeft(false)
end
function eventPlayerDied()
local i=0
for playerName in next, tfm.get.room.playerList do
if not tfm.get.room.playerList[playerName].isDead then
i=i+1
end
end
if i==0 and getTableSize(tfm.get.room.playerList) > 1 then
playMap("Tigrounette#0001",getRandomMap())
end
end
function eventNewPlayer(playerName)
system.bindMouse(playerName,true)
tfm.exec.bindKeyboard(playerName,KEYS.SHIFT,true,true)
tfm.exec.bindKeyboard(playerName,KEYS.SHIFT,false,true)
players[playerName] = { shift = false }
end
function eventMouse(playerName,x,y)
if players[playerName].shift and tfm.get.room.playerList[playerName].isShaman == true then
tfm.exec.movePlayer(playerName,x,y,false,0,0,false)
end
end
function eventKeyboard(playerName, key, down, x, y)
if key==KEYS.SHIFT and down==true then
players[playerName].shift=true
elseif key==KEYS.SHIFT and down==false then
players[playerName].shift=false
end
end
function eventChatCommand(playerName, command)
local words = {}
for word in string.gmatch(command, "%S+") do
table.insert(words, word)
end
if(commands[words[1]] ~= nil) then
local command_var = commands[words[1]]
if(command_var.admin == 1) then
if(isPresentInArray(admins, playerName)) then
command_var.handler(playerName, words)
else
print("You can't use this command.")
end
else
command_var.handler(playerName, words)
end
else
print("Can't find that command.")
end
end
for playerName in next, tfm.get.room.playerList do
eventNewPlayer(playerName)
end
function eventPlayerWon(playerName, timeElapsed, timeElapsedSinceRespawn)
if (getTableSize(tfm.get.room.playerList) == 1) then playMap("Tigrounette#0001",getRandomMap()) end
tfm.exec.setPlayerScore(playerName, 10, true)
eventPlayerDied()
end
playMap("Tigrounette#0001",getRandomMap())
print("Loaded!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment