Advertisement
Wav

*#ShamanWIP

Wav
Sep 2nd, 2013
3,618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.83 KB | None | 0 0
  1.  
  2. --People who want to join lua it's not a good idea to copy this.
  3.    
  4. --Globals
  5. map={}
  6. shaman={}
  7. players={}
  8. roomLang=tfm.get.room.community
  9. loaded=false
  10.  
  11. --Cool cats incorporated
  12. admins={
  13.     "Thewav",
  14.     "Gogoninja",
  15.     "Fxie",
  16.     "Begentle"
  17.     }
  18.  
  19. --All the maps
  20. maps={
  21.     --Difficulty : 1
  22.         {"98","72","36","5","17","16","91","90","93","4","0","40","3","66","@145968","@156966","@129420","@243562","@157033","@365011","@426398"},
  23.     --Difficulty : 2
  24.         {"@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"},
  25.     --Difficulty : 3
  26.         {"@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"},
  27.     --Difficulty : 4
  28.         {"@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"},
  29.     --Difficulty : 5
  30.         {"@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"},
  31.     --Difficulty : 6
  32.         {"@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"},
  33.     --Difficulty : 7
  34.         {"@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"},
  35.     --Difficulty : 8
  36.         {"@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"},
  37.     --Difficulty : 9
  38.         {"@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"},
  39.     --Difficulty : 10
  40.         {"@287311","@280839","@514036","@309436","@369744","@234917","@367050","@476207","@503546","@1446346","@203108","@566172","@1745954","@731853","@743329","@3181150","@599878"}
  41.     }
  42.  
  43. --All the words
  44. text={
  45.     welcome="Welcome to the %s minigame. Press %s or write %s for more information.",
  46.     help="Welcome to Room Spiritual!",
  47.     help_setdiff="%s : set difficulty (range must be at least 2)",
  48.     help_skip="%s : skip the map if you are shaman",
  49.     help_mort="%s : die (same as /mort)",
  50.     newgame="%s %s by %s - Difficulty : %d\n%s Shaman : %s - Level : %d",
  51.     get_xp="You got %s Room XP!",
  52.     level_up="%s is now Room Level %s!",
  53.     setlang="Language set : %s",
  54.     setdiff="Set difficulty : %d - %d",
  55.     setdiff_invalid="Invalid difficulty! Try %s instead.",
  56.     spirit_warning="You used %d / %d spirits allowed!",
  57.     stats="%s's Stats: \n Setdiff %s, Level %s, Experience %s"
  58.     }
  59. text.EN=text
  60. text.BR={
  61.     welcome="Bem vindo a sala %s. Aperte %s ou escreva %s para mais informações",
  62.     help="",
  63.     help_setdiff="",
  64.     help_skip="",
  65.     help_mort="",
  66.     newgame="%s %s by %s - Difficulty : %d\n%s Shaman : %s - Level : %d",
  67.     get_xp="",
  68.     level_up="",
  69.     setlang="Idioma da sala alterado para o %s",
  70.     setdiff="Alcance de sua dificuldade: %d - %d",
  71.     setdiff_invalid="Jogadores com nova rosa podem te ajudar.",
  72.     spirit_warning="Cuidado! Você só pode usar mais  %d / %d spirit(s).",
  73.     stats="%s's stats: \n Setdiff %s, Level %s, Experience %s"
  74.     }
  75.  
  76. --Administration
  77. function isAdmin(name)
  78.     for i,admin in ipairs(admins) do
  79.         if name==admin then
  80.             return true
  81.             end
  82.         end
  83.     return false
  84.     end
  85.  
  86. --Send chat messages catered toward your speaking
  87. function sendChatMessage(message,name,prefix,f)
  88.     if name~=nil then
  89.         message=(text[players[name].lang] or text)[message] or "ERROR"
  90.         if prefix then
  91.             message=prefix..message
  92.             end
  93.         if f then
  94.             message=message:format(f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8],f[9])
  95.             end
  96.         tfm.exec.chatMessage(message,name)
  97.     else
  98.         for name,player in pairs(tfm.get.room.playerList) do
  99.             sendChatMessage(message,name,prefix,f)
  100.             end
  101.         end
  102.     end
  103.  
  104. --Game begin
  105. function eventNewGame()
  106.     tfm.exec.setShaman(shaman.name)
  107.     tfm.exec.setUIMapName("<CH>"..map.code.."<N> - Difficulty "..map.diff)
  108.     tfm.exec.setUIShamanName("<CH>"..shaman.name.."<N> Lv. "..shaman.level)
  109.     map.author="Unknown"
  110.     if tfm.get.room.xmlMapInfo~=nil then
  111.         map.author=tfm.get.room.xmlMapInfo.author
  112.         end
  113.     sendChatMessage("newgame",nil,"<ROSE>",{
  114.         "[•Map Info]<N>","<CH>"..map.code.."<N>",map.author,map.diff,
  115.         "<ROSE>[•Map Info]<N>","<CH>"..shaman.name.."<N>",shaman.level
  116.         })
  117.     end
  118.  
  119. --Game goes on
  120. function eventLoop(time,remaining,queue)
  121.     if remaining<=500 then
  122.         if shaman.saves~=nil and shaman.saves>0 then
  123.             local xpgain=shaman.saves*map.diff+map.diff*10
  124.             shaman.xp=shaman.xp+xpgain
  125.             sendChatMessage("get_xp",shaman.name,"<CH>",{"<N>"..xpgain.."<CH>"})
  126.             local nextLv=100*shaman.level+100
  127.             if shaman.xp>nextLv then
  128.                 shaman.xp=shaman.xp-nextLv
  129.                 shaman.level=shaman.level+1
  130.                 sendChatMessage("level_up",nil,"<J>",{shaman.name,shaman.level})
  131.                 end
  132.             end
  133.         local topScore=-1
  134.         for name,player in pairs(tfm.get.room.playerList) do
  135.             if player.score>topScore and not player.isShaman then
  136.                 topScore=player.score
  137.                 shaman=players[name]
  138.                 end
  139.             end
  140.         shaman.saves=0
  141.         shaman.spirits=0
  142.         shaman.died=false
  143.         tfm.exec.setPlayerScore(shaman.name,1,true)
  144.         tmp = {}
  145.         if queue==nil then
  146.             for diff=shaman.diffMin ,shaman.diffMax do
  147.                 for _,value in ipairs(maps[diff]) do
  148.                     table.insert(tmp,value)
  149.                 end
  150.             end
  151.             map.code=tmp[math.random(#tmp)]
  152.             for diff=shaman.diffMin,shaman.diffMax do
  153.                 for _,value in ipairs(maps[diff]) do
  154.                     if value==map.code then
  155.                         map.diff=diff
  156.                     end
  157.                 end                
  158.             end
  159.         else
  160.             map.diff=-1
  161.             map.code=queue
  162.             end
  163.  if map.code == nil then
  164. Tfm.exec.setGameTime(5)
  165. else
  166.  
  167.         tfm.exec.setGameTime(5)
  168.         tfm.exec.newGame(map.code)
  169. end
  170.         end
  171.     end
  172.  
  173.  
  174. --Players join
  175. function eventNewPlayer(name)
  176.     tfm.exec.bindKeyboard(name,9,true,true)
  177.     if not players[name] then
  178.         players[name]={
  179.             name=name,
  180.             lang=roomLang,
  181.             xp=0,
  182.             level=1,
  183.             diffMin=1,
  184.             diffMax=5
  185.             }
  186.         end
  187.     if isAdmin(name) then
  188.         tfm.exec.setNameColor(name,"0xFE8CFF")
  189.     end
  190.     sendChatMessage("welcome",name,"<N>",{"<CH>SPIRITUAL<N>","<CH>TAB<N>","<CH>!help<N>"})
  191.     end
  192.  
  193. --Players die
  194. function eventPlayerDied(name)
  195.     if name==shaman.name and not shaman.died then
  196.         shaman.died=true
  197.         tfm.exec.setGameTime(20,true)
  198.         end
  199.     for name,player in pairs(tfm.get.room.playerList) do
  200.         if not player.isDead then
  201.             return
  202.             end
  203.         end
  204.     eventLoop(0,0)
  205.     end
  206.  
  207. --Players achieve victory
  208. function eventPlayerWon(name)
  209.     if name~=shaman.name then
  210.         shaman.saves=shaman.saves+1
  211.         end
  212.     for name,player in pairs(tfm.get.room.playerList) do
  213.         if not player.isDead then
  214.             return
  215.             end
  216.         end
  217.     eventLoop(0,0)
  218.     end
  219.  
  220. --Players press keys
  221. function eventKeyboard(name,key,down,x,y)
  222.     if key==9 then
  223.         eventChatCommand(name,"help")
  224.         end
  225.     end
  226.  
  227. --Shamans summon
  228. function eventSummoningEnd(name,id,x,y,angle,xSpeed,ySpeed,object,other)
  229.     if id==24 then
  230.         shaman.spirits=shaman.spirits+1
  231.         if shaman.spirits>3 then
  232.             eventLoop(0,0)
  233.         else
  234.             sendChatMessage("spirit_warning",name,"<R>",{shaman.spirits,3})
  235.             end
  236.         end
  237.     end
  238.  
  239. --Chat commands
  240. function eventChatCommand(name,message)
  241.     --Prepwork
  242.     local args={}
  243.     local admin=isAdmin(name)
  244.     for arg in message:gmatch("[^%s]+") do
  245.         table.insert(args,arg:lower())
  246.         end
  247.     message=message:match("%s(.*)") or ""
  248.     --Cmd: help
  249.     if args[1]=="help" or args[1]=="info" or args[1]=="sync" then
  250.         local text=text[players[name].lang] or text
  251.         ui.addPopup(1,0,table.concat({
  252.             "<b>"..(text.help or "HELP").."</b>",
  253.             (text.help_setdiff or "SETDIFF"):format("<font color='#98E2EB'>!setdiff x-y</font>"),
  254.             (text.help_skip or "SKIP"):format("<font color='#98E2EB'>!skip</font>"),
  255.             (text.help_mort or "MORT"):format("<font color='#98E2EB'>!mort</font>")
  256.             },"\n\n"),name,300,150,200)
  257.     --Cmd: set difficulty
  258.     elseif args[1]=="setdiff" then
  259.         local min,max
  260.         if args[2] then
  261.             min,max=string.match(args[2],"(%d)-(%d+)")
  262.             min,max=tonumber(min),tonumber(max)
  263.             end
  264.         if min==nil or max==nil or min<1 or min>=max-1 or max>10 then
  265.             sendChatMessage("setdiff_invalid",name,"<R>",{"<N>!setdiff 1-5<R>"})
  266.         else
  267.             players[name].diffMin=min
  268.             players[name].diffMax=max
  269.             sendChatMessage("setdiff",name,"<N>",{min,max})
  270.             end
  271.     --Cmd: die
  272.     elseif args[1]=="mort" then
  273.         tfm.exec.killPlayer(name)
  274.     --Cmd: skip map
  275.     elseif args[1]=="skip" and (shaman.name==name or admin) then
  276.         eventLoop(0,0)
  277.     --Cmd: become shaman
  278.     elseif admin and args[1]=="shaman" then
  279.         tfm.exec.setShaman(name)
  280.     --Cmd: play map
  281.     elseif admin and args[1]=="play" then
  282.         eventLoop(0,0,args[2])
  283.     --Cmd: get paid
  284.     elseif admin and args[1]=="score" then
  285.         tfm.exec.setPlayerScore(name,tonumber(args[2]) or 0)
  286.     elseif args[1]=="stats" then
  287.         if not args[2] then args[2]=name end
  288.         if players[args[2]]then sendChatMessage("stats",name,"<N>",{"<CH>"..args[2].."<N>","<CH>"..players[args[2]].diffMin.."<N>-<CH>"..players[args[2]].diffMax.."<N>","<CH>"..players[args[2]].level.."<N>","<CH>"..players[args[2]].xp.."<N>"}) end
  289.     elseif admin and args[1]=="mod" then
  290.         tfm.exec.chatMessage("<ROSE>["..name.."]<N> "..message)
  291.     --Cmd: set language
  292.     elseif text[args[1]:upper()] then
  293.         players[name].lang=args[1]:upper()
  294.         sendChatMessage("setlang",name,"<N>",{"<VP>"..args[1]:upper().."<N>"})
  295.         end
  296.     end
  297.  
  298. --Hide commands
  299. 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
  300.     system.disableChatCommandDisplay(command)
  301.     end
  302.  
  303. --Join existing players
  304. system.newTimer( function()
  305. for name,player in pairs(tfm.get.room.playerList) do
  306.     eventNewPlayer(name)
  307.     shaman=players[name]
  308.     end eventLoop(0,0)end,3000)
  309.  
  310. --Set up everything
  311. tfm.exec.disableAutoShaman(true)
  312. tfm.exec.disableAutoNewGame(true)
  313.  
  314. --Initiate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement