Quantcast

Jump to content

» «
Photo

[VC][SCM] completing a simple code, help appreciated.

9 replies to this topic
Speccy
  • Speccy

    Square Civilian

  • Members
  • Joined: 10 Apr 2008

#1

Posted 17 December 2013 - 02:45 PM

Hello all. I have very basic knowledge of SCM coding. Currently, i'm experimenting with some codes for a map i'm working on. I am not using cleo. Basically, i'm trying to have music playing inside a bar, which is not a separate interior.

The way i figured this could work, is by replacing one of the .wav files in the audio folder with a .wav version of the song i chose. Then a code starts the .wav when the player is near a point which has a radius covering the bar. Here is the code so far:
 

:Label008769
0001: wait  1000 ms
03A4: name_thread "MUSIC1"
03CF: load_wav "GIMME01" as  2
00D6: if  0
00F5:   player $PLAYER_CHAR  0 ()near_point -17.0 -33.0  6.5 radius  5.5  5.5  3.0
004D: jump_if_false ££Label0087E5
0050: gosub ££Label0087C2
0050: gosub ££Label0087F7

:Label0087C2
00D6: if  0
83D0:   NOT   wav  2 loaded
004D: jump_if_false ££Label0087F3
0001: wait  0 ms
00D6: if  0
8256:   NOT   player $PLAYER_CHAR defined
004D: jump_if_false ££Label0087EC

:Label0087E5
0002: jump ££Label008769

:Label0087EC
0002: jump ££Label0087C2

:Label0087F3
03D1: play_wav  2

:Label0087F7
00D6: if  0
03D2:   wav  2 ended
0459: end_thread_named "MUSIC1"

It works, and the music starts playing when the player enters the bar. Now i need to modify the code so that when the player is no longer in this radius, the wav ends. I have made numerous unsuccessful attempts at this, and each time the game crashes.

Since it was not difficult to get this far, and i have indeed had the wav stop and restart in some versions of the code (not in the right conditions), i'm assuming it is possible to do exactly what i'm trying to do.

Any help to complete this code would be deeply appreciated. Thanks in advance!


 


ChopTheDog.
  • ChopTheDog.

    War. War never changes.

  • Members
  • Joined: 31 May 2010
  • None

#2

Posted 17 December 2013 - 03:33 PM Edited by ChopTheDog., 17 December 2013 - 03:37 PM.

Maybe something like this:

:1
wait 0
if
0256:   player $PLAYER_CHAR defined 
jf @1
03CF: load_wav "GIMME01" as  2

:2
wait 0
if
00F5:   player $PLAYER_CHAR 0 -17.0 -33.0  6.5 radius 5.5  5.5  3.0
jf @2
wait 0
if
03D0:   wav 2 loaded 
jf @1
03D1: play_wav  2

:3
wait 0
if
83D2:   not wav  2 ended
jf @4
wait 0
if
00F5:   player $PLAYER_CHAR 0 -17.0 -33.0  6.5 radius 5.5  5.5  3.0
jf @4
jump @3

:4
040D: unload_wav 2
jump @1

This was scripted in Sanny Builder.

 

If like you said you'd be using this in SCM and not CLEO you could probably use the:

Create_thread @1

Command to run this script alongside others in the main.


Speccy
  • Speccy

    Square Civilian

  • Members
  • Joined: 10 Apr 2008

#3

Posted 17 December 2013 - 05:08 PM Edited by Dr.Dbl-Gee, 17 December 2013 - 06:46 PM.

Thanks for the quick reply! As soon as I get home, I'll fiddle around with Sanny Builder and give your code a try. I was using Vice Builder, but I'll set up Sanny Builder.

*edit:

 

This is the entire SCM now:

DEFINE OBJECTS 1
DEFINE OBJECT SANNY BUILDER 3.1.2     

DEFINE MISSIONS 0

//-------------MAIN---------------
thread 'MAIN' 
fade 0 0 
01F0: set_max_wanted_level_to 6 
set_wb_check_to 0 
00C0: set_current_time 12 0 
04E4: unknown_refresh_game_renderer_at 83.0 -849.8 
Camera.SetAtPos(83.0, -849.8, 9.3)
$PLAYER_CHAR = Player.Create(#NULL, -16.5, -54.8, 9.5)
$PLAYER_ACTOR = Actor.EmulateFromPlayer($PLAYER_CHAR)
wait 0 
set_weather 0 
if 
   not Actor.Dead($PLAYER_ACTOR)
else_jump @MAIN_133 
0352: set_actor $PLAYER_ACTOR skin_to 'PLAYER' 
038B: load_requested_models 
0353: refresh_actor $PLAYER_ACTOR 

:MAIN_133
fade 1 1000 
if 
   Player.Defined($PLAYER_CHAR)
else_jump @MAIN_273 
select_interior 0 
Player.CanMove($PLAYER_CHAR) = True
01B7: release_weather 
Model.Load(#LANDSTAL)
Model.Load(#SENTINEL)
Model.Load(#DELUXO)

:MAIN_184
wait 0 
if 
   Model.Available(#LANDSTAL)
else_jump @MAIN_184 
$6 = Car.Create(#LANDSTAL, -68.0, -20.0, 4.5)
$6 = Car.Create(#SENTINEL, -68.0, -13.0, 4.5)
$6 = Car.Create(#DELUXO, -17.0, -33.0, 6.5)

:MAIN_273
wait 0 
if 
   Player.Defined($PLAYER_CHAR)
else_jump @MAIN_273 
03CF: load_wav "GIMME01" as 2 

:MAIN_306
wait 0 
if 
00F5:   player $PLAYER_CHAR 0 -17.0 -33.0 6.5 radius 5.5 5.5 3.0 
else_jump @MAIN_306 
wait 0 
if 
03D0:   wav 2 loaded 
else_jump @MAIN_273 
03D1: play_wav 2 

:MAIN_381
wait 0 
if 
83D2:   not wav 2 ended 
else_jump @MAIN_459 
wait 0 
if 
00F5:   player $PLAYER_CHAR 0 -17.0 -33.0 6.5 radius 5.5 5.5 3.0 
else_jump @MAIN_459 
jump @MAIN_381 

:MAIN_459
040D: unload_wav 2 
jump @MAIN_273 

I get an unhandled exception 5 seconds after spawning. Please if you spot an error, let me know. Unfortunately it doesn't work.



 


Speccy
  • Speccy

    Square Civilian

  • Members
  • Joined: 10 Apr 2008

#4

Posted 17 December 2013 - 06:52 PM Edited by Dr.Dbl-Gee, 17 December 2013 - 06:53 PM.

Just realized that it is not your code that is causing the crash. I just decompiled my original SCM (which functioned properly before) in Sanny Builder and compiled it again, and i get the same crash. I'll have to look into it, and perhaps ill just try to replicate your code in Vice Builder and see if that works.


ChopTheDog.
  • ChopTheDog.

    War. War never changes.

  • Members
  • Joined: 31 May 2010
  • None

#5

Posted 17 December 2013 - 08:16 PM Edited by ChopTheDog., 17 December 2013 - 08:17 PM.

Take a look at this stripped main scm for Vice City:

 

// Converted from BW`s Totally_stripped.txt
// DEFINE OBJECTS 0 // no needed at all
DEFINE MISSIONS 0
//DEFINE MISSION {ID} 0 AT {LABEL} @mission


//-------------MAIN---------------
thread 'MAIN'
 var
  $PLAYER_CHAR: Player 
 end // var
fade 0  0 ms
01F0: set_max_wanted_level_to 6
set_wb_check_to 0
00C0: set_current_time 12 0
04E4: unknown_refresh_game_renderer_at 468.7745 -1298.6228 
Camera.SetAtPos(468.7745, -1298.6228, 11.0712)
$PLAYER_CHAR = Player.Create(#NULL, 468.7745, -1298.6228, 11.0712)
$PLAYER_ACTOR = Actor.EmulateFromPlayer($PLAYER_CHAR)
set_weather 0
wait 0 ms                  
0180: set_on_mission_flag_to $ONMISSION // Note: your missions should use the variable defined here ($ONMISSION)
if
  NOT Actor.Dead($PLAYER_ACTOR)
then
  0352: set_actor $PLAYER_ACTOR skin_to 'PLAYER'
  038B: load_requested_models
  0353: refresh_actor $PLAYER_ACTOR
end
fade 1 (out)  1000 ms
if
  $PLAYER_CHAR.Defined
then
  select_interior 0  // select render area
  $PLAYER_CHAR.CanMove = True
  01B7: release_weather
end
// put your create_thread commands here
  
end_thread


// put your mods (threads) here






//-------------Mission 0---------------
// put your missions here

You need to make sure that your main follows that structure.

 

Define and set the mandatory code at the top then use the:

Create_thread @1 

Opcode to start your "Music in interior" part of the script like I said in my last post.

 

Then plop the code I posted above under the last:

end_thread

It should work fine.


Speccy
  • Speccy

    Square Civilian

  • Members
  • Joined: 10 Apr 2008

#6

Posted 17 December 2013 - 11:56 PM

Ok, so i tried that. When I include your code, the SCM looks like this:

 

DEFINE MISSIONS 0

//-------------MAIN---------------
thread 'MAIN'
 var
  $PLAYER_CHAR: Player 
 end // var
fade 0  0 ms
01F0: set_max_wanted_level_to 6
set_wb_check_to 0
00C0: set_current_time 12 0
04E4: unknown_refresh_game_renderer_at 83.0 -849.8 
Camera.SetAtPos(83.0, -849.8, 9.3)
$PLAYER_CHAR = Player.Create(#NULL, -16.5, -54.8, 9.5)
$PLAYER_ACTOR = Actor.EmulateFromPlayer($PLAYER_CHAR)
set_weather 0
wait 0 ms                  
0180: set_on_mission_flag_to $ONMISSION
if
  NOT Actor.Dead($PLAYER_ACTOR)
then
  0352: set_actor $PLAYER_ACTOR skin_to 'PLAYER'
  038B: load_requested_models
  0353: refresh_actor $PLAYER_ACTOR
end
fade 1 (out)  1000 ms
if
  $PLAYER_CHAR.Defined
then
  select_interior 0  // select render area
  $PLAYER_CHAR.CanMove = True
  01B7: release_weather
end
Create_thread @1 ]
  
end_thread

:1
wait 0
if
0256:   player $PLAYER_CHAR defined 
jf @1
03CF: load_wav "GIMME01" as  2

:2
wait 0
if
00F5:   player $PLAYER_CHAR 0 -17.0 -33.0  6.5 radius 5.5  5.5  3.0
jf @2
wait 0
if
03D0:   wav 2 loaded 
jf @1
03D1: play_wav  2

:3
wait 0
if
83D2:   not wav  2 ended
jf @4
wait 0
if
00F5:   player $PLAYER_CHAR 0 -17.0 -33.0  6.5 radius 5.5  5.5  3.0
jf @4
jump @3

:4
040D: unload_wav 2
jump @1

The game crashes right after loading. However, when i just use the the stripped main scm that you provided, the game runs fine. Now i'm certain that the game has an issue with the code.

Thanks for your feedback though! Maybe we can figure something out..


ChopTheDog.
  • ChopTheDog.

    War. War never changes.

  • Members
  • Joined: 31 May 2010
  • None

#7

Posted 18 December 2013 - 12:50 AM

Create_thread @1 ]

Why is there a "]" after create_thread?


Speccy
  • Speccy

    Square Civilian

  • Members
  • Joined: 10 Apr 2008

#8

Posted 18 December 2013 - 01:30 AM

Create_thread @1 ]

Why is there a "]" after create_thread?

 

got rid of it.. That didn't solve the problem. Also i converted the script i had made in Vice Builder (working SCM, starts the wav in game as intended) into SB:

Create_thread @1
  
end_thread

:1
wait  1000 ms
03CF: load_wav "GIMME01" as  2
if
00F5:   player $PLAYER_CHAR  0 ()near_point -17.0 -33.0  6.5 radius  5.5  5.5  3.0
jf @3
gosub @2
gosub @6

:2
if
83D0:   NOT   wav  2 loaded
jf @5
wait  0 ms
if
8256:   NOT   player $PLAYER_CHAR defined
jf @4

:3
jump @1

:4
jump @2

:5
03D1: play_wav  2

:6
if
03D2:   wav  2 ended
end_thread

And the same code now crashes the game. I'm blank on what's going on.


Speccy
  • Speccy

    Square Civilian

  • Members
  • Joined: 10 Apr 2008

#9

Posted 18 December 2013 - 01:51 AM Edited by Dr.Dbl-Gee, 18 December 2013 - 01:54 AM.

OK WAIT.

 

You, sir, are a genius.

 

I fiddled around with your code, and indeed, it works! Not that it matters now, but all i did was rewrite your code in Vice Builder, and the game runs flawlessly!

 

For anyone that will possibly stumble upon this topic in the future and find this usefull, here is the code to play music without entering an interior:

:Label008769
0001: wait  1000 ms
00D6: if  0
0256:   player $PLAYER_CHAR defined 
004D: jump_if_false ££Label008769
03CF: load_wav "GIMME01" as  2

:Label0087C2
0001: wait  0 ms
00D6: if  0
00F5:   player $PLAYER_CHAR 0 -17.0 -33.0  6.5 radius 5.5  5.5  3.0
004D: jump_if_false ££Label0087C2
0001: wait  0 ms
00D6: if  0
03D0:   wav  2 loaded
004D: jump_if_false ££Label008769
03D1: play_wav  2

:Label0087E5
0001: wait  0 ms
00D6: if  0
83D2:   not wav  2 ended
004D: jump_if_false ££Label0087F3
0001: wait  0 ms
00D6: if  0
00F5:   player $PLAYER_CHAR 0 -17.0 -33.0  6.5 radius 5.5  5.5  3.0
004D: jump_if_false ££Label0087F3
0002: jump ££Label0087E5

:Label0087F3
040D: unload_wav 2
0002: jump ££Label008769

*obviously before, you must replace the wav in the audio folder (eg. gimme01.wav) with your song in .wav format under the same exact name.

ChopTheDog, you're the man! :)

  • ChopTheDog. likes this

ChopTheDog.
  • ChopTheDog.

    War. War never changes.

  • Members
  • Joined: 31 May 2010
  • None

#10

Posted 18 December 2013 - 03:43 AM

Glad you sorted it :^: 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users