Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

delete corpses & gibs after few seconds

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
The_JOKER
Fighter
Fighter
Posts: 38
Joined: Mon Jul 18, 2016 2:35 am
Title: I'm Korean JOKER :)
SFD Account: JOKER_Korea
SFD Alias: JOKER
Started SFD: April 2016
Location: South Korea
Gender:
Age: 23
Contact:

delete corpses & gibs after few seconds

Post by The_JOKER » Thu Aug 17, 2017 11:26 am

since corpses and gibs are making the map buggy,
is it able to delete after few seconds with script?
0 x

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Thu Aug 17, 2017 1:48 pm

The_JOKER wrote:
Thu Aug 17, 2017 11:26 am
since corpses and gibs are making the map buggy,
is it able to delete after few seconds with script?
Let me guess, the previous script you requested to me doesn't remove corpses? I knew that gibbed parts aren't removed, I can include some script to your current respawn system to fix this.
0 x

User avatar
The_JOKER
Fighter
Fighter
Posts: 38
Joined: Mon Jul 18, 2016 2:35 am
Title: I'm Korean JOKER :)
SFD Account: JOKER_Korea
SFD Alias: JOKER
Started SFD: April 2016
Location: South Korea
Gender:
Age: 23
Contact:

Post by The_JOKER » Thu Aug 17, 2017 2:32 pm

JakSparro98 wrote:
Thu Aug 17, 2017 1:48 pm
The_JOKER wrote:
Thu Aug 17, 2017 11:26 am
since corpses and gibs are making the map buggy,
is it able to delete after few seconds with script?
Let me guess, the previous script you requested to me doesn't remove corpses? I knew that gibbed parts aren't removed, I can include some script to your current respawn system to fix this.
no, It does remove player's corpses, but I want to delete Bot's Corpses and Gibs after few seconds
I'm making D-Day map and u know, there are toooo many corpses.

give me without respawn script unless they conflict together.
0 x

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Thu Aug 17, 2017 3:19 pm

The_JOKER wrote:
Thu Aug 17, 2017 2:32 pm
no, It does remove player's corpses, but I want to delete Bot's Corpses and Gibs after few seconds
I'm making D-Day map and u know, there are toooo many corpses.

give me without respawn script unless they conflict together.
You only need to add this piece of code at bottom of the script page:

Code: Select all

public void CleanCorpses(TriggerArgs arg)
{
foreach(IPlayer pl in Game.GetPlayers())
{
if (pl.IsDead && pl.IsBot)
		pl.Remove();
	
}	

string[] IDs={"giblet00","giblet01","giblet02","giblet03","giblet04"};

foreach(IObject ToRemove in Game.GetObjectsByName(IDs))
ToRemove.Remove();
	
}
This will dispose all the gibs and bots corpses only.
Place a TimerTrigger with method CleanCorpses, finally a time interval you like; make sure the timer is looped.
0 x

User avatar
The_JOKER
Fighter
Fighter
Posts: 38
Joined: Mon Jul 18, 2016 2:35 am
Title: I'm Korean JOKER :)
SFD Account: JOKER_Korea
SFD Alias: JOKER
Started SFD: April 2016
Location: South Korea
Gender:
Age: 23
Contact:

Post by The_JOKER » Fri Aug 18, 2017 2:20 am

JakSparro98 wrote:
Thu Aug 17, 2017 3:19 pm
You only need to add this piece of code at bottom of the script page:

Code: Select all

public void CleanCorpses(TriggerArgs arg)
{
foreach(IPlayer pl in Game.GetPlayers())
{
if (pl.IsDead && pl.IsBot)
		pl.Remove();
	
}	

string[] IDs={"giblet00","giblet01","giblet02","giblet03","giblet04"};

foreach(IObject ToRemove in Game.GetObjectsByName(IDs))
ToRemove.Remove();
	
}
This will dispose all the gibs and bots corpses only.
Place a TimerTrigger with method CleanCorpses, finally a time interval you like; make sure the timer is looped.
It's Not exactly what I expected, but the problem is solved. thanks a lot
0 x

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Fri Aug 18, 2017 1:04 pm

