View unanswered posts | View active topics It is currently Wed Dec 25, 2024 5:49 pm



Reply to topic  [ 6 posts ] 
 Play a fixed sound when weapon stops firing. 
Author Message

Joined: Mon Dec 21, 2015 9:30 am
Posts: 89
Reply with quote
Post 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.


Fri Jun 10, 2016 3:56 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Sun Jun 12, 2016 4:35 am
Profile

Joined: Mon Dec 21, 2015 9:30 am
Posts: 89
Reply with quote
Post 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?


Mon Jun 13, 2016 8:43 pm
Profile
Forum Moderator
User avatar

Joined: Fri Feb 02, 2007 3:53 pm
Posts: 1896
Location: in my little gay bunker
Reply with quote
Post 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


Tue Jun 28, 2016 12:58 pm
Profile

Joined: Fri Jul 06, 2012 7:20 am
Posts: 44
Reply with quote
Post 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.


Sun Jan 22, 2017 12:03 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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


Sun Jan 22, 2017 5:01 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.094s | 13 Queries | GZIP : Off ]