I'd like to have a DealDamage() method in IObject similar to the one in IPlayer. Right now when dealing damage on an object, I have to check if the object is player, then call the DealDamage() if it is and call SetHealth(o.GetHealth() - damage) if it's not, which is a bit cumbersome. Adding DealDamage() in the base class allow me to simlify the code in this case, also it's easier to read than SetHealth(o.GetHealth() - damage)
Some IObjects is indestructible so you may want to return true or false to indicate if you can successfully damage that object.
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.
New to the forum? Say hello in this topic! Also make sure to read the rules.
Add IObject.DealDamage()
Forum rules
By using the forum you agree to the following rules.
By using the forum you agree to the following rules.
-
- Superfighter
- Posts: 97
- Joined: Thu Feb 07, 2019 4:36 am
- Danger Ross
- Superfighter
- Posts: 154
- Joined: Thu Mar 31, 2016 12:56 am
- Title: Dangerous
- SFD Alias: Danger Ross
- Started SFD: 14 june 2012 (launch day)
- Location: California
- Gender:
- Age: 23
This can also help with interacting with the ObjectDamageCallback. There's no way to artificially trigger that event at the moment, so it makes some things harder to integrate.
Would love to have a method that simulates object damage in a similar way how DealDamage simulates player damage.
Would love to have a method that simulates object damage in a similar way how DealDamage simulates player damage.
0 x
sorry bucko, you can't punch with swords
- Gurt
- Lead Programmer
- Posts: 1884
- Joined: Sun Feb 28, 2016 3:22 pm
- Title: Lead programmer
- Started SFD: Made it!
- Location: Sweden
- Gender:
- Age: 34
Fixed after v.1.3.5:
Moved IPlayer.DealDamage to IObject.DealDamage and added a Destructable property as used internally by our code.
IObject:
Moved IPlayer.DealDamage to IObject.DealDamage and added a Destructable property as used internally by our code.
IObject:
Code: Select all
/// <summary>
/// Gets if this object is destructable (initial health > 0). This does not account for any possible modifiers. Always returns true for players.
/// </summary>
bool IObject.Destructable { get; }
/// <summary>
/// Forcefully deals damage to the object.
/// The object will be destoryed if it's destructable and health reaches 0.
/// Runs the ObjectDamageCallback event if registered with ObjectDamageType.Other if not currently running for the specific IObject to avoid recursive traps.
///
/// For IPlayer:
/// Deals misc damage to the player following all the health and death rules for a player.
/// This counts towards TotalOtherDamageTaken.
/// Runs the PlayerDamageCallback and OnPlayerDamageTriggers if they are not currently running. Calling DealDamage inside OnPlayerDamage or OnPlayerDamageTrigger won't trigger the damage event again.
/// This will run OnPlayerDeath triggers and events if the player dies calling this.
/// </summary>
/// <param name="damage">Amount of forced damage to deal (must be positive).</param>
/// <param name="sourceID">(Optional) SourceID of the damage, used by the ObjectDamageCallback event.</param>
void IObject.DealDamage(float damage, int sourceID = 0);
1 x
Gurt