UT99Vehicle: Overhaul of VehiclePawn from old GusPack

Discussions about Coding and Scripting
Post Reply
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

UT99Vehicle: Overhaul of VehiclePawn from old GusPack

Post by Gustavo6046 »

This used to be a thread asking for help, but now I'm asking for help in little details of this cool vehicle, other than sometimes it hangin' you around in the air, it's OK :)

This is a vehicle code I'm doing. It's gonna be the first vehicle ever done in Unreal Tournament 1999!

Code: Select all

//=============================================================================
// UT99Vehicle.
//=============================================================================
class UT99Vehicle expands Pickup;

var(Vehicle)	Vector	DriverOffset;
var(Vehicle)	Vector	PassengerOffsets[63];
var(Vehicle)	float	TopSpeed;
var(Vehicle)	float	VehicleHealth;
var				byte	PeopleInside;
var				Pawn	PassengerPawns[63];
var				Pawn	DriverPawn;
var(Vehicle)	bool	bTeamGame;
var(Vehicle)	float	ActorBumpForce;
var(Vehicle)	int		MyTeam;
var(Vehicle)	bool	bSetTeamToDriverTeam;
var(Vehicle)	int		PawnBumpDamage;
var(Vehicle)	float	Weight;
var(Vehicle)	Vector	BlastOffset;
var(Vehicle)	string	KillMessage[3];
var(Vehicle)	int		MaxPassengers;
var(Vehicle)	Texture	DestroyedTexture;
var(Vehicle)	float	Acceleration;
var				Texture	OldTexture;

static function vector NewVector(float X, float Y, float Z)
{
	local Vector V;

	V.X = X;
	V.Y = Y;
	V.Z = Z;

	return V;
}

function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType)
{
	if ( DamageType == 'AntiVehicle' )
		self.Velocity += Momentum / (Weight / 2);
	else self.Velocity += Momentum / Weight;
}

simulated function Touch(Actor Other)
{

	if ( Pawn(Other) != None && PeopleInside > 1 )
	{
		if
		(
			( Level.Game.IsA(class'TeamGamePlus'.Name)
			&&	(
					(
						!bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo != None
					&&	Pawn(Other).PlayerReplicationInfo.Team == MyTeam
					)
				||	(
						bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo != None
					&&	DriverPawn.PlayerReplicationInfo != None
					&&	Pawn(Other).PlayerReplicationInfo.Team == DriverPawn.PlayerReplicationInfo.Team
					)
				)
			)
			&& Pawn(Other).PlayerReplicationInfo.Team != 255
			&& PeopleInside <= MaxPassengers
		)
		{
			PassengerPawns[PeopleInside - 1] = Pawn(Other);
			PeopleInside++;
		}
		else
		{
			Other.TakeDamage(PawnBumpDamage, DriverPawn, Location, Velocity, 'vehiclebump');
			Other.Velocity = (Other.Location - Location) * ActorBumpForce;
				if ( Pawn(Other).Health < 1 )
			{
				Pawn(Other).GoToState('Dying');
				BroadcastMessage(KillMessage[0] @ DriverPawn.Name @ KillMessage[1] @ Pawn(Other).Name @ KillMessage[2], false, 'deathmessage');
			}
		}	
	}
	else if ( Projectile(Other) != None )
	{
		TakeDamage(Projectile(Other).Damage, None, Other.Location, Self.Location - Other.Location, Projectile(Other).MyDamageType);
		Projectile(Other).Touch(Self);
	}

	else if ( Other.bBlockActors )
		Other.Velocity = (Other.Location - Location) * ActorBumpForce;
}

function Activate()
{
	bHidden = false;
}

function vector AdjustMotion(vector OldLocation, pawn Driver)
{
	local Vector result;
	local Vector tresult;
	local Vector unused;
	local Vector halp;

	halp = OldLocation - Location * Acceleration;
	halp.Z = Location.Z;

	Trace(result, unused, halp, OldLocation - Location, false);

	if ( VSize(result) > TopSpeed )
		result = Normal(result) * TopSpeed;

	SetLocation(OldLocation + result);

	if ( Location.Z > OldLocation.Z + 64 && !FastTrace(Location, Location + static.NewVector(0, 0, -64)) )
	{
		Trace(tresult, unused, static.NewVector(Location.X, Location.Y, OldLocation.Z), Location, false);
		result = Location - tresult;
	}

	SetLocation(OldLocation);

	return result;
}

function LeaveVehicle(byte Index)
{
	local int i;

	if ( Index == 0 )
	{
		DriverPawn = None;
		PeopleInside--;
		for (i = 0; i < 64; i++)
			if ( PassengerPawns[i] != None )
				PassengerPawns[i] = None;
	}
	else if ( Index < 64 )
	{
		for ( i = Index--; i < 63; i++ )
		{
			if ( PassengerPawns[i++] != None )
				PassengerPawns[i] = PassengerPawns[i++];
			else
				return;
		}
	}
}

function PickupFunction(Pawn Other)
{
	if ( IsInState('DestroyedVehicle') || IsInState('Activated') )
		return;

	DriverPawn = Other;
	PeopleInside++;	

	GoToState('Activated');
}

simulated function Tick(float TimeDelta)
{
	local vector OldLocation;
	local int i;
	local Pawn Passenger;

	if ( ( DriverPawn == None || DriverPawn.IsInState('Dying') ) && !IsInState('Pickup') )
		GoToState('DestroyedVehicle');

	if ( PeopleInside < 1 || !IsInState('Activated') )
		return;

	if ( VehicleHealth < 1 )
	{
		Spawn(class'ExplosionChain', self, '__vehicle_blast__', Location + (BlastOffset * (VRand() * 2))).Trigger(self, DriverPawn);
		GoToState('Destroyed');
	}

	OldLocation = Location;

	if ( DriverPawn != None )
		SetLocation(DriverPawn.Location - DriverOffset);

	SetLocation(OldLocation + AdjustMotion(OldLocation, DriverPawn));

	DriverPawn.SetLocation(Location + DriverOffset);
	
	for ( i = 0; i < 63; i++ )
	{
		Passenger = PassengerPawns[i];
		if ( Passenger != None )
			Passenger.SetLocation(Location + PassengerOffsets[i]);
	}
}

State DestroyedVehicle
{
	function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType);
	function Tick(float TimeDelta);
	function PickupFunction(Pawn Other);
	function Touch(Actor Other)
	{
		if ( Pawn(Other) != None )
		{
			Pawn(Other).Health -= 1;
			if ( Pawn(Other).Health < 1 )
				Other.GoToState('Dying');
		}
	}

	Begin:
		OldTexture = Texture;
		Texture = DestroyedTexture;

		Sleep(RespawnTime);

		Texture = OldTexture;
		OldTexture = None;
		GoToState('Pickup');
}

State Pickup
{
	Begin:
		VehicleHealth = default.VehicleHealth;
}
Original post:
Hello all again! :D

I'm doing a complete overhaul of VehiclePawn (from the old GusPack) to it's own Vehicles package (and a way of bumping with stuff without bBlockActors, enabling players to get in! :D ) however I have a very strange error:

Code: Select all

Error in UT99Vehicle, line 155: 'state': expecting State, got Function
This is the full code:

Code: Select all

//=============================================================================
// UT99Vehicle.
//=============================================================================
class UT99Vehicle expands Pickup;

var(Vehicle)	Vector	DriverOffset;
var(Vehicle)	Vector	PassengerOffsets[63];
var(Vehicle)	float	TopSpeed;
var(Vehicle)	float	VehicleHealth;
var				byte	PeopleInside;
var				Pawn	PassengerPawns[63];
var				Pawn	DriverPawn;
var(Vehicle)	bool	bTeamGame;
var(Vehicle)	float	ActorBumpForce;
var(Vehicle)	int		MyTeam;
var(Vehicle)	bool	bSetTeamToDriverTeam;
var(Vehicle)	int		PawnBumpDamage;
var(Vehicle)	float	Weight;
var(Vehicle)	string	KillMessage[3];
var(Vehicle)	int		MaxPassengers;
var(Vehicle)	float	RespawnTime;
var(Vehicle)	Texture	DestroyedTexture;
var				Texture	OldTexture;


simulated function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType)
{
	if ( DamageType != 'AntiVehicle' )
		self.Velocity += Momentum / (Weight / 2);
	else self.Velocity += Momentum / Weight;
}

simulated function Touch(Actor Other)
{

	if ( Other.IsA(class'Pawn'.Name) && PeopleInside > 1 )
	{
		if
		(
			( Level.Game.IsA(class'TeamGamePlus'.Name)
			&&	(
					(
						!bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo.Team == MyTeam
					)
				^^	(
						bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo.Team == DriverPawn.PlayerReplicationInfo.Team
					)
				)
			)
			&& Pawn(Other).PlayerReplicationInfo.Team != 255
			&& PeopleInside <= MaxPassengers
		)
		{
			PassengerPawns[PeopleInside - 1] = Pawn(Other);
			PeopleInside++;
		}
		else
		{
			Other.TakeDamage(PawnBumpDamage, DriverPawn, Location, Velocity, 'vehiclebump');
			Other.Velocity = (Other.Location - Location) * ActorBumpForce;
				if ( Pawn(Other).Health < 1 )
			{
				Pawn(Other).GoToState('Dying');
				BroadcastMessage(KillMessage[0] @ DriverPawn.Name @ KillMessage[1] @ Pawn(Other).Name @ KillMessage[2]);
			}
		}	
	}
	else if ( Other.IsA(class'Projectile'.Name) )
	{
		Projectile(Other).ProcessTouch(self, self.Location);
	}
	else if ( Other.bBlockActors )
		Other.Velocity = (Other.Location - Location) * ActorBumpForce;
}


simulated function AdjustMotion(vector OldLocation, pawn Driver)
{
	if ( VSize(OldLocation - Location) > TopSpeed )
	{
		return Normal(OldLocation - Location) * TopSpeed;
	}
}

simulated function LeaveVehicle(byte Index)
{
	local int i;

	if ( Index == 0 )
	{
		DriverPawn == None;
		PeopleInside--;
		for (i = 0; i < 64; i++)
			if ( PassengerPawns[i] != None )
				PassengerPawns[i] == None;
	}
	elif ( Index < 64 )
	{
		for ( i = Index--; i < 63; i++ )
		{
			if ( PassengerPawns[i++] != None )
				PassengerPawns[i] = PassengerPawns[i++];
			else
				return;
		}
	}
}

function PickupFunction(Pawn Other)
{
	if ( IsInState('Destroyed') || IsInState('Activated') )
		return;

	DriverPawn = Other;
	PeopleInside++;	

	GoToState('Activated');
}

simulated function Tick(float TimeDelta)
{
	local vector OldLocation;
	local int i;

	if ( PeopleInside < 1 || !IsInState('Activated') )
		return;

	if ( VehicleHealth < 1 )
	{
		Spawn(class'ExplosionChain', self, Location + (BlastOffset * (VRand() * 2 ))).Trigger(self, DriverPawn);
		GoToState('Destroyed')
	}

	OldLocation = Location;

	if ( DriverPawn != None )
	{
		Self.Location = DriverPawn.Location - DriverOffset;
	}

	Move(AdjustMotion(OldLocation, DriverPawn))

	DriverPawn.SetLocation(Location + DriverOffset);
	
	for ( i = 0; i < 64; i++ )
		if ( PassengerPawns[i] != None )
		{
			PassengerPawns[í].SetLocation(Location + PassengerOffsets[i]);
		}
}

State() Destroyed
{
	function TakeDamage();
	function Tick();
	function LeaveVehicle();
	function PickupFunction();
	function Touch();

	simulated function BeginState()
	{
		OldTexture = Texture;
		Texture = DestroyedTexture;

		Super.Sleep(RespawnTime);

		Texture = OldTexture
		GoToState(InitialState);
	}
}
I tried looking for something in the Wiki, but all I've got is:
The Wiki: https://wiki.beyondunreal.com/Compiler_errors_overview#States wrote: Error, 'state': expecting State, got Function
This was caused by calling a state sleep where sleep is a function of state. Im guessing any function previously defined can conflict with a state.
However, I already tried calling sleep() from Global and it didn't work ._.

And a Google search for the exact terms

Code: Select all

unrealscript "expecting state got function"
only had 3 unuseful results, even with my incredible Google-Fu X1000.

I remember having this error once, but I don't recall how did I fix it! Please :help: !

EDIT: Oh, and almost forgetting; I made ##unrealscript1 channel in irc.freenode.net for very quick help :)
Last edited by Gustavo6046 on Wed Apr 20, 2016 6:32 pm, edited 2 times in total.
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
Barbie
Godlike
Posts: 2806
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: 'state': Expecting State, got Function

Post by Barbie »

Maybe reading Declaration syntax helps?

Code: Select all

State Destroyed {}
Does this work?
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: 'state': Expecting State, got Function

Post by Gustavo6046 »

Barbie wrote:Maybe reading Declaration syntax helps?

Code: Select all

State Destroyed {}
Does this work?
Not either :(
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
Barbie
Godlike
Posts: 2806
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: 'state': Expecting State, got Function

Post by Barbie »

Just had a quick look at your code, line 100:

Code: Select all

elif ( Index < 64 )
should be

Code: Select all

else if ( Index < 64 )
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: 'state': Expecting State, got Function

Post by Gustavo6046 »

Barbie wrote:Just had a quick look at your code, line 100:

Code: Select all

elif ( Index < 64 )
should be

Code: Select all

else if ( Index < 64 )
Thanks for pointing that out :)

What did you think of my code?
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
Barbie
Godlike
Posts: 2806
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: 'state': Expecting State, got Function

Post by Barbie »

Rename the state Destroyed because it is the name of an event declared in Actor.
What did you think of my code?
I stumbled over several things:
1)

Code: Select all

Other.IsA(class'Pawn'.Name)
could be shortened and changed to a spell-error-free version:

Code: Select all

Pawn(Other) != None
2) You access Pawn.PlayerReplicationInfo without verifying that PRI exists.

3) Why are so many functions simulated?
...
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: 'state': Expecting State, got Function

Post by Gustavo6046 »

Oh ok, thanks for pointing that out as well :)

One more thing: what event do you think should happen for a guy to leave the vehicle? A keypress?

EDIT: Now I get a unexplainable "bad or missing expression in array index" at line 159 :/ :

Code: Select all

//=============================================================================
// UT99Vehicle.
//=============================================================================
class UT99Vehicle expands Pickup;

var(Vehicle)	Vector	DriverOffset;
var(Vehicle)	Vector	PassengerOffsets[63];
var(Vehicle)	float	TopSpeed;
var(Vehicle)	float	VehicleHealth;
var				byte	PeopleInside;
var				Pawn	PassengerPawns[63];
var				Pawn	DriverPawn;
var(Vehicle)	bool	bTeamGame;
var(Vehicle)	float	ActorBumpForce;
var(Vehicle)	int		MyTeam;
var(Vehicle)	bool	bSetTeamToDriverTeam;
var(Vehicle)	int		PawnBumpDamage;
var(Vehicle)	float	Weight;
var(Vehicle)	Vector	BlastOffset;
var(Vehicle)	string	KillMessage[3];
var(Vehicle)	int		MaxPassengers;
var(Vehicle)	float	RespawnTime;
var(Vehicle)	Texture	DestroyedTexture;
var				Texture	OldTexture;


function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType)
{
	if ( DamageType != 'AntiVehicle' )
		self.Velocity += Momentum / (Weight / 2);
	else self.Velocity += Momentum / Weight;
}

simulated function Touch(Actor Other)
{

	if ( Pawn(Other) != None && PeopleInside > 1 )
	{
		if
		(
			( Level.Game.IsA(class'TeamGamePlus'.Name)
			&&	(
					(
						!bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo != None
					&&	Pawn(Other).PlayerReplicationInfo.Team == MyTeam
					)
				^^	(
						bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo != None
					&&	DriverPawn.PlayerReplicationInfo != None
					&&	Pawn(Other).PlayerReplicationInfo.Team == DriverPawn.PlayerReplicationInfo.Team
					)
				)
			)
			&& Pawn(Other).PlayerReplicationInfo.Team != 255
			&& PeopleInside <= MaxPassengers
		)
		{
			PassengerPawns[PeopleInside - 1] = Pawn(Other);
			PeopleInside++;
		}
		else
		{
			Other.TakeDamage(PawnBumpDamage, DriverPawn, Location, Velocity, 'vehiclebump');
			Other.Velocity = (Other.Location - Location) * ActorBumpForce;
				if ( Pawn(Other).Health < 1 )
			{
				Pawn(Other).GoToState('Dying');
				BroadcastMessage(KillMessage[0] @ DriverPawn.Name @ KillMessage[1] @ Pawn(Other).Name @ KillMessage[2]);
			}
		}	
	}
	else if ( Projectile(Other) != None )
	{
		Projectile(Other).ProcessTouch(self, self.Location);
	}
	else if ( Other.bBlockActors )
		Other.Velocity = (Other.Location - Location) * ActorBumpForce;
}


function vector AdjustMotion(vector OldLocation, pawn Driver)
{
	local Vector result;

	if ( VSize(OldLocation - Location) > TopSpeed )
		result = Normal(OldLocation - Location) * TopSpeed;

	if ( Location.Z > OldLocation.Z + 64 && !FastTrace(Location, Location + NewVector(0, 0, -64)) )
		result.Z = OldLocation.Z;

	return result;
}

function 

function LeaveVehicle(byte Index)
{
	local int i;

	if ( Index == 0 )
	{
		DriverPawn == None;
		PeopleInside--;
		for (i = 0; i < 64; i++)
			if ( PassengerPawns[i] != None )
				PassengerPawns[i] == None;
	}
	else if ( Index < 64 )
	{
		for ( i = Index--; i < 63; i++ )
		{
			if ( PassengerPawns[i++] != None )
				PassengerPawns[i] = PassengerPawns[i++];
			else
				return;
		}
	}
}

function PickupFunction(Pawn Other)
{
	if ( IsInState('Destroyed') || IsInState('Activated') )
		return;

	DriverPawn = Other;
	PeopleInside++;	

	GoToState('Activated');
}

simulated function Tick(float TimeDelta)
{
	local vector OldLocation;
	local int i;

	if ( PeopleInside < 1 || !IsInState('Activated') )
		return;

	if ( VehicleHealth < 1 )
	{
		Spawn(class'ExplosionChain', self, '__vehicle_blast__', Location + (BlastOffset * (VRand() * 2))).Trigger(self, DriverPawn);
		GoToState('Destroyed');
	}

	OldLocation = Location;

	if ( DriverPawn != None )
		SetLocation(DriverPawn.Location - DriverOffset);

	Move(AdjustMotion(OldLocation, DriverPawn));

	DriverPawn.SetLocation(Location + DriverOffset);
	
	for ( i = 0; i < 64; i++ )
		if ( PassengerPawns[i] != None )
		{
			PassengerPawns[í].SetLocation(Location + PassengerOffsets[i]);
		}
}

State DestroyedVehicle
{
	function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType);
	function Tick(float TimeDelta);
	function PickupFunction(Pawn Other);
	function Touch(Actor Other)
	{
		if ( Pawn(Other) != None )
		{
			Pawn(Other).Health -= 1;
			if ( Pawn(Other).Health < 1 )
				Other.GoToState('Dying');
		}
	}

	Begin:
		OldTexture = Texture;
		Texture = DestroyedTexture;

		Sleep(RespawnTime);

		Texture = OldTexture;
		OldTexture = None;
		GoToState('Pickup');		
}
EDIT2: nevermind :P
EDIT3: Yeah it compiles now:

Code: Select all

//=============================================================================
// UT99Vehicle.
//=============================================================================
class UT99Vehicle expands Pickup;

var(Vehicle)	Vector	DriverOffset;
var(Vehicle)	Vector	PassengerOffsets[63];
var(Vehicle)	float	TopSpeed;
var(Vehicle)	float	VehicleHealth;
var				byte	PeopleInside;
var				Pawn	PassengerPawns[63];
var				Pawn	DriverPawn;
var(Vehicle)	bool	bTeamGame;
var(Vehicle)	float	ActorBumpForce;
var(Vehicle)	int		MyTeam;
var(Vehicle)	bool	bSetTeamToDriverTeam;
var(Vehicle)	int		PawnBumpDamage;
var(Vehicle)	float	Weight;
var(Vehicle)	Vector	BlastOffset;
var(Vehicle)	string	KillMessage[3];
var(Vehicle)	int		MaxPassengers;
var(Vehicle)	float	RespawnTime;
var(Vehicle)	Texture	DestroyedTexture;
var				Texture	OldTexture;

static function vector NewVector(float X, float Y, float Z)
{
	local Vector V;

	V.X = X;
	V.Y = Y;
	V.Z = Z;

	return V;
}

function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType)
{
	if ( DamageType != 'AntiVehicle' )
		self.Velocity += Momentum / (Weight / 2);
	else self.Velocity += Momentum / Weight;
}

simulated function Touch(Actor Other)
{

	if ( Pawn(Other) != None && PeopleInside > 1 )
	{
		if
		(
			( Level.Game.IsA(class'TeamGamePlus'.Name)
			&&	(
					(
						!bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo != None
					&&	Pawn(Other).PlayerReplicationInfo.Team == MyTeam
					)
				^^	(
						bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo != None
					&&	DriverPawn.PlayerReplicationInfo != None
					&&	Pawn(Other).PlayerReplicationInfo.Team == DriverPawn.PlayerReplicationInfo.Team
					)
				)
			)
			&& Pawn(Other).PlayerReplicationInfo.Team != 255
			&& PeopleInside <= MaxPassengers
		)
		{
			PassengerPawns[PeopleInside - 1] = Pawn(Other);
			PeopleInside++;
		}
		else
		{
			Other.TakeDamage(PawnBumpDamage, DriverPawn, Location, Velocity, 'vehiclebump');
			Other.Velocity = (Other.Location - Location) * ActorBumpForce;
				if ( Pawn(Other).Health < 1 )
			{
				Pawn(Other).GoToState('Dying');
				BroadcastMessage(KillMessage[0] @ DriverPawn.Name @ KillMessage[1] @ Pawn(Other).Name @ KillMessage[2]);
			}
		}	
	}
	else if ( Projectile(Other) != None )
		Projectile(Other).ProcessTouch(self, self.Location);

	else if ( Other.bBlockActors )
		Other.Velocity = (Other.Location - Location) * ActorBumpForce;
}


function vector AdjustMotion(vector OldLocation, pawn Driver)
{
	local Vector result;

	if ( VSize(OldLocation - Location) > TopSpeed )
		result = Normal(OldLocation - Location) * TopSpeed;

	if ( Location.Z > OldLocation.Z + 64 && !FastTrace(Location, Location + static.NewVector(0, 0, -64)) )
		result.Z = OldLocation.Z;

	return result;
}

function LeaveVehicle(byte Index)
{
	local int i;

	if ( Index == 0 )
	{
		DriverPawn = None;
		PeopleInside--;
		for (i = 0; i < 64; i++)
			if ( PassengerPawns[i] != None )
				PassengerPawns[i] = None;
	}
	else if ( Index < 64 )
	{
		for ( i = Index--; i < 63; i++ )
		{
			if ( PassengerPawns[i++] != None )
				PassengerPawns[i] = PassengerPawns[i++];
			else
				return;
		}
	}
}

function PickupFunction(Pawn Other)
{
	if ( IsInState('Destroyed') || IsInState('Activated') )
		return;

	DriverPawn = Other;
	PeopleInside++;	

	GoToState('Activated');
}

simulated function Tick(float TimeDelta)
{
	local vector OldLocation;
	local int i;
	local Pawn Passenger;

	if ( PeopleInside < 1 || !IsInState('Activated') )
		return;

	if ( VehicleHealth < 1 )
	{
		Spawn(class'ExplosionChain', self, '__vehicle_blast__', Location + (BlastOffset * (VRand() * 2))).Trigger(self, DriverPawn);
		GoToState('Destroyed');
	}

	OldLocation = Location;

	if ( DriverPawn != None )
		SetLocation(DriverPawn.Location - DriverOffset);

	Move(AdjustMotion(OldLocation, DriverPawn));

	DriverPawn.SetLocation(Location + DriverOffset);
	
	for ( i = 0; i < 64; i++ )
	{
		Passenger = PassengerPawns[i];
		if ( Passenger != None )
			Passenger.SetLocation(Location + PassengerOffsets[i]);
	}
}

State DestroyedVehicle
{
	function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType);
	function Tick(float TimeDelta);
	function PickupFunction(Pawn Other);
	function Touch(Actor Other)
	{
		if ( Pawn(Other) != None )
		{
			Pawn(Other).Health -= 1;
			if ( Pawn(Other).Health < 1 )
				Other.GoToState('Dying');
		}
	}

	Begin:
		OldTexture = Texture;
		Texture = DestroyedTexture;

		Sleep(RespawnTime);

		Texture = OldTexture;
		OldTexture = None;
		GoToState('Pickup');
}
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
Barbie
Godlike
Posts: 2806
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: 'state': Expecting State, got Function

Post by Barbie »

Do you really mean logical XOR here?
Attachments
XOR.jpg
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: 'state': Expecting State, got Function

Post by Gustavo6046 »

Barbie wrote:Do you really mean logical XOR here?
Yeah, I guess...

EDIT: The vehicle makes me fly to oblivion in DM-SpaceNoxx! Why ?

EDIT 2: New code:

Code: Select all

//=============================================================================
// UT99Vehicle.
//=============================================================================
class UT99Vehicle expands Pickup;

var(Vehicle)	Vector	DriverOffset;
var(Vehicle)	Vector	PassengerOffsets[63];
var(Vehicle)	float	TopSpeed;
var(Vehicle)	float	VehicleHealth;
var				byte	PeopleInside;
var				Pawn	PassengerPawns[63];
var				Pawn	DriverPawn;
var(Vehicle)	bool	bTeamGame;
var(Vehicle)	float	ActorBumpForce;
var(Vehicle)	int		MyTeam;
var(Vehicle)	bool	bSetTeamToDriverTeam;
var(Vehicle)	int		PawnBumpDamage;
var(Vehicle)	float	Weight;
var(Vehicle)	Vector	BlastOffset;
var(Vehicle)	string	KillMessage[3];
var(Vehicle)	int		MaxPassengers;
var(Vehicle)	Texture	DestroyedTexture;
var(Vehicle)	float	Acceleration;
var				Texture	OldTexture;

static function vector NewVector(float X, float Y, float Z)
{
	local Vector V;

	V.X = X;
	V.Y = Y;
	V.Z = Z;

	return V;
}

function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType)
{
	if ( DamageType == 'AntiVehicle' )
		self.Velocity += Momentum / (Weight / 2);
	else self.Velocity += Momentum / Weight;
}

simulated function Touch(Actor Other)
{

	if ( Pawn(Other) != None && PeopleInside > 1 )
	{
		if
		(
			( Level.Game.IsA(class'TeamGamePlus'.Name)
			&&	(
					(
						!bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo != None
					&&	Pawn(Other).PlayerReplicationInfo.Team == MyTeam
					)
				||	(
						bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo != None
					&&	DriverPawn.PlayerReplicationInfo != None
					&&	Pawn(Other).PlayerReplicationInfo.Team == DriverPawn.PlayerReplicationInfo.Team
					)
				)
			)
			&& Pawn(Other).PlayerReplicationInfo.Team != 255
			&& PeopleInside <= MaxPassengers
		)
		{
			PassengerPawns[PeopleInside - 1] = Pawn(Other);
			PeopleInside++;
		}
		else
		{
			Other.TakeDamage(PawnBumpDamage, DriverPawn, Location, Velocity, 'vehiclebump');
			Other.Velocity = (Other.Location - Location) * ActorBumpForce;
				if ( Pawn(Other).Health < 1 )
			{
				Pawn(Other).GoToState('Dying');
				BroadcastMessage(KillMessage[0] @ DriverPawn.Name @ KillMessage[1] @ Pawn(Other).Name @ KillMessage[2], false, 'deathmessage');
			}
		}	
	}
	else if ( Projectile(Other) != None )
	{
		TakeDamage(Projectile(Other).Damage, None, Other.Location, Self.Location - Other.Location, Projectile(Other).MyDamageType);
		Projectile(Other).Touch(Self);
	}

	else if ( Other.bBlockActors )
		Other.Velocity = (Other.Location - Location) * ActorBumpForce;
}

function Activate()
{
	bHidden = false;
}

function vector AdjustMotion(vector OldLocation, pawn Driver)
{
	local Vector result;
	local Vector tresult;
	local Vector unused;

	Trace(result, unused, OldLocation - Location * Acceleration, OldLocation - Location, false);

	if ( VSize(result) > TopSpeed )
		result = Normal(result) * TopSpeed;

	SetLocation(OldLocation + result);

	if ( Location.Z > OldLocation.Z + 64 && !FastTrace(Location, Location + static.NewVector(0, 0, -64)) )
	{
		Trace(tresult, unused, static.NewVector(Location.X, Location.Y, OldLocation.Z), Location, false);
		result = Location - tresult;
	}

	SetLocation(OldLocation);

	return result;
}

function LeaveVehicle(byte Index)
{
	local int i;

	if ( Index == 0 )
	{
		DriverPawn = None;
		PeopleInside--;
		for (i = 0; i < 64; i++)
			if ( PassengerPawns[i] != None )
				PassengerPawns[i] = None;
	}
	else if ( Index < 64 )
	{
		for ( i = Index--; i < 63; i++ )
		{
			if ( PassengerPawns[i++] != None )
				PassengerPawns[i] = PassengerPawns[i++];
			else
				return;
		}
	}
}

function PickupFunction(Pawn Other)
{
	if ( IsInState('DestroyedVehicle') || IsInState('Activated') )
		return;

	DriverPawn = Other;
	PeopleInside++;	

	GoToState('Activated');
}

simulated function Tick(float TimeDelta)
{
	local vector OldLocation;
	local int i;
	local Pawn Passenger;

	if ( ( DriverPawn == None || DriverPawn.IsInState('Dying') ) && !IsInState('Pickup') )
		GoToState('DestroyedVehicle');

	if ( PeopleInside < 1 || !IsInState('Activated') )
		return;

	if ( VehicleHealth < 1 )
	{
		Spawn(class'ExplosionChain', self, '__vehicle_blast__', Location + (BlastOffset * (VRand() * 2))).Trigger(self, DriverPawn);
		GoToState('Destroyed');
	}

	OldLocation = Location;

	if ( DriverPawn != None )
		SetLocation(DriverPawn.Location - DriverOffset);

	SetLocation(OldLocation + AdjustMotion(OldLocation, DriverPawn));

	DriverPawn.SetLocation(Location + DriverOffset);
	
	for ( i = 0; i < 63; i++ )
	{
		Passenger = PassengerPawns[i];
		if ( Passenger != None )
			Passenger.SetLocation(Location + PassengerOffsets[i]);
	}
}

State DestroyedVehicle
{
	function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType);
	function Tick(float TimeDelta);
	function PickupFunction(Pawn Other);
	function Touch(Actor Other)
	{
		if ( Pawn(Other) != None )
		{
			Pawn(Other).Health -= 1;
			if ( Pawn(Other).Health < 1 )
				Other.GoToState('Dying');
		}
	}

	Begin:
		OldTexture = Texture;
		Texture = DestroyedTexture;

		Sleep(RespawnTime);

		Texture = OldTexture;
		OldTexture = None;
		GoToState('Pickup');
}

State Pickup
{
	Begin:
		VehicleHealth = default.VehicleHealth;
}
How do I make the vehicle take damage like a pawn from any damage source? And why is it going up so high when I just pick up?
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: UT99Vehicle: Overhaul of VehiclePawn from old GusPack

Post by Gustavo6046 »

Code Update! Why doesn't anything different happens once you drive it?

Code: Select all

//=============================================================================
// UT99Vehicle.
//=============================================================================
class UT99Vehicle expands Pickup;

var(Vehicle)	Vector	DriverOffset;
var(Vehicle)	Vector	PassengerOffsets[63];
var(Vehicle)	float	TopSpeed;
var(Vehicle)	float	VehicleHealth;
var(Vehicle)	bool	bTeamGame;
var(Vehicle)	float	ActorBumpForce;
var(Vehicle)	int		MyTeam;
var(Vehicle)	bool	bSetTeamToDriverTeam;
var(Vehicle)	int		PawnBumpDamage;
var(Vehicle)	float	Weight;
var(Vehicle)	Vector	BlastOffset;
var(Vehicle)	string	KillMessage[3];
var(Vehicle)	int		MaxPassengers;
var(Vehicle)	Texture	DestroyedTexture;
var(Vehicle)	float	Acceleration;
var				byte	PeopleInside;
var				Pawn	PassengerPawns[63];
var				Pawn	DriverPawn;
var				Texture	OldTexture;
var				float	StartingVehicleHealth;

function PreBeginPlay()
{
	StartingVehicleHealth = VehicleHealth;
}

static function vector NewVector(float X, float Y, float Z)
{
	local Vector V;

	V.X = X;
	V.Y = Y;
	V.Z = Z;

	return V;
}

function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType)
{
	if ( DamageType == 'AntiVehicle' )
		self.Velocity += Momentum / (Weight / 2);
	else self.Velocity += Momentum / Weight;
}

simulated function Touch(Actor Other)
{

	if ( Pawn(Other) != None && PeopleInside > 1 )
	{
		if
		(
				TeamGamePlus(Level.Game) != None
			&&	(
					(
						!bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo != None
					&&	Pawn(Other).PlayerReplicationInfo.Team == MyTeam
					)
				||	(
						bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo != None
					&&	DriverPawn.PlayerReplicationInfo != None
					&&	Pawn(Other).PlayerReplicationInfo.Team == DriverPawn.PlayerReplicationInfo.Team
					)
				)
			&& Pawn(Other).PlayerReplicationInfo.Team != 255
			&& PeopleInside <= MaxPassengers
		)
			JoinVehicle(Pawn(Other));

		else
		{
			Other.TakeDamage(PawnBumpDamage, DriverPawn, Location, Velocity, 'vehiclebump');
			Other.Velocity = (Other.Location - Location) * ActorBumpForce;
				if ( Pawn(Other).Health < 1 )
			{
				Pawn(Other).GoToState('Dying');
				BroadcastMessage(KillMessage[0] @ DriverPawn.Name @ KillMessage[1] @ Pawn(Other).Name @ KillMessage[2], false, 'deathmessage');
			}
		}	
	}
	else if ( Projectile(Other) != None )
	{
		TakeDamage(Projectile(Other).Damage, None, Other.Location, Self.Location - Other.Location, Projectile(Other).MyDamageType);
		Projectile(Other).Touch(Self);
	}

	else if ( Other.bBlockActors )
		Other.Velocity = (Other.Location - Location) * ActorBumpForce;
}

function Activate()
{
	bHidden = false;
}

function vector AdjustMotion(vector OldLocation, out pawn Driver)
{
	local Vector result;
	local Vector tresult;
	local Vector unused;
	local Vector halp;

	halp = OldLocation - Location * Acceleration;
	halp.Z = OldLocation.Z;

	Trace(result, unused, OldLocation + halp, Location, false);
	result -= OldLocation;

	if ( VSize(result) > TopSpeed )
		result = Normal(result) * TopSpeed;

	SetLocation(OldLocation);

	return result;
}

function JoinVehicle(Pawn Entering)
{
	if ( PeopleInside > MaxPassengers )
		return;

	PeopleInside++;

	if ( PeopleInside < 2 )
		DriverPawn = Entering;

	else
		PassengerPawns[PeopleInside - 2] = Entering;
}

function LeaveVehicle(byte Index)
{
	local int i;

	if ( Index == 0 )
	{
		DriverPawn = None;
		PeopleInside--;
		for (i = 0; i < 64; i++)
			if ( PassengerPawns[i] != None )
				PassengerPawns[i] = None;
	}
	else if ( Index < 64 )
	{
		for ( i = Index--; i < 63; i++ )
		{
			if ( PassengerPawns[i++] != None )
				PassengerPawns[i] = PassengerPawns[i++];
			else
				return;
		}
	}
}

function PickupFunction(Pawn Other)
{
	if ( !IsInState('Pickup') )
		return;

	if ( PeopleInside < 1 )
	{
		DriverPawn = Other;
		PeopleInside++;	
		GoToState('Activated');
	}
}

simulated function Tick(float TimeDelta)
{
	local vector OldLocation;
	local int i;
	local Pawn Passenger;

	if ( PeopleInside > 64 )
		PeopleInside = 64;

	if ( ( DriverPawn == None || DriverPawn.IsInState('Dying') ) && !IsInState('Pickup') )
		GoToState('DestroyedVehicle');

	if ( PeopleInside < 1 || !IsInState('Activated') )
		return;

	if ( VehicleHealth < 1 )
	{
		Spawn(class'ExplosionChain', self, '__vehicle_blast__', Location + (BlastOffset * (VRand() * 2))).Trigger(self, DriverPawn);
		GoToState('Destroyed');
	}

	OldLocation = Location;

	if ( DriverPawn != None )
		SetLocation(DriverPawn.Location - DriverOffset);

	SetLocation(OldLocation + AdjustMotion(OldLocation, DriverPawn));

	DriverPawn.SetLocation(Location + DriverOffset);
	
	for ( i = 0; i < 63; i++ )
	{
		Passenger = PassengerPawns[i];
		if ( Passenger != None )
			Passenger.SetLocation(Location + PassengerOffsets[i]);
	}
}

State DestroyedVehicle
{
	function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType);
	function Tick(float TimeDelta);
	function PickupFunction(Pawn Other);
	function Touch(Actor Other)
	{
		if ( Pawn(Other) != None )
		{
			Pawn(Other).Health -= 1;
			if ( Pawn(Other).Health < 1 )
				Other.GoToState('Dying');
		}
	}

	Begin:
		OldTexture = Texture;
		Texture = DestroyedTexture;

		Sleep(RespawnTime);

		Texture = OldTexture;
		OldTexture = None;
		GoToState('Pickup');
}

State Pickup
{
	Begin:
		VehicleHealth = StartingVehicleHealth;
}
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
OjitroC
Godlike
Posts: 3630
Joined: Sat Sep 12, 2015 8:46 pm

Re: UT99Vehicle: Overhaul of VehiclePawn from old GusPack

Post by OjitroC »

Just a thought - have you looked at the code of other vehicles? Like the hovertank and hovercar found in
Hovervehicles.u
(651.39 KiB) Downloaded 98 times
There are others but this is just one example.
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: UT99Vehicle: Overhaul of VehiclePawn from old GusPack

Post by Gustavo6046 »

I made the ability of doing custom Controller classes to control the motion of the vehicle!

UT99Vehicle:

Code: Select all

//=============================================================================
// UT99Vehicle.
//=============================================================================
class UT99Vehicle expands Pickup;

var(Vehicle)	float							Speed;
var(Vehicle)	Vector							DriverOffset;
var(Vehicle)	Vector							PassengerOffsets[63];
var(Vehicle)	float							VehicleHealth;
var(Vehicle)	bool							bTeamGame;
var(Vehicle)	float							ActorBumpForce;
var(Vehicle)	int								MyTeam;
var(Vehicle)	bool							bSetTeamToDriverTeam;
var(Vehicle)	int								PawnBumpDamage;
var(Vehicle)	float							Weight;
var(Vehicle)	Vector							BlastOffset;
var(Vehicle)	string							KillMessage[3];
var(Vehicle)	int								MaxPassengers;
var(Vehicle)	Texture							DestroyedTexture;
var(Vehicle)	class<Actor>					DestroyedEffect;
var(Vehicle)	class<Actor>					VehicleTrail;
var				byte							PeopleInside;
var				Pawn							PassengerPawns[63];
var				Pawn							DriverPawn;
var				Texture							OldTexture;
var				float							StartingHealth;
var(Vehicle)	Class<VehicleMotionController>	MotionController;

function PreBeginPlay()
{
	StartingHealth = VehicleHealth;
}

static function vector NewVector(float X, float Y, float Z)
{
	local Vector V;

	V.X = X;
	V.Y = Y;
	V.Z = Z;

	return V;
}

function bool HasPawnInside(Pawn Other)
{
	local int i;

	for (i = 0; i < PeopleInside - 1; i++)
		if ( DriverPawn == Other || PassengerPawns[i] == Other )
			return True;

	return False;
}

function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType)
{
	if ( DamageType == 'AntiVehicle' )
		self.Velocity += Momentum / (Weight / 2);
	else self.Velocity += Momentum / Weight;

	VehicleHealth -= Health;

	if ( VehicleHealth < 0 )
		GoToState('DestroyedVehicle');
}

simulated function Touch(Actor Other)
{

	if ( Pawn(Other) != None && PeopleInside > 1 && !HasPawnInside(Pawn(Other)) )
	{
		if
		(
				TeamGamePlus(Level.Game) != None
			&&	(
					(
						!bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo != None
					&&	Pawn(Other).PlayerReplicationInfo.Team == MyTeam
					)
				||	(
						bSetTeamToDriverTeam
					&&	Pawn(Other).PlayerReplicationInfo != None
					&&	DriverPawn.PlayerReplicationInfo != None
					&&	Pawn(Other).PlayerReplicationInfo.Team == DriverPawn.PlayerReplicationInfo.Team
					)
				)
			&& Pawn(Other).PlayerReplicationInfo.Team != 255
			&& PeopleInside <= MaxPassengers
		)
			JoinVehicle(Pawn(Other));

		else
		{
			Other.TakeDamage(PawnBumpDamage, DriverPawn, Location, Velocity, 'vehiclebump');
			Other.Velocity = (Other.Location - Location) * ActorBumpForce;

			if ( Pawn(Other).Health < 1 )
			{
				Pawn(Other).GoToState('Dying');
				BroadcastMessage(KillMessage[0] @ DriverPawn.Name @ KillMessage[1] @ Pawn(Other).Name @ KillMessage[2], false, 'deathmessage');
			}
		}	
	}
	else if ( Projectile(Other) != None )
	{
		TakeDamage(Projectile(Other).Damage, None, Other.Location, Self.Location - Other.Location, Projectile(Other).MyDamageType);
		Projectile(Other).Touch(Self);
	}

	else if ( Other.bBlockActors )
		if ( Other.bMovable )
			Other.Velocity = (Other.Location - Location) * ActorBumpForce;
		else
			Bump(Other);
}

function Bump(Actor Other)
{
	Move(-(Other.Location - Location));
}

function Activate()
{
	bHidden = false;
}

function JoinVehicle(Pawn Entering)
{
	if ( PeopleInside > MaxPassengers )
		return;

	PeopleInside++;

	if ( PeopleInside < 1 )
		DriverPawn = Entering;

	else
		PassengerPawns[PeopleInside - 2] = Entering;
}

function LeaveVehicle(byte Index)
{
	local int i;

	if ( Index == 0 )
	{
		DriverPawn = None;
		PeopleInside--;
		for (i = 0; i < 64; i++)
			if ( PassengerPawns[i] != None )
				PassengerPawns[i] = None;
	}
	else if ( Index < 64 )
	{
		for ( i = Index--; i < 63; i++ )
		{
			if ( PassengerPawns[i++] != None )
				PassengerPawns[i] = PassengerPawns[i++];
			else
				return;
		}
	}
}

function PickupFunction(Pawn Other)
{
	if ( !IsInState('Pickup') )
		return;

	if ( PeopleInside < 1 )
	{
		DriverPawn = Other;
		PeopleInside++;	
		GoToState('Activated');
	}
}

simulated function Tick(float TimeDelta)
{
	local vector DriverDelta;
	local int i;
	local Pawn Passenger;

	if ( VehicleTrail != None )
		Spawn(VehicleTrail, self);
	
	if ( ( DriverPawn == None || DriverPawn.IsInState('Dying') ) && !IsInState('Pickup') && !IsInState('DestroyedVehicle') )
		GoToState('DestroyedVehicle');

	if ( PeopleInside < 1 || !IsInState('Activated') )
		return;

	if ( VehicleHealth < 1 )
	{
		Spawn(class'ExplosionChain', self, '__vehicle_blast__', Location + (BlastOffset * (VRand() * 2))).Trigger(self, DriverPawn);
		GoToState('DestroyedVehicle');
	}

	DriverDelta = DriverPawn.Location - (Location + DriverOffset);

	Move(MotionController.static.AdjustMotion(DriverDelta, TimeDelta, Speed, DriverPawn, PassengerPawns) * TimeDelta);

	if ( DriverPawn == None )
	{
		return;
		GoToState('DestroyedVehicle');
	}

	DriverPawn.SetLocation(Location + DriverOffset);
	
	for ( i = 0; i < PeopleInside - 1; i++ )
	{
		Passenger = PassengerPawns[i];
		if ( Passenger != None )
			Passenger.SetLocation(Location + PassengerOffsets[i]);
	}
}

State DestroyedVehicle
{
	function TakeDamage(int Health, Pawn EventInstigator, vector HitLocation, vector Momentum, name DamageType);
	function Tick(float TimeDelta);
	function PickupFunction(Pawn Other);
	function Touch(Actor Other)
	{
		if ( Pawn(Other) != None )
		{
			Pawn(Other).Health -= 1;
			if ( Pawn(Other).Health < 1 )
				Other.GoToState('Dying');
		}
	}

	Begin:
		if ( DestroyedEffect != None )
			Spawn(DestroyedEffect, self).Trigger(self, DriverPawn);

		OldTexture = Texture;
		Texture = DestroyedTexture;

		Sleep(RespawnTime);

		Texture = OldTexture;
		OldTexture = None;
		GoToState('Pickup');
}

State Pickup
{
	Begin:
		VehicleHealth = StartingHealth;
}
VehicleMotionController:

Code: Select all

//=============================================================================
// VehicleMotionController.
//=============================================================================
class VehicleMotionController expands Info;

static function vector AdjustMotion(vector TriggerDelta, float TimeDelta, optional float VelocityScale, optional out Pawn Driver, optional out Pawn Passengers[63])
{
	local int i;

	if ( TriggerDelta.Z > 300 * TimeDelta )
	{
		Driver = None;
		for (i = 0; i < 64; i++)
			Passengers[i] = None;

		return vect(0, 0, 0);
	}
	
	return class'UT99Vehicle'.static.NewVector(TriggerDelta.X * VelocityScale, TriggerDelta.Y * VelocityScale, (TriggerDelta.Z * VelocityScale) / 1.825);
}
The vehicle now does many things it's expected to, BUT it does NOT accelerate your movement, even with a theoretically correct code, AND it does not protect the driver from being attacked!

EDIT: Oops, almost forgot to reply to a reply! :P
OjitroC wrote:
OjitroC wrote:Just a thought - have you looked at the code of other vehicles? Like the hovertank and hovercar found in
Hovervehicles.u
There are others but this is just one example.
I will check it out.
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
Post Reply