Page 1 of 1

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

Posted: Thu Apr 03, 2014 1:45 pm
by SwordGrunt
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)

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

Posted: Thu Apr 03, 2014 8:52 pm
by Dusk
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.

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

Posted: Fri Apr 04, 2014 12:58 am
by SwordGrunt
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...

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

Posted: Fri Apr 04, 2014 3:09 am
by SwordGrunt
got this working, thanks Qent

GetActorX(0) >> 16 instead of GetActorX(0) did it

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

Posted: Fri Apr 04, 2014 3:24 am
by Ænima
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

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

Posted: Fri Apr 04, 2014 4:51 am
by SwordGrunt
Æ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:

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

Posted: Fri Apr 04, 2014 5:23 am
by Ænima
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.