Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Tiberian Technologies / Blackhand Studios » Tiberian Technologies Forum » Multiple Respawns Causes Bug
Re: Multiple Respawns Causes Bug [message #479276 is a reply to message #479262] Wed, 13 February 2013 11:31 Go to previous message
Troll King is currently offline  Troll King
Messages: 56
Registered: June 2012
Location: Netherlands
Karma:
Recruit
EXACT CODE:
Console_Output("spawning new obj\n");
	// Invalid obj, not enabled or not alive.
	if(!Enabled || !obj || Commands->Get_Health(obj) <= 0 || !obj->As_SoldierGameObj())
		return;

	Console_Output("1\n");

	cPlayer *PData = Find_Player(Get_Player_ID(obj));
	// Somehow the player does not have any WW player data.
	if(!PData)
		return;
	Console_Output("2\n");
	bool NewPlayer = false;
	TC_Player *Player = Find_TC_Player(obj);
	// Player data does not exist yet.
	if(!Player)
	{
		NewPlayer = true;
		TC_Player *NewPlayer = new TC_Player(PData->Get_Id());
		NewPlayer->Set_Spawns(InitialSpawns);
		Players.Add(NewPlayer);
		Player = NewPlayer;
	}

	if(!Player->Has_Collisions_Enabled())
	{
		Player->Toggle_Collisions_Enabled(true);
		Player->Respawn_Me();
		return;
	}
	Console_Output("3\n");
	// Invalid team.
	int PlayerType = Commands->Get_Player_Type(obj); // Must be done via Commands, becouse elseway we get an access violation.
	if(PlayerType != 1 && Player->Get_Spawns() > 0)
	{
		Commands->Attach_Script(obj, "TC_Change_Team_Fix", "1");
		return;
	}
	Console_Output("4\n");
	// Change the spawns if we should.
	if(!NewPlayer)
		Player->Decrease_Spawns();

	if(PlayerType != -2 && Player->Get_Spawns() <= 0)
	{
		Commands->Attach_Script(obj, "TC_Change_Team_Fix", "-2");
		return;
	}
	Console_Output("5\n");
	// Only display a message when we're not in a cinematic.
	if(!IsInCinematic)
	{
		StringClass Str;
		// Player still has spawns available.
		if(Player->Get_Spawns() > 0)
		{
			Str.Format("%s, you have %d spawn(s) left!", Get_Player_Name(obj), Player->Get_Spawns());
			Send_Message_Player(obj, 0, 255, 0, Str.Peek_Buffer());
		}
		else
		{
			Str.Format("%s, you have no spawns left!", Get_Player_Name(obj));
			Send_Message_Player(obj, 255, 0, 0, Str.Peek_Buffer());
			Send_Message_Player(obj, 255, 0, 0, "You can only respawn if somebody picks up a spawn powerup.");
		}
	}
	else if(CinematicStarted)
	{
		StringClass Str;
		Str.Format("%s, there is currently a cinematic playing, please wait.", Get_Player_Name(obj));
		Send_Message_Player(obj, 255, 255, 0, Str.Peek_Buffer());
	}

	// Check if we should make the screen black
	Set_Screen_Fade_Color_Player(obj, 0,0,0,0.1f);
	Set_Screen_Fade_Opacity_Player(obj, IsScreenHidden ? 1.0f : 0.0f, 0.1f);

	// Check if we should render the player.
	bool Render = !IsInCinematic;
	if(Player->Get_Spawns() <= 0)
		Render = false;

	// Default object stuff, doesn't matter if we should render or not.
	if(NewPlayer || Player->Is_Marked_As_Leaver())
	{
		Player->Mark_As_Leaver(false);
		Set_Background_Music_Player(obj, BackgroundMusic.Peek_Buffer());
	}

	Set_Max_Health(obj, Health);
	Commands->Set_Health(obj, Health);
	Set_Max_Shield_Strength(obj, Shield);
	Commands->Set_Shield_Strength(obj, Shield);
	Set_Skin(obj, "SkinFlesh");
	Commands->Set_Shield_Type(obj, "ShieldKevlar");
	Commands->Clear_Weapons(obj);
	//////////////////////////////////////////////////////////////////

	// Stuff that is dependand on rendering.
	Commands->Set_Model(obj, Render ? SpawnModel : "null");
	Enable_HUD_Player(obj, Render);
	Commands->Set_Is_Visible(obj, Render);

	// Check if we should be able to fly.
	HumanStateClass::HumanStateType State = obj->As_SoldierGameObj()->Get_State();
	if((State == HumanStateClass::DEBUG_FLY && !IsInCinematic && Render) || (State != HumanStateClass::DEBUG_FLY && IsInCinematic) || (State != HumanStateClass::DEBUG_FLY && !Render))
		Toggle_Fly_Mode(obj);

	if(Render)
	{
		int WeaponCount = WeaponList.Count();
		for(int x = 0; x < WeaponCount; x++)
		{
			StringClass *CurrentWeapon = WeaponList[x];
			if(CurrentWeapon)
				Commands->Give_PowerUp(obj, CurrentWeapon->Peek_Buffer(), false);
		}
	}
	else
	{
		obj->As_SoldierGameObj()->Set_Max_Speed(15.0f);
		Commands->Disable_Physical_Collisions(obj);
		Player->Toggle_Collisions_Enabled(false);
	}
	
	////////////////////////////////////////////////////////////////

	// Stuff that should only be toggled when we are in a cinematic.
	Commands->Control_Enable(obj, !IsInCinematic);


The script Netcode_Fix is to try to do the teamchange in the script created event instead, but does not appear to work properly aswell


Also Known As: Neijwiert
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PT lag
Next Topic: Fix Homing logic
Goto Forum:
  


Current Time: Tue Oct 01 00:14:49 MST 2024

Total time taken to generate the page: 0.00912 seconds