sinivi 2 Posted December 31, 2012 Hello This is my first script request. I read the guidelines, checked to see if there was a script out there already and I couldn't find one (unless I overlooked? ) Anyways, you know how in Pokemon when the player runs into something, it makes a kind of a buzz sound effect? I kind of thought it was interesting, so I wanted it for my game!~ (and all the other people who wants to use it like me ) So, basically a script that enables a sound effect to be played when the player runs into something non-passable.....if possible It's not something that I need immediatley at all o3o Thank you community~♥ ~Vhirous-Chan Share this post Link to post Share on other sites
DP3 188 Posted January 3, 2013 Oddly enough, in my scripting tutorials I was going to make exactly this as the first complete script. If you wanna wait a few days until I get around to that tut, you'll get it. Though this should only really take 3-5 minutes if someone else is willing. Share this post Link to post Share on other sites
artlis 0 Posted January 3, 2013 This works but its not very pretty: on the "RPG::SE.new("Cancel1", 50, 100).play" line put the sound name, volume, and pitch that you want. class Game_CharacterBase alias old_init_private_members init_private_members def init_private_members old_init_private_members @sound_timer = 0 end alias old_update_stop update_stop def update_stop old_update_stop @sound_timer += 1 end alias old_passable? passable? def passable?(x, y, d) if (!old_passable?(x,y,d)) if (@sound_timer > 30) @sound_timer = 0 RPG::SE.new("Cancel1", 50, 100).play end return false end return true end end Share this post Link to post Share on other sites
sinivi 2 Posted January 13, 2013 This works but its not very pretty: on the "RPG::SE.new("Cancel1", 50, 100).play" line put the sound name, volume, and pitch that you want. class Game_CharacterBase alias old_init_private_members init_private_members def init_private_members old_init_private_members @sound_timer = 0 end alias old_update_stop update_stop def update_stop old_update_stop @sound_timer += 1 end alias old_passable? passable? def passable?(x, y, d) if (!old_passable?(x,y,d)) if (@sound_timer > 30) @sound_timer = 0 RPG::SE.new("Cancel1", 50, 100).play end return false end return true end end Sorry for the late reply everyone D: Thank you for responding to my post you guys! @artlis I tested the script and got an error at line 11 where it says @ sound_timer += 1. Oddly enough, in my scripting tutorials I was going to make exactly this as the first complete script.If you wanna wait a few days until I get around to that tut, you'll get it. Though this should only really take 3-5 minutes if someone else is willing. @DP3 I'm willing to wait as long as I could :3 this is a very small feature in my game, so it's not a big deal if I wait very long. Share this post Link to post Share on other sites
DP3 188 Posted January 13, 2013 (edited) I still haven't gotten around to doing the tut for it, but I'm not one to make people wait #============================================================================== # ** Game_Player #------------------------------------------------------------------------------ # This class handles the player. It includes event starting determinants and # map scrolling functions. The instance of this class is referenced by # $game_player. #============================================================================== class Game_Player < Game_Character #------------------------------ # Editable Region -- #------------------------------ Collision_SE = [ "Thunder1", 80, 100 ] # Filename, Volume, Pitch Collision_Wait_Timer = 60 # Wait Time (In Frames) before next Collision Sound #------------------------------ #-------------------------------------------------------------------------- # * Alias Listings #-------------------------------------------------------------------------- alias dp3_gameplayer_update_10dju update alias dp3_gameplayer_passable_10dju passable? #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update $game_temp.dp3_collision_sound_timer -= 1 if $game_temp.dp3_collision_sound_timer > 0 dp3_gameplayer_update_10dju() end #-------------------------------------------------------------------------- # * Determine if Passable #-------------------------------------------------------------------------- def passable?( *args ) passable = dp3_gameplayer_passable_10dju( *args ) unless passable || $game_temp.dp3_collision_sound_timer > 0 RPG::SE.new( *Collision_SE ).play $game_temp.dp3_collision_sound_timer = Collision_Wait_Timer end return passable end end #============================================================================== # ** Game_Temp #------------------------------------------------------------------------------ # This class handles temporary data that is not included with save data. # The instance of this class is referenced by $game_temp. #============================================================================== class Game_Temp #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :dp3_collision_sound_timer # Collision Sound Timer #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- alias dp3_gametemp_initialise_10dju initialize #-------------------------------------------------------------------------- def initialize @dp3_collision_sound_timer = 0 dp3_gametemp_initialise_10dju() end end @artlis - Allow me to present a few pointers into why that error occured. Your script inserts collision sound on every event, not just the player (and that's kind of a negative in this case). It works fine upon initialisation for all events, but the player is only initialised upon starting a new game, which is to say that 'Vhirous' was continuing from an old save and the script was working fine until it got up to the player, which had its timer as nil because it never got initialised. That said, your collision sound should be in the Game_Player class rather than Character_Base, and since your sound_timer is only a temporary variable, you can use Game_Temp to store it, because it will always be initialised that way, whether the user is starting a new game or not Edited January 13, 2013 by DP3 Share this post Link to post Share on other sites
sinivi 2 Posted January 17, 2013 I still haven't gotten around to doing the tut for it, but I'm not one to make people wait #============================================================================== # ** Game_Player #------------------------------------------------------------------------------ # This class handles the player. It includes event starting determinants and # map scrolling functions. The instance of this class is referenced by # $game_player. #============================================================================== class Game_Player < Game_Character #------------------------------ # Editable Region -- #------------------------------ Collision_SE = [ "Thunder1", 80, 100 ] # Filename, Volume, Pitch Collision_Wait_Timer = 60 # Wait Time (In Frames) before next Collision Sound #------------------------------ #-------------------------------------------------------------------------- # * Alias Listings #-------------------------------------------------------------------------- alias dp3_gameplayer_update_10dju update alias dp3_gameplayer_passable_10dju passable? #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update $game_temp.dp3_collision_sound_timer -= 1 if $game_temp.dp3_collision_sound_timer > 0 dp3_gameplayer_update_10dju() end #-------------------------------------------------------------------------- # * Determine if Passable #-------------------------------------------------------------------------- def passable?( *args ) passable = dp3_gameplayer_passable_10dju( *args ) unless passable || $game_temp.dp3_collision_sound_timer > 0 RPG::SE.new( *Collision_SE ).play $game_temp.dp3_collision_sound_timer = Collision_Wait_Timer end return passable end end #============================================================================== # ** Game_Temp #------------------------------------------------------------------------------ # This class handles temporary data that is not included with save data. # The instance of this class is referenced by $game_temp. #============================================================================== class Game_Temp #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :dp3_collision_sound_timer # Collision Sound Timer #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- alias dp3_gametemp_initialise_10dju initialize #-------------------------------------------------------------------------- def initialize @dp3_collision_sound_timer = 0 dp3_gametemp_initialise_10dju() end end @artlis - Allow me to present a few pointers into why that error occured. Your script inserts collision sound on every event, not just the player (and that's kind of a negative in this case). It works fine upon initialisation for all events, but the player is only initialised upon starting a new game, which is to say that 'Vhirous' was continuing from an old save and the script was working fine until it got up to the player, which had its timer as nil because it never got initialised. That said, your collision sound should be in the Game_Player class rather than Character_Base, and since your sound_timer is only a temporary variable, you can use Game_Temp to store it, because it will always be initialised that way, whether the user is starting a new game or not I just tested your correction and followed your instruction, it works ^^ This is exactly what I wanted Thank you DP3 and artlis! Didn't work Test it in a new game file, it will work Share this post Link to post Share on other sites