Randomize weapon firing states/muzzle flashes

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Randomize weapon firing states/muzzle flashes

Postby superscrungus » Mon Mar 25, 2019 9:41 pm

What it says on the tin. Is there a way to code a weapon actor so that it plays randomly-selected animations during it's firing state? Or at least achieve similar randomization with muzzle flash sprites?
User avatar
superscrungus
 
Joined: 28 Sep 2018
Discord: superscrungus#4557

Re: Randomize weapon firing states/muzzle flashes

Postby Cherno » Mon Mar 25, 2019 10:08 pm

I guess it could be done via GetSpriteIndex, like this:

Code: Select allExpand view
Fire:
MGUN A 2
{
     if(random(0,1) == 0)
     {
           sprite = GetSpriteIndex("MGUNB");
     }
}
//...

Dummy://always pre-load all possible sprites that could get used with GetSpriteIndex in a dummy state, otherwise bad things will happen!
MGUN A 0;
MGUN B 0;
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: Randomize weapon firing states/muzzle flashes

Postby Dr. Van Nostrand » Mon Oct 12, 2020 7:23 pm

Did anyone have any success with this?

I've been trying to randomize sprites in my weapon's fire state but have so far gotten nowhere. After hours of tinkering I ended up with this:

Code: Select allExpand view
Fire:
TNT1 A 1 BRIGHT
            {
               invoker.sprite = GetSpriteIndex("MFLS");
               invoker.frame = random(0, 2);
// more firing state code, etc.
            }


This doesn't work though, nothing gets displayed for this frame. Ideally the result would display one of these at random:

MFLS A 1
MFLS B 1
MFLS C 1

The sprites are all valid if I define them directly, no issue there. I'm running out of ideas on what to try next.

Does anyone know how to get this done?
User avatar
Dr. Van Nostrand
 
Joined: 10 May 2015
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Randomize weapon firing states/muzzle flashes

Postby Player701 » Mon Oct 12, 2020 11:36 pm

Code: Select allExpand view
let psp = player.GetPSprite(PSP_WEAPON);
psp.Sprite = GetSpriteIndex("MFLS");
psp.Frame = random(0, 2);
User avatar
Player701
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Randomize weapon firing states/muzzle flashes

Postby Dr. Van Nostrand » Tue Oct 13, 2020 6:04 am

Thank you, that worked!

I think I understand where I was going wrong now... For anyone googling this issue in the future, have a look at the available internal overlay layers here:

https://zdoom.org/wiki/A_ClearOverlays
User avatar
Dr. Van Nostrand
 
Joined: 10 May 2015
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests