Breakable Crates

From The DarkMod Wiki
Revision as of 12:19, 23 June 2007 by Springheel (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

When it comes time to have our crates splinter into various pieces when you break them, here's a link to how someone did it already on D3World :

http://www.doom3world.org/phpbb2/viewtopic.php?t=8131

Here's the relevant part in case that thread ever disappears:

!!!Pre Warning i am no C program, a little back in the eighties along with z80 machinecode but since then just a little scripting. So general syntax is ok pointer, structures, enum yer think i got the hang to here classes ARRRgGGg classes mm understand the idea but all that -> . this can access that because its an inheritance of that but cant do this because that members private higher up the chain just makes me wanna scream. But i am enjoying running around trying to piece it alltogether so with that in mind this is my first attempt at anything to do with the SDK only managed to get it compiling the other night after the fifth attempt.

Which btw if your a noob and are having trouble getting it all to compile i recommend this way http://www.doom3world.org/phpbb2/viewtopic.php?t=6855 worked first time for me .yes you dont get an IDE you have to use a txt editor like ultraedit.

Anyway the way ive been working on this is with the drop gibs. I found that if i changed the def for say env_gibs_leftarm so that "gib" "1" and "def_dropGibAF1" "env_gibs_leftarm" it will just keep creating another one each time it gibs but only for a period of 4 seconds at which point they all disappear.

Looking at the SDK for def_drop returns dAFEntity_Base::DropAFs and idMoveableItem::DropItems and both of these are called from idActor::Startragdoll and idAFEntity::SpawnGibs. So this rings true we know we cant gib anything unless it is an idAFEntity or inheritance of.

I decided to what looked like the easiest route first DROPAFS. As i had no need for messing around with Actors. IDAFEntity_Gibbable::SpawnGibs it is then.where you will find this line

Code:
list[i]->PostEventSec( &EV_Remove, 4.0f );


At the top of the function i put this

Code:
bool breakable;
breakable = spawnArgs.GetBool( "breakable" );


Only remove entity if its not breakable

Code:
if (breakable == 0 ){
    list[i]->GetRenderEntity()->noShadow = true;
    list[i]->GetRenderEntity()->shaderParms[ SHADERPARM_TIME_OF_DEATH ] = gameLocal.time * 0.001f;
    list[i]->PostEventSec( &EV_Remove, 4.0f );
      }

Enclosed the other 2 lines aswell as we dont want this to happen if our entity is staying in the level.

Then before the very last }

Code:
if ( breakable == 1 ){
   this->PostEventMS( &EV_Remove, 0 );
}

Removes original entity.

This should be enough to get it ROUGHLY working although there are few other things ive done but i am still experimenting with them.

So i created 11 models plank, plankhalf1, plankhalf2, plankquarter1 etc etc then pointed each def like so.

Code:
entityDef env_plank {
  ~usual stuff~
"breakable" "1"
"gib" "1"
"def_dropGibAF1"  "env_plankhalf1"
"def_dropGibAF2"  "env_plankhalf2"
}
entityDef env_plankhalf1{
 ~usual stuff~
"breakable" "1"
"gib" "1"
"def_dropGibAF1"  "env_plankquarter1"
"def_dropGibAF2"  "env_plankquarter2"
}


Run a map up spawn env_plank and shoot away.

Sorry if this post seems a little disjointed. And hope that it helps point others into writing a better solution.Im off to explore the other side DROPITEMS could do with the positioning stuff it does e.g offset and rotate.