Hello,
I am currently facing an issue where I require script which can end the map when either all players are dead, or when a certain object is destroyed. I have managed to solve the latter problem, but I still struggle with the first one. Can anyone help me with this problem?
This forum is locked and will eventually go offline. If you have feedback to share you can find us in our Discord channel "MythoLogic Interactive" https://discord.gg/nECKnbT7gk
Forum rules
Forum rules
Detecting when players are alive or dead.
Forum rules
By using the forum you agree to the following rules.
By using the forum you agree to the following rules.
- JakSparro98
- Superfighter

- Posts: 530
- Joined: Fri Jul 15, 2016 7:56 pm
- Started SFD: PreAlpha 1.0.5
- Location: Rome, Italy
- Gender:
- Age: 27
it's pretty simple to detect player state with the IsDead command that returns true if the player is dead (of course) and false when is alive.
You only need to execute this piece of code to check that and end the round.
Remember that the script doesn't count the bots as players, if you want also that when all bots are dead the round is ended change the 11th line if(!temp.IsBot && !temp.IsDead) to if(!temp.IsDead)
You only need to execute this piece of code to check that and end the round.
Code: Select all
Events.UpdateCallback m_updateEvent = null;
public void OnStartup() {
m_updateEvent = Events.UpdateCallback.Start(OnUpdate, 0);
}
public void OnUpdate(float elapsed) {
int PlayersAlive=0;
foreach(IPlayer temp in Game.GetPlayers())
{
if(!temp.IsBot && !temp.IsDead)
PlayersAlive++;
}
if(PlayersAlive<1)
Game.SetGameOver("some text");
}
0 x
