Wed Jan 12, 2022 10:17 am

Hello folks, while testing something in Slade, i've found something interesting about RandomPick using the A_CustomBulletAttack function. Here's what i found and i wish to know if this intended or not:

I made (or rather, customizing) a 40 hitscan bullets attack, and my idea to make it more consistent while using the vanilla 5*random(1,3) damage parameter, was to use randompick with the following line of code:

Code:
`TNT1 A 0 A_FireBullets(14, 8, 40, randompick(5, 10, 10, 15), "NewBulletPuff", FBF_NORANDOM);`

But here is the quirk, randompick seems to be picking a number and applying it TO EVERY iteration of this function. So the damage ALWAYS is coming out as 200, 400 and 600. It NEVER delivers anything else. Nothing on the wiki states this behavior, so i'm a bit confused here, isn't RANDOMPick suppose to pick a random value for every iteration? And if this is the intended way, how could i fix this to make the damage a bit more consistent?

Thanks!

Wed Jan 12, 2022 10:40 am

RandomPick is just another function, and it gets resolved entirely before A_FireBullets does. That means you get one result, and it will be used for all bullets in A_FireBullets. You can get 40 bullets with random damage each by calling A_FireBullets 40 times.

Code:
`TNT1 A 0 {   for(int ii = 0; ii < 40; ii++) {      A_FireBullets(14, 8, 1, randompick(5, 10, 10, 15), "NewBulletPuff", FBF_NORANDOM);   }}`

Like sooooo or by screaming TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAetc at your code if you like that.

edit: i forgot to change the 40 to a 1 so i nearly made you shoot 40 bullets 40 times lelel
Last edited by KeksDose on Wed Jan 12, 2022 10:48 am, edited 1 time in total.

Wed Jan 12, 2022 10:43 am

`RandomPick` is only called once in this case, and sending its value to the `A_FireBullets` damage calculation. Or put another way, you can't send a function into another function, only a value. `RandomPick` is selecting a random value to pass as the damage parameter into `A_FireBullets`.

I'll try to clarify because I imagine this can be a little confusing.

What you're thinking is supposed to happen:
Code:
`randompick(5, 10, 10, 15) * 1 bulletrandompick(5, 10, 10, 15) * 1 bulletrandompick(5, 10, 10, 15) * 1 bulletrandompick(5, 10, 10, 15) * 1 bullet...`

What's actually happening:
Code:
`A_FireBullets(14, 8, 40, randompick(5, 10, 10, 15), "NewBulletPuff", FBF_NORANDOM);// becomes                          |A_FireBullets(14, 8, 40,            5             , "NewBulletPuff", FBF_NORANDOM);5 * 1 bullet5 * 1 bullet5 * 1 bullet5 * 1 bullet...`

EDIT: Keks explained it better than me I think.

Wed Jan 12, 2022 11:05 am

Yep, that's what i thought was the "quirk" here. That's interesting. Thanks Caligari (and Keks, lol)! I will try to use Keks solution up there and credit it on the code, since it is ZScript after all.

Wed Jan 12, 2022 1:15 pm

Like sooooo or by screaming TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAetc at your code if you like that.

I actually tried to do this right now, and it seems horizontal and vertical spread breaks with A_FireBullets if you do this. There is no vertical and horizontal spread. Even if i try to do something like this:

Code:
`TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_FireBullets(random(-14, 14), random(-8, 8), 1, randompick(5, 10, 10, 15), "NewBulletPuff", FBF_NORANDOM);`

Wed Jan 12, 2022 1:31 pm

That's how A_FireBullets works:
Wiki wrote:If numbullets is 1 and this is the first bullet fired in the Fire (not Hold) sequence, the bullet is fired with perfect accuracy, ignoring the specified spread

To make single bullet calls be affected by accuracy, you have to change amount of bullets from 1 to -1.

Wed Jan 12, 2022 1:34 pm

Oh yeah, there's that from the chaingun and pistol too. Oops. Thanks Jarewill!