CLEO Help Detect if the audio is already playing

CLEO related
Status
Not open for further replies.

alborosie

Active member
Joined
Aug 16, 2017
Messages
67
Reaction score
3
Hi.
I have this code:
PHP:
{$CLEO .cs}
0000: NOP

// this part requires sampfuncs
repeat
wait 50
until 0AFA: is_samp_structures_available

0b34: "play1" @play1
0b34: "stop1" @stop1
0b34: "play2" @play2
0b34: "stop2" @stop2
0b34: "play3" @play3
0b34: "stop3" @stop3
0b34: "play4" @play4
0b34: "stop4" @stop4
0b34: "play5" @play5
0b34: "stop5" @stop5
0b34: "play6" @play6
0b34: "stop6" @stop6
0b34: "play7" @play7
0b34: "stop7" @stop7
0b34: "play8" @play8
0b34: "stop8" @stop8
0b34: "play9" @play9
0b34: "stop9" @stop9
0b34: "play10" @play10
0b34: "stop10" @stop10

:cmd_999
wait 0
jump @cmd_999

repeat
wait 50
until 056D: actor $PLAYER_ACTOR defined

////////////////////PLAY 1////////////////////
:play1
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP1
        0AAC: $hMP1 = load_audiostream "cleo/music/1.mp3"
        0ABC: set_audiostream $hMP1 volume 1.0
        0AAD: set_mp3 $hMP1 perform_action 1 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////STOP 1////////////////////
:stop1
SAMP.IsCommandTyped(20@)   
        0AAE: release_mp3 $hMP1
        0AAC: $hMP1 = load_audiostream "cleo/music/1.mp3"
        0ABC: set_audiostream $hMP1 volume 1.0
        0AAD: set_mp3 $hMP1 perform_action 0 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////PLAY 2//////////////////// 
:play2
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP2
        0AAC: $hMP2 = load_audiostream "cleo/music/2.mp3"
        0ABC: set_audiostream $hMP2 volume 1.0
        0AAD: set_mp3 $hMP2 perform_action 1 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////STOP 2////////////////////     
:stop2
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP2
        0AAC: $hMP2 = load_audiostream "cleo/music/2.mp3"
        0ABC: set_audiostream $hMP2 volume 1.0
        0AAD: set_mp3 $hMP2 perform_action 0 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()     
////////////////////PLAY 3////////////////////
:play3
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP3
        0AAC: $hMP3 = load_audiostream "cleo/music/3.mp3"
        0ABC: set_audiostream $hMP3 volume 1.0
        0AAD: set_mp3 $hMP3 perform_action 1 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////STOP 3////////////////////
:stop3
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP3
        0AAC: $hMP3 = load_audiostream "cleo/music/3.mp3"
        0ABC: set_audiostream $hMP3 volume 1.0
        0AAD: set_mp3 $hMP3 perform_action 0 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////PLAY 4////////////////////     
:play4
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP4
        0AAC: $hMP4 = load_audiostream "cleo/music/4.mp3"
        0ABC: set_audiostream $hMP4 volume 1.0
        0AAD: set_mp3 $hMP4 perform_action 1 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////STOP 4////////////////////
:stop4
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP4
        0AAC: $hMP4 = load_audiostream "cleo/music/4.mp3"
        0ABC: set_audiostream $hMP4 volume 1.0
        0AAD: set_mp3 $hMP4 perform_action 0 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////PLAY 5////////////////////
:play5
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP5
        0AAC: $hMP5 = load_audiostream "cleo/music/5.mp3"
        0ABC: set_audiostream $hMP5 volume 1.0
        0AAD: set_mp3 $hMP5 perform_action 1 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////STOP 5////////////////////
:stop5
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP5
        0AAC: $hMP5 = load_audiostream "cleo/music/5.mp3"
        0ABC: set_audiostream $hMP5 volume 1.0
        0AAD: set_mp3 $hMP5 perform_action 0 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////PLAY 6////////////////////
:play6
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP6
        0AAC: $hMP6 = load_audiostream "cleo/music/6.mp3"
        0ABC: set_audiostream $hMP6 volume 1.0
        0AAD: set_mp3 $hMP6 perform_action 1 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////STOP 6////////////////////
:stop6
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP6
        0AAC: $hMP6 = load_audiostream "cleo/music/6.mp3"
        0ABC: set_audiostream $hMP6 volume 1.0
        0AAD: set_mp3 $hMP6 perform_action 0 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////PLAY 7////////////////////
:play7
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP7
        0AAC: $hMP7 = load_audiostream "cleo/music/7.mp3"
        0ABC: set_audiostream $hMP7 volume 1.0
        0AAD: set_mp3 $hMP7 perform_action 1 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////STOP 7////////////////////
:stop7
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP7
        0AAC: $hMP7 = load_audiostream "cleo/music/7.mp3"
        0ABC: set_audiostream $hMP7 volume 1.0
        0AAD: set_mp3 $hMP7 perform_action 0 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////PLAY 8////////////////////
:play8
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP8
        0AAC: $hMP8 = load_audiostream "cleo/music/8.mp3"
        0ABC: set_audiostream $hMP8 volume 1.0
        0AAD: set_mp3 $hMP8 perform_action 1 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////STOP 8////////////////////
:stop8
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP8
        0AAC: $hMP8 = load_audiostream "cleo/music/8.mp3"
        0ABC: set_audiostream $hMP8 volume 1.0
        0AAD: set_mp3 $hMP8 perform_action 0 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////PLAY 9////////////////////
:play9
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP9
        0AAC: $hMP9 = load_audiostream "cleo/music/9.mp3"
        0ABC: set_audiostream $hMP9 volume 1.0
        0AAD: set_mp3 $hMP9 perform_action 1 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////STOP 9////////////////////
:stop9
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP9
        0AAC: $hMP9 = load_audiostream "cleo/music/9.mp3"
        0ABC: set_audiostream $hMP9 volume 1.0
        0AAD: set_mp3 $hMP9 perform_action 0 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////PLAY 10////////////////////
:play10
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP10
        0AAC: $hMP10 = load_audiostream "cleo/music/10.mp3"
        0ABC: set_audiostream $hMP10 volume 1.0
        0AAD: set_mp3 $hMP10 perform_action 1 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
////////////////////STOP 10////////////////////
:stop10
SAMP.IsCommandTyped(20@)
        0AAE: release_mp3 $hMP10
        0AAC: $hMP10 = load_audiostream "cleo/music/10.mp3"
        0ABC: set_audiostream $hMP10 volume 1.0
        0AAD: set_mp3 $hMP10 perform_action 0 //0=stop, 1=play
        wait 1000
SAMP.CmdRet()
How i can detect if the "play1" is activated? Like if it's activated, send a chat message with "Audio1 is already playing. Use /stop1 to stop it" and so on.
@monday helped me with the code above.
Thanks in advance.
Sorry for my bad english
 
Last edited:

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
You can use variables to check like:
PHP:
:stop1
SAMP.IsCommandTyped(20@)   
        0AAE: release_mp3 $hMP1
        0AAC: $hMP1 = load_audiostream "cleo/music/1.mp3"
        0ABC: set_audiostream $hMP1 volume 1.0
        0AAD: set_mp3 $hMP1 perform_action 0 //0=stop, 1=play
0@ = true // set 1 activated
        wait 1000
SAMP.CmdRet()
////////////////////PLAY 2//////////////////// 
:play2
SAMP.IsCommandTyped(20@)
if
0@ == false
then
        0AAE: release_mp3 $hMP2
        0AAC: $hMP2 = load_audiostream "cleo/music/2.mp3"
        0ABC: set_audiostream $hMP2 volume 1.0
        0AAD: set_mp3 $hMP2 perform_action 1 //0=stop, 1=play
        wait 1000
