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.

Possible to check if IObject is damaged?

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
Ol1vver
Fighter
Fighter
Posts: 30
Joined: Mon Nov 19, 2018 4:55 pm
SFD Alias: Ol1vver
Started SFD: PreAlpha 1.6
Gender:

Possible to check if IObject is damaged?

Post by Ol1vver » Sat Dec 01, 2018 10:47 pm

Hello,
I am making a boss fight with a giant ragdoll made out of DeadMeat. I need a script that whenever the object "Head1" gets hit, a ScriptTrigger named "BlockBullets" gets activated.
Is that possible?
0 x
Why are you reading my signature?

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

Post by JakSparro98 » Sun Dec 02, 2018 12:29 am

This is what you asked for:

Code: Select all

Events.UpdateCallback m_updateEvent = null;
float m_totalElapsed = 0f;

IObject HitTarget;
IObjectTrigger Trigger;
float StoredHealth = 0;

public void OnStartup() {

 Trigger = (IObjectTrigger) Game.GetSingleObjectByCustomID("BlockBullets");
 HitTarget = (IObject) Game.GetSingleObjectByCustomID("Head1");
 StoredHealth = HitTarget.GetHealth();

 m_updateEvent = Events.UpdateCallback.Start(OnUpdate, 0);
}
public void OnUpdate(float elapsed) {

 if (StoredHealth != HitTarget.GetHealth()) {
  Trigger.Trigger();
  StoredHealth = HitTarget.GetHealth();
 }

}
2 x

Post Reply