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

Detecting when players are alive or dead.

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Locked
User avatar
Relgap
Fighter
Fighter
Posts: 36
Joined: Sun Mar 20, 2016 11:34 am
SFD Alias: (LM) Relgap
Started SFD: 1000 bc
Gender:
Age: 28

Detecting when players are alive or dead.

Post by Relgap » Sat Mar 18, 2017 3:36 pm

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?
0 x
Big memes on the daily

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: 27

Post by JakSparro98 » Sat Mar 18, 2017 6:21 pm

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.

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");
 }
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)
0 x

Locked