class DirtHandler : MaterialHandler
{
override void OnRegister()
{
health = 20;
textures.Push("FLAT10");
textures.Push("GRASS1");
}
override void MaterialFloorDestroyed(WorldEvent e)
{
Super.MaterialFloorDestroyed(e);
// Dig
int newHeight = e.damageSector.floorPlane.ZAtPoint(e.damageSector.centerSpot) - 32;
e.damageSector.MoveFloor(1, -newHeight, 0, 1, false, true);
// Mow the lawn
e.damageSector.SetTexture(Sector.floor, TexMan.CheckForTexture("FLAT10", TexMan.Type_Flat));
// Reset health so we can dig some more
e.newDamage = (e.newDamage - e.damageSector.GetHealth(SECPART_Floor)) % health;
e.damageSector.SetHealth(SECPART_Floor, health);
//Spawn debris here
}
}
class DestructableDecorationBase : Actor
{
Default
{
Radius 32;
Height 32;
Mass 100;
Friction 1;
Health 100;
+SOLID
+PUSHABLE
+DROPOFF
+SLIDESONWALLS
+CANPASS
+ACTLIKEBRIDGE
+FLOORCLIP;
+SHOOTABLE;
+NOBLOOD;
+NEVERTARGET;
PushFactor 0.25;
}
void A_BitsExplode(int ammount ,string bit)
{
Actor mo = null;
int i;
for(i = ammount; i; i--)
{
mo = Spawn (bit, Pos, ALLOW_REPLACE);
if (mo)
{
mo.SetState (mo.SpawnState + random[Pottery](0, 4));
mo.Vel.X = random2[Pottery]() / 64.;
mo.Vel.Y = random2[Pottery]() / 64.;
mo.Vel.Z = random[Pottery](5, 12) * 0.75;
}
}
}
}
void EjectDebris(int amount, class<Actor> debrisCls, Vector3 pos, float maxVel)
{
for (int i = 0; i < amount; i++)
{
let mo = Actor.Spawn(debrisCls, pos);
mo.vel.x = frandom(-maxVel, maxVel);
mo.vel.y = frandom(-maxVel, maxVel);
mo.vel.z = frandom(-maxVel, maxVel);
}
}
override void MaterialFloorDestroyed(WorldEvent e)
{
Super.MaterialFloorDestroyed(e);
// Dig
int newHeight = e.damageSector.floorPlane.ZAtPoint(e.damageSector.centerSpot) - 32;
// btw you can solve the dig-height problem like this
// 0 might not be the right number, but it keeps you from digging down forever
if (newHeight < 0) return;
e.damageSector.MoveFloor(1, -newHeight, 0, 1, false, true);
// Mow the lawn
e.damageSector.SetTexture(Sector.floor, TexMan.CheckForTexture("FLAT10", TexMan.Type_Flat));
// Reset health so we can dig some more
e.newDamage = (e.newDamage - e.damageSector.GetHealth(SECPART_Floor)) % health;
e.damageSector.SetHealth(SECPART_Floor, health);
//Spawn debris here
Vector3 pos = (e.damageSector.centerSpot, newHeight + 16); // center of the part just destroyed
EjectDebris(8, "BrickDebris", pos, 64);
}
class void EjectDebris(int amount, class<Actor> debrisCls, Vector3 pos, float maxVel)
{
for (int i = 0; i < amount; i++)
{
let mo = Actor.Spawn(debrisCls, pos);
mo.vel.x = frandom(-maxVel, maxVel);
mo.vel.y = frandom(-maxVel, maxVel);
mo.vel.z = frandom(-maxVel, maxVel);
}
}
override void MaterialCeilingDestroyed(WorldEvent e)
{
Super.MaterialCeilingDestroyed(e);
// Move ceiling up
int newHeight = e.damageSector.ceilingPlane.ZAtPoint(e.damageSector.centerSpot) + 16;
//Limit how far up ceiling breaks
//if (newHeight > 128) return;
e.damageSector.MoveCeiling(1, newHeight, 0, -1, false);
// Change the ceiling texture to represent "broken" state
e.damageSector.SetTexture(Sector.ceiling, TexMan.CheckForTexture("CRATOP2", TexMan.Type_Flat));
// Reset health so a new block can be breaked
e.newDamage = (e.newDamage - e.damageSector.GetHealth(SECPART_Ceiling)) % health;
e.damageSector.SetHealth(SECPART_Ceiling, health);
Vector3 pos = (e.damageSector.centerSpot, newHeight - 8); // center of the part just destroyed
EjectDebris(8, "WoodenBit", pos, 32);
}
//Limit how far down floor breaks, this it keeps you from digging down forever
Double lowestNearFloor = e.damageSector.FindLowestFloorSurrounding();
if (newHeight < lowestNearFloor) return;
https://github.com/marrub--/zscript-doc/blob/8081cd640bb2805a95918c142144751a00249bf4/api/level/Sector.md
Spoiler:
Spoiler:
class WoodHandler : MaterialHandler
{
const Sector_Set3DFloor = 160;
// ...
override void Material3DDestroyed(WorldEvent e)
{
Super.Material3dDestroyed(e);
int tag;
for (int i = 0; i < e.damageSector.lines.Size(); i++)
{
Line l = e.damageSector.lines[i];
if (l.special == Sector_Set3DFloor)
{
tag = l.args[0]
break;
}
}
let it = level.CreateSectorTagIterator(tag);
int idx;
while (idx = it.Next())
{
Sector s = level.sectors[idx];
Vector3 pos = (s.centerSpot, s.floorPlane.ZAtPoint(s.centerSpot));
EjectDebris(8, "WOODGIB", pos, 32); //Alternate debris, use this WoodenBit
}
e.damageSector.MoveFloor(1, 1024, 0, 1, false, true);
e.damageSector.MoveCeiling(1, -1024, 0, 1, false);
}
}
Users browsing this forum: No registered users and 0 guests