damn it not again Posted 7 hours ago Posted 7 hours ago Okay I need some help. I have very very very limited knowledge on LUA. I'm trying to score bombs dropped on a specific target but I cannot get a return on this script. Where did I go wrong or do I just need to scrap it. -- Define target point local targetPoint = { x = 451519, y = 623, z = 897725 } -- Bounding box size in meters local delta = 30 -- +/- 30 meters local targetZone = { x_min = targetPoint.x - delta, x_max = targetPoint.x + delta, y_min = targetPoint.y - delta, y_max = targetPoint.y + delta, z_min = targetPoint.z - delta, z_max = targetPoint.z + delta } local score = 0 local bombsTracked = {} -- Function to check if position is within target zone local function isWithinTargetZone(pos) return pos.x >= targetZone.x_min and pos.x <= targetZone.x_max and pos.y >= targetZone.y_min and pos.y <= targetZone.y_max and pos.z >= targetZone.z_min and pos.z <= targetZone.z_max end -- Event handler for bomb impact local function onEvent(event) if event.id == world.event.S_EVENT_SHOT then local initiator = event.initiator if initiator and initiator:getTypeName() == "MK-82" then local pos = initiator:getPosition().p local bombID = initiator:getID() -- Avoid scoring multiple times for the same bomb if not bombsTracked[bombID] then bombsTracked[bombID] = true if isWithinTargetZone(pos) then score = score + 100 trigger.action.outText(string.format("MK-82 #%d hit the target! Score: %d", bombID, score), 10) else trigger.action.outText(string.format("MK-82 #%d missed.", bombID), 10) end end end end end -- Register event handler world.addEventHandler({onEvent = onEvent})
Actium Posted 5 hours ago Posted 5 hours ago S_EVENT_SHOT triggers when firing a weapon, not when it impacts. Dunno whether S_EVENT_HIT will trigger when a bomb hits the ground without damaging any units. Also unsure whether your use of addEventHandler() is correct. See here for an exemplary use of S_EVENT_HIT to detect (H)ARMs that hit a ship:
Recommended Posts