The_JOKER wrote:
Fri Aug 18, 2017 2:20 am
It's Not exactly what I expected, but the problem is solved. thanks a lot
Maybe you expected that corpses and gibs are destroyed in x second from the moment they are created? If you like this other way of disposing objects I can change that, you decide.
0 x

User avatar
The_JOKER
Fighter
Fighter
Posts: 38
Joined: Mon Jul 18, 2016 2:35 am
Title: I'm Korean JOKER :)
SFD Account: JOKER_Korea
SFD Alias: JOKER
Started SFD: April 2016
Location: South Korea
Gender:
Age: 23
Contact:

Post by The_JOKER » Fri Aug 18, 2017 2:10 pm

JakSparro98 wrote:
Fri Aug 18, 2017 1:04 pm
Maybe you expected that corpses and gibs are destroyed in x second from the moment they are created? If you like this other way of disposing objects I can change that, you decide.
yes please
1 x

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Fri Aug 18, 2017 3:58 pm

The_JOKER wrote:
Fri Aug 18, 2017 2:10 pm
yes please
Ok, so, replace the last piece of code I gave to you to clean bot corpses and giblets with this:

Code: Select all

class CleanItem
{
public static List<CleanItem> CleanList = new List<CleanItem>();
public IObject item;
public float Time=0;
	
	public CleanItem(IObject ItemToRemove, float _Time)
	{
	Time=_Time;
	item=ItemToRemove;
	CleanList.Add(this);
	}	
	
	public void Remove()
	{
	CleanList.Remove(this);
	item.Remove();		
	}	
}

const int CleanInterval=3; //in seconds

public void CleanCorpses(TriggerArgs arg)
{CleanItem itm;

foreach(IPlayer pl in Game.GetPlayers())
if (pl.IsDead && pl.IsBot && CleanItem.CleanList.Find(tmp => tmp.item.Equals(pl))==null)
		itm= new CleanItem(pl,Game.TotalElapsedGameTime);

string[] IDs={"giblet00","giblet01","giblet02","giblet03","giblet04"};

foreach(IObject ToRemove in Game.GetObjectsByName(IDs))
if(CleanItem.CleanList.Find(tmp => tmp.item.Equals(ToRemove))==null)
itm= new CleanItem(ToRemove,Game.TotalElapsedGameTime);

for(int i=0; i<CleanItem.CleanList.Count;i++)
if(IsElapsed(CleanItem.CleanList[i].Time,CleanInterval*1000))
	CleanItem.CleanList[i].Remove();	
}
Then keep the timer that activates the method but make it to repeat after 0 seconds interval (istantly).
You can modify the time to clean with CleanInterval.
0 x

User avatar
The_JOKER
Fighter
Fighter
Posts: 38
Joined: Mon Jul 18, 2016 2:35 am
Title: I'm Korean JOKER :)
SFD Account: JOKER_Korea
SFD Alias: JOKER
Started SFD: April 2016
Location: South Korea
Gender:
Age: 23
Contact:

Post by The_JOKER » Sat Aug 19, 2017 1:10 pm

JakSparro98 wrote:
Fri Aug 18, 2017 3:58 pm
Then keep the timer that activates the method but make it to repeat after 0 seconds interval (istantly).
You can modify the time to clean with CleanInterval.
Working good, Thanks
0 x

User avatar
Su20ma
Fighter
Fighter
Posts: 15
Joined: Thu Jul 20, 2017 9:19 pm
Title: BONELESS
SFD Account: Su20ma
Started SFD: Alpha 1.3.4c
Location: SA
Gender:
Age: 23

Post by Su20ma » Fri Sep 01, 2017 12:01 am

so you gonna release the script or we just gonna copy this
0 x

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Fri Sep 01, 2017 12:27 am

Su20ma wrote:
Fri Sep 01, 2017 12:01 am
so you gonna release the script or we just gonna copy this
If you want to only clear gibs you need to copy the script code I posted previously.
I split the script in two threads because I was no idea how Joker wanted the script to work, the complete script was supposed to respawn two teams, and is this:

Code: Select all

const int RespawnSeconds = 15;
const int CleanInterval=3; //seconds to clean gibs

