damn it not again Posted Tuesday at 01:56 AM Posted Tuesday at 01:56 AM 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 Tuesday at 03:31 AM Posted Tuesday at 03:31 AM 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:
damn it not again Posted Tuesday at 10:34 PM Author Posted Tuesday at 10:34 PM Thank you, I'll give it a try
Draken35 Posted Tuesday at 11:20 PM Posted Tuesday at 11:20 PM (edited) S_EVENT_HIT will tell you nothing about where the bomb hit unfortunately. Worse, by the time it triggers, the weapon object will not longer exists and you will be able to get any info about it. The strategy is to detect a drop with S_EVENT_SHOT and track its position with a scheduled function every 0.001 seconds , stop when the bomb is not longer alive and return the position... I don't have an example without using MIST or MOOSE but attached is one of my scripts with MOOSE . If you look under my user files, you will find some of my range scripts using MIST (they are a bit more complicated to setup_ sbsa.lua EDIT to add: This script depends on another (for TTS comms with the player). To use you will have to make the highlighted changes: I'll post an example mission to the user files and when it is approved, I'll link it in this thread Edited yesterday at 11:37 AM by Draken35
rob10 Posted Tuesday at 11:24 PM Posted Tuesday at 11:24 PM And to add to the last, checking for a bomb in a small zone is tricky/inconsistent if you don't do something like the last post suggests because the standard triggers are only checking about once per second. So a bomb falling can pass into and out or into and blow up and therefore no longer exist between the 1 second intervals.
Draken35 Posted 3 hours ago Posted 3 hours ago Mission file finally approved: https://www.digitalcombatsimulator.com/en/files/3347231/
Recommended Posts