English Looping music system, score based, on/off switch icon

2 comments
03.12.17 04:37:04 pm
like 1 likes it!
594 kb, 7 Downloads
olie18
User
Offline Off
> A simple script made for people wanting to add original music for cs2d mods.
> Loops a piece of music for a player if their score is a certain amount.
> Detailed notes on what to change to add your music for newbies.
> Includes an on/off switch (F4) for each player.

Edit: updated to fix bugs
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
addhook("serveraction","musicOnOff")
addhook("leave","musicReset")
addhook("spawn","musicHud")
musicBpm = {}
lengthLoop = {}
wantMusic = {}
waiting = {}

-- list the bpms of your music --
musicBpm[1] = 100 -- add 1 to the square bracketed number to add another bpm
musicBpm[2] = 110
musicBpm[3] = 120

for id = 1,32 do
wantMusic[id] = false
waiting[id] = false
end

for bpmToMs = 1,table.maxn(musicBpm) do
musicBpm[bpmToMs] = 240000/musicBpm[bpmToMs] -- works out the length of a bar in ms at each bpm you added
end

function musicReset(id)
wantMusic[id] = false
waiting[id] = false
end

function musicHud(id)
     if wantMusic[id] == false then
     parse('hudtxt2 '..id..' 0 "©000255255Press F4 to turn music on!" 640 462 1 0 12')
     parse('hudtxtalphafade '..id..' 0 500 0.7')
     elseif wantMusic[id] == true then
     parse('hudtxt2 '..id..' 0 "©000255255Press F4 to turn music off!" 640 462 1 0 12')
     parse('hudtxtalphafade '..id..' 0 500 0.7')
     end
end

function musicOnOff(id,action)
     if (action == 3) and wantMusic[id] == false and waiting[id] == false then -- press f4 to turn music on and off
     wantMusic[id] = true
     parse('hudtxt2 '..id..' 0 "©000255255Press F4 to turn music off!" 640 462 1 0 12')
     parse('hudtxtalphafade '..id..' 0 500 0.7')
     musicOnScore(id)
     print(""..player(id,"name").." "..player(id,"score").." music on")
     elseif (action == 3) and wantMusic[id] == true then
     wantMusic[id] = false
     waiting[id] = true
     parse('hudtxt2 '..id..' 0 "©000255255Turning off music..." 640 462 1 0 12')
     parse('hudtxtalphafade '..id..' 0 500 0.7')
     print(""..player(id,"name").." "..player(id,"score").." music off")
     end
end

function musicOnScore(id)
id = tonumber(id)
     if wantMusic[id] == true then
          if player(id,"score")<=50 then -- if the players score is lower or equal to 125 then play music, change the number to what you want
          parse("sv_sound2 "..id.." /machette_madness_sounds/mm_music_level_one.ogg") -- change the file location to your first piece of music in the cs2d sfx folder
          timer(musicBpm[1]*8, "musicOnScore", id) -- change musicBpm's square bracketed number to one on the list you made and match the bpm of your file and multiply it by the length of your file in bars
          elseif player(id,"score")>50 and player(id,"score")<= 100 then -- add more by copying and pasting these three lines of code
          parse("sv_sound2 "..id.." /machette_madness_sounds/mm_music_level_two.ogg")
          timer(musicBpm[2]*4, "musicOnScore", id)
          elseif player(id,"score")>100 then -- keep a score ceiling to prevent players exceeding your score ranges and the music system bugging out
          parse("sv_sound2 "..id.." /machette_madness_sounds/mm_music_level_three.ogg")
          timer(musicBpm[3]*8, "musicOnScore", id)
          end
     elseif wantMusic[id] == false then
     parse('hudtxt2 '..id..' 0 "©000255255Press F4 to turn music on!" 640 462 1 0 12')
     parse('hudtxtalphafade '..id..' 0 500 0.7')
     waiting[id] = false
     end
end
edited 8×, last 05.12.17 10:37:53 am
x This file has been reviewed and declined by Yates (11.12.17 07:57:39 pm)
Note the guidelines when uploading files! Only upload or modify files by others when you have their permission! Do not upload trash, write a good description and upload appropriate screenshots when it makes sense!

This file is based on a very specific, unlikely or vague use-case and it is highly unlikely that any user would like to download this script and instead create their own. This file is considered a personal script that is unfit for the global archive.

Comments

2 comments
Goto Page
To the start Previous 1 Next To the start

Log in!

You need to log in to be able to write comments!Log in
05.12.17 06:06:02 am
like I like it!
Up
Chingy
User
Offline Off
@user Communism: He included an on/off switch for communists that dislike fancy loop sounds in the background.
03.12.17 07:28:55 pm
Up
Communism
Reviewer
Offline Off
I don't think it's too useful, most likely annoying for the person more than anything.
To the start Previous 1 Next To the start