Advertisement
Fooksie

shoeman

Sep 1st, 2013
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.97 KB | None | 0 0
  1. --Globals
  2. map={}
  3. shaman={}
  4. players={}
  5. roomLang=tfm.get.room.community
  6.  
  7. --Cool cats incorporated
  8. admins={
  9.     "Thewav",
  10.     "Gogoninja",
  11.     "Fxie",
  12.     "Begentle"
  13.     }
  14.  
  15. --All the maps
  16. maps={
  17.     --Difficulty : 1
  18.         {"98","72","36","5","17","16","91","90","93","4","0","40","3","66","@145968","@156966","@129420","@243562","@157033","@365011","@426398"},
  19.     --Difficulty : 2
  20.         {"@126092","@173024","@120806","@237106","@165741","@187088","@299158","@182878","@156104","@306731","@158963","@159709","@340220","@576319","@595756","@500471","@596640","@1324782","@392150","@497021","@576456","@1655360","@420875","@740663","@953233","@1900072","@460646","@222673","@348367","@2080619","@1641473","@1974090","@326777"},
  21.     --Difficulty : 3
  22.         {"@166138","@215312","@164213","@252478","@169710","@172357","@155582","@215337","@151712","@165565","@199112","@157743","@182896","@213781","@184833","@131444","@149095","@361032","@239941","@184961","@310507","@448567","@206400","@196584","@508150","@176748","@442510","@224120","@798052","@499562","@384181","@511088","@273240","@1331620","@413750","@268534","@187466","@1411844","@183895","@505403","@950364","@1203037","@1143235","@1317866","@521183","@1547749","@2116521","@781753","@1751612","@388828","@1233889","@1777037","@2068355","@1618577","@953826","@2012449","@757907","@1796429","@1786437","@2209096","@2462668","@1746907","@2092021","@268191","@3120329","@3298111"},
  23.     --Difficulty : 4
  24.         {"@263781","@194688","@219444","@196529","@156461","@191222","@234665","@355630","@164663","@158480","@168872","@187059","@220435","@198928","@185911","@171093","@178025","@183740","@185090","@198246","@315827","@202863","@171097","@364705","@193690","@553883","@261584","@365009","@868945","@1701298","@1092673","@858366","@2038478","@1620772","@1949565","@2088714","@2878646","@2092977","@2129724","@3112222","@1669376","@1766183","@2138532","@2472758","@771582"},
  25.     --Difficulty : 5
  26.         {"@200017","@185570","@217636","@188815","@232796","@188810","@191021","@245354","@714532","@188816","@188821","@714532","@178354","@256626","@164118","@202107","@180000","@187136","@198666","@180079","@158280","@196843","@190415","@226758","@173231","@314322","@263777","@232664","@205541","@235616","@308787","@230521","@215419","@183705","@214161","@196702","@307703","@417959","@182121","@257766","@227056","@221709","@247831","@241331","@481062","@307669","@258688","@740158","@476149","@314374","@199936","@212588","@609692","@308831","@356895","@968374","@359813","@379440","@262174","@2363288","@1751914","@1938417","@1995986","@2126726","@1203208","@2703245","@401476","@3262738","@2964954","@2096219"},
  27.     --Difficulty : 6
  28.         {"@235625","@238131","@197214","@198940","@234373","@188813","@193340","@213336","@210113","@209554","@232698","@241344","@225254","@244332","@264934","@194703","@242120","@203474","@196275","@187081","@188818","@206502","@192668","@237240","@233480","@387184","@212456","@295751","@199394","@200667","@212526","@214593","@212573","@206881","@355007","@343593","@335523","@276705","@236693","@551627","@217836","@276705","@236693","@551627","@217836","@225132","@322562","@213725","@240475","@205448","@227051","@258638","@334816","@969655","@305377","@306675","@416256","@338383","@923918","@352614","@1629869","@1481868","@1461340","@2371243","@2998412","@1345939","@2494537","@2359943","@3111491","@1494939","@2923482","@2412377","@3008779"},
  29.     --Difficulty : 7
  30.         {"@231731","@206992","@197353","@188823","@188820","@198024","@204088","@209528","@217864","@219864","@209446","@247680","@230991","@205344","@198784","@263784","@197293","@231132","@196828","@233166","@226248","@208640","@217000","@237064","@192020","@187080","@283029","@201801","@216219","@288084","@262099","@307610","@252937","@234380","@218468","@197595","@319985","@207798","@236796","@233629","@205419","@240739","@194233","@238375","@236131","@237406","@370752","@238455","@401492","@241457","@245860","@220335","@242375","@226413","@214937","@268623","@357228","@252048","@315809","@299382","@249822","@330892","@312031","@481056","@338181","@257757","@231528","@242278","@399349","@208736","@191592","@341559","@258637","@274146","@271587","@289645","@615238","@320494","@468071","@503884","@545807","@287449","@260221","@527447","@233649","@227971","@414660","@519242","@1417248","@414661","@846342","@512456","@417810","@553899","@752417","@542413","@556279","@733440","@234115","@520924","@2472679","@1423563","@1691055","@967215","@2406146","@1403042","@770904","@812076","@999188","@2023691","@1244150","@3176673","@2459719","@2841670","@2501595","@2852108","@2703587","@2998240","@2767741","@3056124","@2005081","@3184079","@1418785"},
  31.     --Difficulty : 8
  32.         {"@234123","@188822","@226778","@321526","@267955","@236791","@232571","@235336","@264225","@233647","@219832","@196829","@193002","@264915","@234632","@204664","@203470","@216341","@206309","@242370","@248286","@242983","@306627","@268246","@370516","@444297","@369747","@220380","@260509","@411326","@244891","@311356","@215993","@241751","@358290","@230969","@234309","@267842","@396930","@425908","@241553","@296711","@443132","@338190","@547559","@265010","@364005","@277898","@217526","@404228","@335297","@388986","@257186","@264935","@236798","@447984","@276392","@240682","@474472","@373987","@277983","@336989","@391241","@739499","@378580","@252438","@511728","@365768","@263329","@467414","@627202","@441346","@624118","@731489","@380166","@466490","@749021","@345151","@568364","@446198","@462403","@514457","@242459","@515899","@626181","@506517","@619280","@1340877","@534718","@578388","@814410","@231265","@593131","@785898","@1166601","@482681","@2127662","@528312","@1701589","@607825","@994954","@779801","@2389050","@763472","@735805","@1413649","@1351329","@2310061","@2534197","@959180","@1929795","@2331792","@998473","@1410949","@600603","@2840630","@2544586","@2537023","@2810439","@2799635","@2928258","@476182","@2978051","@2388832"},
  33.     --Difficulty : 9
  34.         {"@242369","@231308","@214832","@234430","@210051","@205530","@264943","@376296","@373949","@360293","@446312","@476210","@234352","@203079","@455544","@264936","@337908","@311349","@282609","@315828","@218679","@199601","@373344","@448969","@399871","@377583","@425781","@465681","@476209","@206508","@469323","@495986","@492211","@342786","@370472","@588036","@763403","@584718","@227131","@575724","@455636","@392885","@450444","@500142","@366667","@454431","@449352","@426294","@450439","@763385","@722487","@1449740","@441360","@883592","@615403","@567350","@1541093","@506058","@1375151","@619677","@696092","@692479","@726596","@632273","@713910","@1366068","@602412","@1788125","@781651","@1402219","@1081183","@476201","@2829045","@1915615","@2945559","@1649747","@2537078","@1448991","@2414363","@3062525","@2777149","@2780650","@2639999","@2777341","@1111111","@2408475","@3216511","@3049564","@2978100"},
  35.     --Difficulty : 10
  36.         {"@287311","@280839","@514036","@309436","@369744","@234917","@367050","@476207","@503546","@1446346","@203108","@566172","@1745954","@731853","@743329","@3181150","@599878"}
  37.     }
  38.  
  39. --All the words
  40. text={
  41.     welcome="Welcome to the %s minigame. Press %s or write %s for more information.",
  42.     help="Welcome to Room Shaman!",
  43.     help_setdiff="%s : set difficulty (range must be at least 2)",
  44.     help_skip="%s : skip the map if you are shaman",
  45.     help_mort="%s : die (same as /mort)",
  46.     newgame="%s %s by %s - Difficulty : %d\n%s Shaman : %s - Level : %d",
  47.     get_xp="You got %s Room XP!",
  48.     level_up="%s is now Room Level %s!",
  49.     setlang="Language set : %s",
  50.     setdiff="Set difficulty : %d - %d",
  51.     setdiff_invalid="Invalid difficulty! Try %s instead.",
  52.     spirit_warning="You used %d / %d spirits allowed!"
  53.     }
  54. text.EN=text
  55. text.BR={
  56.     welcome="Bem vindo a sala %s. Aperte %s ou escreva %s para mais informações",
  57.     help="",
  58.     help_setdiff="",
  59.     help_skip="",
  60.     help_mort="",
  61.     newgame="%s %s by %s - Difficulty : %d\n%s Shaman : %s - Level : %d",
  62.     get_xp="",
  63.     level_up="",
  64.     setlang="Idioma da sala alterado para o %s",
  65.     setdiff="Alcance de sua dificuldade: %d - %d",
  66.     setdiff_invalid="Jogadores com nova rosa podem te ajudar.",
  67.     spirit_warning="Cuidado! Você só pode usar mais  %d / %d spirit(s)."
  68.     }
  69.  
  70. --Administration
  71. function isAdmin(name)
  72.     for i,admin in ipairs(admins) do
  73.         if name==admin then
  74.             return true
  75.             end
  76.         end
  77.     return false
  78.     end
  79.  
  80. --Send chat messages catered toward your speaking
  81. function sendChatMessage(message,name,prefix,f)
  82.     if name~=nil then
  83.         message=(text[players[name].lang] or text)[message] or "ERROR"
  84.         if prefix then
  85.             message=prefix..message
  86.             end
  87.         if f then
  88.             message=message:format(f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8],f[9])
  89.             end
  90.         tfm.exec.chatMessage(message,name)
  91.     else
  92.         for name,player in pairs(tfm.get.room.playerList) do
  93.             sendChatMessage(message,name,prefix,f)
  94.             end
  95.         end
  96.     end
  97.  
  98. --Game begin
  99. function eventNewGame()
  100.     tfm.exec.setShaman(shaman.name)
  101.     tfm.exec.setUIMapName("<CH>"..map.code.."<N> - Difficulty "..map.diff)
  102.     tfm.exec.setUIShamanName("<CH>"..shaman.name.."<N> Lv. "..shaman.level)
  103.     map.author="Unknown"
  104.     if tfm.get.room.xmlMapInfo~=nil then
  105.         map.author=tfm.get.room.xmlMapInfo.author
  106.         end
  107.     sendChatMessage("newgame",nil,"<ROSE>",{
  108.         "[•Map Info]<N>","<CH>"..map.code.."<N>",map.author,map.diff,
  109.         "<ROSE>[•Map Info]<N>","<CH>"..shaman.name.."<N>",shaman.level
  110.         })
  111.     end
  112.  
  113. --Game goes on
  114. function eventLoop(time,remaining,queue)
  115.     if remaining<=500 then
  116.         if shaman.saves~=nil and shaman.saves>0 then
  117.             local xpgain=shaman.saves*map.diff+map.diff*10
  118.             shaman.xp=shaman.xp+xpgain
  119.             sendChatMessage("get_xp",shaman.name,"<CH>",{"<N>"..xpgain.."<CH>"})
  120.             local nextLv=100*shaman.level+100
  121.             if shaman.xp>nextLv then
  122.                 shaman.xp=shaman.xp-nextLv
  123.                 shaman.level=shaman.level+1
  124.                 sendChatMessage("level_up",nil,"<J>",{shaman.name,shaman.level})
  125.                 end
  126.             end
  127.         local topScore=-1
  128.         for name,player in pairs(tfm.get.room.playerList) do
  129.             if player.score>topScore and not player.isShaman then
  130.                 topScore=player.score
  131.                 shaman=players[name]
  132.                 end
  133.             end
  134.         shaman.saves=0
  135.         shaman.spirits=0
  136.         shaman.died=false
  137.         tfm.exec.setPlayerScore(shaman.name,1,true)
  138.         if queue==nil then
  139.             map.diff=math.random(shaman.diffMin,shaman.diffMax)
  140.             map.code=maps[map.diff][math.random(#maps[map.diff])]
  141.         else
  142.             map.diff=-1
  143.             map.code=queue
  144.             end
  145.         tfm.exec.setGameTime(5)
  146.         tfm.exec.newGame(map.code)
  147.         end
  148.     end
  149.  
  150.  
  151. --Players join
  152. function eventNewPlayer(name)
  153.     tfm.exec.bindKeyboard(name,9,true,true)
  154.     if not players[name] then
  155.         players[name]={
  156.             name=name,
  157.             lang=roomLang,
  158.             xp=0,
  159.             level=1,
  160.             diffMin=1,
  161.             diffMax=5
  162.             }
  163.         end
  164.     if isAdmin(name) then
  165.         tfm.exec.setNameColor(name,"0xFE8CFF")
  166.         end
  167.     sendChatMessage("welcome",name,"<N>",{"<CH>SHAMAN<N>","<CH>TAB<N>","<CH>!help<N>"})
  168.     end
  169.  
  170. --Players die
  171. function eventPlayerDied(name)
  172.     if name==shaman.name and not shaman.died then
  173.         shaman.died=true
  174.         tfm.exec.setGameTime(20,true)
  175.         end
  176.     for name,player in pairs(tfm.get.room.playerList) do
  177.         if not player.isDead then
  178.             return
  179.             end
  180.         end
  181.     eventLoop(0,0)
  182.     end
  183.  
  184. --Players achieve victory
  185. function eventPlayerWon(name)
  186.     if name~=shaman.name then
  187.         shaman.saves=shaman.saves+1
  188.         end
  189.     for name,player in pairs(tfm.get.room.playerList) do
  190.         if not player.isDead then
  191.             return
  192.             end
  193.         end
  194.     eventLoop(0,0)
  195.     end
  196.  
  197. --Players press keys
  198. function eventKeyboard(name,key,down,x,y)
  199.     if key==9 then
  200.         eventChatCommand(name,"help")
  201.         end
  202.     end
  203.  
  204. --Shamans summon
  205. function eventSummoningEnd(name,id,x,y,angle,xSpeed,ySpeed,object,other)
  206.     if id==24 then
  207.         shaman.spirits=shaman.spirits+1
  208.         if shaman.spirits>3 then
  209.             eventLoop(0,0)
  210.         else
  211.             sendChatMessage("spirit_warning",name,"<R>",{shaman.spirits,3})
  212.             end
  213.         end
  214.     end
  215.  
  216. --Chat commands
  217. function eventChatCommand(name,message)
  218.     --Prepwork
  219.     local args={}
  220.     local admin=isAdmin(name)
  221.     for arg in message:gmatch("[^%s]+") do
  222.         table.insert(args,arg:lower())
  223.         end
  224.     message=message:match("%s(.*)") or ""
  225.     --Cmd: help
  226.     if args[1]=="help" or args[1]=="info" or args[1]=="sync" then
  227.         local text=text[players[name].lang] or text
  228.         ui.addPopup(1,name,0,table.concat({
  229.             "<b>"..(text.help or "HELP").."</b>",
  230.             (text.help_setdiff or "SETDIFF"):format("<font color='#98E2EB'>!setdiff x-y</font>"),
  231.             (text.help_skip or "SKIP"):format("<font color='#98E2EB'>!skip</font>"),
  232.             (text.help_mort or "MORT"):format("<font color='#98E2EB'>!mort</font>")
  233.             },"\n\n"),300,150,200)
  234.     --Cmd: set difficulty
  235.     elseif args[1]=="setdiff" then
  236.         local min,max
  237.         if args[2] then
  238.             min,max=string.match(args[2],"(%d)-(%d+)")
  239.             min,max=tonumber(min),tonumber(max)
  240.             end
  241.         if min==nil or max==nil or min<1 or min>=max-1 or max>10 then
  242.             sendChatMessage("setdiff_invalid",name,"<R>",{"<N>!setdiff 1-5<R>"})
  243.         else
  244.             players[name].diffMin=min
  245.             players[name].diffMax=max
  246.             sendChatMessage("setdiff",name,"<N>",{min,max})
  247.             end
  248.     --Cmd: die
  249.     elseif args[1]=="mort" then
  250.         tfm.exec.killPlayer(name)
  251.     --Cmd: skip map
  252.     elseif args[1]=="skip" and (shaman.name==name or admin) then
  253.         eventLoop(0,0)
  254.     --Cmd: become shaman
  255.     elseif admin and args[1]=="shaman" then
  256.         tfm.exec.setShaman(name)
  257.     --Cmd: play map
  258.     elseif admin and args[1]=="play" then
  259.         eventLoop(0,0,args[2])
  260.     --Cmd: get paid
  261.     elseif admin and args[1]=="score" then
  262.         tfm.exec.setPlayerScore(name,tonumber(args[2]) or 0)
  263.     elseif admin and args[1]=="mod" then
  264.         tfm.exec.chatMessage("<ROSE>["..name.."]<N> "..message)
  265.     --Cmd: set language
  266.     elseif text[args[1]:upper()] then
  267.         players[name].lang=args[1]:upper()
  268.         sendChatMessage("setlang",name,"<N>",{"<VP>"..args[1]:upper().."<N>"})
  269.         end
  270.     end
  271.  
  272. --Hide commands
  273. for i,command in ipairs({"help","shaman","mod","mort","setdiff","stats","add","save","delete","info","maps","reset","fr","en","br","pt","pl","nl","vk","cn","tr","es"}) do
  274.     system.disableChatCommandDisplay(command)
  275.     end
  276.  
  277. --Join existing players
  278. for name,player in pairs(tfm.get.room.playerList) do
  279.     eventNewPlayer(name)
  280.     shaman=players[name]
  281.     end
  282.  
  283. --Set up everything
  284. tfm.exec.disableAutoShaman(true)
  285. tfm.exec.disableAutoNewGame(true)
  286.  
  287. --Initiate
  288. eventLoop(0,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement