Multiple Unit Sounds.

Discuss almost anything about RailWorks.

Multiple Unit Sounds.

Unread postby Rich_S » Mon Feb 21, 2011 11:04 am

Hello Group,
Not sure how many folks have been following this thread on another board, but for those who have not I figured I'd post my findings here :D The first thing I recommend is getting Pike's tutorial on how to update your freight car fleet using InfoRapid Search & Replace. The tutorial can be found on his website, [url][http://www.pikesproducts.com/14201.html/url] item #8.

The hard part is manually updating your locomotive fleet. You can either use RW_Tools to edit the engines bin files, or after linking your bin files to serz.exe, use a text editor to edit the xml files. For a text editor I prefer the ConText editor. Now onto the upgrade :)

The first thing you'll have to add to then engines bin file is the active paragraph:

Code: Select all
     

<cControlContainerBlueprint-cControlValue d:id="90078136">
       <ControlName d:type="cDeltaString">Active</ControlName>
       <DefaultValue d:type="sFloat32" d:alt_encoding="0000000000000000" d:precision="string">0.0000</DefaultValue>
       <MinimumValue d:type="sFloat32" d:alt_encoding="0000000000000000" d:precision="string">0.0000</MinimumValue>
       <MaximumValue d:type="sFloat32" d:alt_encoding="000000000000F03F" d:precision="string">1.0000</MaximumValue>
       <BriefDescription d:type="cDeltaString"></BriefDescription>
       <DetailedDescription d:type="cDeltaString"></DetailedDescription>
       <ApplyToConsist d:type="cDeltaString">eTrue</ApplyToConsist>
       <InterfaceElements/>
</cControlContainerBlueprint-cControlValue>



This paragraph is inserted just above the RPM paragraph and just below the opening paragraph statement <ControlValues>

Next search for the Regulator paragraph, you need to update the line ApplyToConsist, it's currently set to eFalse, change it to read eTrue Then save the file.

Next you'll need to add a engine script to each locomotives Engine folder.

Code: Select all

--------------------------------------------------------------------------------------
-- Engine Script for controlling additional engines
-- RailWorks 2: Train Simulator
--------------------------------------------------------------------------------------


IDLERPM = 1000
FULLRPM = 1500

RPM_ID = 1709
RPMD_ID = 1710


function Initialise ()

   gPrevRPM = 0
   gPrevRPMDelta = 0

   Call( "BeginUpdate" )

end


function OnControlValueChange ( name, index, value )

   if Call( "*:ControlExists", name, index ) then
      Call( "*:SetControlValue", name, index, value );
   end

end

function Update ( time )

-- Get rpm values for this vehicle.

   rpm = Call( "*:GetControlValue", "RPM", 0 )
   rpm_change = Call( "*:GetControlValue", "RPMDelta", 0 )
   
   if ( Call( "*:GetControlValue", "RPM", 0 ) < 200 ) then
      Call( "Exhaust:SetEmitterActive", 0 )
   else
      Call( "Exhaust:SetEmitterActive", 1 )
   end

-- If this is a player train and this vehicle is the driven one, then send
-- RPM values in both directions along train. Note the Driven control is set
-- by the simulation script, which only runs on the vehicle the player is driving.
-- Only send messages if values have changed.

   if ( Call( "GetIsPlayer" ) == 1 ) then
      if ( Call( "*:GetControlValue", "Active", 0 ) == 1 ) then
         if ( rpm ~= gPrevRPM ) then
            Call( "SendConsistMessage", RPM_ID, rpm, 1 )
            Call( "SendConsistMessage", RPM_ID, rpm, 0 )
         end
         if ( rpm_change ~= gPrevRPMDelta ) then
            Call( "SendConsistMessage", RPMD_ID, rpm_change, 1 )
            Call( "SendConsistMessage", RPMD_ID, rpm_change, 0 )
         end
      end

      gPrevRPM = rpm
      gPrevRPMDelta = rpm_change

   end

end

-- Core sim function executed if a consist message is received.

function OnConsistMessage ( msg, argument, direction )

-- If this is not the driven vehicle then update the controls for RPM values with the supplied data.

   if ( Call( "*:GetControlValue", "Active", 0 ) == 0 ) then
           if ( msg == RPM_ID ) then
              Call( "*:SetControlValue", "RPM", 0, argument )
           elseif ( msg == RPMD_ID ) then
              Call( "*:SetControlValue", "RPMDelta", 0, argument )
           end

-- Pass message along in same direction.

           Call( "SendConsistMessage", msg, argument, direction )
        end

end




The above script will work for just about all locomotive with just a couple of simple changes. First change, open your engines bin file and search for

ScriptComponent

To find the name of the script the engine will use, in this case I'm using the Black ES44AC as an example engine, so the line I'm looking for reads:

Code: Select all
 

<Name d:type="cDeltaString">Kuju\RailSimulatorUS\RailVehicles\Diesel\ES44AC\Black\Engine\ES44ACEngineScript</Name>



The name of the script is: ES44ACEngineScript, so your script file needs to be named ES44ACEngineScript.lua

