Dubstep Gun

A place to discuss mods in development and concepts for new mods.
Post Reply
Tshark9999
Miner
Miner
Posts: 34
Joined: Sat Dec 01, 2012 8:22 pm

So, I was planning on making a dubstep gun for my first mod, but it turned out waaaay more complicated than I thought it would be. Avan and I were on the IRC and we discussed how to set up the music events. We managed to get it to play upon firing, and made it so only the player could activate the music upon firing, but the problem was that with each shot it would start a new instance of the music.

Code: Select all

<Tshark> Repeating dubs
<Tshark> Also, the shots didn't appear for some reason
<Avan> yes, just like when you put it in the 'sound='?
<Tshark> Yup
<Avan> Right
<Tshark> You did warn me about it
<Avan> thats supposed to happen
<Tshark> K
<Tshark> So, there's no way to make a sound gun like that?
<Avan> There is no way to get it to play
<Tshark> Also, the laser shots didn't appear
<Avan> and then stop playing
<Tshark> I see
<Avan> once you stop shotting
<Avan> *Shooting
<Avan> unless you stop shooting at the same time
<Avan> that the track ends
<Tshark> Hmm
<Tshark> Wait a minute
<Tshark> There is a uiStopMusic
<Tshark> And a uiPlayMusic
<Avan> hm, that should do what you want
<Tshark> But I need to figure out how to make it stop when I stop shooting
<Avan> Just create a virtual station
<Avan> then each time the weapon is fired
<Avan> search the system for a station with that exact unid
<Avan> cancel any pending events
<Avan> on that station
<Avan> then do a timer event to run in 60 ticks (1 second) or so
<Avan> that event, when it fires, will just run uiStopMusic
So far, this is the code I have:

Code: Select all

<?xml version="1.0" ?>
<!DOCTYPE TranscendenceExtension
[
   <!ENTITY unidExtension   "0xDEF3FF00">
   <!ENTITY itDubstepGun   "0xDEF3FF01">
   <!ENTITY Dubstep        "0xDEF3FF03">
]>
<TranscendenceExtension UNID="&unidExtension;" version="1.0" name="DubstepGun" credits="Tshark">


<ItemType UNID="&itDubstepGun;"
         name=            "dubstep gun"
         level=            "7"
         value=            "50000"
         mass=            "75000"
		 omnidirectional=  "true"
         frequency=         "rare"
         modifiers=        "EnergyWeapon; Military; MajorItem"
         showReference=      "true"

         description=      "Dubstep guns fire condensed, explosive sound waves using specialized foci."
         >

      <Image imageID="&rsItems1;" imageX="96" imageY="0" imageWidth="96" imageHeight="96"/>
      <Weapon
	  
            type=             "beam"
            damage=           "ion:2d6+6; momentum1"
            fireRate=         "7"
            omnidirectional=  "true"
            lifetime=         "50"
            powerUse=         "50"
            >
         <Effect>
            <Beam
                  beamType= "blueparticle"
                  />
         </Effect>
		 
      </Weapon>
		<Events>
			<onFireWeapon>
				(block nil (if (eq gSource gPlayership) (sysPlaySound &Dubstep; gPlayership)))
			</onFireWeapon>
		</Events>
   </ItemType>
   
   
   <ShipClass UNID="&scSapphirePlayer;"
         manufacturer=      "Zubrin Systems"
         class=            "Sapphire"
         type=            "yacht"
         score=            "95"

         mass=            "30"
         reactorPower=      "150"
         fuelCapacity=      "37500"
         cargoSpace=         "50"
         thrust=            "150"
         rotationCount=      "40"
         maneuver=         "2"
         maxSpeed=         "20"

         maxArmor=         "6000"
         maxCargoSpace=      "150"
         maxDevices=         "8"

         leavesWreck=      "30"
         
         attributes=         ""
         >

      <Armor>
         <ArmorSection start="315" span="90" armorID="&itReactiveArmor;" areaSet="0,2" />
         <ArmorSection start="225" span="90" armorID="&itReactiveArmor;" areaSet="3,4" />
         <ArmorSection start="45"  span="90" armorID="&itReactiveArmor;" areaSet="7,13" />
         <ArmorSection start="135" span="90" armorID="&itReactiveArmor;" areaSet="1,6" />
      </Armor>

      <Devices>
         <Device deviceID="&itDubstepGun;"/>
         <Device deviceID="&itClass1Deflector;"/>
      </Devices>

      <Items>
         <Item count="4d6" item="&itHelium3FuelRod;"/>
      </Items>

      <AISettings
         fireRateAdj=      "30"
         fireAccuracy=      "90"
         perception=         "4"
         />

      <Image imageID="&rsSapphireYacht;" imageX="0" imageY="0" imageWidth="48" imageHeight="48"/>

      <DriveImages>
         <NozzleImage imageID="&rsDriveExhaust2;" imageX="0" imageY="0" imageWidth="48" imageHeight="48"/>
         <NozzlePos x="-28" y="-4"/>
         <NozzlePos x="-28" y="5"/>
      </DriveImages>

      <PlayerSettings
         desc=            "The versatile Sapphire yacht strikes a good balance between a gunship and a freighter."
         largeImage=         "&rsZubrinLarge;"
         initialClass=      "true"
         startingCredits=   "10d100+1000"

         startingSystem=      "SE"
         startingPos=      "Start"
         >

         <ArmorDisplay>
            <ArmorSection name="forward"
                  imageID="&rsZubrinArmor;" 
                  imageX="0" imageY="0" imageWidth="52" imageHeight="29"
                  destX="42" destY="15" hpX="55" hpY="14"
                  nameY="8" nameBreakWidth="200" nameDestX="0" nameDestY="10" />

            <ArmorSection name="starboard"
                  imageID="&rsZubrinArmor;" 
                  imageX="52" imageY="0" imageWidth="22" imageHeight="59"
                  destX="92" destY="45" hpX="95" hpY="60"
                  nameY="30" nameBreakWidth="360" nameDestX="12" nameDestY="0" />

            <ArmorSection name="port"
                  imageID="&rsZubrinArmor;" 
                  imageX="142" imageY="0" imageWidth="22" imageHeight="59"
                  destX="22" destY="45" hpX="15" hpY="60"
                  nameY="52" nameBreakWidth="200" nameDestX="0" nameDestY="8" />

            <ArmorSection name="aft"
                  imageID="&rsZubrinArmor;" 
                  imageX="74" imageY="0" imageWidth="68" imageHeight="14"
                  destX="34" destY="103" hpX="55" hpY="105"
                  nameY="74" nameBreakWidth="360" nameDestX="12" nameDestY="0" />
         </ArmorDisplay>

         <ShieldDisplay>
            <Image imageID="&rsZubrinShields;" imageX="0" imageY="0" imageWidth="136" imageHeight="136"/>
         </ShieldDisplay>

         <ReactorDisplay>
            <Image imageID="&rsZubrinReactor;" 
                  imageX="0" imageY="0" imageWidth="256" imageHeight="60"/>

            <PowerLevelImage imageID="&rsZubrinReactor;"
                  imageX="0" imageY="60" imageWidth="202" imageHeight="14"
                  destX="54" destY="9"/>

            <FuelLevelImage imageID="&rsZubrinReactor;"
                  imageX="0" imageY="74" imageWidth="194" imageHeight="14"
                  destX="54" destY="37"/>

            <FuelLowLevelImage imageID="&rsZubrinReactor;"
                  imageX="0" imageY="88" imageWidth="194" imageHeight="14"/>

            <ReactorText x="62" y="22" width="154" height="14"/>
            <PowerLevelText x="62" y="0" width="154" height="9"/>
            <FuelLevelText x="62" y="51" width="154" height="9"/>
         </ReactorDisplay>

      </PlayerSettings>

   </ShipClass>
   
   
   <Sound UNID="&Dubstep;"  filename="Dubstep.wav"/>
   
   
   </TranscendenceExtension>
