Advertisement
podoko_Lua

Challenge 1

Apr 30th, 2014
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. --[[ http://www.transformice.com/forum/?s=715842&p=0 Challenge_1 ]]
  2.  
  3.  
  4. listP = {}
  5.  
  6. godOfSpeed = " "
  7. godSelect = " "
  8.  
  9. itL = "<p align='center'><a href='event:-10'>&#171;</a><a href='event:-1'>&lt;</a> "
  10. itR = " <a href='event:+1'>&gt;</a><a href='event:+10'>&#187;</a></p>"
  11.  
  12. function init()
  13.     for name, key in pairs(tfm.get.room.playerList) do
  14.         eventNewPlayer(name)
  15.     end
  16. end
  17.  
  18.  
  19. function eventNewGame()
  20.    
  21.     ui.removeTextArea(2, godOfSpeed)
  22.     godOfSpeed = listP[math.random(#listP)]['name']
  23.     godSelection = godOfSpeed
  24.     print("Your new god of speed is "..godOfSpeed)
  25.    
  26.     ui.addTextArea(2, "<a href='event:listP'>•</a>", godOfSpeed,345, 375, 20, 20, 1, 1, 0, true)
  27. end
  28.  
  29.  
  30. function eventNewPlayer(name)
  31.     ui.addTextArea(1, itL.."0"..itR, name, 355, 375, 90, 20, 1, 1, 0, true)
  32.     table.insert(listP, {['name']=name, ['vx']=0, ['vy']=0 })
  33. end
  34.  
  35. function eventPlayerLeft(name)
  36.     table.remove(listP, findPlayer(listP, name))
  37.     if name == godSelection then godSelection = godOfSpeed end
  38. end
  39.  
  40.  
  41. function eventTextAreaCallback(id, name, call)
  42.  
  43.     if id == 1 then
  44.        
  45.         god = name == godOfSpeed
  46.         cible = (god and godSelection) or name
  47.         cibleK = findPlayer(listP, cible)
  48.         listP[cibleK]["vx"] = listP[cibleK]["vx"] + ((god and call) or callV(listP[cibleK]["vx"], call))
  49.        
  50.         if listP[cibleK]["vx"] ~= 0 then tfm.exec.movePlayer(cible, 0, 0, true, listP[cibleK]["vx"] , tfm.get.room.playerList[cible]['vy'], false) end
  51.        
  52.         ui.updateTextArea(1, itL..tostring(listP[cibleK]["vx"])..itR, cible)
  53.         if name == godOfSpeed then ui.updateTextArea(1, itL..tostring(listP[cibleK]["vx"])..itR, name) end
  54.     elseif id == 2 then
  55.         for key, tab in ipairs(listP) do ui.addTextArea(key+2, "<a href='event:"..tab.name.."'>"..tab.name.."</a>", godOfSpeed, 270, 375-(key-1)*13, 70, 15, 1, 1, 0, true) end
  56.     elseif id >= 3 then
  57.         godSelection = call
  58.         for key in ipairs(listP) do ui.removeTextArea(key + 2, godOfSpeed) end
  59.     end
  60.    
  61. end
  62.  
  63.  
  64.  
  65. function callV (v, add)
  66.     local vT = v + add
  67.     if vT < -50 then
  68.         return -v-50
  69.     else
  70.         return ((vT < 50 and add) or 50-v)
  71.     end
  72. end
  73.  
  74.  
  75.  
  76. function findPlayer(tab, name)
  77.     for key, elmt in pairs(tab) do
  78.         if elmt.name == name then return key end
  79.     end
  80. end
  81.  
  82.  
  83. init()
  84. tfm.exec.newGame(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement