Advertisement
BennyNovice

Cage In The House (multi-ppl version)

Aug 23rd, 2014
1,100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.68 KB | None | 0 0
  1. --Cage In The House (multi-ppl version)
  2.  
  3. --change the size of the cage
  4. cageSize=60
  5.  
  6. players = {}
  7. nextGroundID = 1001
  8.  
  9. bodyDef = {
  10.     type = 0,
  11.     width = 60,
  12.     height = 10,
  13.     foreground = false,
  14.     friction = 0.3,
  15.     restitution = 0.2,
  16.     angle = 0,
  17.     color = 0xffffff,
  18.     miceCollision = true,
  19.     groundCollision = false,
  20.     dynamic = false,
  21.     fixedRotation = true,
  22.     mass = 0,
  23.     linearDamping = 0,
  24.     angularDamping = 0
  25. }
  26.  
  27. colors = {
  28.     red = "0xFF0000",
  29.     pink = "0xFFC0CB",
  30.     purple = "0x800080",
  31.     chocolate = "0xD2691E",
  32.     orangered = "0xFF4500",
  33.     tomato = "0xFF6347",
  34.     gold = "0xFFD700",
  35.     yellow = "0xFFFF00",
  36.     lightyellow = "0xFFFFE0",
  37.     olive = "0x808000",
  38.     darkgreen = "0x006400",
  39.     forestgreen = "0x228B22",
  40.     lightseagreen = "0x20B2AA",
  41.     lime = "0x00FF00",
  42.     aquamarine = "0x7FFFD4",
  43.     blue = "0x0000FF",
  44.     cyan = "0x00FFFF",
  45.     black = "0x000000",
  46.     gray = "0x808080",
  47.     white = "0xFFFFFF"
  48. }
  49.  
  50. function inColorTable(str)
  51.     for k,v in pairs(colors) do
  52.         if k==str then return true end
  53.     end
  54.    
  55.     return false
  56. end
  57.  
  58. function eventNewPlayer(name)
  59.     for i,key in ipairs({40,83}) do
  60.     tfm.exec.bindKeyboard(name,key,true,true)
  61.     end
  62.    
  63.     table.insert(players, name)
  64.     players[name] = {
  65.         color = "default",
  66.         groundID = nextGroundID,
  67.         lastX = 0,
  68.         lastY = 0
  69.     }
  70.     nextGroundID = nextGroundID + 4
  71. end
  72.  
  73. for name,player in pairs(tfm.get.room.playerList) do
  74.     eventNewPlayer(name)
  75. end
  76.  
  77. function eventKeyboard(name,key,down,x,y)
  78.     players[name].lastX = x
  79.     players[name].lastY = y
  80.     if players[name].color == "default" then
  81.         bodyDef.type = 0
  82.     else
  83.         bodyDef.type = 12
  84.         bodyDef.color = players[name].color
  85.     end
  86.    
  87.     -- up and down ground
  88.     tfm.exec.removePhysicObject(players[name].groundID)
  89.     bodyDef.width=cageSize
  90.     bodyDef.height=10
  91.     bodyDef.miceCollision = true
  92.     tfm.exec.addPhysicObject(players[name].groundID, x, y+20, bodyDef)
  93.     tfm.exec.removePhysicObject(players[name].groundID+3)
  94.     tfm.exec.addPhysicObject(players[name].groundID+3, x, y-cageSize+30, bodyDef)
  95.    
  96.     -- left and right ground
  97.     tfm.exec.removePhysicObject(players[name].groundID+1)
  98.     bodyDef.width=10
  99.     bodyDef.height=cageSize
  100.     bodyDef.miceCollision = true
  101.     tfm.exec.addPhysicObject(players[name].groundID+1, x-cageSize/2+5, y-cageSize/2+25, bodyDef)
  102.     tfm.exec.removePhysicObject(players[name].groundID+2)
  103.     tfm.exec.addPhysicObject(players[name].groundID+2, x+cageSize/2-5, y-cageSize/2+25, bodyDef)
  104.    
  105.    
  106. end
  107.  
  108. function eventEmotePlayed(name,emote)
  109.     if emote==3 then
  110.         bodyDef.type=8
  111.        
  112.         -- up and down ground
  113.         tfm.exec.removePhysicObject(players[name].groundID)
  114.         bodyDef.width=cageSize
  115.         bodyDef.height=10
  116.         bodyDef.miceCollision = false
  117.         tfm.exec.addPhysicObject(players[name].groundID, players[name].lastX, players[name].lastY+20, bodyDef)
  118.         tfm.exec.removePhysicObject(players[name].groundID+3)
  119.         tfm.exec.addPhysicObject(players[name].groundID+3, players[name].lastX, players[name].lastY-cageSize+30, bodyDef)
  120.        
  121.         -- left and right ground
  122.         tfm.exec.removePhysicObject(players[name].groundID+1)
  123.         bodyDef.width=10
  124.         bodyDef.height=cageSize
  125.         bodyDef.miceCollision = false
  126.         tfm.exec.addPhysicObject(players[name].groundID+1, players[name].lastX-cageSize/2+5, players[name].lastY-cageSize/2+25, bodyDef)
  127.         tfm.exec.removePhysicObject(players[name].groundID+2)
  128.         tfm.exec.addPhysicObject(players[name].groundID+2, players[name].lastX+cageSize/2-5, players[name].lastY-cageSize/2+25, bodyDef)
  129.     end
  130. end
  131.  
  132. function eventChatCommand(name, command)
  133.     args = {}
  134.     num=1
  135.     for word in string.gmatch(command, "%w+") do
  136.         args[num] = word
  137.         num = num + 1
  138.     end
  139.    
  140.     if args[1] == "color" then
  141.         if inColorTable(args[2]) then
  142.             players[name].color = colors[args[2]]
  143.         else
  144.             players[name].color = args[2]
  145.         end
  146.     end
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement