How to make spectators using teleporters

Discussions about Coding and Scripting
User avatar
Barbie
Godlike
Posts: 2536
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

How to make spectators using teleporters

Post by Barbie »

I tried that spectators can use teleporters by pressing JUMP with the following code:

Code: Select all

class SpectatorSB extends CHSpectator;


exec function Jump(optional float F) {
local Teleporter CloseTeleporter;
local bool bTeleFound;

	bTeleFound = false;
	broadcastmessage("bPressedJump=" $ bPressedJump $ ", bCanTeleport=" $ bCanTeleport $ ", CurrentState=" $ InitialState);
	foreach RadiusActors(class'Teleporter', CloseTeleporter, class'PlayerPawn'.Default.CollisionRadius, Location)
	{
		broadcastmessage("CloseTeleporter=" $ CloseTeleporter $ ", PreTeleport=" $ PreTeleport(CloseTeleporter));
		// SetCollision(true, true, true);
		CloseTeleporter.Touch(self);
		bTeleFound = true;
		break;
	}
	if ( ! bTeleFound)
		broadcastmessage("No Teleporter around found");
}

defaultproperties {
	bCollideActors=false
	bBlockActors=false
	bBlockPlayers=false
	bCollideWorld=false
}
Although a teleporter is found nearby the spectator is not teleported and even the teleporter message (found/not found) is omitted sometimes. What's wrong here?

PS: The spectator class is set in function PlayerPawn Login() of the game class (class'MonsterHuntSB' in this case).

PPS: I got the following entries in server's log:
Log: Possessed PlayerPawn: SpectatorSB TestmapV2(SB).SpectatorSB0
ScriptLog: TestmapV2(SB).SpectatorSB0 invalid state
What's invalid? :omfg:
PPPS: It appears only in client's log, not server's.
Last edited by Barbie on Fri Aug 13, 2021 7:41 pm, edited 1 time in total.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Buggie
Godlike
Posts: 1921
Joined: Sat Mar 21, 2020 5:32 am

Re: How to make spectators using teleporters

Post by Buggie »

You can break many maps with that, because many mappers use Event from destination point for actions. Not sure if erase/restore Event field even help for all cases.

Automatically merged

https://github.com/Slipyx/UT99/blob/f2e ... n.uc#L3960

Code: Select all

auto state InvalidState
{
	event PlayerTick( float DeltaTime )
	{
		log(self$" invalid state");
		if ( bUpdatePosition )
			ClientUpdatePosition();

		PlayerMove(DeltaTime);
	}
Or state not replicated to client (if message appear only on client side) or state not set properly and used auto one.
User avatar
EvilGrins
Godlike
Posts: 9058
Joined: Thu Jun 30, 2011 8:12 pm
Personal rank: God of Fudge
Location: Palo Alto, CA

Re: How to make spectators using teleporters

Post by EvilGrins »

There are some maps that have teleports that spectators can use · https://unreal-games.livejournal.com/132579.html · although, the teleports are more like portals.
http://unreal-games.livejournal.com/
Image
medor wrote:Replace Skaarj with EvilGrins :mrgreen:
Smilies · viewtopic.php?f=8&t=13758
OwYeaW
Average
Posts: 77
Joined: Fri Jan 09, 2015 4:24 pm

Re: How to make spectators using teleporters

Post by OwYeaW »

this is how i got spectators to use teleporters: https://github.com/bunnytrack/OwYeaW-US ... or.uc#L168
though i believe, especially in MH maps, specs could trigger events. there should be a way to avoid that though
User avatar
Barbie
Godlike
Posts: 2536
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: How to make spectators using teleporters

Post by Barbie »

OwYeaW wrote: Sun Aug 29, 2021 2:13 pmthis is how i got spectators to use teleporters
Looking around all x ms for a teleporter nearby and simulating its transport was in my mind, too.
I'm on it with the JUMP event atm but I still have issues with
1) finding the destination teleporter (in my test map a class'Teleporter' is found as destination but to a class'VisibleTeleporer' isn't)
2) setting Spectators' location with SetLocation() does not work.
Spoiler

Code: Select all

exec function Jump(optional float F) {
local Teleporter NearbyTeleporter, DestTeleporter;
local bool bTeleFound;

	bTeleFound = false;
	ClientMessage("bPressedJump=" $ bPressedJump $ ", bCanTeleport=" $ bCanTeleport $ ", CurrentState=" $ InitialState);
	foreach RadiusActors(class'Teleporter', NearbyTeleporter, class'PlayerPawn'.Default.CollisionRadius, Location)
	{
		ClientMessage("NearbyTeleporter=" $ NearbyTeleporter $ ", URL=" $ NearbyTeleporter.URL);
		bTeleFound = true;
		if (FindDestinationTeleporter(NearbyTeleporter, DestTeleporter))
		{
			ClientMessage("Setting location to" @ DestTeleporter.Location);
			if ( ! self.SetLocation(DestTeleporter.Location))
				ClientMessage("Setting location was not successful");
		}
		else
			ClientMessage("Teleport destination for" @ NearbyTeleporter @ "not found!");
	}
	if ( ! bTeleFound)
		ClientMessage("No Teleporter is close to you");
}



function bool FindDestinationTeleporter(Teleporter SrcTele, out Teleporter DestTele) {
/******************************************************************************
Searches Teleporter with the given *WhatTag* and returns TRUE if one ore more
were found. If multiple exist, a random one is returned. (See also code in stock
Teleporter.uc)
******************************************************************************/
local int i;

// for now use the first found matching teleporter:
	foreach AllActors(class'Teleporter', DestTele)
	{
		ClientMessage("checking" @ DestTele @ "with Tag=" $ DestTele.Tag);
		if (string(DestTele.tag) ~= SrcTele.URL && SrcTele != DestTele)
		{
			ClientMessage("found" @ DestTele);
			return DestTele != None;
		}
	}
return false;


	foreach AllActors(class'Teleporter', DestTele)
		if (string(DestTele.tag) ~= SrcTele.URL && SrcTele != DestTele)
			i++;
	i = rand(i);
	foreach AllActors(class'Teleporter', DestTele)
		if (string(DestTele.tag) ~= SrcTele.URL && SrcTele != DestTele && i-- == 0)
			break;
	return DestTele != None;
}
As I see your code respects visible teleporters only?
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett