logo
Main

Forums

Downloads

Unreal-Netiquette

Donate for Oldunreal:
Donate

borderline

Links to our wiki:
Wiki

Walkthrough

Links

Tutorials

Unreal Reference

Usermaps

borderline

Contact us:
Submit News
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic FellOutOfWorld() should be restricted according to the authority on the local machine (Read 163 times)
Masterkent
Developer Team
Offline



Posts: 848
Location: Russia
Joined: Apr 5th, 2013
Gender: Male
FellOutOfWorld() should be restricted according to the authority on the local machine
Aug 11th, 2017 at 9:28pm
Print Post  
[The first part of the proposal was removed as irrelevant]

Function Pawn.FellOutOfWorld

Code
Select All
event FellOutOfWorld()
{
	if (PlayerReplicationInfo != none)
	{
		Health = -1;
		SetPhysics(PHYS_None);
		Died(None, 'fell', Location);
	}
	else
	{
		Died(None, 'fell', Location);
		Destroy();
	}
} 


should not try to kill a Pawn whose Role is ROLE_AutonomousProxy; only the machine where the actor has Role == ROLE_Authority should be allowed to decide whether the pawn dies or not, so the given function definition should be changed to

Code
Select All
event FellOutOfWorld()
{
	if (Role != ROLE_Authority)
		return;
	if (PlayerReplicationInfo != none)
	{
		Health = -1;
		SetPhysics(PHYS_None);
		Died(None, 'fell', Location);
	}
	else
	{
		Died(None, 'fell', Location);
		Destroy();
	}
} 

« Last Edit: Aug 12th, 2017 at 10:36am by Masterkent »  
Back to top
 
IP Logged
 
.:..:
Board Moderator
Developer Team
*****
Offline



Posts: 1414
Location: Finland
Joined: Aug 16th, 2005
Gender: Male
Re: FellOutOfWorld() should be restricted according to the authority on the local machine
Reply #1 - Aug 12th, 2017 at 5:57am
Print Post  
DestroyActor does already ignore destroy calls on non-authority actors in client side, so Actor one is fine as it is.

Code (C++)
Select All
		// Can't kill if wrong role.
		if( ThisActor->Role!=ROLE_Authority && !bNetForce && !ThisActor->bNetTemporary )
			return 0; 

  

Shivaxi wrote on Jul 25th, 2013 at 12:50pm:
...and now im stuck trying to fix everything you broke for the next 227 release xD Tongue

(ಠ_ಠ)
Back to top
ICQYIM  
IP Logged
 
Masterkent
Developer Team
Offline



Posts: 848
Location: Russia
Joined: Apr 5th, 2013
Gender: Male
Re: FellOutOfWorld() should be restricted according to the authority on the local machine
Reply #2 - Aug 12th, 2017 at 10:34am
Print Post  
.:..: wrote on Aug 12th, 2017 at 5:57am:
DestroyActor does already ignore destroy calls on non-authority actors in client side, so Actor one is fine as it is.

Code (C++)
Select All
		// Can't kill if wrong role.
		if( ThisActor->Role!=ROLE_Authority && !bNetForce && !ThisActor->bNetTemporary )
			return 0; 


That's good. I didn't actually check if Destroy succeeds, but a possible client-side modification of Health in Pawn.FellOutOfWorld can really be observed. E.g. when you cancel the ghost mode being inside a wall, the server-side mod may prevent your death, but your client will set your Health to -1 anyway, and the HUD may display wrong Health value until the server replicates a new value when actual Health is changed.
  
Back to top
 
IP Logged
 
Masterkent
Developer Team
Offline



Posts: 848
Location: Russia
Joined: Apr 5th, 2013
Gender: Male
Re: FellOutOfWorld() should be restricted according to the authority on the local machine
Reply #3 - Aug 12th, 2017 at 12:28pm
Print Post  
Another tweak can be done as a part of resolution of the issue #17: in case if death was prevented using GameRules.PreventDeath

Code
Select All
function Died(pawn Killer, name damageType, vector HitLocation)
{
	local pawn OtherPawn;
	local GameRules GR;

	if ( bDeleteMe || Level.NetMode==NM_Client )
		return; //already destroyed

	if ( Level.Game!=None && Level.Game.GameRules!=None )
	{
		for ( GR=Level.Game.GameRules; GR!=None; GR=GR.NextRules )
			if ( GR.bHandleDeaths && GR.PreventDeath(Self,Killer,damageType) )
			{
				Health = Max(1,Health);
				Return;
			} 


the original value of Health should be restored for players and destruction should not take place for non-players:

Code
Select All
event FellOutOfWorld()
{
+	local int OldHealth;
+
+	if (Role != ROLE_Authority)
+		return;
	if (PlayerReplicationInfo != none)
	{
-		Health = -1;
-		SetPhysics(PHYS_None);
-		Died(None, 'fell', Location);
+		if (Health > 0)
+		{
+			OldHealth = Health;
+			Health = -1;
+			SetPhysics(PHYS_None);
+			Died(None, 'fell', Location);
+			if (Health == 1)
+				Health = OldHealth;
+		}
+		else
+			SetPhysics(PHYS_None);
	}
-	else
+	else if (Health > 0)
	{
		Died(None, 'fell', Location);
-		Destroy();
+		if (Health <= 0)
+			Destroy();
	}
} 


and I think that we can omit an attempt to kill the pawn if it's already dead (Health is less than or equal to zero).
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint
Bookmarks: del.icio.us Digg Facebook Google Google+ Linked in reddit StumbleUpon Twitter Yahoo