Data Realms Fan Forums http://45.55.195.193/ |
|
Requesting a Lua Script http://45.55.195.193/viewtopic.php?f=75&t=31928 |
Page 1 of 2 |
Author: | YouKnowMe [ Thu Oct 11, 2012 10:25 pm ] |
Post subject: | Requesting a Lua Script |
So apparently for this mod I've been working on, It will apparently require lua because one function doesn't exist, and the other doesn't work properly and I need a work-around. Everything else for the mod is already made, It only needs this, and a bit of balancing. It seems to be a pretty straight forward but i'm clueless with lua. This lua script is for some hacky-work-arounds for sounds. Here's what it needs to do. 1 : When the gun is first starting to be fired, it needs to somehow play a sound. a particle or an emitter, whatever. It only needs to play once. 2 : When the gun finishes its spinup time / X-ms have passed, it needs to create an emitter that will loop a sound. 3 : when the gun stops firing, or runs out of ammo, it needs to remove the emitter, abruptly silencing the looped sound, regardless of the length of the .wav 4 : When 3 happens it also needs to somehow trigger yet another 1-off sound that doesn't loop. I figured doing it with reload or empty-click would work, except the reload doesn't always happen automatically, and the empty click can spam. furthermore if both trigger the sound, it can trigger different sounds, which I don't want. As you can tell, sound is pretty important for this thing. Thank you to whoever can do this for me. |
Author: | Asklar [ Fri Oct 12, 2012 12:13 am ] |
Post subject: | Re: Requesting a Lua Script |
Code: function Create(self) self.ClickSound = 0 self.StopFiring = 1 self.CurrRoundsOnMag = self.Magazine.RoundCount end function Update(self) if self.CurrRoundsOnMag < self.Magazine.RoundCount then self.FiringSound = CreateAEmitter("Emitter Name",YourFaction.rte) self.FiringSound.Pos = self.MuzzlePos MovableMan:AddParticle(self.FiringSound) end self.CurrRoundsOnMag = self.Magazine.RoundCount if self:IsActive() and self.ClickSound == 0 then self.ClickSoundEmitter = CreateAEmitter("Emitter Name",YourFaction.rte) self.ClickSoundEmitter.Pos = self.MuzzlePos MovableMan:AddParticle(self.ClickSoundEmitter) self.ClickSound = 1 self.StopFiring = 0 end if not self:IsActive() and self.StopFiring == 0 then self.ClickSound = 0 self.StopFiring = 1 self.EndSound = CreateAEmitter("Emitter Name"),YourFaction.rte) self.EndSound.Pos = self.MuzzlePos MovableMan:AddParticle(self.EndSound) end end It has three chunks, the first one checks if the magazine is losing rounds (the gun is firing and not just active), and if it does, it creates an emitter which should play the sound (Note here, whenever the gun loses fires one round it will create the emitter, though I think there can be other ways to do it). The second one creates a single emitter when the gun is activated and the third one creates a single emitter when it stops firing. This is untested and I doubt that it will work properly at all, and maybe someone will come up with something better. |
Author: | YouKnowMe [ Fri Oct 12, 2012 6:42 am ] |
Post subject: | Re: Requesting a Lua Script |
Asklar wrote: Code: function Create(self) self.ClickSound = 0 self.StopFiring = 1 self.CurrRoundsOnMag = self.Magazine.RoundCount end function Update(self) if self.CurrRoundsOnMag < self.Magazine.RoundCount then self.FiringSound = CreateAEmitter("Emitter Name",YourFaction.rte) self.FiringSound.Pos = self.MuzzlePos MovableMan:AddParticle(self.FiringSound) end self.CurrRoundsOnMag = self.Magazine.RoundCount if self:IsActive() and self.ClickSound == 0 then self.ClickSoundEmitter = CreateAEmitter("Emitter Name",YourFaction.rte) self.ClickSoundEmitter.Pos = self.MuzzlePos MovableMan:AddParticle(self.ClickSoundEmitter) self.ClickSound = 1 self.StopFiring = 0 end if not self:IsActive() and self.StopFiring == 0 then self.ClickSound = 0 self.StopFiring = 1 self.EndSound = CreateAEmitter("Emitter Name"),YourFaction.rte) self.EndSound.Pos = self.MuzzlePos MovableMan:AddParticle(self.EndSound) end end It has three chunks, the first one checks if the magazine is losing rounds (the gun is firing and not just active), and if it does, it creates an emitter which should play the sound (Note here, whenever the gun loses fires one round it will create the emitter, though I think there can be other ways to do it). The second one creates a single emitter when the gun is activated and the third one creates a single emitter when it stops firing. This is untested and I doubt that it will work properly at all, and maybe someone will come up with something better. I'll test it in a bit. it sounds like this will *partially* work. The problem is I'm already using the guns fire sound to play a sound per shot. I'm trying to get an additional sound to constantly loop in the background while the gun is firing, that isn't the spin-up sound, because it's buggy, it loops forever, it stretches, and it plays the sound when its spinning up but NOT firing yet, which I had a different one-off sound for. From what you say, steps 2 and 3 will do what I need it to do, but step 1 will cause the loop to also loop overtop of its self, which will create a mountain of noise. considering they range between 1.5 and 6 seconds, and would be triggering every 1.5 seconds. It's like I said though, if this is right, I should only need one additional thing, and if I can figure it out, creating 2 different emitters when it becomes active should fix the whole problem, 1 emitter plays the one-off sound, the other emitter plays the looping sound... It just means the looping sounds will overlap with the charge-up sound, which is actually fine considering what they are. If I don't get it working I'll post again. |
Author: | YouKnowMe [ Fri Oct 12, 2012 11:55 am ] |
Post subject: | Re: Requesting a Lua Script |
Well That script doesn't do what I need to do the way I need it to, so I tried zombifying the thing. I came up with this Code: function Create(self) end function Update(self) if self:IsActive() then self.sometimer = Timer() self.Charge = CreateAEmitter("shiggy",TradeStar.rte) self.Charge.Pos = self.MuzzlePos MovableMan:AddParticle(self.charge) if self.sometimer:IsPastSimMS(3000) self.spinning = CreateAEmitter("diggy",TradeStar.rte) self.spinning.pos = self.MuzzlePos MovableMan:AddParticle(self.spinning) end if not self:IsActive() then if not self.sometimer = 0 self.sometimer = 0 end end end end So when its active (including spinning up) it should create an emitter that plays a sound and start a timer, Then when the gun is firing and the timer is past a set time, it should create another emitter that plays a sound. Then when the gun is not active, and the timer is not 0, it sets the thing to 0. Sadly, this code does ABSOLUTELY NOTHING. IT DOESN'T EVEN CRASH! It doesn't give me any errors or anything. NOTHING... HAPPENS... The gun still shoots, so it doesn't break anything either. Oh yeah, and one of the emitters needs to be able to check if the gun is active, and if it ISN'T active then it needs to gib itself. yeah. I'm bad at lua... I think... Did I have to specifically define ELSE? can self.variable = Timer() even be reset? God damn stupid lousy nested logic statements. if this and this then this else if this then this else else die. |
Author: | helifreak [ Fri Oct 12, 2012 2:07 pm ] |
Post subject: | Re: Requesting a Lua Script |
YouKnowMe wrote: Well That script doesn't do what I need to do the way I need it to, so I tried zombifying the thing. I came up with this Code: function Create(self) end function Update(self) if self:IsActive() then self.sometimer = Timer() self.Charge = CreateAEmitter("shiggy",TradeStar.rte) self.Charge.Pos = self.MuzzlePos MovableMan:AddParticle(self.charge) if self.sometimer:IsPastSimMS(3000) self.spinning = CreateAEmitter("diggy",TradeStar.rte) self.spinning.pos = self.MuzzlePos MovableMan:AddParticle(self.spinning) end if not self:IsActive() then if not self.sometimer = 0 self.sometimer = 0 end end end end Doesn't that code recreate the timer every update, just after checking if the gun is active? (Might not be it, I haven't learnt Lua yet but it seemed logical.) |
Author: | YouKnowMe [ Fri Oct 12, 2012 5:44 pm ] |
Post subject: | Re: Requesting a Lua Script |
Oh damn, you're right, that might be happening. uh..... maybe... If self:IsActive() and not self.sometimer:IsPastSimMS(0) then self.sometimer = Timer() stupid lousy god damn code. I totally didn't account for it updating that every step. |
Author: | Asklar [ Fri Oct 12, 2012 6:52 pm ] |
Post subject: | Re: Requesting a Lua Script |
I still can't understand what was the problem you had with my script, and what do you want to do. You want to play the looping sound after the gun charges up? Or play it anytime the gun is active? |
Author: | YouKnowMe [ Fri Oct 12, 2012 7:41 pm ] |
Post subject: | Re: Requesting a Lua Script |
Asklar wrote: I still can't understand what was the problem you had with my script, and what do you want to do. You want to play the looping sound after the gun charges up? Or play it anytime the gun is active? I have 4 sounds Sound 1 is a spin-up sound. It plays ONE time, not a loop, when you are spinning up the barrel. This sound is the length of the spin up time. (consists of 8, 3000 ms .wav files) Sound 2 is a 'the barrel is spinning' sound. It does not start until after the spin-up time is finished It is a loop. Technically I need to fix this because right now the way the game handles loops, if you make a sound with multiple files, when one file finishes, it picks another at random from the list to continue, rather than continuing to loop a fixed sound. It'd be fine except some of the loops are 1500 ms, and others are 3000, and 6000 ms, which can cause the loops to run-over. there's another problem here that i'll mention later. (4 .wav files, of 1500, 3000, and 6000 ms durrations) Sound 3 is a firing sound. These are played each time a bullet is fired. This is the only sound that works perfectly as is. (23 separate 1500 ms .wavs) Sound 4 was a 'stop firing sound'. Technically I'd need a spin-down time, and the sound would play once AFTER it finished spinning down. Instead I'm just making the re-load time 1500 MS (what the spin-down time would have been), and making the 'reload finished' sound into this sound... This is mostly working. (5 .wav files) Sounds 1 and 2 do not work with the normal spin-up sound options because of the following reasons. --No matter what, the sound loops. --there are bugs that cause the sounds to loop forever --if you stop firing, the sound continues either until the end of the loop, playing the ENTIRE file, or just loops forever --spin up starts the sound pitched/stretched and speeds up until it's in normal time. The sounds i've made don't work with this, and go horribly out of sync. Timing is very important because I made all my sounds as a set, and there's a reason for that. This gun is a BASS CANNON. The linked audio has the sounds arranged together as they should be in game. spin-up, firing, and re-loading, repeated for 4 full clips worth, followed by a spin-up & reload, and then all the remaining samples, plus some slightly more arranged samples. Everything else except for a sprite that I'm working on updating, and the lua necesary to fix this, is finished. the gun works fine except for the sound, and the sprite being incomplete. What I need lua for is. 1 A script for the gun that creates an emitter when you first pull the trigger, that plays a sound. the emitter expires (and stops the sound) after 3000 ms, (all of which is in that emitter, except for the emitter's creation) --Then after a 3000 ms timer that starts when you first pull the trigger, it then creates another emitter that has to loop sound 2 until the emitter is destroyed. 2 a lua script for the 2nd emitter that checks the parent (the gun that created it) if it's active. When the gun stops being active, this emitter is erased (stopping the looped sound abruptly, when the gun stops shooting) If anything else I need to figure out a way to force the game to run at 1.0 timescale even if the physics go buggy, just to make sure the sounds are syncing up properly, but that can come after the sounds are actually playing at all. |
Author: | Technomancer [ Fri Oct 12, 2012 7:51 pm ] |
Post subject: | Re: Requesting a Lua Script |
Code: function Create(self) self.fireState = 0; self.warmTimer = Timer(); self.chargeSound = CreateAEmitter(">>ChargeEmitter<<",Your.rte); --Emitter should play the 3 second charge sound as the EmissionSound, be non-looping, and have a lifetime of -1. We will delete it later. self.loopSound = CreateAEmitter(">>FiringLoopEmitter<<",Your.rte); --Your looping while firing sound, EmissionSound, looping, lifetime -1. self.stopSound = CreateAEmitter(">>EndEmitter<<,Your.rte); --For this one you can set your sound to the BurstSound. Make the lifetime about as long as the stop sound, in ms. end function Update(self) if self:IsActivated() and self.fireState == 0 and self.Magazine ~= nil then self.fireState = 1; self.chargeSound.Pos = self.Pos; MovableMan:AddParticle(self.chargeSound); self.warmTimer:Reset(); self:Deactivate(); --These stop it from firing until the charging is complete. As such, you don't need ActivationDelay in the ini. end if self.fireState == 1 then if self:IsActivated() then if self.warmTimer:IsPastSimMS(3000) then --replace 3000 with the length of your chageup sound. self.chargeSound.ToDelete = true; self.fireState = 2; self.loopSound.Pos = self.Pos; MovableMan:AddParticle(self.loopSound); self:Deactivate(); else self:Deactivate(); end end else self.chargeSound.ToDelete = true; self.fireState = 0; self:Deactivate(); end end if self.fireState == 2 then -- This is where your gun will be firing using the bullets as set up in your ini. If you wanted to do the bullets in lua, this section is where you'd put them. In that case add "self:Deactivate()"s, or you could have one self:Deactivate at the end of the Update function, outside of an if statement. self.loopSound.Pos = self.Pos; if not self.IsActivated() or self.Magazine == nil or self.RoundCount <= 0 then self.loopSound.toDelete = true; self.fireState = 0; self.stopSound.Pos = self.Pos; MovableMan:AddParticle(self.stopSound); end end end Another untested bit of code, but might be worth a try? I didn't realise you were doing the "spindown" using the reload sound, so you can probably drop the stopSound bits, and just make it reload? The main problem with that way would be if you don't expend the full clip, it won't play the stop sound. Or you won't be able to have a partial clip at rest, it'll be all or nothing. If this mainly works except for the end bit, let me know and I might be able to rejig it a bit for you. EDIT: though looking at your files this'll need a fair bit more work for all the various sounds it could be. Let me know if it's doing ANYTHING, and we'll see where it goes from there. |
Author: | YouKnowMe [ Fri Oct 12, 2012 8:41 pm ] |
Post subject: | Re: Requesting a Lua Script |
Technomancer wrote: Another untested bit of code, but might be worth a try? I didn't realise you were doing the "spindown" using the reload sound, so you can probably drop the stopSound bits, and just make it reload? The main problem with that way would be if you don't expend the full clip, it won't play the stop sound. Or you won't be able to have a partial clip at rest, it'll be all or nothing. If this mainly works except for the end bit, let me know and I might be able to rejig it a bit for you. EDIT: though looking at your files this'll need a fair bit more work for all the various sounds it could be. Let me know if it's doing ANYTHING, and we'll see where it goes from there. Well... No error messages, It didn't crash. Sometimes the gun fires right away when I pull the trigger, others it has to wait up to 3 seconds (because self.warmtimer = timer(); is in function create(self) ) I have no idea how that would be fixed. I also don't know why it doesn't seem to be creating my emitters. Either it's not creating my emitters, or something os so horribly wrong with my emitters that they're gib-ing the instant they spawn. I don't know, making my sound emitters i just copied a wound, replaced the emitted particle, lifetime, sound, and sprite. Since then I've changed the mass in case that was it. I think using lua to manually control if the gun is firing is probably a bad idea, because the spin-up FUNCTION is fine, just not the spin-up sound. I've currently got no ini spinup sound defined (removed that refference) so it won't mess anything up. I only mention this because it's fairly random when it can or can't fire, because of when the timer seems to start. maybe just have a timer with an MS duration that's the same as the spinup time, rather than forcibly changing the spin-up time. It seems to needlessly complicate things and add glitches. Not that it matters at this point though because it seems to either never create my emitters, or my emitters don't work... I've never been that good with emitters either... I tend to just copy emitters that already do what I want them to and change some values. Also I just got an idea for a totally different sprite that would look cooler than what i've got... I'm gonna do that while I wait for an answer. |
Author: | Technomancer [ Fri Oct 12, 2012 9:15 pm ] |
Post subject: | Re: Requesting a Lua Script |
For sound Emitters I have this template in my Effects.ini file: And then I do CopyOfs for each sound I need, eg: Code: AddEffect = AEmitter CopyOf = AudioDummy PresetName = WailAim BurstSound = Sound AddSample = ContentFile FilePath = Venerari.rte/Devices/Weapons/Special/Wail/WailAim.wav That usually works for me as far as getting all my sounds working. Then you call the emitter in the code eg "self.sound = CreateAEmitter("WailAim","Venerari.rte");" I've also adjusted the script a bit, fixed an error or two I made. It's still controlling whether or not it can fire via lua, but hopefully better such that it should ONLY fire when it's charged and activated. If it's not I've done something wrong and let me know again. If you're really opposed to deactivating it, you can just remove the "else" and "self:Deactivate();" lines at the end, and it should work, provided the "IsPastSimMS" is set to the chargeup sound time. Since the timer is reset whenever you start the firing chain, you shouldn't be getting time inconsistency for firing. |
Author: | YouKnowMe [ Fri Oct 12, 2012 9:39 pm ] |
Post subject: | Re: Requesting a Lua Script |
Technomancer wrote: For sound Emitters I have this template in my Effects.ini file: And then I do CopyOfs for each sound I need, eg: Code: AddEffect = AEmitter CopyOf = AudioDummy PresetName = WailAim BurstSound = Sound AddSample = ContentFile FilePath = Venerari.rte/Devices/Weapons/Special/Wail/WailAim.wav That usually works for me as far as getting all my sounds working. Then you call the emitter in the code eg "self.sound = CreateAEmitter("WailAim","Venerari.rte");" I've also adjusted the script a bit, fixed an error or two I made. It's still controlling whether or not it can fire via lua, but hopefully better such that it should ONLY fire when it's charged and activated. If it's not I've done something wrong and let me know again. If you're really opposed to deactivating it, you can just remove the "else" and "self:Deactivate();" lines at the end, and it should work, provided the "IsPastSimMS" is set to the chargeup sound time. Since the timer is reset whenever you start the firing chain, you shouldn't be getting time inconsistency for firing. Code: Buyable = 1 ScriptPath = TradeStar.rte/October 2012/Technomancer.lua SpriteFile = ContentFile I'm using the emitters you gave me, just to be sure. I updated the sprite to my own null image that I've been using. Named the instances and set the sounds. It should be working I made technomancer.lua, I copy/pasted that code. I fixed the wierd bug where instead of tabs it's using 4 spaces (lol forums) using find/replace. I updated the instance names and .rte names, and changed nothing else. I placed the lua here in my held device Code: Buyable = 1 ScriptPath = TradeStar.rte/October 2012/Technomancer.lua SpriteFile = ContentFile I launch the game. I get the gun... Still doesn't play any of the sounds in the emitters, which means the lua isn't making the emitters. The gun still shoots though. also, i'm dumb, the seemingly random delay was because hurp-a-durp ROF 40 and i'm a dumb for forgetting. This means the lua isn't even affecting the gun in any way shape or form, and I can't tell why. I made sure to put ScriptPath = path exactly where it was in other devices (including dummy destroyer). This should work. It doesn't work. It doesn't even error or crash. It's simply not running the lua at all. |
Author: | Arcalane [ Sat Oct 13, 2012 7:53 am ] |
Post subject: | Re: Requesting a Lua Script |
This might be an occasion for a really primitive debugging trick -- though inefficient, it can be a great help for progress-checking the status of a script; just throw in a bunch of print calls at various places in the script. For example; print("Spawning spinup sound emitter..."); That way you can check the console and see exactly where the script is grinding to a halt, because any following prints won't... well, print. You can also use this to print the results of a check, for instance, if 'self.ShotsFired' should return 1, then you could check like so; print("Shots Fired: "..self.ShotsFired); It's slow and more importantly laggy as hell if it runs during Update(self) because in most cases it spams up the Lua console, but I found it quite helpful in the past. Just printing a couple of variables can be of great help too; if they return the desired values then you know everything is fine. If they don't then you know it's not. It should at least give you a good idea of where to start checking. |
Author: | YouKnowMe [ Sat Oct 13, 2012 9:41 am ] |
Post subject: | Re: Requesting a Lua Script |
Arcalane wrote: This might be an occasion for a really primitive debugging trick -- though inefficient, it can be a great help for progress-checking the status of a script; just throw in a bunch of print calls at various places in the script. For example; print("Spawning spinup sound emitter..."); That way you can check the console and see exactly where the script is grinding to a halt, because any following prints won't... well, print. You can also use this to print the results of a check, for instance, if 'self.ShotsFired' should return 1, then you could check like so; print("Shots Fired: "..self.ShotsFired); It's slow and more importantly laggy as hell if it runs during Update(self) because in most cases it spams up the Lua console, but I found it quite helpful in the past. Just printing a couple of variables can be of great help too; if they return the desired values then you know everything is fine. If they don't then you know it's not. It should at least give you a good idea of where to start checking. I think i'm gonna add that it should just be print("message") or print("message about variable"..variable) I can put that like all over the lua that I have. since it's crashing when it passes the spin-up time and tries to shoot, I could find out exactly where. |
Author: | YouKnowMe [ Sat Oct 13, 2012 12:04 pm ] |
Post subject: | Re: Requesting a Lua Script |
okay. Here's the script... I added print messages so I could keep track of everything since it's not automatically making a log of what happens. Here's the script now. I gave an actor the gun, put them in the tutorial mission inside the bunker where they can see the target dummy, toggled to another actor and opened the console. It got to line line 47 and it the actor automatically stopped trying to fire. i switched back to that actor after closing the consol, and the instant i touched the trigger the game crashed. no errors, no abort screen, it was just gone. Since it's not giving me an abort screen, and it's stopped giving me logs, I don't know how to check how far it gets in that frame. |
Page 1 of 2 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |