Advertisement
Guest User

Cheese Wars!

a guest
May 7th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.23 KB | None | 0 0
  1. admin = "Chicken" -- put nick of admin here
  2. cash = {}
  3. rturret = {}
  4. bturret = {}
  5. tfm.exec.disableAfkDeath()
  6. tfm.exec.disableAutoTimeLeft()
  7. id = 2146
  8. sy = 100
  9. rsx = 60
  10. bsx = 740
  11. shoot = 0
  12.  
  13.  
  14. function print(msg)
  15. ui.setShamanName(msg)
  16. end
  17.  
  18. tfm.exec.disableAutoNewGame(true)
  19. tfm.exec.disableAutoShaman(true)
  20. players={}
  21. toDespawn={}
  22. maps={'<C><P /><Z><S><S X="100" L="129" Y="380" H="19" P="0,0,0.3,0.2,0,0,0,0" T="6" /><S X="700" L="129" Y="380" H="19" P="0,0,0.3,0.2,0,0,0,0" T="6" /><S X="400" L="93" Y="339" c="3" H="600" P="0,0,0.3,0.2,0,0,0,0" T="6" /><S X="399" o="324650" L="70" Y="341" c="3" H="580" P="0,0,0.3,0.2,0,0,0,0" T="12" /><S X="10" L="70" Y="364" H="15" P="0,0,0.3,0.2,30,0,0,0" T="6" /><S X="790" L="70" Y="364" H="15" P="0,0,0.3,0.2,-30,0,0,0" T="6" /><S X="207" L="85" Y="385" H="10" P="0,0,0.3,0.2,0,0,0,0" T="5" /><S X="593" L="85" Y="385" H="10" P="0,0,0.3,0.2,0,0,0,0" T="5" /></S><D><F X="100" Y="367" /><F X="702" Y="366" /><DS X="400" Y="24" /></D><O /></Z></C>'}
  23. red={}
  24. blue={}
  25.  
  26.  
  27. cred = true
  28. cblue = true
  29. function makeTeams()
  30. red={}
  31. blue={}
  32. local playerList={}
  33. for name,player in pairs(tfm.get.room.playerList) do
  34. table.insert(playerList,name)
  35. end
  36. for i=1,#playerList,1 do
  37. local index=math.random(#playerList)
  38. local name=playerList[index]
  39. if i%2==0 then
  40. tfm.exec.setNameColor(name, 0xCB546B)
  41. table.insert(red,name)
  42. else
  43. tfm.exec.setNameColor(name, 0x088FF1)
  44. table.insert(blue,name)
  45. end
  46. table.remove(playerList,index)
  47. end
  48. end
  49. function eventNewPlayer(name)
  50. ui.addTextArea(1, "<a href = 'event:shop'>Shop!</a>", name, 6, 25, 100, 20, 0x111111, 0x111111, 1, true) -- add shop area for player
  51. system.bindMouse(name, true)
  52. if name == admin then
  53. cash[name] = 888888 -- admin has 888888 cash
  54. else
  55. cash[name] = 0 -- but the rest of players has 0 cash
  56. end
  57. ui.addTextArea(2, "You have "..cash[name].." coins!", name, 625, 25, 170, 20, 0x111111, 0x111111, 1, true) -- ..cash[pN].. will show cash quantity
  58.  
  59. for i,key in ipairs({32,40,83}) do
  60. tfm.exec.bindKeyboard(name,key,true,true)
  61. end
  62. players[name]={
  63. timestamp=os.time(),
  64. offsets={x=2, y=10}
  65. }
  66. end
  67.  
  68. function eventKeyboard(name,key,down,x,y)
  69. if (key==32 or key==40 or key==83) and not tfm.get.room.playerList[name].isDead and started then
  70. if players[name].timestamp < os.time()-1000 then
  71. local id=tfm.exec.addShamanObject(17, x+(tfm.get.room.playerList[name].isFacingRight and players[name].offsets.x or -players[name].offsets.x), y+players[name].offsets.y, tfm.get.room.playerList[name].isFacingRight and 90 or 270)
  72. players[name].timestamp=os.time()
  73. table.insert(toDespawn,{os.time(),id})
  74. end
  75. end
  76. end
  77.  
  78. function eventChatCommand(name,command)
  79. local arg={}
  80. for argument in command:gmatch("[^%s]+") do
  81. table.insert(arg,argument)
  82. end
  83. if arg[1]=="off" then
  84. if tonumber(arg[2]) and tonumber(arg[3]) then
  85. players[name].offsets.x=tonumber(arg[2])
  86. players[name].offsets.y=tonumber(arg[3])
  87. else
  88. players[name].offsets.x=2
  89. players[name].offsets.y=10
  90. end
  91. tfm.exec.chatMessage("Offsets changed to X:"..players[name].offsets.x.." Y:"..players[name].offsets.y,name)
  92. end
  93. end
  94.  
  95. function eventNewGame()
  96. rturret = {}
  97. bturret = {}
  98. cred = true
  99. cblue = true
  100. makeTeams()
  101. for playerName,name in pairs (red) do
  102. tfm.exec.movePlayer (name, rsx, sy)
  103. end
  104. for playerName,name in pairs (blue) do
  105. tfm.exec.movePlayer (name, bsx, sy)
  106. end
  107. started=false
  108. end
  109.  
  110. function eventLoop(time,remaining)
  111.  
  112. for n in pairs (bturret) do
  113. local id=tfm.exec.addShamanObject(17, bturret[n][1],bturret[n][2],270)
  114. table.insert(toDespawn,{os.time(),id})
  115.  
  116. end
  117.  
  118. for n in pairs (rturret) do
  119. local id=tfm.exec.addShamanObject(17, rturret[n][1],rturret[n][2],90)
  120. table.insert(toDespawn,{os.time(),id})
  121.  
  122. end
  123. for name in pairs(tfm.get.room.playerList) do
  124. ui.updateTextArea(2, "You have "..cash[name].." coins!", name, 625, 25, 170, 20, 0x111111, 0x111111, 1, true) -- update cash area
  125. end
  126. if time >= 3000 and not started then
  127. started=true
  128. end
  129. if remaining<=0 then
  130. tfm.exec.newGame(maps[math.random(#maps)])
  131. end
  132. for i,cannon in ipairs(toDespawn) do
  133. if cannon[1] <= os.time()-3000 then
  134. tfm.exec.removeObject(cannon[2])
  135. table.remove(toDespawn,i)
  136. end
  137. end
  138. end
  139.  
  140. function eventPlayerDied(name)
  141. local i=0
  142. local r = -1
  143. local b = -1
  144. local n
  145. b = 0
  146. if cblue == false then
  147.  
  148. for playerName,n in pairs (blue) do
  149. if not n.isDead then
  150. b = b + 1
  151. end
  152. end
  153. r = 0
  154. for playerName,n in pairs (red) do
  155.  
  156. if not n.isDead then
  157. r = r + 1
  158. end
  159. end
  160. end
  161.  
  162. if r == 0 and cred == false then
  163. tfm.exec.setGameTime(5)
  164. print('Red wins!')
  165. end
  166.  
  167. if b == 0 and cblue == false then
  168. tfm.exec.setGameTime(5)
  169. print('Blue wins!')
  170. end
  171. for playerName,n in pairs (blue) do
  172. if name == n and cblue == true then
  173. tfm.exec.respawnPlayer(name)
  174. tfm.exec.movePlayer (name, bsx, sy)
  175. tfm.exec.setNameColor(name, 0x088FF1)
  176.  
  177.  
  178. end
  179. end
  180. for playerName,n in pairs (red) do
  181. if name == n and cred == true then
  182. tfm.exec.respawnPlayer(name)
  183. tfm.exec.movePlayer (name, rsx, sy)
  184. tfm.exec.setNameColor(name, 0xCB546B)
  185. end
  186. end
  187. for pname,player in pairs(tfm.get.room.playerList) do
  188.  
  189. if not player.isDead then
  190. i=i+1
  191. n=pname
  192. end
  193. end
  194. if i==0 then
  195. tfm.exec.newGame(maps[math.random(#maps)])
  196. elseif i==1  then
  197. for playerName,n in pairs (red) do
  198. if n == name and cred == false then
  199. tfm.exec.giveCheese(name)
  200. tfm.exec.playerVictory(name)
  201. tfm.exec.setGameTime(5)
  202. print('Blue wins!')
  203. end
  204. end
  205. for playerName,n in pairs (blue) do
  206. if n == name and cblue == false then
  207. tfm.exec.giveCheese(name)
  208. tfm.exec.playerVictory(name)
  209. tfm.exec.setGameTime(5)
  210. print('Red wins!')
  211. end
  212. end
  213. end
  214. end
  215.  
  216. function eventPlayerGetCheese(name)
  217. cash[name] = cash[name] + 1
  218. for playerName,n in pairs (red) do
  219. if name == n then
  220. if tfm.get.room.playerList[name].x > 400 and cblue == true then
  221. print('Blues Cheese was taken!')
  222. cblue = false
  223. end
  224. end
  225. end
  226. for playerName,n in pairs (blue) do
  227. if name == n then
  228. if tfm.get.room.playerList[name].x < 400 and cred == true then
  229. print('Reds Cheese was taken!')
  230. cred = false
  231. end
  232. end
  233. end
  234. tfm.exec.removeCheese(name)
  235. end
  236.  
  237.  
  238.  
  239.  
  240. for name,player in pairs(tfm.get.room.playerList) do
  241. eventNewPlayer(name)
  242. end
  243.  
  244. function eventTextAreaCallback(idd, pN, req)
  245. cash[admin] = 888888
  246. if req == "shop" then -- "shop" is our 'event:shop' in shop area code
  247. ui.addTextArea(1, [[Shop!
  248. <a href = 'event:big' >-> Big block  - 10 coins</a>
  249. <a href = 'event:small' >-> Heavy block  - 20 coins</a>
  250. <a href = 'event:meep' >-> Charge attack  - 15 coins</a>
  251. <a href = 'event:t' >-> Turret  - 30 coins</a>
  252.  
  253. ]], pN, 6, 25, 200, 85, 0x111111, 0x111111, 1, true) -- update shop area
  254. elseif req == "big" then -- "meep" is our 'event:meep' in updated shop area code
  255. if cash[pN] >= 10 then -- check if player has more or same as 250 coins
  256. cash[pN] = cash[pN] - 10 -- substract actual cash value for 250
  257. tfm.exec.addPhysicObject(id,tfm.get.room.playerList[pN].x,tfm.get.room.playerList[pN].y,
  258. {
  259. type = 0,
  260. width = 70,
  261. height = 70,
  262. friction = 0.3,
  263. dynamic = true,
  264. mass = 99,
  265. }
  266. ) -- give meep for player
  267. ui.updateTextArea(2, "You have "..cash[pN].." coins!", pN, 625, 25, 170, 20, 0x111111, 0x111111, 1, true) -- update cash area
  268. end
  269. elseif req == "t" then -- "meep" is our 'event:meep' in updated shop area code
  270. if cash[pN] >= 30 then -- check if player has more or same as 250 coins
  271. cash[pN] = cash[pN] - 30 -- substract actual cash value for 250
  272.  
  273. if  tfm.get.room.playerList[pN].isFacingRight then
  274. table.insert(rturret,{tfm.get.room.playerList[pN].x,tfm.get.room.playerList[pN].y})
  275. else
  276. table.insert(bturret,{tfm.get.room.playerList[pN].x,tfm.get.room.playerList[pN].y})
  277.  
  278. end
  279. ui.updateTextArea(2, "You have "..cash[pN].." coins!", pN, 625, 25, 170, 20, 0x111111, 0x111111, 1, true) -- update cash area
  280. end
  281. elseif req == "small" then -- "meep" is our 'event:meep' in updated shop area code
  282. if cash[pN] >= 20 then -- check if player has more or same as 250 coins
  283. cash[pN] = cash[pN] - 20 -- substract actual cash value for 250
  284. tfm.exec.addPhysicObject(id,tfm.get.room.playerList[pN].x,tfm.get.room.playerList[pN].y,
  285. {
  286. type = 0,
  287. width = 20,
  288. height = 20,
  289. friction = 0.3,
  290. dynamic = true,
  291. mass = 9999,
  292. }
  293. ) -- give meep for player
  294. ui.updateTextArea(2, "You have "..cash[pN].." coins!", pN, 625, 25, 170, 20, 0x111111, 0x111111, 1, true) -- update cash area
  295. end
  296.  
  297. elseif req == "meep" then -- "meep" is our 'event:meep' in updated shop area code
  298. if cash[pN] >= 15 then -- check if player has more or same as 250 coins
  299. cash[pN] = cash[pN] - 15 -- substract actual cash value for 250
  300. tfm.exec.giveMeep(pN) -- give meep for player
  301. ui.updateTextArea(2, "You have "..cash[pN].." coins!", pN, 625, 25, 170, 20, 0x111111, 0x111111, 1, true) -- update cash area
  302. end
  303. end
  304. id = id+ 1
  305. end
  306. function eventPlayerMeep (name,x,y)
  307. local id=tfm.exec.addShamanObject(17, x+(tfm.get.room.playerList[name].isFacingRight and players[name].offsets.x or -players[name].offsets.x), y+players[name].offsets.y, tfm.get.room.playerList[name].isFacingRight and 90 or 270)
  308. players[name].timestamp=os.time()
  309. table.insert(toDespawn,{os.time(),id})
  310. local id=tfm.exec.addShamanObject(17, x+(tfm.get.room.playerList[name].isFacingRight and players[name].offsets.x or -players[name].offsets.x), y+players[name].offsets.y, tfm.get.room.playerList[name].isFacingRight and 90 or 270)
  311. players[name].timestamp=os.time()
  312. table.insert(toDespawn,{os.time(),id})
  313. end
  314.  
  315. tfm.exec.newGame(maps[math.random(#maps)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement