Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name Simple Platform Game
- @inputs Start
- @outputs
- @persist Ent:array Chip:entity Model:string BS Mode
- @persist MaxX MaxY CurrX CurrY
- @persist Color:array Song:array Player:array Countdown AtPlayer SongCount AtEnt EntCount Colors ColorChange
- @trigger
- if(first() | dupefinished())
- {
- runOnTick(1)
- runOnLast(1)
- runOnChat(1)
- Chip = entity()
- Model = "models/hunter/blocks/cube2x2x025.mdl"
- BS = 97
- Mode = 1
- CurrX = 1
- CurrY = 1
- MaxX = 5
- MaxY = 5
- Ent = array()
- timer("spawn", 250)
- Player = array()
- AtPlayer = 1
- Color:pushVector(vec(255,0,0))
- Color:pushVector(vec(0,255,0))
- Color:pushVector(vec(0,0,255))
- Color:pushVector(vec(255,255,0))
- Color:pushVector(vec(255,0,255))
- Color:pushVector(vec(255,30,100))
- Colors = Color:count()
- Song:pushString("/music/hl2_song20_submix0.mp3")
- Song:pushString("/music/hl2_song3.mp3")
- Song:pushString("/music/hl2_song12_long.mp3")
- Song:pushString("/music/hl2_song16.mp3")
- Song:pushString("/music/hl2_song14.mp3")
- SongCount = Song:count()
- AtEnt = 1
- ColorChange = 0
- function delete_ents()
- {
- for(N=1, Ent:count())
- {
- Ent[N, entity]:propDelete()
- }
- }
- function number isAPlayer(E:entity)
- {
- for(N=1, Player:count())
- {
- if(E == Player[N, entity])
- {
- return N
- }
- }
- return 0
- }
- function void startGame()
- {
- Countdown = 5
- print("Attention! The game will start in " + Countdown + " seconds!")
- timer("timedown", 1000)
- }
- function play_music()
- {
- SelSong = Song[random(1, SongCount), string]
- SongDur = soundDuration(SelSong)
- soundPlay(1, 0, SelSong)
- timer("next_song", SongDur*1000)
- }
- }
- if(clk("next_song"))
- {
- play_music()
- }
- if(last())
- {
- delete_ents()
- }
- if(chatClk())
- {
- Pl = lastSpoke()
- C = Pl:lastSaid():explode(" ")
- if(C[1, string] == "-game")
- {
- if(C[2, string] == "join")
- {
- if(Mode == 2)
- {
- if(!isAPlayer(Pl))
- {
- Player:pushEntity(Pl)
- print(Pl:name() + " joined the game")
- }
- else
- {
- print(Pl:name() + " already is in the game")
- }
- }
- else
- {
- print(Pl:name() + ", you can't join now.")
- }
- }
- elseif(C[2,string] == "quit")
- {
- Num = isAPlayer(Pl)
- if(Num)
- {
- Player:remove(Num)
- if(Mode==2)
- {
- print(Pl:name() + " quit the game.")
- }
- else
- {
- print(Pl:name() + " was a chicken and left the game!")
- }
- }
- }
- elseif(C[2, string] == "start")
- {
- if(Mode==2)
- {
- if(Pl==owner())
- {
- Mode = 3
- startGame()
- }
- else
- {
- print("You don't have permission to start the game, "+Pl:name())
- }
- }
- else
- {
- print("The game is already running!")
- }
- }
- elseif(C[2, string] == "add")
- {
- E = Pl:aimEntity()
- if(!isAPlayer(E))
- {
- print("Added an entity.")
- Player:pushEntity(E)
- }
- }
- elseif(C[2, string] == "color")
- {
- ColorChange = C[4, string]:toNumber()
- }
- }
- }
- if(Mode==1 & clk("spawn"))
- {
- E = propSpawn(Model, 1)
- E:setPos(Chip:toWorld(vec((-BS*2.5)+BS*CurrX, (-BS*2.5)+BS*CurrY, 200)))
- E:setMaterial("phoenix_storms/fender_white")
- E:setColor(Color[random(1,6), vector])
- Ent:pushEntity(E)
- soundPlay(1,0,"/buttons/blip1.wav")
- CurrX++
- timer("spawn", 250)
- if(CurrX>5)
- {
- CurrX = 1
- CurrY++
- if(CurrY>5)
- {
- Mode = 2
- EntCount = Ent:count()
- print("You can join now!")
- soundPlay(1, 0, "/buttons/bell1.wav")
- }
- }
- }
- if(Mode==3 & clk("timedown"))
- {
- Countdown--
- if(Countdown!=0)
- {
- print(Countdown + " seconds to go")
- soundPlay(1, 0, "/buttons/blip2.wav")
- timer("timedown", 1000)
- }
- else
- {
- print("The game has started! Good Luck!")
- soundPlay(1, 0, "/buttons/bell1.wav")
- play_music()
- Mode = 4
- }
- }
- if(changed(Mode))
- {
- if(Mode==4)
- {
- for(N=1, Ent:count())
- {
- Ent[N, entity]:propFreeze(0)
- }
- }
- }
- if(Mode==4)
- {
- for(N=1, Ent:count())
- {
- E = Ent[N, entity]
- E:propFreeze(0)
- E:applyForce(-E:vel()*E:mass() + vec(0,0,12)*E:mass())
- E:applyAngForce(-E:angVel()*E:mass()*20)
- }
- Pl = Player[AtPlayer, entity]
- if(Pl:pos():z() < (Chip:pos():z()+20))
- {
- print(Pl:name() + " fell.")
- Player:remove(AtPlayer)
- }
- AtPlayer = (AtPlayer+1)%(Player:count()+1)
- if(Player:count()==1)
- {
- Pl = Player[1, entity]
- print(Pl:name() + " has won the round! Congratulations!")
- Mode = 5
- print("The game will restart in 10 seconds!")
- timer("restart", 10000)
- }
- if(ColorChange)
- {
- E = Ent[AtEnt, entity]
- E:setColor(Color[random(1, Colors),vector])
- AtEnt = (AtEnt+1)%(EntCount+1)
- }
- }
- if(Mode==5 & clk("restart"))
- {
- reset()
- }
Advertisement
Add Comment
Please, Sign In to add comment