Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

How do you damage and repair?

Discussion in 'Modding API' started by erisco, Apr 7, 2015.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. erisco Trainee Engineer

    Messages:
    30
    How do you damage and repair entities in the game? Entities such as armour blocks, reactors, and thrusters.

    I searched this forum for "damage", "weld", "repair", "health", and "hitpoints" and all returned zero results. I also searched the API Docs and found IMySlimBlock which has properties such as AccumulatedDamage but they are readonly.

    Thanks,
    Eric
     
  2. Arcturus Senior Engineer

    Messages:
    1,649
    There are two types of damage in the game, and they work in parallel: integrity, and deformation.

    If you look in components.sbc, you can see that steel plates have <MaxIntegrity>100</MaxIntegrity>. A large ship light armor block that uses 25 steel plates would therefore have 2500 integrity - you just add up the integrities from the components. If you look in ammos.sbc, you will see that a large caliber (gatling) bullet has <ProjectileMassDamage>60</ProjectileMassDamage>. It would therefore take exactly 2500/60 = 42 gatling gun bullets to remove all the integrity and destroy the block. The block can also have partial integrity because not all of the components have been welded.

    Deformation damage is... complicated. To save retyping, I have a thread here: http://forums.keenswh.com/threads/se-physics-deformation-ratio-mass-forces-and-you.7311577/
    Bullets will cause a tiny amount of deformation, but a ship collision will only deform without hurting integrity.

    IMySlimBlock:
    BuildIntegrity = 1 for a new block, 2500 for our example fully-built block
    CurrentDamage = 0 for a block with no integrity damage, and perhaps 120 if we shot it with 2 gatling bullets
    HasDeformation or IsFullIntegrity are true/false and self-explanatory
    Ma:woot:eformation = 0 to 2.5 for a large ship, it is the distance in meters the block has been deformed
    MaxIntegrity = 2500 for our example block. It doesn't change.

    As far as I know, it is read-only, so you can write "damage report" scripts, but not cause/repair damage.
     
  3. Digi Senior Engineer

    Messages:
    2,384
    There's IMyDestroyableObject which has DoDamage().
    As for repair... hmm, if it works to do damage try using negative damage values.
     
  4. erisco Trainee Engineer

    Messages:
    30
    Thanks for the information Arcturus.

    Digi, how do you get objects of the type IMyDestroyableObject? I am unable to find classes or interfaces which extend it.
     
  5. Digi Senior Engineer

    Messages:
    2,384
    I tested it just now, you can cast IMySlimBlock to IMyDestroyableObject, and DoDamage() seems to work but you need high values :p

    EDIT: negative values do nothing :(
     
  6. erisco Trainee Engineer

    Messages:
    30
    I found just the contrary, that negative values do work. The integrity indicator on the UI will update if you call ApplyAccumulatedDamage() on the block (the IMySlimBlock object).

    What I have not figured out is how to replace missing build components and restore entities to working condition.
     
  7. Dereknor Trainee Engineer

    Messages:
    81
    I try to make a mod that do damage, too. But I cant use the IMyDestroyableObject. Each time I try to use it, I just get the message "The type 'IMyDestroyableObject' couldnt be found". How can I cast IMySlimBlock to IMyDestroyableObject? I still new to modding and havent found a way to do that. I searched the whole internet, but couldnt find any way to do damage in a mod ;)
     
  8. Dereknor Trainee Engineer

    Messages:
    81
    Ah, I just found this:
    IMyDesctructeableObject - Inaccessible as of version 01.066 (22.1.2015)

    Does that mean we cant do damage in mods anymore?
     
  9. Dereknor Trainee Engineer

    Messages:
    81
    oh, my fault, I forgot to using Sandbox.ModAPI.Interfaces;
     
  10. Mortisfire Apprentice Engineer

    Messages:
    148
    Did you ever make any progress with adding components back into a grid?
     
Thread Status:
This last post in this thread was made more than 31 days old.