Patasuss

Expression 2 Game

Jan 27th, 2013
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.66 KB | None | 0 0
  1. @name Simple Platform Game
  2. @inputs Start
  3. @outputs
  4. @persist Ent:array Chip:entity Model:string BS Mode
  5. @persist MaxX MaxY CurrX CurrY
  6. @persist Color:array Song:array Player:array Countdown AtPlayer SongCount AtEnt EntCount Colors ColorChange
  7. @trigger
  8.  
  9. if(first() | dupefinished())
  10. {
  11.     runOnTick(1)
  12.     runOnLast(1)
  13.     runOnChat(1)
  14.     Chip = entity()
  15.    
  16.     Model = "models/hunter/blocks/cube2x2x025.mdl"
  17.     BS = 97
  18.    
  19.    
  20.     Mode = 1
  21.    
  22.     CurrX = 1
  23.     CurrY = 1
  24.     MaxX = 5
  25.     MaxY = 5  
  26.     Ent = array()
  27.     timer("spawn", 250)
  28.    
  29.     Player = array()
  30.     AtPlayer = 1
  31.    
  32.     Color:pushVector(vec(255,0,0))
  33.     Color:pushVector(vec(0,255,0))
  34.     Color:pushVector(vec(0,0,255))
  35.     Color:pushVector(vec(255,255,0))
  36.     Color:pushVector(vec(255,0,255))
  37.     Color:pushVector(vec(255,30,100))
  38.     Colors = Color:count()
  39.    
  40.     Song:pushString("/music/hl2_song20_submix0.mp3")
  41.     Song:pushString("/music/hl2_song3.mp3")
  42.     Song:pushString("/music/hl2_song12_long.mp3")
  43.     Song:pushString("/music/hl2_song16.mp3")
  44.     Song:pushString("/music/hl2_song14.mp3")
  45.     SongCount = Song:count()
  46.     AtEnt = 1
  47.    
  48.     ColorChange = 0
  49.    
  50. function delete_ents()
  51. {
  52.     for(N=1, Ent:count())
  53.     {
  54.         Ent[N, entity]:propDelete()
  55.     }
  56. }
  57.  
  58. function number isAPlayer(E:entity)
  59. {
  60.     for(N=1, Player:count())
  61.     {
  62.         if(E == Player[N, entity])
  63.         {
  64.             return N
  65.         }
  66.     }
  67.     return 0
  68. }
  69.  
  70. function void startGame()
  71. {
  72.     Countdown = 5
  73.     print("Attention! The game will start in " + Countdown + " seconds!")
  74.     timer("timedown", 1000)
  75. }
  76.  
  77. function play_music()
  78. {
  79.     SelSong = Song[random(1, SongCount), string]
  80.     SongDur = soundDuration(SelSong)
  81.     soundPlay(1, 0, SelSong)
  82.     timer("next_song", SongDur*1000)
  83. }
  84.    
  85. }
  86.  
  87. if(clk("next_song"))
  88. {
  89.     play_music()
  90. }
  91.  
  92.  
  93. if(last())
  94. {
  95.     delete_ents()
  96. }
  97.  
  98. if(chatClk())
  99. {
  100.     Pl = lastSpoke()
  101.     C = Pl:lastSaid():explode(" ")
  102.    
  103.     if(C[1, string] == "-game")
  104.     {
  105.         if(C[2, string] == "join")
  106.         {
  107.             if(Mode == 2)
  108.             {
  109.             if(!isAPlayer(Pl))
  110.             {
  111.                 Player:pushEntity(Pl)
  112.                 print(Pl:name() + " joined the game")
  113.             }
  114.             else
  115.             {
  116.                 print(Pl:name() + " already is in the game")
  117.             }
  118.            }
  119.            else
  120.             {
  121.                 print(Pl:name() + ", you can't join now.")
  122.             }
  123.    
  124.         }
  125.         elseif(C[2,string] == "quit")
  126.         {
  127.             Num = isAPlayer(Pl)
  128.             if(Num)
  129.             {
  130.                 Player:remove(Num)
  131.                 if(Mode==2)
  132.                 {
  133.                     print(Pl:name() + " quit the game.")
  134.                 }
  135.                 else
  136.                 {
  137.                     print(Pl:name() + " was a chicken and left the game!")
  138.                 }
  139.             }
  140.         }
  141.         elseif(C[2, string] == "start")
  142.         {
  143.             if(Mode==2)
  144.             {
  145.                 if(Pl==owner())
  146.                 {
  147.                     Mode = 3
  148.                     startGame()
  149.                 }
  150.                 else
  151.                 {
  152.                     print("You don't have permission to start the game, "+Pl:name())
  153.                 }
  154.             }
  155.             else
  156.             {
  157.                 print("The game is already running!")
  158.             }
  159.         }
  160.         elseif(C[2, string] == "add")
  161.         {
  162.             E = Pl:aimEntity()
  163.             if(!isAPlayer(E))
  164.             {
  165.                 print("Added an entity.")
  166.                 Player:pushEntity(E)
  167.             }
  168.         }
  169.         elseif(C[2, string] == "color")
  170.         {
  171.             ColorChange = C[4, string]:toNumber()
  172.         }
  173.     }
  174. }
  175.  
  176. if(Mode==1 & clk("spawn"))
  177. {
  178.     E = propSpawn(Model, 1)
  179.     E:setPos(Chip:toWorld(vec((-BS*2.5)+BS*CurrX, (-BS*2.5)+BS*CurrY, 200)))
  180.     E:setMaterial("phoenix_storms/fender_white")
  181.     E:setColor(Color[random(1,6), vector])
  182.     Ent:pushEntity(E)
  183.     soundPlay(1,0,"/buttons/blip1.wav")
  184.    
  185.     CurrX++
  186.     timer("spawn", 250)
  187.     if(CurrX>5)
  188.     {  
  189.         CurrX = 1
  190.         CurrY++
  191.         if(CurrY>5)
  192.         {
  193.             Mode = 2
  194.             EntCount = Ent:count()
  195.             print("You can join now!")
  196.             soundPlay(1, 0, "/buttons/bell1.wav")
  197.         }
  198.     }
  199. }
  200.  
  201. if(Mode==3 & clk("timedown"))
  202. {
  203.     Countdown--
  204.     if(Countdown!=0)
  205.     {
  206.         print(Countdown + " seconds to go")
  207.         soundPlay(1, 0, "/buttons/blip2.wav")
  208.         timer("timedown", 1000)
  209.     }
  210.     else
  211.     {
  212.         print("The game has started! Good Luck!")
  213.         soundPlay(1, 0, "/buttons/bell1.wav")
  214.         play_music()
  215.         Mode = 4
  216.     }
  217.    
  218. }
  219.  
  220.  
  221. if(changed(Mode))
  222. {
  223.     if(Mode==4)
  224.     {
  225.         for(N=1, Ent:count())
  226.         {
  227.             Ent[N, entity]:propFreeze(0)
  228.         }
  229.     }
  230. }
  231.  
  232. if(Mode==4)
  233. {
  234. for(N=1, Ent:count())
  235. {
  236.     E = Ent[N, entity]
  237.     E:propFreeze(0)
  238.     E:applyForce(-E:vel()*E:mass() + vec(0,0,12)*E:mass())
  239.     E:applyAngForce(-E:angVel()*E:mass()*20)
  240. }
  241.  
  242. Pl = Player[AtPlayer, entity]
  243. if(Pl:pos():z() < (Chip:pos():z()+20))
  244. {
  245.     print(Pl:name() + " fell.")
  246.     Player:remove(AtPlayer)
  247. }
  248.  
  249. AtPlayer = (AtPlayer+1)%(Player:count()+1)
  250. if(Player:count()==1)
  251. {
  252.     Pl = Player[1, entity]
  253.     print(Pl:name() + " has won the round! Congratulations!")
  254.     Mode = 5
  255.     print("The game will restart in 10 seconds!")
  256.     timer("restart", 10000)
  257. }
  258.  
  259. if(ColorChange)
  260. {
  261.     E = Ent[AtEnt, entity]
  262.     E:setColor(Color[random(1, Colors),vector])
  263.     AtEnt = (AtEnt+1)%(EntCount+1)
  264. }
  265.  
  266. }
  267.  
  268. if(Mode==5 & clk("restart"))
  269. {
  270.     reset()
  271. }
Advertisement
Add Comment
Please, Sign In to add comment