else
chatmsg "stop play 1" -
end
SAMP.CmdRet()
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
You could check this out, it automatically loads all the mp3 filenames from "CLEO/audio/" directory (just make sure the names don't contain dots)


So then you can use:
/play 1 (that would play "hotel california" song)

/stop
/pause (these 2 commands don't need a number, because it is assumed that only 1 song is meant to be played at once)
/show_titles

Code:
{$CLEO .cs}
0000: NOP

/*
  VARIABLES USED:
  0@ = length of currently played song
  1@ = count of titles
  2@ = was any song loaded since the game started
  3@ = song title storage
  $hMP1 = mp3 handle (only 1 because it is planned to play 1 song at once)
  

*/

repeat
wait 50
until 0AFA: is_samp_structures_available

0B34: samp register_client_command "play" to_label @cmd_play
0B34: samp register_client_command "pause" to_label @cmd_pause
0B34: samp register_client_command "stop" to_label @cmd_stop
0B34: samp register_client_command "show_titles" to_label @cmd_show_titles

2@ = false
alloc 3@ 10000

call @load_title_names 1 destination_pointer 3@ returned_count_of_loaded_files 1@

//chatmsg "title array pointer = 0x%X" -1 3@   // you can examine what is stored at this address using "Cheat Engine" program

while true
wait 1000
end

:load_title_names 
31@ = 0
alloc 30@ 400
alloc 27@ 400

if 0AE6: 29@ = find_first_file "CLEO/audio/*.mp3" get_filename_to 30@ // IF and SET
then            
    repeat
    wait 0 
        0AA5: call 0x8220AD num_params 3 pop 3 27@ "%[^.]" 30@  // just so the title doesn't contain ".mp3" at the end   
        31@ += 1
        0C13: strcpy destination 0@ source 27@
        0C17: 28@ = strlen 27@  
        005A: 0@ += 28@
        0@ += 1
    until 8AE7: 30@ = find_next_file 29@ 
    
    0AE8: find_close 29@
    0A8C: write_memory 0@ size 1 value 0 virtual_protect 0 
else
    printf "No CLEO/audio/*.mp3 files found at all" 10000
end

free 30@
free 27@
ret 1 31@ 


/*

    SONG TITLES FUNCTIONS

*/

:get_nth_song_title
/*
0@ = title_array
1@ = n (starting with 1)
*/
1@ -= 1

29@ = 0

if 003B:   29@ == 1@  // (int)
then
    0485:  return_true
   ret 1 0@
end
    
0A8D: 30@ = read_memory 0@ size 1 virtual_protect 0
while 30@ <> 0
    while 30@ <> 0
    wait 0
        0@ += 1
        0A8D: 30@ = read_memory 0@ size 1 virtual_protect 0
    end

    29@ += 1
    0@ += 1
    
    if 003B:   29@ == 1@  // (int)
    then
        0485:  return_true
       ret 1 0@
    end
    
    0A8D: 30@ = read_memory 0@ size 1 virtual_protect 0
end

alloc 27@ 5
format 27@ "none" 
059A:  return_false
ret 1 27@  


/*

    MP3 FUNCTIONS

*/


/* 0AB9: get_mp3 return:
1 - playing
2 - paused
-1 - stopped, or not started at all
*/

// Usage: if call @is_mp3_playing 1 $hMP1 
:is_mp3_playing
0AB9: get_mp3 0@ state_to 31@
if 31@ == 1
then
    0485:  return_true      
else
    059A:  return_false
end
ret 0

// Usage: if call @is_mp3_paused 1 $hMP1 
:is_mp3_paused
0AB9: get_mp3 0@ state_to 31@
if 31@ == 2
then
0485:  return_true
else
059A:  return_false
end
ret 0

// Usage: if call @is_mp3_stopped 1 $hMP1 
:is_mp3_stopped
0AB9: get_mp3 0@ state_to 31@
if 31@ == -1 
then
0485:  return_true
else
059A:  return_false
end
ret 0

/*

  COMMANDS

*/


:cmd_play
0B35: samp 31@ = get_last_command_params
if 0AD4: $NOT_USED = scan_string 31@ format "%d" 30@ //IF and SET
then
    if 30@ <= 0
    then
        printf "Songs start with index of 1, so 1 was assumed." 5000
        30@ = 0
    end
    
    if 001D:  30@ > 1@
    then
       0085: 30@ = 1@ // (int)
       printf "The provided (%d) number exceeds the total number of mp3 files (%d)." 5000 30@ 1@
    end    
    
    // change song
    if call @get_nth_song_title 2 title_array 3@ n 30@ song_title 29@ 
    then
        alloc 28@ 200
        format 28@ "CLEO/audio/%s.mp3" 29@
        if 0AAB:   file_exists 28@
        then
            0AAE: release_mp3 $hMP1
            0AAC: $hMP1 = load_audiostream 28@
            0ABC: set_audiostream $hMP1 volume 1.0
            0AAF: 0@ = get_mp3_length $hMP1
            0AAD: set_mp3 $hMP1 perform_action 1 //0=stop, 1=play, 2=pause, 3=resume
            2@ = true     // 2@ = was_any_song_loaded_since_game_started
        else
            printf "%s doesn't exist" 5000 28@
        end
        free 28@
    end
else
    if 2@ == true
    then
        if call @is_mp3_paused 1 $hMP1
        then
            0AAD: set_mp3 $hMP1 perform_action 3 //0=stop, 1=play, 2=pause, 3=resume
        else
            0AAD: set_mp3 $hMP1 perform_action 1 //0=stop, 1=play, 2=pause, 3=resume
        end
    else
        printf "Before using /play, use /play <song_number> (to pick a song)" 2000
    end
end
samp.CmdRet()

:cmd_pause
if 2@ == true
then
    0AAD: set_mp3 $hMP1 perform_action 2
else
    printf "Before using /pause, use /play <song_number> (to pick a song)" 2000
end    
samp.CmdRet()

:cmd_stop
if 2@ == true
then
    0AAD: set_mp3 $hMP1 perform_action 0    
else
    printf "Before using /stop, use /play <song_number> (to pick a song)" 2000
end   
samp.CmdRet()

:cmd_show_titles
chatmsg "Songs:" -1
for 30@ = 1 to 1@
    call @get_nth_song_title 2 title_array 3@ n 30@ song_title 29@
    chatmsg "%d. %s" -1 30@ 29@ 
end
samp.CmdRet()
 

Attachments

  • Untitled.png
    Untitled.png
    100.1 KB · Views: 13
Last edited:
Status
Not open for further replies.
Top