Mousetat

Scissors paper stone 1v1

Jan 7th, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.53 KB | None | 0 0
  1. tfm.exec.disableAutoNewGame(true)
  2. tfm.exec.disableAfkDeath(true)
  3. tfm.exec.disableAutoShaman(true)
  4.  
  5. admins={"Mousetat", "Reshman", "Merrennor"}
  6. keys={32,72,75,74}
  7.  
  8. tfm.exec.newGame('<C><P D="x_transformice/x_evt/x_evt_10/YIKDFERT/Fond.jpg" d="x_transformice/x_evt/x_evt_10/YIKDFERT/OL_AnvilGod.png" Ca="" /><Z><S><S P="0,0,0.3,0.2,0,0,0,0" i="0,0,x_transformice/x_evt/x_evt_10/YIKDFERT/PLTFRM_AnvilGod.png" L="50" o="324650" X="25" c="4" Y="114" T="12" H="50" /><S P="0,0,0.3,0.2,-1,0,0,0" L="281" o="324650" H="22" Y="208" T="12" m="" X="141" /><S L="300" o="324650" H="22" X="150" Y="375" T="12" m="" P="0,0,0.3,0.2,-0,0,0,0" /><S P="0,0,0.3,0.2,-10,0,0,0" L="90" o="324650" X="304" Y="362" T="12" m="" H="22" /><S P="0,0,0.3,0.2,-0,0,0,0" L="150" o="324650" X="421" Y="377" T="12" m="" H="40" /><S L="120" o="324650" X="415" H="100" Y="345" T="12" m="" P="0,0,0.3,0,0,0,0,0" /><S L="281" o="324650" H="22" X="141" Y="103" T="12" m="" P="0,0,0.3,0.2,-0,0,0,0" /><S L="18" X="-10" H="399" Y="201" T="1" P="0,0,0,0.2,0,0,0,0" /><S L="18" H="399" X="810" Y="201" T="1" P="0,0,0,0.2,0,0,0,0" /><S L="18" H="900" X="394" Y="-9" T="1" P="0,0,0,0.2,90,0,0,0" /><S i="0,0,x_transformice/x_evt/x_evt_10/YIKDFERT/PLTFRM_offrande.png" L="50" o="324650" H="50" c="4" N="" Y="25" T="12" X="25" P="0,0,0.3,0.2,0,0,0,0" /><S L="30" o="324650" X="497" H="10" Y="265" T="12" m="" P="0,0,0.3,0.2,200,0,0,0" /><S P="0,0,0.3,0.2,110,0,0,0" L="50" o="324650" H="10" Y="338" T="12" m="" X="507" /><S P="0,0,20,0.2,80,0,0,0" L="50" o="324650" H="10" Y="291" T="12" m="" X="511" /><S L="30" o="324650" H="10" X="480" Y="153" T="12" m="" P="0,0,0.3,0.2,0,0,0,0" /><S P="0,0,0.3,0.2,-40,0,0,0" L="30" o="324650" X="489" Y="150" T="12" m="" H="10" /><S P="0,0,0,0.2,0,0,0,0" L="10" o="" X="359" Y="233" T="12" H="500" /><S P="0,0,,,,0,0,0" L="76" X="317" Y="186" T="9" m="" H="374" /><S P="0,0,0.3,0.2,0,0,0,0" L="100" o="" X="415" Y="260" T="12" H="10" /><S P="0,0,0.3,0.2,0,0,0,0" L="30" o="" X="410" Y="280" T="12" H="30" /><S P="0,0,0.3,0.2,0,0,0,0" L="10" o="" X="460" Y="283" T="12" H="44" /></S><D><DS Y="343" X="55" /></D><O /></Z></C>')
  9. p={}
  10. players={}
  11. player1=""
  12. player2=""
  13. spstimes=5
  14.  
  15. ui.addTextArea(3,"<font size='25' color='#ffffff'> H:</font",nil,680,130,50,50,nil,nil,0,true)
  16. ui.addTextArea(2,"<font size='25' color='#ffffff'> J:</font",nil,680,185,50,50,nil,nil,0,true)
  17. ui.addTextArea(1,"<font size='25' color='#ffffff'> K:</font",nil,680,245,50,50,nil,nil,0,true)
  18. noid=tfm.exec.addImage("153f8d06d84.jpg", "&1", 735, 130)
  19.  
  20. tfm.exec.addImage("153f8d05236.jpg", "&3", 735, 185)
  21.  
  22.  
  23. tfm.exec.addImage("153f8d00af1.jpg", "&2", 735, 245)
  24.  
  25.  
  26. function eventPlayerDied(name)
  27. tfm.exec.respawnPlayer(name)
  28. end
  29.  
  30. function eventPlayerLeft(playerName)
  31. for i=#players, 1, -1 do
  32. table.remove(players)
  33. end
  34. for name, player in pairs(tfm.get.room.playerList) do
  35. table.insert(players, name)
  36. end
  37. if playerName==player1 or playerName==player2 then
  38. randomplayer()
  39. end
  40. end
  41.  
  42. function eventNewPlayer(name)
  43. print(name)
  44. tfm.exec.respawnPlayer(name)
  45. p[name]={chosen1=false, chosen2=false, sps=0, ready1=false, ready2=false, id=99999999999, admin=false}
  46. table.insert(players, name)
  47. for i=#keys,1,-1 do
  48. tfm.exec.bindKeyboard(name,keys[i],true,true)
  49. end
  50. tfm.exec.chatMessage("<font color='#2ECF73'>Welcome to the game of SPS!</font>",name)
  51. tfm.exec.chatMessage("<font color='#2ECF73'>Press SPACE to throw scissors, paper or stone randomly. Alternatively, press H for stone, J for scissors, K for paper</font>",name)
  52. tfm.exec.chatMessage("<font color='#2ECF73'>The first to reach "..spstimes.." scores wins!</font>",name)
  53. tfm.exec.chatMessage("<font color='#2ECF73'>Type !help to see this again, and !mods to see the list of mods in this room.</font>",name)
  54. local count=0
  55. while count<=#admins do
  56. count=count+1
  57. if name==admins[count] then
  58. p[name].admin=true
  59. tfm.exec.chatMessage("<font color='#FEB1FC'>You are an admin, type !c (new score) to change the score that a player must attain to win, and !t (message) to say something, !skip to skip someone's turn.</font>",name)
  60. end
  61. end
  62. tfm.exec.chatMessage("<font color='#ffffff'>The current players competing are: "..player1.." versus "..player2.."</font>",name)
  63. end
  64.  
  65. tfm.exec.chatMessage("<font color='#2ECF73'>Welcome to the game of SPS!</font>")
  66. tfm.exec.chatMessage("<font color='#2ECF73'>Press SPACE to throw scissors, paper or stone randomly. Alternatively, press H for stone, J for scissors, K for paper</font>")
  67. tfm.exec.chatMessage("<font color='#2ECF73'>The first to reach "..spstimes.." scores wins!</font>")
  68. tfm.exec.chatMessage("<font color='#2ECF73'>Type !help to see this again, and !mods to see the list of mods in this room.</font>")
  69.  
  70. for name,player in pairs(tfm.get.room.playerList) do
  71. p[name]={chosen1=false, chosen2=false, sps=0, ready1=false, ready2=false, id=9999999999999, admin=false}
  72. tfm.exec.setPlayerScore(name,0,false)
  73. table.insert(players, name)
  74. for i=#keys,1,-1 do
  75. tfm.exec.bindKeyboard(name,keys[i],true,true)
  76. end
  77. local count=0
  78. while count<=#admins do
  79. count=count+1
  80. if name==admins[count] then
  81. p[name].admin=true
  82. end
  83. end
  84. if p[name].admin==true then
  85. tfm.exec.chatMessage("<font color='#FEB1FC'>You are an admin, type !c (new score) to change the score that a player must attain to win, and !t (message) to say something, !skip to skip someone's turn.</font>",name)
  86. end
  87. end
  88.  
  89. space=true
  90. bufferr=false
  91.  
  92. function eventRPS(random3,random4)
  93. ui.updateTextArea(69, "<font size='30' color='#ffffff'> "..p[player1].sps.." : "..p[player2].sps.."</font>", nil)
  94. if os.time()<timestamp+2000 then
  95. space=false
  96. tfm.exec.playEmote(player1,27,nil)
  97. tfm.exec.playEmote(player2,27,nil)
  98. elseif os.time()>timestamp+3000 and os.time()<timestamp+4000 then
  99. space=true
  100. if random3==1 then
  101. p[player1].id=tfm.exec.addImage("153f8d06d84.jpg","$"..player1,-25,-80) --stone
  102. elseif random3==2 then
  103. p[player1].id=tfm.exec.addImage("153f8d05236.jpg","$"..player1,-25,-80) --scissors
  104. elseif random3==3 then
  105. p[player1].id=tfm.exec.addImage("153f8d00af1.jpg","$"..player1,-25,-80) --paper
  106. end
  107. if random4==1 then
  108. p[player2].id=tfm.exec.addImage("153f8d06d84.jpg","$"..player2,-25,-80) --stone
  109. elseif random4==2 then
  110. p[player2].id=tfm.exec.addImage("153f8d05236.jpg","$"..player2,-25,-80) --scissors
  111. elseif random4==3 then
  112. p[player2].id=tfm.exec.addImage("153f8d00af1.jpg","$"..player2,-25,-80) --paper
  113. end
  114. if (random3%3)+1==random4 then
  115. p[player1].sps=p[player1].sps +1
  116. tfm.exec.setPlayerScore(player1,1,true)
  117. elseif (random4%3)+1==random3 then
  118. p[player2].sps=p[player2].sps +1
  119. tfm.exec.setPlayerScore(player2,1,true)
  120. end
  121.  
  122. if p[player1].sps<spstimes and p[player2].sps<spstimes then
  123. p[player1].ready1=false
  124. p[player2].ready2=false
  125. ui.updateTextArea(69, "<font size='30' color='#ffffff'> "..p[player1].sps.." : "..p[player2].sps.."</font>", nil)
  126. elseif p[player1].sps==spstimes then
  127. p[player1].sps=p[player1].sps
  128. ui.updateTextArea(69,"<font size='15' color='#ffffff'>"..player1.." won!")
  129. tfm.exec.chatMessage("<font color='#BABD2F'>"..player1.." won! Restarting game...</font>")
  130. space=false
  131. bufferr=true
  132. p[player1].ready1=false
  133. p[player2].ready2=false
  134. ui.updateTextArea(69, "<font size='30' color='#ffffff'> "..p[player1].sps.." : "..p[player2].sps.."</font>", nil)
  135. elseif p[player2].sps==spstimes then
  136. p[player2].sps=p[player2].sps
  137. ui.updateTextArea(69,"<font size='15' color='#ffffff'>"..player2.." won!")
  138. tfm.exec.chatMessage("<font color='#BABD2F'>"..player2.." won! Restarting game...</font>")
  139. space=false
  140. bufferr=true
  141. p[player1].ready1=false
  142. p[player2].ready2=false
  143. ui.updateTextArea(69, "<font size='30' color='#ffffff'> "..p[player1].sps.." : "..p[player2].sps.."</font>", nil)
  144. end
  145. ui.removeTextArea(30, nil)
  146. ui.removeTextArea(31, nil)
  147.  
  148. end
  149. end
  150. randomplayering=0
  151.  
  152. function buffer()
  153. if os.time()>timestamp+8000 then
  154. tfm.exec.removeImage(p[player1].id)
  155.  
  156. tfm.exec.removeImage(p[player2].id)
  157.  
  158. randomplayer()
  159. bufferr=false
  160. end
  161. end
  162.  
  163. function randomplayer()
  164. space=true
  165. ui.updateTextArea(69, "<font size='30' color='#FFFFFF'>Ready?</font>", nil)
  166. randomplayering=randomplayering+1
  167. for name, player in pairs(tfm.get.room.playerList) do
  168. p[name].sps=0
  169. tfm.exec.movePlayer(name,55,343,false,0,50,false)
  170. end
  171. if randomplayering==#players then
  172. for name, player in pairs(tfm.get.room.playerList) do
  173. p[name]={chosen1=false, chosen2=false, sps=0, ready1=false, ready2=false}
  174. randomplayering=0
  175. end
  176. end
  177. local random1=math.random(1,#players)
  178. player1=players[random1]
  179. while p[player1].chosen1==true do
  180. random1=math.random(1,#players)
  181. player1=players[random1]
  182. end
  183. player2=player1
  184. local random2=math.random(1,#players)
  185. while player1==player2 do
  186. player2=players[random2]
  187. random2=math.random(1,#players)
  188. end
  189. p[player1].chosen1=true
  190. p[player2].chosen2=true
  191. tfm.exec.movePlayer(player1,380,279,false,0,50,false)
  192. tfm.exec.movePlayer(player2,440,279,false,0,50,false)
  193. for name, player in pairs(tfm.get.room.playerList) do
  194. tfm.exec.removeImage(p[name].id)
  195.  
  196. local count=0
  197. while count<=#admins do
  198. count=count+1
  199. if name==admins[count] then
  200. p[name].admin=true
  201. end
  202. end
  203. end
  204. tfm.exec.chatMessage("<font color='#ffffff'>The current players competing are: "..player1.." versus "..player2.."</font>")
  205. end
  206. randomplayer()
  207. ui.addTextArea(69, "<font size='30' color='#FFFFFF'>Ready?</font>", nil, 360, 310, 120, 50, nil, nil, 0.8, true)
  208. timestamp=0
  209. choose1=0
  210. choose2=0
  211.  
  212. function eventKeyboard(name, key, down, x, y)
  213. if space==true then
  214. if name==player1 and tfm.get.room.playerList[name].isFacingRight then
  215. p[name].ready1=true
  216. ui.addTextArea(30, "<font size='10' color='#FFFFFF'>I'm ready</font>", nil, 345, 200, 60, 20, nil, nil, 0.8, true)
  217. timestamp=os.time()
  218. tfm.exec.removeImage(p[player1].id)
  219.  
  220. if key==32 then
  221. choose1=math.random(1,3)
  222. elseif key==72 then
  223. choose1=1
  224. elseif key==74 then
  225. choose1=2
  226. elseif key==75 then
  227. choose1=3
  228. end
  229. elseif name==player2 and not tfm.get.room.playerList[name].isFacingRight then
  230. p[name].ready2=true
  231. ui.addTextArea(31, "<font size='10' color='#FFFFFF'>I'm ready</font>", nil, 415, 200, 60, 20, nil, nil, 0.8, true)
  232. timestamp=os.time()
  233. tfm.exec.removeImage(p[player2].id)
  234.  
  235. if key==32 then
  236. choose2=math.random(1,3)
  237. elseif key==72 then
  238. choose2=1
  239. elseif key==74 then
  240. choose2=2
  241. elseif key==75 then
  242. choose2=3
  243. end
  244. else
  245. tfm.exec.chatMessage("You have to face your opponent and press space.",name)
  246. end
  247.  
  248. end
  249. end
  250.  
  251.  
  252. function eventLoop(time,remaining)
  253. if bufferr==true then
  254. buffer()
  255. end
  256. if #players==1 then
  257. tfm.exec.chatMessage("1 person cannot play this game. Exiting game...",nil)
  258. system.exit()
  259. end
  260.  
  261. if p[player1].ready1==true and p[player2].ready2==true then
  262. eventRPS(choose1,choose2)
  263. end
  264. end
  265.  
  266. system.disableChatCommandDisplay("t",true)
  267. system.disableChatCommandDisplay("c",true)
  268. system.disableChatCommandDisplay("admin",true)
  269.  
  270. function eventChatCommand(name, message)
  271. if string.sub(message,0,1)=="c" and p[name].admin==true then
  272. spstimes=tonumber(string.sub(message,3))
  273.  
  274. tfm.exec.chatMessage("<font color='#C53DFF'>[~SPS Moderation] The score to be attained to win has been changed to "..spstimes.." scores.</font>")
  275. elseif string.sub(message,0,1)=="t" and p[name].admin==true then
  276. tfm.exec.chatMessage("<font color='#C53DFF'>[~SPS Moderation] "..string.sub(message,3).."</font>")
  277. elseif string.sub(message,0,5)=="admin" and p[name].admin==true then
  278. for name, player in pairs(tfm.get.room.playerList) do
  279. if name==string.sub(message,7) then
  280. tfm.exec.chatMessage("<font color='#C53DFF'>[~SPS Moderation] "..name.." is now an SPS moderator! Congrats!.</font>")
  281. p[name].admin=true
  282. end
  283. end
  284. elseif message=="mods" then
  285. local mnm=""
  286. for name, player in pairs(tfm.get.room.playerList) do
  287. if p[name].admin==true then
  288. mnm=mnm..name..", "
  289. end
  290. end
  291. mnm=string.sub(mnm,0,string.len(mnm)-2)
  292. tfm.exec.chatMessage("The SPS Moderators are: "..mnm..".",name)
  293. elseif message=="skip" then
  294. randomplayer()
  295. ui.removeTextArea(30)
  296. ui.removeTextArea(31)
  297. elseif message=="help" then
  298. tfm.exec.chatMessage("<font color='#2ECF73'>Press SPACE to throw scissors, paper or stone randomly. Alternatively, press H for stone, J for scissors, K for paper</font>",name)
  299. tfm.exec.chatMessage("<font color='#2ECF73'>The first to reach "..spstimes.." scores wins!</font>",name)
  300. tfm.exec.chatMessage("<font color='#2ECF73'>Type !help to see this again, and !mods to see the list of mods in this room.</font>", name)
  301. if p[name].admin==true then
  302. tfm.exec.chatMessage("<font color='#FEB1FC'>You are an admin, type !c (new score) to change the score that a player must attain to win, and !t (message) to say something, !skip to skip someone's turn.</font>",name)
  303. end
  304. elseif message=="players" then
  305. for i=#players, 1, -1 do
  306.  
  307. end
  308. end
  309. end
Advertisement
Add Comment
Please, Sign In to add comment