Stealth's Music Player: Version 0.1d - UPDATE 12/24

Stealth's Music Player: Version 0.1d - UPDATE 12/24

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Stealth's Music Player: Version 0.1d - UPDATE 12/24

Post by Stealth870 »

LATEST VERSION HERE.

Hurray! My first real widget! So, I finally figured out all the basic stuff. Thanks Lurker for the help on the timer stuff.

This widget contains all the TA songs in OGG format. I guess if you already have them in MP3, you can just convert so I'll attach the widget by itself if you want it like that.

It's very messy, I'm quite the Lua noob, so it might not be as efficient as it should be, buuut...it does:
Randomly play tracks
Dynamically activate battle music with fading
Kill babies


Here ya go: http://www.just-deserts.com/misc_files/ ... h_music.7z

I only have 2 kinks to be fixed. 1 is a nil error, that pops its head now and again. I can't really figure out why, but restarting the widget helps if you see it. It works for the most part. :P The second is I need to get the battle music to play a little better.

Right now it will activate battle music nicely with a fadeout, and then a timer launches. It will take approximately 1 minute for the widget to say "Ok, we're not in battle mode". However, if a unit is attacked right afterwards, it will activate battle mode again. This means, sometimes during a battle, the music will fade and play another battle song. It's really not that annoying, as 1 minute is good for battle music I assume, but I definitely want to get that working properly. :mrgreen:

Anyway, hope you guys like it. It's under the CC License, so do what you want with it, just throw my name somewhere in there. :-)
Attachments
snd_musicplayer.lua
Widget by itself.
(4.95 KiB) Downloaded 135 times
Last edited by Stealth870 on 24 Dec 2008, 15:48, edited 2 times in total.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Stealth's Music Player: Version 0.1

Post by imbaczek »

what does your widget consider as "battle"? any battle or only on-screen battle?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Stealth's Music Player: Version 0.1

Post by Argh »

any battle or only on-screen battle?
Any damage, to any Unit anywhere, on any Team, as currently written. I'd strongly suggest filtering it by Team.
User avatar
REVENGE
Posts: 2382
Joined: 24 Aug 2006, 06:13

Re: Stealth's Music Player: Version 0.1

Post by REVENGE »

Hey, mind if I go through and make revisions if I have the time later this week?
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Stealth's Music Player: Version 0.1

Post by Stealth870 »

Oooh snap. Good point Argh. I didn't realize that UnitDamaged included everyone's. O_O So I guess that will need fixing as well. :lol:

Go for it REVENGE, it is CC. I'm just throwing it out there since everyone wants "something" rather than nothing I guess. :mrgreen:
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Stealth's Music Player: Version 0.1

Post by Argh »

Meh, it's no problem, just a quickie fix anyhow. IIRC, UnitDamaged returns the unitID, unitDefID, and Team as the first three parameters anyhow.

Just check team vs. Team, and voila, problem's fixed.
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Stealth's Music Player: Version 0.1

Post by Stealth870 »

Cool. I'm looking through the Lua doc but can't find the section where the widget:blabla stuff is. Is it even documented or am I suppose to look in the LuaUI folder for that info?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Stealth's Music Player: Version 0.1

Post by Argh »

The default return values of the various callins aren't documented at all, basically, so it's either check out stuff in CA (where trepan helped out jK a lot, and jK wrote some of the source, so they both knew what did what) or just puzzle it out, by testing vs callin(a,b,c,d)--> Spring.Echo(a,b,c,d), see if it returns nil or not.

A lot of callins return (u, ud, team) as the first three parameters, but there are numerous exceptions, such as GameFrame.

I should probably document this in the Wiki, it annoys me that such a basic and important piece of information isn't available.
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Stealth's Music Player: Version 0.1

Post by Stealth870 »

It would be most appreciated. :mrgreen:
Super Mario
Posts: 823
Joined: 21 Oct 2008, 02:54

Re: Stealth's Music Player: Version 0.1

Post by Super Mario »

It would be nice if we can add our music to it manually. :-)
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Stealth's Music Player: Version 0.1

Post by Stealth870 »

You could always just change around the values in the tables (2 tables, one for battle songs, and another for construction songs). Problem is, I use the length of each specific song for specific calculations, and seeing as how there is no function to get that easily (which would also simplify custom music) it will probably be left out for a bit. ;P I've requested the function, hopefully next version will have it. :)
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Stealth's Music Player: Version 0.1

Post by Argh »

I'm in the process of documenting the callins right now, I'll put up on the Wiki when it's done, so that it can get looked over and any holes can get fixed (I'm sure there will be mistakes, I'm just going through what I can find anything for).

Should make this a bit easier in the future, eh?
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Stealth's Music Player: Version 0.1

Post by lurker »

On that note, if you just want a list of parameters without additional helpful information, open LuaUI/widgets.lua and skip most of the way down the file.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Stealth's Music Player: Version 0.1

Post by Argh »

The very basic version is up now. Still cleaning it up.
Warlord Zsinj
Imperial Winter Developer
Posts: 3742
Joined: 24 Aug 2004, 08:59

Re: Stealth's Music Player: Version 0.1

Post by Warlord Zsinj »

I don't understand the complexity involved here at all, so apologies if I'm requesting the impossible/unfeasible, but would it be possible to adjust the algorithm as follows:

(Excuse my shitty pseudocode, I'm no coder)

if nothing is happening play [building music]

if anything takes damage anywhere play [tension music]

if damage is being dealt at a rate of (0.1*[total HP on the map])/60 seconds then play battle/victory/defeat music.

Decide which to play of battle/victory/defeat music based on:

if damage is being dealt in a minute is at a rate of:
(total damage dealt vs total damage being dealt to your troops ) <0.25 then play victory music

if damage is being dealt in a minute is at a rate of:
(total damage dealt vs total damage being dealt to your troops ) >0.75 then play defeat music

else play battle music

does that make sense?

(the actual detail values can be adjusted of course, but hopefully you get the idea)
Last edited by Warlord Zsinj on 05 Nov 2008, 03:23, edited 2 times in total.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Stealth's Music Player: Version 0.1

Post by lurker »

Don't forget aftermath music :twisted:
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Stealth's Music Player: Version 0.1

Post by Argh »

I think that doing what you want would be too expensive CPU-side to bother with, WZ. Getting total HP, etc. would involve giant table searches, which is bad news in terms of performance.

Better to just trigger states based on simpler stuff- the number of unit deaths over X seconds, etc.

Oh, and the call-ins are documented at a basic level and sorted out, although I need to get back to learning about FBO stuff now so I can't be arsed to write example code. See the Wiki.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Stealth's Music Player: Version 0.1

Post by lurker »

It wouldn't be expensive nor require any table searches the way I would design it...

And an hp scan every couple seconds would be cheap if you did feel like table searching.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Stealth's Music Player: Version 0.1

Post by Argh »

Eh? You read what he wants, in terms of logic?
if damage is being dealt at a rate of (0.1*[total HP on the map])/60 seconds then play battle/victory/defeat music.
if damage is being dealt in a minute is at a rate of:
(total damage dealt vs total damage being dealt to your troops ) <0.25 then play victory music
If you have a way to do that without table searches, great, but I can't think of a way to do that properly without iterating through the UnitIDs, myself.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Stealth's Music Player: Version 0.1

Post by aegis »

the dps widget isn't extremely cpu intensive...
Post Reply

Return to “Lua Scripts”