Any way to ensure teleport success?
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!)
Any way to ensure teleport success?
I have a situation where I am teleporting a couple of boss enemies into an arena, I am doing this via TeleportOther.
It works fine but I worry that the teleport might fail. I have done my best to ensure that can't happen (it's highly unlikely - perhaps even impossible that it will fail with the way that I have set up the map), but I was wondering if there was any way to check whether the teleport has been successful or not and, if not keep trying until it is?
Thanks.
It works fine but I worry that the teleport might fail. I have done my best to ensure that can't happen (it's highly unlikely - perhaps even impossible that it will fail with the way that I have set up the map), but I was wondering if there was any way to check whether the teleport has been successful or not and, if not keep trying until it is?
Thanks.
- MartinHowe
- Posts: 2061
- Joined: Mon Aug 11, 2003 1:50 pm
- Preferred Pronouns: He/Him
- Location: East Suffolk (UK)
Re: Any way to ensure teleport success?
Is this from a monster closet (Vanilla/Limit-Removing) or is ZScript available? And do these monsters already have context or could they be spawned?
Re: Any way to ensure teleport success?
They already exist on the map, and the player may have interacted with them (and damaged them a bit) before the teleport happens. They appear, the player does stuff, they go away, and then they come back at a later point in a different area of the map.
ZScript is a possibility.
ZScript is a possibility.
- MartinHowe
- Posts: 2061
- Joined: Mon Aug 11, 2003 1:50 pm
- Preferred Pronouns: He/Him
- Location: East Suffolk (UK)
Re: Any way to ensure teleport success?
Well, you know you can spawn an item and check if it was spawned? I'm thinking something like this:
This is what I use for repeated attempted spawns:
- Define an actor the same size as the one to be teleported.
- Make it invisible but solid
- Use SpawnItemEx to spawn it, checking if it was spawned, until it is
- Make the monster non-solid and invisible
- Teleport it to the desired area using the co-ordinates of the other actor
- Make the original monster solid again
- Destroy() the other actor
- Spawn a teleport flash at the same location (these are not solid so should be OK)
- Make the monster visible again
This is what I use for repeated attempted spawns:
Code: Select all
const SPAWNCATS_Y_SPREAD = 256;
void SpawnCats(actor player, array<BlackCatToken> catsToSpawn)
{
uint count = catsToSpawn.Size();
if (!count)
{
return;
}
int yofs = -(SPAWNCATS_Y_SPREAD / 2);
int ystep = SPAWNCATS_Y_SPREAD / count;
double a = player.angle;
double s = sin(a);
double c = cos(a);
double z = player.pos.z;
// Offset code adapted from that in A_SpawnItemEx
for (int cat = 0 ; cat < count ; cat++)
{
BlackCatToken catToken = catsToSpawn[cat];
for (int attempt = 0; attempt < 32; attempt++)
{
int xofs = 32 * attempt;
vector3 newpos = player.Vec2OffsetZ(xofs * c + yofs * s, xofs * s - yofs * c, z);
if (Level.IsPointInLevel(newpos))
{
bool wasSpawned;
actor whatWasSpawned;
[wasSpawned, whatWasSpawned] = player.A_SpawnItemEx(catToken.catClass, xofs, yofs, 0);
if (wasSpawned && whatWasSpawned)
{
BlackCat aCat = BlackCat(whatWasSpawned);
aCat.StartHealth = catToken.startHealth;
aCat.Health = catToken.currentHealth;
aCat.FriendPlayer = catToken.FriendPlayer;
aCat.bSpawnWithTeleportFog = true;
aCat.bFollowPlayerToMap = catToken.followToMap;
aCat.bFollowPlayerInHub = catToken.followInHub;
aCat.bFollowPlayerToHub = catToken.followToHub;
break;
}
}
}
yofs = yofs + ystep;
}
}
Re: Any way to ensure teleport success?
OK, yes, thanks. I can work with and adapt that to my needs. 

-
- Posts: 5040
- Joined: Sun Nov 14, 2010 12:59 am
Re: Any way to ensure teleport success?
There's an easier and simpler way.
The script will attempt to teleport the monster. If the teleportation fails, it'll try again every second until it succeeds.
Code: Select all
script 1 (void)
{
while (!TeleportOther(...))
{
Delay(35);
}
}
Re: Any way to ensure teleport success?
Oh, I didn't realise that you could effectively check for TeleportOther success like that (and presumably other teleports). That is simpler. Thanks. 

- MartinHowe
- Posts: 2061
- Joined: Mon Aug 11, 2003 1:50 pm
- Preferred Pronouns: He/Him
- Location: East Suffolk (UK)
Re: Any way to ensure teleport success?
Yep, same for me. I checked the Wiki and when I didn't see any way of checking success listed, I started this thread.