01-17-2015, 05:23 PM
The entire server is event-driven and the plugins are synchronous - while plugin code is executing, most of the rest of the server is waiting for it to finish. This means that you cannot use any kind of a sleep function, you need to make use of the scheduler instead. There's a cWorld:ScheduleTask() function that basically says "call this function after this many ticks". Additionally, you need to take care of the situation that your plugin is using a note entity and a player destroys the block during that time - the note entity object becomes invalid. Therefore, the code should look something like this:
--- Schedules the specified note block to play the specified melody -- a_Melody is an array-table of notes, each note being a table with two members, delay (in ticks) and pitch function StartPlaying(a_World, a_NoteBlockX, a_NoteBlockY, a_NoteBlockZ, a_Melody) for _, note in ipairs(a_Melody) do a_World:ScheduleTask(note.delay, function (a_CBWorld) a_CBWorld:DoWithNoteAt(a_NoteBlockX, a_NoteBlockY, a_NoteBlokZ, function (a_CBNoteBlock) a_CBNoteBlock:SetPitch(note.pitch) a_CBNoteBlock:MakeSound() end ) end ) end end -- Example usage: local Melody = { {0, F5}, {4, F5}, {8, F5}, {12, D5}, {14, F5}, } StartPlaying(World, 100, 100, 100, Melody)