Search In
• More options...
Find results that contain...
Find results in...
• 0

# Retaining velocity for a spawned... spawner

## Question

TNT1 A 0 A_print("Hello world! Yes, it's me. AGAIN")

I got a lootable closed chest up and working and now I'm writing the loot spawners for when it is opened by the player:

Spoiler

ACTOR OpenCrate
{
+FloorClip
Scale 0.5
States
{
Spawn:
CHOP A 1
CHOP A 1 A_SpawnItemEx("Armorloot",0,0,0,1,-2,8)
CHOP A 1 A_SpawnItemEx("Ammoloot",0,0,0,1,2,8)
CHOP A 1 A_SpawnItemEx("Healingloot",0,0,0,1,0,8)

Rest:
CHOP A 1
loop
}

Now, here's the catch: each one of the "loot" objects is a random spawner that picks between different items of the same type (of course armor, ammo, and healing items). Since this is just a prototype (there will be more spawn states with more loot combinations of three) and I want them to be randomized, I want those items to retain the velocity of the "loot" spawner actors written above, so the loot won't clip with itself and the three categories always pop up  in those 3 directions. Is it possible?

Edit: maybe a pointer with change_velocity? But how can I get the spawner point to the loot item?

Edited by Grey_Wolf

## Recommended Posts

• 0

For anyone wondering, I managed to solve it making the closed chest acquire the player as its target and then facing it, before spawning the items.

Thank you very much for the time you spent answering me.

But I'll be back. I'm always back.

• 1

there are `velx`/`vely`/`velz` decorate variables that holds current item velocity. so you can pass them to `A_SpawnItemEx()` in your loot spawner. i.e. spawn loot spawner with the required velocities, and use `A_SpawnItemEx("RealLoot",0,0,0,velx,vely,velz)` in it to spawn a real loot.

• 1

that is what i wrote (if i got you right). you spawned your spawner with some velocity, and then from inside the spawned spawner you can spawn a real loot, passing current spawner's velocity to that real loot. so the chain is:

spawn spawner -> spawner spawns loot with `vel[xyz]` and dies -> loot is flying away with spawners velocity

• 1

note that velocity is relative to the parents velocity by default. there is `SXF_ABSOLUTEVELOCITY` flag to make it absolute. that is, with your code, `vel[xyz]` is added to spawner's velocity, and it causes chaos.

also note that just using (0,0,0) as velocity will not work as expected: it actually changes velocity according to spawner's angle -- that's why you need both to specify velocity manually, and use `SXF_ABSOLUTEVELOCITY` flag.

p.s.: i forgot about that too in my example. sorry.

• 1

as far as i remember, replacing actual loot spawns in spawner, i.e.:

A_SpawnItemEx("ArmorBoots",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)

with

A_SpawnItemEx("ArmorBoots",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)

(and other instances) should do the trick.

at least this is what source code for a port tells me. hope it will work as expected. ;-)

10 minutes ago, Grey_Wolf said:

sorry if I'm bothering you for so long

no problems, we're both here to make it finally work (and to create something other people may refer to). ;-)

p.s.: please note `0` after velocities! there is `angle` argument before `flags`!

• 0

Ok it's either me that I didn't understand correctly or you that didn't look at the code I posted under spoilers.

I already set the spawner velocity, but i want the items spawned from it to retain the same velocity as the spawner.

• 0

Ok now I did understand what you meant. But something seems off:

This is my prototype for the open chest:

Spoiler

ACTOR OpenCrate
{
+FloorClip
Scale 0.5
States
{
Spawn:
CHOP A 1
CHOP A 1 A_SpawnItemEx("Armorloot",0,0,0,2,-3,10)
CHOP A 1 A_SpawnItemEx("Healloot",0,0,0,2,3,10)

Rest:
CHOP A 1
loop
}
}

And these are the first two types of spawners:

Spoiler

actor ArmorLoot : CustomInventory
{
+Inventory.QUIET
States
{

Spawn:
TNT1 A 0
TNT1 A 0 A_jump(255, "Spawn1", "Spawn2", "Spawn3", "Spawn4", "Spawn5", "Spawn6")
loop

Vanilla:
Spawn1:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("ArmorBoots",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)
TNT1 A 0 A_jump(40, "Spawn")
TNT1 A 1
Stop

Spawn2:
TNT1 A 0
TNT1 A 0 A_SpawnItemEx("ArmorHelmet",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)
TNT1 A 0 A_jump(40, "Spawn")
TNT1 A 1
Stop

Spawn3:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("ArmorUniform",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)
TNT1 A 0 A_jump(40,"Spawn")
TNT1 A 1
Stop

Spawn4:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("MediumArmor",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)
TNT1 A 0 A_jump(40, "Spawn")
TNT1 A 1
Stop

Spawn5:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx ("HeavyArmorBelt",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)
TNT1 A 0 A_jump(40, "Spawn")
TNT1 A 1
Stop

Spawn6:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx ("Armorbonus",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)
TNT1 A 0 A_jump(100, "Spawn")
TNT1 A 1
Stop

}}

actor Healloot : CustomInventory
{
+Inventory.QUIET
States
{

Spawn:
TNT1 A 0
TNT1 A 0 A_jump(255, "Spawn1", "Spawn2", "Spawn3", "Spawn4", "Spawn5", "Spawn6")
loop

Vanilla:
Spawn1:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("medikit2",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)
TNT1 A 0 A_jump(40, "Spawn")
TNT1 A 1
Stop

Spawn2:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("stimpack2",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)
TNT1 A 0 A_jump(80, "Spawn")
TNT1 A 1
Stop

Spawn3:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("Healthbackpack",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)
TNT1 A 0 A_jump(40,"Spawn")
TNT1 A 1
Stop

Spawn4:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("PackMedikit",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)
TNT1 A 0 A_jump(40, "Spawn")
TNT1 A 1
Stop

Spawn5:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx ("Healthbonus",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)
TNT1 A 0 A_jump(100, "Spawn")
TNT1 A 1
Stop

Spawn6:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx ("Bandages",0,0,0,velx,vely,velz,SXF_NOCHECKPOSITION)
TNT1 A 0 A_jump(100, "Spawn")
TNT1 A 1
Stop

}}

when i open the chest the items actually spawn, BUT:

-Sometimes they spawn with the right velocity

-Sometimes they just retain vertical velocity but stay in place.

-Sometimes they spawn behind the chest insted of in front of it (wrong xvelocity direction)

Looks like the vel(x,y,z) is randomizing velocity rather than retaining it. But the vertical velocity always look to be the same.

Could be this related to the spawner's angle?

• 0

So wait, and sorry if I'm bothering you for so long, but should I put SXF_ABSOLUTEVELOCITY on the spawner or on the spawned items? And where should I manually write velocity values? Can you give me a small practical example? Thanks again for your patience.

• 0

These are the updated crate and spawner codes:

CRATE:

Spoiler

ACTOR OpenCrate
{
+FloorClip
Scale 0.5
States
{
Spawn:
CHOP A 1
CHOP A 1 A_JumpifCloser(100,"See")
Goto see
See:
CHOP A 1 A_Facetarget
CHOP A 5
CHOP A 1 A_SpawnItemEx("Armorloot",0,0,0,2,-3,10,0)
CHOP A 1 A_SpawnItemEx("Healloot",0,0,0,2,3,10,0)
goto rest
Rest:
CHOP A 1
loop
}
}

SPAWNERS:

Spoiler

actor ArmorLoot : CustomInventory
{
States
{

Spawn:
TNT1 A 0
TNT1 A 0 A_jump(255, "Spawn1", "Spawn2", "Spawn3", "Spawn4", "Spawn5", "Spawn6")
loop

Vanilla:
Spawn1:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("ArmorBoots",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)
TNT1 A 0 A_jump(40, "Spawn")
TNT1 A 1
Wait

Spawn2:
TNT1 A 0
TNT1 A 0 A_SpawnItemEx("ArmorHelmet",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)
TNT1 A 0 A_jump(40, "Spawn")
TNT1 A 1
Wait

Spawn3:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("ArmorUniform",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)
TNT1 A 0 A_jump(40,"Spawn")
TNT1 A 1
Wait

Spawn4:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("MediumArmor",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)
TNT1 A 0 A_jump(20, "Spawn")
TNT1 A 1
Wait

Spawn5:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx ("HeavyArmorBelt",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)
TNT1 A 0 A_jump(20, "Spawn")
TNT1 A 1
Wait

Spawn6:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx ("Armorbonus",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)
TNT1 A 0 A_jump(100, "Spawn")
TNT1 A 1
Wait

}}

actor Healloot : CustomInventory
{
+Inventory.QUIET
States
{

Spawn:
TNT1 A 0
TNT1 A 0 A_jump(255, "Spawn1", "Spawn2", "Spawn3", "Spawn4", "Spawn5", "Spawn6")
loop

Vanilla:
Spawn1:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("medikit2",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)
TNT1 A 0 A_jump(40, "Spawn")
TNT1 A 1
Wait

Spawn2:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("stimpack2",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)
TNT1 A 0 A_jump(80, "Spawn")
TNT1 A 1
Wait

Spawn3:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("Healthbackpack",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)
TNT1 A 0 A_jump(20,"Spawn")
TNT1 A 1
Wait

Spawn4:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx("HealthPack2",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)
TNT1 A 0 A_jump(20, "Spawn")
TNT1 A 1
Wait

Spawn5:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx ("Healthbonus",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)
TNT1 A 0 A_jump(100, "Spawn")
TNT1 A 1
Wait

Spawn6:
TNT1 A 0
TNT1 A 1 A_SpawnItemEx ("Bandages",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION|SXF_ABSOLUTEVELOCITY)
TNT1 A 0 A_jump(100, "Spawn")
TNT1 A 1
Wait

}}

I even made the crate face the player (I think) before spawning the items, but they still spawn toward a fixed direction of the map. Here's some screenshots of what happens: no matter the starting position of the player when he opens them (I tried approaching the crates from different directions), the items always spawns "to the left" of the map.

• 0

• 0

I have to edit it a little since my mod is full of custom items, but yeah, coming up.

• 0

There you  go. use "summon closedcrate" and "summon cratekey" to test it ingame.

Again, thanks for your patience and support!

CrateDemo.zip

• 0

kick me if i know why, but your code always spawns loot flying in player's direction (in \|/ pattern), althrough it shouldn't. i checked it in gzdoom (quite old, like ~2 years old), and in my k8vavoom (after i implemented `A_CheckProximity()` decorate action ;-).

i should prolly take some sleep and try it all again. ;-)

• 0

Well considering how inexperienced I am, the chances that my code is very dirty and unrefined is very high. I also noticed a pattern, but this pattern resets and changes when I start a new game, so maybe the engine "picks" the random chances in advance and then stores them for all the incoming checks? I don't know.