Another problem I had was that the shots fired did not appear and did not exist. Any help would be appreciated!

PS: I am an absolute newb lord at coding, I literally just started yesterday by reading a few tutorials, so please explain what you mean in your reply. Thanks!
Last edited by Tshark9999 on Thu Mar 20, 2014 11:41 pm, edited 1 time in total.
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

You're returning a non-nil value from onfireweapon. This indicates to the engine that you are handling the weapon fire manually.
Literally is the new Figuratively
Tshark9999
Miner
Miner
Posts: 34
Joined: Sat Dec 01, 2012 8:22 pm

Atarlost wrote:You're returning a non-nil value from onfireweapon. This indicates to the engine that you are handling the weapon fire manually.
Can you elaborate? I have absolutely no experience with coding.
User avatar
sun1404
Militia Captain
Militia Captain
Posts: 527
Joined: Thu Nov 03, 2011 10:32 am
Location: Heretic. (Finally!)

Just add 'Nil' at the last line of the OnFireWeapon event. The shot should come out normally. :D
Yes, look at my avatar, I have a wyvera type ship.
Tshark9999
Miner
Miner
Posts: 34
Joined: Sat Dec 01, 2012 8:22 pm

Like so?

Code: Select all

 <onFireWeapon>
            (block nil (if (eq gSource gPlayership) (sysPlaySound &Dubstep; gPlayership)))
            nil
         </onFireWeapon>
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

Tshark9999 wrote:Like so?

Code: Select all

 <onFireWeapon>
            (block nil (if (eq gSource gPlayership) (sysPlaySound &Dubstep; gPlayership)))
            nil
         </onFireWeapon>
nearly, use parenthesis :)

Code: Select all

 <onFireWeapon>
            (block Nil
              (if (eq gSource gPlayership) (sysPlaySound &Dubstep; gPlayership))
            Nil
             )
         </onFireWeapon>
Tshark9999
Miner
Miner
Posts: 34
Joined: Sat Dec 01, 2012 8:22 pm

Thanks digdug! Now I just have to stare at RPC's Media Player code until I figure it out.
Also, what do I use if I want to:

Code: Select all

<Avan> Just create a virtual station
<Avan> then each time the weapon is fired
<Avan> search the system for a station with that exact unid
<Avan> cancel any pending events
<Avan> on that station
<Avan> then do a timer event to run in 60 ticks (1 second) or so
<Avan> that event, when it fires, will just run uiStopMusic
1. Search the system for a virtual station? (I used some code from RPC's Nueros Media Player mod to create a station)

2. Cancel pending events?
Tshark9999
Miner
Miner
Posts: 34
Joined: Sat Dec 01, 2012 8:22 pm

Code: Select all

 <Events>
         <onFireWeapon>
            (block Nil
                (if (eq gSource gPlayership) (sysPlaySound &Dubstep; gPlayership))
                Nil
                )
            (block Nil    
                (if (eq station &stVirtualStation;) (staGetType &stVirtualStation;)) true
                    then
                        ((sysAddObjTimerEvent 50 &stVirtualStation; uiStopMusic)
                Nil
                )
         </onFireWeapon>
      </Events>
Does this look anywhere near correct?
Post Reply