Forum

> > CS2D > Scripts > Music script mistake or timers not working
Forums overviewCS2D overview Scripts overviewLog in to reply

English Music script mistake or timers not working

1 reply
To the start Previous 1 Next To the start

old Music script mistake or timers not working

olie18
User Off Offline

Quote
I was trying to make the following test script which should hit a bass drum on beat 1 and 3 and a snare on beat 2 and 4. Currently the first snare and bass drum hit on the first beat then 3 and 4 hit as they should. Very weird.

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
bpm = 100 -- only bpms divisible by 2400 into whole numbers

sixteenth = {}
bpmBar = 240000/bpm -- one bar = 2400ms
bpmSixteenth = bpmBar/16
for position = 1,16 do
sixteenth[position] = bpmSixteenth*(position-1)
parse("sv_msg "..sixteenth[position].."") -- prints out correct times for each 16th note
end

addhook("join","start")
function start(id)
	if player(id,"bot") == false then
	timer(sixteenth[1], "loopKickOne") -- trigger kick at 0 ms (it does)
	timer(sixteenth[9], "loopKickTwo") -- trigger second kick at 1200 ms (it does)
	timer(sixteenth[5], "loopSnareOne") -- trigger snare at 600ms (it doesn't)
	timer(sixteenth[13], "loopSnareTwo") -- trigger snare at 1800ms (it does)
	end
end

function loopKickOne()
parse("sv_sound /machette_madness_sounds/kick.ogg")
timer(bpmBar,"loopKickOne") -- wait 2400ms (a bar) and repeat
end

function loopKickTwo()
parse("sv_sound /machette_madness_sounds/kick.ogg")
timer(bpmBar,"loopKickTwo")
end

function loopSnareOne()
parse("sv_sound /machette_madness_sounds/Snare.ogg")
timer(bpmBar,"loopSnareOne")
end

function loopSnareTwo()
parse("sv_sound /machette_madness_sounds/Snare.ogg")
timer(bpmBar,"loopSnareTwo")
end

It's staying in time as it's repeating but the sound triggers aren't in the correct places to begin with.

I replaced the table values in the timers with the actual values that it should be and got the same result.

Added 1000 to each value and it fixed it. Do the timers not handle values below 1000?

Last update, for anyone wondering, even with it working, no it doesn't keep in time very well. Noticeably sounds like someone who has just learnt the drums playing badly.
edited 8×, last 02.12.17 09:54:31 pm

old Re: Music script mistake or timers not working

VADemon
User Off Offline

Quote
Timers should be able to handle values down to 20ms or recently 16,6ms (timer resolution: each game frame).
That's where your second problem would come from. Each timer will not only be wrong by player ping, but also timer resolution and how long the server scripts need to be computed (if one frame lags by about 50ms because of a heavy script, you will notice this while listening).

Honestly, just cut your songs into short segments that fit into 250 KB and glue them together into a song or loop. Don't forget to raise transfer speeds. 25 KB/s is nothing
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview