VE Lua Documentation

Press F to search!

beamBroken

Definition


-- @/lua/vehicle/beamstate.lua:800

local function beamBroken(id, energy)
  --beamDamageTracker[id] = 0
  --beamDamageTrackerDirty = true

  local bodyPart = beamBodyPartLookup[id]
  if bodyPart then
    bodyPartDamageTracker[bodyPart] = bodyPartDamageTracker[bodyPart] + 1
    local damage = bodyPartDamageTracker[bodyPart] * invBodyPartBeamCount[bodyPart]
    if damage > 0.001 then
      damageTracker.setDamage("body", bodyPart, damage)
    end
  end

  luaBreakBeam(id)
  if v.data.beams[id] ~= nil then
    local beam = v.data.beams[id]
    if beam.partPath and partDamageData[beam.partPath] then
      partDamageData[beam.partPath].beamsBroken = partDamageData[beam.partPath].beamsBroken + 1
    end

    -- Check for punctured tire
    if beam.wheelID ~= nil then
      deflateTire(beam.wheelID)
    elseif beam.pressureGroupId then
      obj:deflatePressureGroup(v.data.pressureGroups[beam.pressureGroupId])
    end

    -- Break coll tris
    if beam.collTris and not beam.disableTriangleBreaking then --allow beams to disable triangle breaking
      for _, ctid in ipairs(beam.collTris) do
        if collTriState[ctid] then
          collTriState[ctid] = collTriState[ctid] - 1
          if collTriState[ctid] <= 1 or beam.wheelID then
            obj:breakCollisionTriangle(ctid)
          end
        end
      end
    end

    -- Break the meshes
    if beam.disableMeshBreaking == nil or not beam.disableMeshBreaking then
      obj:breakMeshes(id)
    end

    -- Break rails
    obj:breakRails(id)

    -- breakgroup handling
    -- this same code is also in torsionbarBroken, if you change this, check the other one too
    if beam.breakGroup then
      if type(beam.breakGroup) ~= "table" and breakGroupCache[beam.breakGroup] == nil then
        -- shortcircuit in case of broken single breakGroup
      else
        local breakGroups = type(beam.breakGroup) == "table" and beam.breakGroup or {beam.breakGroup}
        for _, g in ipairs(breakGroups) do
          if breakGroupCache[g] then
            props.hidePropsInBreakGroup(g)

            -- breakGroupType = 0 breaks the group
            -- breakGroupType = 1 does not break the group but will be broken by the group
            if beam.breakGroupType == 0 or beam.breakGroupType == nil then
              breakBreakGroup(g)
            end
          end
        end
      end
    end

    if beam.deformSwitches then
      breakMaterial(beam)
    end

    --experimental particle code: spawn plastic chunk particles when a beam connecting to plastic nodes breaks
    local breakNode1 = v.data.nodes[beam.id1].cid
    local breakNode2 = v.data.nodes[beam.id2].cid
    local particleType = 55 + math.floor(math.random(3)) --choose random particle number between 56 and 58 for plastic chunks
    local particleType_deformGroup1 = 68
    local particleType_deformGroup2 = 69
    local particleCount_deformGroup1 = 15
    local particleCount_deformGroup2 = 15
    if v.data.nodes[beam.id1].nodeMaterial == 3 or v.data.nodes[beam.id2].nodeMaterial == 3 then --check for plastic nodes connected to the beam
      obj:addParticleByNodesRelative(breakNode1, breakNode2, math.random(1), particleType, 0, 1)
    end
    if v.data.nodes[beam.id1].nodeMaterial == 6 or v.data.nodes[beam.id2].nodeMaterial == 6 then --check if it's a wooden prop, like the piano
      particleType_deformGroup1 = 12
      particleType_deformGroup2 = 12
      particleCount_deformGroup1 = 2
      particleCount_deformGroup2 = 2
    end
    if beam.deformGroup and beam.breakGroup then --check if beam is part of a breakgroup and a deformgroup, indicating that it's glass or wood
      obj:addParticleByNodesRelative(breakNode1, breakNode2, math.random(1), particleType_deformGroup1, (math.random(1) / 5), particleCount_deformGroup1) --spawn glass or wood particles
      obj:addParticleByNodesRelative(breakNode1, breakNode2, math.random(1), particleType_deformGroup2, (math.random(1) / 5), particleCount_deformGroup2)
    end
  else
    --print ("beam "..id.." just broke")
  end
end

Callers

@/lua/vehicle/controller/controllerTemplate.lua

-- local function beamBroken(id, energy)
-- end
@/lua/vehicle/controller/braking/hydraulicPumpBrake.lua

local function beamBroken(id, energy)
  if frontDamageBeamBrokenCoef > 0 then
@/lua/vehicle/main.lua
function onBeamBroke(id, energy)
  beamstate.beamBroken(id, energy)
  wheels.beamBroke(id)