Randomize weapon firing states/muzzle flashes
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.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
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.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
- superscrungus
- Posts: 10
- Joined: Thu Sep 27, 2018 9:30 pm
Randomize weapon firing states/muzzle flashes
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?
Re: Randomize weapon firing states/muzzle flashes
I guess it could be done via GetSpriteIndex, like this:
Code: Select all
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;
- Dr. Van Nostrand
- Posts: 11
- Joined: Sun May 10, 2015 4:33 pm
- Graphics Processor: nVidia with Vulkan support
Re: Randomize weapon firing states/muzzle flashes
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:
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?
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 all
Fire:
TNT1 A 1 BRIGHT
{
invoker.sprite = GetSpriteIndex("MFLS");
invoker.frame = random(0, 2);
// more firing state code, etc.
}
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?
- Player701
-
- Posts: 1708
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
- Contact:
Re: Randomize weapon firing states/muzzle flashes
Code: Select all
let psp = player.GetPSprite(PSP_WEAPON);
psp.Sprite = GetSpriteIndex("MFLS");
psp.Frame = random(0, 2);
- Dr. Van Nostrand
- Posts: 11
- Joined: Sun May 10, 2015 4:33 pm
- Graphics Processor: nVidia with Vulkan support
Re: Randomize weapon firing states/muzzle flashes
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
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