Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local xml=nil
- local author=nil
- local groundTypes={[0]='Bois','Glace','Trampoline','Lave','Chocolat','Terre','Herbe','Sable','Nuage','Eau','Pierre','Neige','Couleur','Cercle'}
- local options={Collision=false, Soulmate=false, Portals=false, Night=false, Wind=0, Gravity=10, Background=nil, Width=800, Height=400}
- local grounds={}
- local keys={}
- local players={}
- function main()
- --tfm.exec.newGame()
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableAutoTimeLeft(true)
- for name in pairs(tfm.get.room.playerList) do eventNewPlayer(name) end
- ui.addTextArea(989,"<p align='center'>Ce script est développé par <VP>Transforcips <N>et <VP>Kmlcan.",nil,200,-25,400,30,1,0,0.8)
- end
- function readOptions()
- if xml then
- options={Collision=false, Soulmate=false, Portals=false, Night=false, Wind=0, Gravity=10, Background=nil, Width=800, Height=400}
- grounds={}
- for attr, val in xml:match('<P .->'):gmatch('(%S+)=(%S+)') do
- if attr == 'C' then options.Collision = true
- elseif attr == 'A' then options.Soulmate = true
- elseif attr == 'P' then options.Portals = true
- elseif attr == 'N' then options.Night = true
- elseif attr == 'G' then
- options.Wind, options.Gravity = val:match('"([%-%d]+),([%-%d]+)"')
- elseif attr == 'F' then
- options.Background = val:match('"([%-%d]+)"')
- elseif attr == 'L' then
- options.Width = val:match('"([%-%d]+)"')
- elseif attr == 'H' then
- options.Height = val:match('"([%-%d]+)"')
- end
- end
- local array = {}
- for attributes in xml:match('<S>(.-)</S>'):gmatch('<S (.-)/>') do
- array = {}
- for attr, val in attributes:gmatch('(%S+)="(%S*)"') do
- array[attr] = val or ""
- end
- if array.P then
- array.P = string.split(array.P or "")
- end
- table.insert(grounds, array)
- end
- end
- end
- function table.swap(t, key, key2)
- local tmp = t[key]
- t[key] = t[key2]
- t[key2] = tmp
- end
- function string.split(str, delimiter)
- local delimiter=delimiter or ','
- local array={}
- for part in str:gmatch('[^'..delimiter..']+') do
- table.insert(array, part)
- end
- return array
- end
- function getOptionsText()
- return string.format("<p align='center'>%s<a href='event:optionCollision'>Collision</a> <G>|%s <a href='event:optionNight'>Nuit</a> <G>|%s <a href='event:optionPortals'>Portails</a> <G>|%s <a href='event:optionSoulmate'>Âme-Soeur</a> <G>|<J> <a href='event:changeGravity'>Gravité: <font color='#c2c2da'>%d</font></a> <G>|<J> <a href='event:changeWind'>Vent: <font color='#c2c2da'>%d</font></a> <G>|<J> <a href='event:changeBackground'>Arrière Plan: <font color='#c2c2da'>%s</font></a> <G>|<J> <a href='event:changeL'>Longueur: <font color='#c2c2da'>%d</font></a> <G>|<J> <a href='event:changeH'>Hauteur: <N>%d",
- options.Collision and '<CH>' or '<R>', options.Night and '<CH>' or '<R>', options.Portals and '<CH>' or '<R>',
- options.Soulmate and '<CH>' or '<R>', options.Gravity, options.Wind, options.Background or 'Yok',
- options.Width, options.Height)
- end
- function showGUI(name)
- ui.addTextArea(333,getOptionsText(),name,40,20,720,nil,1,0,0.8)
- end
- function updateGUI()
- ui.updateTextArea(333,getOptionsText())
- end
- function updateXML()
- local pTag = xml:match('<P .->')
- local attributes = {}
- for attr, val in pTag:gmatch('(%S+)=(%S+)') do
- attributes[attr] = val
- end
- attributes.C = options.Collision and '""' or nil
- attributes.A = options.Soulmate and '""' or nil
- attributes.P = options.Portals and '""' or nil
- attributes.N = options.Night and '""' or nil
- attributes.L = options.Width and '"' .. options.Width .. '"' or nil
- attributes.H = options.Height and '"' .. options.Height .. '"' or nil
- attributes.F = options.Background and '"' .. options.Background .. '"' or nil
- attributes.G = '"' .. options.Wind .. "," .. options.Gravity .. '"'
- local newPTag = '<P '
- for attr, val in pairs(attributes) do
- newPTag = newPTag .. attr .. '=' .. val .. ' '
- end
- newPTag = newPTag .. '/>'
- xml = xml:gsub('<P .->', newPTag, 1)
- local groundStr = ''
- local gStr = ''
- for _, ground in pairs(grounds) do
- gStr = ''
- for key, val in pairs(ground) do
- if key ~= 'P' then
- gStr = gStr .. key .. '="' .. tostring(val) .. '" '
- end
- end
- if ground.P then
- gStr = gStr .. 'P="' .. table.concat(ground.P, ',') .. '" '
- end
- groundStr = groundStr .. string.format('<S %s/>', gStr)
- end
- xml = xml:gsub('<S>.-</S>', '<S>'..groundStr..'</S>', 1)
- print("XML has been updated.")
- end
- function eventNewGame()
- if tfm.get.room.xmlMapInfo and tfm.get.room.xmlMapInfo.xml
- and tfm.get.room.currentMap == '@' .. tfm.get.room.xmlMapInfo.mapCode then
- xml = tfm.get.room.xmlMapInfo.xml
- print("La carte a bien été chargée.")
- readOptions()
- showGUI(name)
- ui.addTextArea(666,"<p align='center'><a href='event:groundSettings'>Options des sols</a> <G>| <N><a href='event:reloadMap'>Jouer la carte</a>",nil,300,380,200,nil,1,0,0.8)
- tfm.exec.setGameTime(5)
- if tfm.get.room.xmlMapInfo and tfm.get.room.xmlMapInfo.author ~= "#Module" and tfm.get.room.xmlMapInfo.xml then
- author = tfm.get.room.xmlMapInfo.author.." <BL>- @"..tfm.get.room.xmlMapInfo.mapCode
- tfm.exec.setUIMapName(author)
- else tfm.exec.setUIMapName(author.." - <VP>Modifiée") end
- else
- tfm.exec.setUIMapName(tfm.get.room.currentMap)
- for id=0,985 do ui.removeTextArea(id) end
- end
- end
- function eventNewPlayer(name)
- keys[name] = {}
- players[name]={edit=nil}
- tfm.exec.bindKeyboard(name, 80, true, true) tfm.exec.bindKeyboard(name, 80, false, true)
- tfm.exec.bindKeyboard(name, 79, true, true) tfm.exec.bindKeyboard(name, 79, false, true)
- system.bindMouse(name, true)
- end
- function eventPlayerLeft(name)
- keys[name] = nil
- end
- function eventKeyboard(name, key, down)
- if keys[name] then
- keys[name][key] = down
- end
- end
- function eventMouse(name, x, y)
- if keys[name] then
- if keys[name][80] then
- tfm.exec.movePlayer(name, x, y)
- elseif keys[name][79] then
- local gID = 0
- for ID, ground in pairs(grounds) do
- if math.abs(ground.X-x) < 11 and math.abs(ground.Y-y) < 11 then
- gID = ID
- end
- end
- if gID ~= 0 then
- eventTextAreaCallback(ID, name, 'groundEdit'..gID)
- end
- end
- end
- end
- function eventChatCommand(name, cmd)
- if cmd:sub(1,4) == "map " then
- tfm.exec.newGame(cmd:sub(5))
- end
- end
- function eventPopupAnswer(ID, name, answer)
- if ID == 40 then
- options.Wind = tonumber(answer) or options.Wind
- elseif ID == 41 then
- options.Gravity = tonumber(answer) or options.Gravity
- elseif ID == 42 then
- if tonumber(answer) then
- local answer = tonumber(answer)
- if answer>=0 and answer<=8 then
- options.Background = answer
- end
- elseif answer:lower() == 'x' then
- options.Background = nil
- end
- elseif ID == 43 then
- if tonumber(answer) then
- local answer = tonumber(answer)
- if answer>=800 and answer<=1600 then
- options.Width = answer
- end
- end
- elseif ID == 44 then
- if tonumber(answer) then
- local answer = tonumber(answer)
- if answer>=400 and answer<=800 then
- options.Height = answer
- end
- end
- elseif ID == 53 then
- if players[name] and players[name].edit and players[name].edit.ID and answer:len()>0 then
- local ground = grounds[players[name].edit.ID]
- if ground then
- if players[name].edit.type == 'type' and tonumber(answer)>=0 and tonumber(answer)<=13 then
- ground.T = tonumber(answer)
- elseif players[name].edit.type == 'x' then
- ground.X = tonumber(answer)
- elseif players[name].edit.type == 'y' then
- ground.Y = tonumber(answer)
- elseif players[name].edit.type == 'l' and tonumber(answer)>=10 and tonumber(answer)<=2000 then
- ground.L = tonumber(answer)
- elseif players[name].edit.type == 'h' and tonumber(answer)>=10 and tonumber(answer)<=2000 then
- ground.H = tonumber(answer)
- elseif players[name].edit.type == 'fri' then
- ground.P[3] = answer
- elseif players[name].edit.type == 'res' then
- ground.P[4] = answer
- elseif players[name].edit.type == 'angle' then
- ground.P[5] = answer
- elseif players[name].edit.type == 'color' and answer:len()>=0 and answer:len()<=6 then
- ground.o = tonumber(answer) or tonumber('0x'..answer) or 0
- end
- eventTextAreaCallback(ID, name, 'groundEdit'..players[name].edit.ID)
- end
- end
- end
- updateGUI()
- end
- function eventTextAreaCallback(ID, name, callback)
- if callback == 'close' then
- ui.removeTextArea(ID, name)
- ui.removeTextArea(121, name)
- elseif callback:sub(1,6) == 'option' and callback:len() > 6 then
- options[callback:sub(7)] = not options[callback:sub(7)]
- updateGUI()
- elseif callback == 'changeWind' then
- ui.addPopup(40,2,"<p align='center'>Entrez une valeur pour déterminer le vent</p>",name,300,55,200)
- elseif callback == 'changeGravity' then
- ui.addPopup(40,2,"<p align='center'>Entrez une valeur pour déterminer la gravité</p>",name,300,55,200)
- elseif callback == 'changeBackground' then
- ui.addPopup(42,2,"<p align='center'>Entrez une valeur pour déterminer l'arrière plan</p>",name,300,55,200)
- elseif callback == 'changeL' then
- ui.addPopup(43,2,"<p align='center'>Entrez une valeur pour déterminer la longueur</p>",name,300,55,200)
- elseif callback == 'changeH' then
- ui.addPopup(44,2,"<p align='center'>Entrez une valeur pour déterminer la hauteur</p>",name,300,55,200)
- elseif callback:sub(1,14) == 'groundSettings' then
- local startID = callback:sub(15)
- startID = startID and tonumber(startID) or 1
- local groundsStr = ''
- for i,ground in ipairs(grounds) do
- if i >= startID then
- if i >= (startID+8) then break end
- groundsStr = groundsStr .. '<N>' .. i .. '<G> - <V><a href="event:groundEdit' .. i .. '">' .. (groundTypes[tonumber(ground.T)] or 'Unknown') .. '</a> <G>-<R> <a href="event:groundDel' .. i .. '">Supprimer</a> <G>-<J> <a href="event:groundZ+' .. i .. '">↑</a> <a href="event:groundZ-' .. i .. '">↓</a>\n'
- end
- end
- groundsStr = groundsStr .. "\n\n<p align='center'>"
- if #grounds > 8 then
- if startID > 8 then
- groundsStr = groundsStr .. string.format('<a href="event:groundSettings%d">< <font color="#c2c2da">%d-%d</font></a>', startID-8, startID-8, startID-1)
- end
- if #grounds > startID+8 then
- startID = startID+8
- groundsStr = groundsStr .. string.format(' %s<a href="event:groundSettings%d">> <font color="#c2c2da">%d-%d</font></a>', startID > 8 and "<G>|<V> " or "", startID, startID, startID+7)
- end
- end
- groundsStr = groundsStr .. "\n<V> Total: <N>" .. #grounds .. " <G>|<V> <R><b><a href='event:close'>Fermer</a></b>"
- ui.addTextArea(45,"<p align='center'><J><font size='20'>Options des sols</font>\n\n<a href='event:groundAdd'>Ajouter</a><p align='left'>\n\n"..groundsStr,name,300,50,200,317,1,0,0.8)
- elseif callback == 'groundAdd' then
- table.insert(grounds, { L=10, H=10, X=0, Y=0, T=0, P=string.split('0,0,0.3,0.2,0,0,0,0') })
- eventTextAreaCallback(ID, name, 'groundSettings')
- elseif callback:sub(1,9) == 'groundDel' then
- local gID = tonumber(callback:sub(10) or 0)
- table.remove(grounds, gID)
- eventTextAreaCallback(ID, name, 'groundSettings')
- elseif callback:sub(1,10) == 'groundEdit' then
- local gID = tonumber(callback:sub(11)) -- zemin id
- if grounds[gID] then
- ui.addTextArea(121,"",name,grounds[gID].X-5,grounds[gID].Y-5,10,10,0xe9c764,0xe9c764,0.5)
- ui.removeTextArea(45, name)
- ui.addTextArea(71,string.format("<p align='center'><b><font color='#BABD2F'>Cliquez sur une de ces options pour modifier le sol</font></b><br><N><a href='event:changeValue%itype'>Type: %s</a> </font><G>|<N> <a href='event:changeValue%ix'>X: %i</a> <G>|<N> <a href='event:changeValue%iy'>Y: %i</a> <G>|<N> Z: %i <G>|<N> <a href='event:changeValue%il'>Longueur: %i</a> <G>|<N> <a href='event:changeValue%ih'>Hauteur: %i</a> <G>|<N> <a href='event:changeValue%ifri'>Friction: %s</a> <G>|<N> <a href='event:changeValue%ires'>Restitution: %s</a> <G>|<N> <a href='event:changeValue%iangle'>Angle: %i</a> <G>|<N> <a href='event:changeValue%icolor'>Couleur: %s</a><br><R><b><p align='left'><a href='event:close'>[Fermer]</a>",
- gID, groundTypes[tonumber(grounds[gID].T or 0)] or 'Unknown', gID, grounds[gID].X or 0, gID, grounds[gID].Y or 0, gID, gID, grounds[gID].L or 0, gID, grounds[gID].H or 0, gID, grounds[gID].P[3] or 0, gID, grounds[gID].P[4] or 0, gID, grounds[gID].P[5] or 0, gID, string.format('%x',grounds[gID].o or '0')),name,40,50,720,nil,1,0,0.8)
- else
- eventTextAreaCallback(ID, name, 'groundSettings')
- end
- elseif callback:sub(1,11) == 'changeValue' and callback:len() > 11 then
- local gID, editType = callback:match('changeValue(%d+)(.+)')
- if gID and editType then
- players[name].edit = { type=editType, ID=tonumber(gID) }
- ui.addPopup(53,2,"Entrez une nouvelle valeur",name,300,105,200)
- print(name.." - "..editType)
- end
- elseif callback:sub(1,7) == 'groundZ' then
- local o, gID = callback:match('groundZ([%+%-])(%d+)')
- gID = gID and tonumber(gID) or 0
- if grounds[gID] and #grounds > 1 then
- if o == '+' then
- table.swap(grounds, gID, gID == 1 and #grounds or gID-1)
- elseif o == '-' then
- table.swap(grounds, gID, gID == #grounds and 1 or gID+1)
- end
- eventTextAreaCallback(ID, name, 'groundSettings')
- end
- elseif callback == 'reloadMap' then
- updateXML()
- tfm.exec.newGame(xml)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement