how to spawn on a fixed coordinate with A_SpawnItemEx? (SOLVED)

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
SwordGrunt
Forum Regular
Posts: 377
Joined: Thu Jun 07, 2012 8:43 pm

how to spawn on a fixed coordinate with A_SpawnItemEx? (SOLVED)

#1

Post by SwordGrunt » Thu Apr 03, 2014 1:45 pm

title.

with sxf_absoluteposition set, here's what I tried on the x/y/z offsets:

- using the absolute coordinates: object spawns right on me

- subtracting the coordinates from my own: object spawns way out of the map (I was so sure this would work but it didn't)

- subtracting my coordinates from the spawn coordinates: object spawns way out of the map, on a different direction than the above

I have no idea what else to try

And I have to use A_SpawnItemEx since I need the monster spawned to be friendly and belong to my team (designatedteam does nothing, my team's monsters still attack it unless I spawn it)

Also the coordinates are passed from scripts:

Code: Select all

script 804 (void) // executed by the original actor, one tic before the new one is spawned to replace it
{
    spherex = GetActorX(0) *;
    spherey = GetActorY(0);
    spherez = GetActorZ(0);
}

script 805 (void)
{
    SetResultValue(spherex);
}

script 806 (void)
{
    SetResultValue(spherey);
}

script 807 (void)
{
    SetResultValue(spherez);
}

Code: Select all

A_SpawnItemEx("RedTeamControlSphere",ACS_ExecuteWithResult(805),ACS_ExecuteWithResult(806),ACS_ExecuteWithResult(807),0,0,0,0,SXF_ABSOLUTEPOSITION|SXF_NOCHECKPOSITION)
Last edited by SwordGrunt on Fri Apr 04, 2014 3:09 am, edited 1 time in total.

User avatar
Dusk
Developer
Posts: 581
Joined: Thu May 24, 2012 9:59 pm
Location: Turku

RE: how to spawn on a fixed coordinate with A_SpawnItemEx?

#2

Post by Dusk » Thu Apr 03, 2014 8:52 pm

First off, GetActorX/Y/Z return fixed point, you seem to want to convert them to integers so you should be dividing by 65536 and not multiplying.
Second off, in the A_SpawnItemEx line you subtract the last x from the actor's current x, yielding a delta. You are treating this delta as an absolute coordinate, of course it will be off.

User avatar
SwordGrunt
Forum Regular
Posts: 377
Joined: Thu Jun 07, 2012 8:43 pm

RE: how to spawn on a fixed coordinate with A_SpawnItemEx?

#3

Post by SwordGrunt » Fri Apr 04, 2014 12:58 am

Yeah the delta thing was silly on my part. And I've never dealt with those fixed point numbers before.

It didn't change anything though; it still spawned way off the map, just like it did when I multiplied. I probably made my post confusing, so I'll try to explain my problem better:

I have some stationary monsters on the map, all of the same kind. I want to make it flexible so that I can use more or less depending on the map. When a monster dies, it executes script 804 to store its coordinates in variables. One tic later, it gives the player (A_GiveToTarget) a custom inventory that uses A_SpawnItemEx to spawn a new monster (friendly to him) on the exact same coordinates of the killed one, no matter where the player is on the map. It also stops (disappears) immediately after this is done (within the same tic).

I don't know where it's going wrong. As I said, if I just use the coordinates obtained without multiplying/dividing by 65536 - which I'd think to be the proper behavior since GetActorX/Y/Z return fixed point numbers and the x/y/z offset arguments are passed as fixed point numbers as well - the monster will simply spawn on the player. I know the scripts are running because I did a test print command on all and they all displayed...

I updated the original post with the current state of the code. I usually find my mistakes with ease and correct them but this one is really throwing me off since everything seems right...
Last edited by SwordGrunt on Fri Apr 04, 2014 1:08 am, edited 1 time in total.

User avatar
SwordGrunt
Forum Regular
Posts: 377
Joined: Thu Jun 07, 2012 8:43 pm

RE: how to spawn on a fixed coordinate with A_SpawnItemEx? (SOLVED)

#4

Post by SwordGrunt » Fri Apr 04, 2014 3:09 am

got this working, thanks Qent

GetActorX(0) >> 16 instead of GetActorX(0) did it
Last edited by SwordGrunt on Fri Apr 04, 2014 3:10 am, edited 1 time in total.

User avatar
Ænima
Addicted to Zandronum
Posts: 3583
Joined: Tue Jun 05, 2012 6:12 pm

RE: how to spawn on a fixed coordinate with A_SpawnItemEx? (SOLVED)

#5

Post by Ænima » Fri Apr 04, 2014 3:24 am

SwordGrunt wrote: got this working, thanks Qent

GetActorX(0) >> 16 instead of GetActorX(0) did it
Ah. Gotta love forgetting to bitshift. I've made the same mistake ... on multiple occasions ... Image
Reinforcements: midgame Survival joining/respawning
Doom64: Unabsolved: Doom64 + Diablo II
ZandroSkins: a pack made by our community
AeniPuffs: 3D blood and bullet puff effects, free to use for your own mods
Squad Radio: a WASD-based radio chat menu, add your own custom sounds!
Mercenaries (on hold)
Image

User avatar
SwordGrunt
Forum Regular
Posts: 377
Joined: Thu Jun 07, 2012 8:43 pm

RE: how to spawn on a fixed coordinate with A_SpawnItemEx? (SOLVED)

#6

Post by SwordGrunt » Fri Apr 04, 2014 4:51 am

Ænima wrote:
SwordGrunt wrote: got this working, thanks Qent

GetActorX(0) >> 16 instead of GetActorX(0) did it
Ah. Gotta love forgetting to bitshift. I've made the same mistake ... on multiple occasions ... Image
Hell I don't even know what that is, I'm just glad this shit is working :lol:

User avatar
Ænima
Addicted to Zandronum
Posts: 3583
Joined: Tue Jun 05, 2012 6:12 pm

RE: how to spawn on a fixed coordinate with A_SpawnItemEx? (SOLVED)

#7

Post by Ænima » Fri Apr 04, 2014 5:23 am

SwordGrunt wrote:
Ænima wrote:
SwordGrunt wrote: got this working, thanks Qent

GetActorX(0) >> 16 instead of GetActorX(0) did it
Ah. Gotta love forgetting to bitshift. I've made the same mistake ... on multiple occasions ... Image
Hell I don't even know what that is, I'm just glad this shit is working :lol:
http://en.wikipedia.org/wiki/Bitwise_op ... Bit_shifts

Basically, if a binary value is 0001101, doing "<< 2" would shift all the digits to the left by 2 places, making it 0110100. Shifting by 16 is very common in ACS for converting between integer and fixed point.
Last edited by Ænima on Fri Apr 04, 2014 5:23 am, edited 1 time in total.
Reinforcements: midgame Survival joining/respawning
Doom64: Unabsolved: Doom64 + Diablo II
ZandroSkins: a pack made by our community
AeniPuffs: 3D blood and bullet puff effects, free to use for your own mods
Squad Radio: a WASD-based radio chat menu, add your own custom sounds!
Mercenaries (on hold)
Image

Post Reply