static List < DeadPlayer > DPlayersList = new List < DeadPlayer > ();
static Vector2 Team1SpawnPoint = Vector2.Zero;
static Vector2 Team2SpawnPoint = Vector2.Zero;
Events.PlayerDeathCallback m_playerDeathEvent = null;
Events.UpdateCallback m_updateEvent = null;

class DeadPlayer {
 IProfile P_profile;
 public IUser P_user;
 IPlayer P_body;
 public float P_DeathTime = 0f;
 PlayerTeam P_team;
 
 public DeadPlayer(IPlayer player) {
  P_profile = player.GetProfile();
  P_user = player.GetUser();
  P_DeathTime = Game.TotalElapsedGameTime;
  P_body = player;
  P_team = player.GetTeam();
 }

 public void Respawn() {
  IPlayer pl = Game.CreatePlayer(Vector2.Zero);
 
   switch(this.P_team)
 {
	 case PlayerTeam.Team1:
	 pl.SetWorldPosition(Team1SpawnPoint);
		break;
	
	case PlayerTeam.Team2:
	pl.SetWorldPosition(Team2SpawnPoint);
		break;
	 
 }
  pl.SetUser(this.P_user);
  pl.SetProfile(this.P_profile);
  pl.SetTeam(this.P_team);
  this.P_body.Remove();
  DPlayersList.Remove(this);
 }
}

public void OnStartup() {
 m_playerDeathEvent = Events.PlayerDeathCallback.Start(OnPlayerDeath);
 m_updateEvent = Events.UpdateCallback.Start(OnUpdate, 0);
}

public void OnPlayerDeath(IPlayer player) {
 if (!player.IsBot && DPlayersList.FirstOrDefault(s => s.P_user.UserID == player.GetUser().UserID) == null) {
  DeadPlayer pl = new DeadPlayer(player);
  DPlayersList.Add(pl);
 }
}

public void OnUpdate(float elapsed) {
 for (int i = 0; i < DPlayersList.Count; i++)
  if (IsElapsed(DPlayersList[i].P_DeathTime, RespawnSeconds * 1000))
   DPlayersList[i].Respawn();
}

public void SetSpawnPoint(TriggerArgs arg) {
 switch(((IObject) arg.Caller).CustomID)
 {
	 case "Team1SpawnPoint":
	 Team1SpawnPoint = ((IObject) arg.Caller).GetWorldPosition();
		break;
	
	case "Team2SpawnPoint":
	Team2SpawnPoint = ((IObject) arg.Caller).GetWorldPosition();
		break;
	 
 }
 
}

public static bool IsElapsed(float TimeStarted, float TimeToElapse) {
 if ((float)(Game.TotalElapsedGameTime - TimeStarted) >= TimeToElapse)
  return true;
 else
  return false;
}

class CleanItem
{
public static List<CleanItem> CleanList = new List<CleanItem>();
public IObject item;
public float Time=0;
	
	public CleanItem(IObject ItemToRemove, float _Time)
	{
	Time=_Time;
	item=ItemToRemove;
	CleanList.Add(this);
	}	
	
	public void Remove()
	{
	CleanList.Remove(this);
	item.Remove();		
	}	
}



public void CleanCorpses(TriggerArgs arg)
{CleanItem itm;

foreach(IPlayer pl in Game.GetPlayers())
if (pl.IsDead && pl.IsBot && CleanItem.CleanList.Find(tmp => tmp.item.Equals(pl))==null)
		itm= new CleanItem(pl,Game.TotalElapsedGameTime);

string[] IDs={"giblet00","giblet01","giblet02","giblet03","giblet04"};

foreach(IObject ToRemove in Game.GetObjectsByName(IDs))
if(CleanItem.CleanList.Find(tmp => tmp.item.Equals(ToRemove))==null)
itm= new CleanItem(ToRemove,Game.TotalElapsedGameTime);

for(int i=0; i<CleanItem.CleanList.Count;i++)
if(IsElapsed(CleanItem.CleanList[i].Time,CleanInterval*1000))
	CleanItem.CleanList[i].Remove();	
}
To know how it works you need to see this discussion too, but only if you want also the respawn system.
0 x

Post Reply