Page 1 of 1

Destroying an Object Multiple Times

Posted: Fri May 19, 2017 11:47 pm
by Psyringe
Caught up in a design workflow fork, the route I'm considering involves multiple destruction's. Done some searching and know a bit about structure; but knowing if the following works with a link or example would be awesome:

Is it possible via LUA (or otherwise) to Transform an Object into a Different Object, with health, on destruction with an animated effect.

The idea is a Prop or Building is partially destroyed but has health remaining to be destroyed more. This is a popular effect; glass cups to fortifying barriers.

Figure it's possible. Not sure. No rush.

Thanks in advance!

Re: Destroying an Object Multiple Times

Posted: Sat May 20, 2017 12:00 pm
by Marth8880
You might be able to do this via Lua scripting with the OnObjectDamage event handler. It'd look something like this:

Code: Select all

propDamage = OnObjectDamageName(
    function(object, damager)
        if GetObjectHealth(object) < 100 then
            SetProperty(object, "GeometryName", "new_msh_file_name")
        end
    end,
"object_class_name"
)
Parts of this might be wrong, but otherwise that's the basis of what would the code block might look like.

Refer to Battlefront2_scripting_system.doc for more information.

Re: Destroying an Object Multiple Times

Posted: Sat May 20, 2017 3:08 pm
by Psyringe
Awesome. Thanks. Stuck on binary; was looking for "destroy" or "dest".

Re: Destroying an Object Multiple Times

Posted: Sun May 21, 2017 1:24 pm
by ForceMaster
I agree with Marth :) but maybe the code needs to extend a bit.

IMPORTANT: your object needs to be

Code: Select all

ClassLabel = "destructablebuilding"
instead of "prop". Props can't be destroyed ingame or via LUA.

Try this:

Code: Select all


objectName = "my_object_name" -- You need specify what object 

OnObjectDamage(
   function(object, damager) --

      if GetObjectHealth(objectName) < 1000 then -- Set a number near the max health. First destruction.

            SetProperty(objectName, "GeometryName", "new_msh_file_name") -- First change of geometry
            KillObject(objectName) --Object dissapears...
            RespawnObject(objectName) -- ...and respawn in les than eye closes!  :D 
            SetProperty(objectName, "MaxHealth", 999)
            SetProperty(objectName, "CurHealth", 999)

      elseif  GetObjectHealth(objectName) < 700 then -- Set a number near the second max health. second destruction.

            SetProperty(objectName, "GeometryName", "second_msh_file_name") -- second change of geometry
            KillObject(objectName) --Object dissapears...
            RespawnObject(objectName) -- ...and respawn in les than eye closes!  :D 
            SetProperty(objectName, "MaxHealth", 699)
            SetProperty(objectName, "CurHealth", 699)

      elseif  GetObjectHealth(objectName) < 500 then -- Set a number near the third max health. Third destruction.

            SetProperty(objectName, "GeometryName", "second_msh_file_name") -- Third change of geometry
            KillObject(objectName) --Object dissapears...
            RespawnObject(objectName) -- ...and respawn in les than eye closes!  :D 
            SetProperty(objectName, "MaxHealth", 499)
            SetProperty(objectName, "CurHealth", 499)

--         If you need more destructions copy from "elseif" to the line above and set new values
       
       end
)
Finally your destructable building needs a destroyed geometry and chunks, that add more realism. Hope help you.

Re: Destroying an Object Multiple Times

Posted: Sun May 21, 2017 3:12 pm
by Psyringe
As soon as I test it; BOOM video example/confirmation. I'll let you know.

Was asking early on because I can do the multi-part destruction when doing the binary destruction; saves time (a lot, actually, and looks better). Thanks so much for that. :D