Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local owner
- do
- local _, err = pcall(nil)
- owner = string.match(err, "(.-)%.")
- end
- assert(owner, "Impossible to find owner name.")
- string.split = function(str, pat)
- local out = { }
- local len = 0
- string.gsub(str, pat, function(value)
- len = len + 1
- out[len] = tonumber(value) or value
- end)
- return out
- end
- eventChatCommand = function(playerName, command)
- if playerName == owner then
- local cmd = string.split(command, "%S+")
- if cmd[1] == "edit" and cmd[2] then
- tfm.exec.newGame(cmd[2])
- end
- end
- end
- local parseProperties = function(data)
- local out = { }
- string.gsub(data, "(%-?%w+)=\"(.-)\"", function(attribute, value)
- if string.find(value, ',') then
- local values, counter = { }, 0
- value = string.gsub(value, "^,", "0,")
- value = string.gsub(value, ",,", ",0,")
- value = string.gsub(value, ",$", ",0")
- string.gsub(value, "[^,]+", function(sub_value)
- counter = counter + 1
- values[counter] = tonumber(sub_value) or sub_value
- value = values
- end)
- else
- value = tonumber(value) or value
- end
- out[attribute] = value
- end)
- return out
- end
- local grounds = { }
- local runAgain = false
- eventNewGame = function()
- local xml = (tfm.get.room.xmlMapInfo or {}).xml
- if xml then
- if runAgain then
- runAgain = false
- for ground = 1, #grounds do
- tfm.exec.addPhysicObject(ground, grounds[ground].X, grounds[ground].Y, {
- angle = grounds[ground].P[5],
- angularDamping = grounds[ground].P[8],
- color = grounds[ground].o and tonumber(grounds[ground].o, 16),
- dynamic = grounds[ground].P[1] == 1,
- fixedRotation = grounds[ground].P[6] == 1,
- foreground = not not grounds[ground].N,
- friction = grounds[ground].P[3],
- groundCollision = (not grounds[ground].c or grounds[ground].c == 1 or grounds[ground].c == 2),
- height = grounds[ground].H,
- linearDamping = grounds[ground].P[7],
- mass = grounds[ground].P[2],
- miceCollision = (not grounds[ground].c or grounds[ground].c == 1 or grounds[ground].c == 3),
- restitution = grounds[ground].P[4],
- type = grounds[ground].T,
- width = grounds[ground].L
- })
- end
- else
- grounds = { }
- local counter = 0
- string.gsub(xml, "<S (.-)>", function(data)
- counter = counter + 1
- grounds[counter] = parseProperties(data)
- end)
- runAgain = true
- end
- end
- end
- eventLoop = function()
- if runAgain then
- tfm.exec.newGame("<C><P /><Z><S /><D /><O /></Z></C>")
- end
- end
- tfm.exec.disableAutoNewGame()
- tfm.exec.disableAutoShaman()
Advertisement
Add Comment
Please, Sign In to add comment