Now scroll up about 40 lines and you should see a line that contains the word Exhaust. Again using the Black ES44AC as an example the line reads:

Code: Select all
 

<ChildName d:type="cDeltaString">Exhaust</ChildName>



Make a note of the exact word or words used between the greater than and less than symbols, they could be Diesel_Exhaust, Engine_Exhaust and so forth. Now that you know the name of the exhaust, open the engine script file and search for the text:

SetEmitterActive

In this case I'm again using the Black ES44ACEngineScript.lua as an example:

Code: Select all

Call( "Exhaust:SetEmitterActive"



Notice the word before the colon, if your engines exhaust statement read Engine_Exhaust, then you'd need to change the above statement to

Code: Select all

Call( "Engine_Exhaust:SetEmitterActive"



Now save the file. The last thing you'll need to do is add a script file to any locomotive that has a Simulation folder. This script file is placed in the Simulation folder.

Code: Select all
--------------------------------------------------------------------------------------
-- Simulation Script for controlling audio in additional engines
-- RailWorks 2: Train Simulator
--------------------------------------------------------------------------------------
-- Update

function Update (inteval)

-- If simulation is running this must be player vehicle, so set Active control to indicate this.

   Call( "*:SetControlValue", "Active", 0, 1 )

end



This file should have the same file name as the bin file in the simulation folder, except the file extension should be lua.

That's it and if all went well, all of your engines in a consists should now produce sound and the exhausts on all engines should emit smoke :) Also if you followed Pike's tutorial to update your freight car fleet, you helper engines and DPU engines should throttle up and emit exhaust as well ;) Lastly I'd like to thank TomKat, Krellnut, MontanaRails and Otto for all of their help on this project, thanks guys !!*ok*!!

Enjoy,
Rich S.
Cheers,
Rich S.
User avatar
Rich_S
 
Posts: 708
Joined: Tue Aug 24, 2010 11:19 pm
Location: Baden, PA, USA

Re: Multiple Unit Sounds.

Unread postby Bart35 » Tue Feb 22, 2011 11:35 am

Nice work!! **!!bow!!** **!!bow!!** now can we get someone to write a program to automate the process ??? !*hp*! !*hp*!
Thanks for your work.. Wish me luck
User avatar
Bart35
 
Posts: 48
Joined: Tue Nov 02, 2010 6:44 pm

Re: Multiple Unit Sounds.

Unread postby imnew » Tue Feb 22, 2011 5:40 pm

Very nice work. Thanks
Intel Core I7-7770K, ZOTAC GTX 1080 Ti AMP
Extreme, ASUS ROG Strix Z270H, 16 GB HyperX Fury DDR4, Samsung 850 EVO 500GB, Corsair Force MP500 240GB M.2, 34" Ultra Wide Samsung Monitor
User avatar
imnew
 
Posts: 2456
Joined: Tue Aug 25, 2009 1:41 pm

Re: Multiple Unit Sounds.

Unread postby mikesimpson » Sat Feb 26, 2011 5:16 pm

>This file should have the same file name as the bin file in the simulation folder, except the file extension should be lua.

Hi Rich,

This is not necessarily true, in the RSC Class 37 Loco, the .bin file is Class37 Engine Simulation.bin but the Simulation file is names 'Class37 simulation.bin'

You need to open the Simulation .bin file and check the ScriptComponent Name path to find the correct name.

I have fixed the new version of RW_Tools so that it now does this.

Mike
mikesimpson
 
Posts: 364
Joined: Sun Feb 15, 2009 4:49 pm

Re: Multiple Unit Sounds.

Unread postby Rich_S » Mon Feb 28, 2011 9:28 am

Good catch Mike !!*ok*!! That was a bug in the making *!embar*! and Thank you for automating this process through RW_Tools. !!howdy!!
Cheers,
Rich S.
User avatar
Rich_S
 
Posts: 708
Joined: Tue Aug 24, 2010 11:19 pm
Location: Baden, PA, USA

Re: Multiple Unit Sounds.

Unread postby micaelcorleone » Mon Feb 28, 2011 9:31 am

Has anyone mailed this to Railsimulator.com?
Maybe they can implement it into all engines in an update.
User avatar
micaelcorleone
 
Posts: 1668
Joined: Tue Oct 05, 2010 11:04 am
Location: Bavaria, Germany

Re: Multiple Unit Sounds.

Unread postby Rich_S » Mon Feb 28, 2011 1:19 pm

I'm sure RSC is aware of this, as these scripts are all based off of the current scripts that were shipped with the SD70's. All we did was removed the unused lines of code and tweaked them to work with all available Diesel-Electric locomotives. Mike then added the programming to RW_Tools to automate the process. Hopefully the next update will not undo what we've accomplished, but if it does at least now we have a automated process available to fix what they break *!twisted!*
Cheers,
Rich S.
User avatar
Rich_S
 
Posts: 708
Joined: Tue Aug 24, 2010 11:19 pm
Location: Baden, PA, USA


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 12 guests