Data Realms Fan Forums
http://forums.datarealms.com/

Play a fixed sound when weapon stops firing.
http://forums.datarealms.com/viewtopic.php?f=73&t=46060
Page 1 of 1

Author:  Hoovytaurus [ Fri Jun 10, 2016 3:56 pm ]
Post subject:  Play a fixed sound when weapon stops firing.

Simple question. Spindown acts all weird if I try to use it. I want this sound to play whenever the gun stops firing. If possible, I'd like it to have different sound files depending on how long the trigger was held.

This is an automatic gun, by the way. I have very little idea how to use Lua. Which is why I'm here.

Cheers.

EDIT: I realized I worded this post kind of a bit meanly. I'm gonna apologize for that and clarify - this isn't a cleverly disguised request/order, this is just a cry for advice on where to begin. No lua code I have lying about handles sounds before/after firing (except 4zk's charge-up code but I wasn't able to reverse engineer that one), and I'm really clueless as to what to actually even try to do.

Author:  CaveCricket48 [ Sun Jun 12, 2016 4:35 am ]
Post subject:  Re: Play a fixed sound when weapon stops firing.

Currently, the most practical way to use Lua to play a sound is to spawn an AEmitter at the location where you want the sound to be played, and the AEmitter's BurstSound is the sound (for when you want single instances of sounds to be played, could using EmissionSound for looping sounds).

Example of code for that is the first chunk in Base.rte/Devices/Explosives/Remote Explosives.ini

To play different sounds based on how long you've held the trigger, could use a timer to keep track of how long the trigger was held and spawn different sounds based on that.

http://wiki.datarealms.com/LuaDocs/HeldDevice

I believe IsActivated() is used to check if a gun is being fired. You can also look in Dummy.rte/Devices/Weapons/Annihiliator.lua for an example of checking when the gun is being fired, and playing an effect based on how long the trigger was held.

Author:  Hoovytaurus [ Mon Jun 13, 2016 8:43 pm ]
Post subject:  Re: Play a fixed sound when weapon stops firing.

IsActivated checks for whether the gun is being fired or not, but I don't think it checks for whether the gun just stopped firing or not. What I need is like a DoneReloading, but for firing. Is that a thing, and if not, how do I jury rig one?

Author:  p3lb0x [ Tue Jun 28, 2016 12:58 pm ]
Post subject:  Re: Play a fixed sound when weapon stops firing.

Something like this pseudo C code might work. Although I am sure you'd need some code to check whether it is time to fire or not.
Code:
firing = isActivated();

if(firing && !firingLastUpdate)
{
   playFirstFireSound();
}
else if(firing && firingLastUpdate)
{
   playContinuousFireSound();
}
else if(!firing && firingLastUpdate)
{
   playEndFireSound();
}
firingLastUpdate = firing;


edit: Sorry for not writing Lua. I haven't modded CC in years

Author:  Visage [ Sun Jan 22, 2017 12:03 pm ]
Post subject:  Re: Play a fixed sound when weapon stops firing.

In CC's Lua, you can make persistent variables using the syntax self.<var>

From there, it's pretty trivial to make a boolean that is set to true whenever you're firing. Then if that's true and you're not firing, then you just finished shooting.

Author:  CaveCricket48 [ Sun Jan 22, 2017 5:01 pm ]
Post subject:  Re: Play a fixed sound when weapon stops firing.

Visage wrote:
In CC's Lua, you can make persistent variables using the syntax self.<var>

From there, it's pretty trivial to make a boolean that is set to true whenever you're firing. Then if that's true and you're not firing, then you just finished shooting.

A bit more detail on what Visage is trying to say, something like

Code:
function Create(self)
    self.doneFiring = false;
end
function Update(self)

    if self:IsActivated() then
        self.doneFiring = false;
    else
        if !self.doneFiring then

            ....
            do stuff here
            ....

            self.doneFiring = true;
        end
    end

end

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/