Mousetat

#Draw minigame

Jul 16th, 2016
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.18 KB | None | 0 0
  1. system.disableChatCommandDisplay("w",true)
  2. system.disableChatCommandDisplay("a",true)
  3. system.disableChatCommandDisplay("llclear",true)
  4. system.disableChatCommandDisplay("np",true)
  5. system.disableChatCommandDisplay("map",true)
  6. system.disableChatCommandDisplay("mdmin",true)
  7. system.disableChatCommandDisplay("unadmin",true)
  8. system.disableChatCommandDisplay("color",true)
  9. system.disableChatCommandDisplay("help",true)
  10. system.disableChatCommandDisplay("clear",true)
  11.  
  12. admin="Tat#0020"
  13. admins={"Ykr#0000", "Trapin#0000"}
  14.  
  15.  
  16.  
  17. p={}
  18. i=0
  19. a=1
  20.  
  21.  
  22. function eventNewPlayer(name)
  23. tfm.exec.addPhysicObject(1,400,-600,{type=0,width=10,height=10,foreground=true,friction=0.3,restitution=0,dynamic=false,miceCollision=true,groundCollision=true})
  24. ui.addTextArea(69,"</b><font color='#ED67EA' size='20'>Welcome to DRAW! Type !help for more information.</font>",nil, 40,370,720,nil,0x324650,0x212F36,0.8,true)
  25. tfm.exec.bindKeyboard(name,17,true,true)
  26. tfm.exec.bindKeyboard(name,17,false,true)
  27. tfm.exec.bindKeyboard(name,90,true,true)
  28. system.bindMouse(name, true)
  29. tfm.exec.respawnPlayer(name)
  30. p[name]={ctrl=false, x1=0, y1=0, click1=false, x2=0, y2=0, color=0x000000, pickerid=0, width=5, apa=1,lineid={}, admin==false}
  31. for k=#admins,0,-1 do
  32. if name==admins[k] then
  33. p[name].admin=true
  34. tfm.exec.chatMessage("<font color='#ED67EA'>Admin commands: !llclear and !np/!map @code</font>",name)
  35. end
  36. end
  37. end
  38.  
  39. for name,player in pairs(tfm.get.room.playerList) do
  40. eventNewPlayer(name)
  41. end
  42.  
  43. function eventNewGame()
  44. for name,player in pairs(tfm.get.room.playerList) do
  45. tfm.exec.addPhysicObject(1,400,-600,{type=0,width=10,height=10,foreground=true,friction=0.3,restitution=0,dynamic=false,miceCollision=true,groundCollision=true})
  46. tfm.exec.bindKeyboard(name,17,true,true)
  47. tfm.exec.bindKeyboard(name,17,false,true)
  48. tfm.exec.bindKeyboard(name,90,true,true)
  49. system.bindMouse(name, true)
  50. tfm.exec.respawnPlayer(name)
  51. p[name]={ctrl=false, x1=0, y1=0, click1=false, x2=0, y2=0, color=0x000000, pickerid=0, width=5, apa=1,lineid={}, admin==false}
  52. for k=#admins,0,-1 do
  53. if name==admins[k] then
  54. p[name].admin=true
  55. end
  56. end
  57. end
  58. end
  59.  
  60.  
  61.  
  62. function eventChatCommand(name,message)
  63. if message:sub(0,3)=="map" then
  64. if p[name].admin==true then
  65. tfm.exec.newGame(message:sub(5))
  66. end
  67. elseif message:sub(0,2)=="np" then
  68. if p[name].admin==true then
  69. tfm.exec.newGame(message:sub(4))
  70. end
  71. elseif message:sub(0,3)=="pta" then
  72. for index, param in pairs(p[name].lineid) do
  73.         print(index..": "..tostring(param))
  74.     end
  75. elseif message=="color" then
  76. ui.showColorPicker (i, name,0, "Color Picker" )
  77. p[name].pickerid=i
  78. i=i+1
  79. elseif message:sub(0,1)=="w" then
  80. p[name].width=tonumber(message:sub(3))
  81. elseif message:sub(0,1)=="a" then
  82. p[name].apa=tonumber(message:sub(3))
  83. elseif message:sub(0,4)=="help" then
  84. ui.addPopup(1,0,"</b><font color='#ffff00'>Ctrl+click on 2 points to draw a line across\nCtrl+z to undo.\n<b>Commands:</b>\n!w (number) to change width(thickness) of line to that number\n!a (number) to change alpha(invisibility) of your line,1 being opaque and 0 being totally invisible\n!color to choose the color you want\n!clear to clear all your drawings</font>",name,100,50,600,true)
  85. elseif message=="clear" then
  86. for z=#p[name].lineid,0,-1 do
  87. tfm.exec.removeJoint(p[name].lineid[z])
  88. end
  89. elseif message=="llclear" and p[name].admin==true then
  90. tfm.exec.chatMessage("<font color='#ED67EA'>Lines cleared.",nil)
  91. for k, player in pairs(tfm.get.room.playerList) do
  92. for z=#p[k].lineid,0,-1 do
  93. tfm.exec.removeJoint(p[k].lineid[z])
  94. end
  95. end
  96. elseif message:sub(0,5)=="mdmin" and name==admin then
  97. for k,player in pairs(tfm.get.room.playerList) do
  98. if k==message:sub(7) then
  99. p[k].admin=true
  100. tfm.exec.chatMessage("<font color='#ED67EA'>"..k.." is now a #draw admin!",nil)
  101. tfm.exec.chatMessage("<font color='#ED67EA'>You are promoted! Congrats!",k)
  102. end
  103. end
  104. elseif message:sub(0,7)=="unadmin" and name==admin then
  105. for k,player in pairs(tfm.get.room.playerList) do
  106. if k==message:sub(9) then
  107. p[k].admin=false
  108. tfm.exec.chatMessage("<font color='#ED67EA'>"..k.." is demodded",nil)
  109. tfm.exec.chatMessage("<font color='#ED67EA'>You are demoted.",k)
  110. end
  111. end
  112. end
  113. end
  114.  
  115.  
  116.  
  117. function eventKeyboard(name,code,down,x,y)
  118. if code==17 and down==true then
  119. p[name].ctrl=true
  120. elseif code==17 and down==false then
  121. p[name].ctrl=false
  122. end
  123. if p[name].ctrl==true and code==90 then
  124. tfm.exec.removeJoint(p[name].lineid[#p[name].lineid])
  125. table.remove(p[name].lineid)
  126. end
  127. end
  128.  
  129.  
  130. function eventMouse(name,xp,yp)
  131. if p[name].ctrl==true then
  132. if p[name].click1==false then
  133. p[name].x1=xp
  134. p[name].y1=yp
  135. print(p[name].click1)
  136. print(p[name].x1)
  137. print(p[name].y1)
  138. p[name].click1=true
  139. elseif p[name].click1==true then
  140. p[name].x2=xp
  141. p[name].y2=yp
  142. print(p[name].click1)
  143. print(p[name].x2)
  144. print(p[name].y2)
  145. tfm.exec.addJoint(a,1,1,{type=0,point1=p[name].x1..","..p[name].y1, point2=p[name].x2..","..p[name].y2, frequency=10, damping=0.2, line=p[name].width,color=p[name].color, alpha=p[name].apa, foreground=true})
  146. table.insert(p[name].lineid,a)
  147. a=a+1
  148. p[name].click1=false
  149. end
  150. end
  151. end
  152.  
  153. function eventColorPicked(id,name,colour)
  154. p[name].color=colour
  155. end
  156.  
  157. function eventPlayerLeft(name)
  158. for z=#p[name].lineid,0,-1 do
  159. tfm.exec.removeJoint(p[name].lineid[z])
  160. end
  161. end
Advertisement
Add Comment
Please, Sign In to add comment