Athesdrake

Random V1.1

Aug 31st, 2017
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.26 KB | None | 0 0
  1. function main()
  2.     --vars:
  3.         version = "1.1"
  4.         format = string.format
  5.     --tables:
  6.         players   = {}
  7.         countries = {"AF", "ZA", "AX", "AL", "DZ", "DE", "DD", "AD", "AO", "AI", "AQ", "AG", "AN", "SA", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "BN", "BG", "BF", "BI", "CV", "KY", "KH", "CM", "CA", "CL", "CN", "CX", "CY", "CC", "CO", "KM", "CG", "CD", "CK", "KR", "KP", "CR", "CI", "HR", "CU", "CW", "DK", "DJ", "DO", "DM", "EG", "SV", "AE", "EC", "ER", "ES", "EE", "US", "ET", "FK", "FO", "FJ", "FI", "FR", "GA", "GM", "GE", "GS", "GH", "GI", "GR", "GD", "GL", "GP", "GU", "GT", "GG", "GN", "GW", "GQ", "GY", "GF", "HT", "HM", "HN", "HK", "HU", "IM", "UM", "VG", "VI", "IN", "IO", "ID", "IR", "IQ", "IE", "IS", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KG", "KI", "KW", "LA", "LS", "LV", "LB", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MY", "MW", "MV", "ML", "MT", "MP", "MA", "MH", "MQ", "MU", "MR", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MZ", "MM", "NA", "NR", "NP", "NI", "NE", "NG", "NU", "NF", "NO", "NC", "NZ", "OM", "UG", "UZ", "PK", "PW", "PS", "PA", "PG", "PY", "NL", "XX", "ZZ", "PE", "PH", "PN", "PL", "PF", "PR", "PT", "QA", "SY", "CF", "RE", "RO", "GB", "RU", "RW", "EH", "BL", "KN", "SM", "MF", "SX", "PM", "VA", "VC", "SH", "LC", "SB", "WS", "AS", "ST", "SN", "RS", "SC", "SL", "SG", "SK", "SI", "SO", "SD", "SS", "LK", "SE", "CH", "SR", "SJ", "SZ", "TJ", "TW", "TZ", "TD", "CS", "CZ", "TF", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TM", "TC", "TR", "TV", "UA", "SU", "UY", "VU", "VE", "VN", "VD", "WF", "YE", "YU", "ZR", "ZM", "ZW"}
  8.         aft = {}
  9.     --sytème:
  10.         table.foreach({"AutoNewGame", "AutoShaman", "AutoTimeLeft", "MortCommand", "DebugCommand"}, function(_,v) tfm.exec["disable"..v](true) end) -- disable
  11.         table.foreach(tfm.get.room.playerList, function(pl) eventNewPlayer(pl) end)
  12.         newMap()
  13. end
  14.  
  15. function eventNewPlayer(name)
  16.     players[name] = {afk=true}
  17.     table.foreach({0,1,2,3}, function(_,key) system.bindKeyboard(name, key, true, true) end)
  18.     ui.setMapName(format("Random V%s <g>|</g> <n>Module créé par</n> <b><v>Athesdrake</v></b>", version))
  19. end
  20.  
  21. function eventPlayerDied(name)
  22.     players[name].afk = true
  23.     if playerLeft()==0 then
  24.         tfm.exec.setGameTime(1)
  25.     elseif playerLeft()==1 then
  26.         tfm.exec.setGameTime(10)
  27.     elseif playerLeft()==2 then
  28.         tfm.exec.setGameTime(20)
  29.     end
  30. end
  31.  
  32. eventPlayerWon = eventPlayerDied
  33.  
  34. function eventNewGame()
  35.     for pl, data in pairs(players) do
  36.         data.afk = true
  37.         after(3, function() tfm.exec.playEmote(pl, 6) end)
  38.     end
  39. end
  40.  
  41. function newMap()
  42.     local canvas = '<C><P G="0,0" /><Z><S><S L="10" o="324650" H="400" X="-5" Y="200" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S P="0,0,0.3,0.2,0,0,0,0" L="10" o="324650" X="805" Y="200" T="12" H="400" /><S L="820" o="324650" X="400" H="10" Y="-5" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S P="0,0,0.3,0.2,0,0,0,0" L="820" o="324650" H="10" Y="405" T="12" X="400" /></S><D><T Y="%d" X="%d" /><F Y="%d" X="%d" /><DS Y="%d" X="%d" /></D><O /></Z></C>'
  43.     tfm.exec.newGame(canvas:format(math.random(50,350), math.random(50,750), math.random(50,350), math.random(50,750), math.random(50,350), math.random(50,750)))
  44. end
  45.  
  46. function playerLeft()
  47.     local alive = {}
  48.     table.foreach(tfm.get.room.playerList, function(k,v) if not v.isDead then table.insert(alive, k) end end)
  49.     return #alive
  50. end
  51.  
  52. function after(temps, func) -- Exec a function after the given time
  53.     table.insert(aft, {t=os.time()+temps*1000, f=func})
  54. end
  55.  
  56. function math.rand_negative(...) -- Return a random negative or positive number with the given args
  57.     return (math.random()>0.5 and 1 or -1)*math.random(table.unpack({...}))
  58. end
  59.  
  60. function eventKeyboard(name, key, down, x, y)
  61.     players[name].afk = false
  62. end
  63.  
  64. function eventLoop(t1, t2)
  65.     if t2<=0 then
  66.         newMap()
  67.     end
  68.     for key,data in ipairs(aft) do
  69.         if data.t<=os.time() then
  70.             data.f()
  71.             table.remove(aft, key)
  72.         end
  73.     end
  74.     for pl, data in pairs(tfm.get.room.playerList) do
  75.         if not players[pl].afk and not (t2<=500) then
  76.             tfm.exec.movePlayer(pl, 0, 0, true, math.rand_negative(50, 100), math.rand_negative(50, 100), false)
  77.             tfm.exec.playEmote(pl, math.random(35), countries[math.random(#countries)])
  78.             tfm.exec.setNameColor(pl, math.random(0xffffff))
  79.         end
  80.     end
  81. end
  82.  
  83. main()
Advertisement
Add Comment
Please, Sign In to add comment