RotorVR Posted August 30, 2022 Posted August 30, 2022 (edited) I am curious, are there any good examples out there of a script that enables tracking of a supply count for an airfield or FARP that is provided by crate delivery? -track supply value for an airfield -add to supply value with delivering crates and despawning said crate once delivered -subtract from supply value with takeoff event and add with landing event I see lots of servers do this and for our little private scenario in a small group I’d prefer to avoid trying to build something from the ground up. Does anyone have any good example that they could reference or would be willing to share? I experimented using CTLD’s crate counter function and associating that with a flag value that I associated with an airfield but I think most scripts use a table value instead of flag counters and it counts any crate whether it’s a proper supply crate or a humvee crate. I don’t know any scripters to bounce ideas off of. Edited August 30, 2022 by RotorVR
RotorVR Posted August 31, 2022 Author Posted August 31, 2022 (edited) Here is the code I was using. Even if unwilling to share example scripts that others may have worked hard on, I'd love if I could get any help on my work: THIS WORKS: I used CTLD's built-in functions to spawn a crate via standard DCS trigger and DO Script: ctld.spawnCrateAtZone("blue", 2701, "Crate Factory TEST") --spawns a BLUE coalition HMMWV at the trigger zone "crateSpawnTrigger" THIS WORKS: I used CTLD's built-in functions to designate a trigger zone to be a crate dropzone and count every 5 seconds via normal DCS trigger Do Script: ctld.cratesInZone("Crate Dropzone TEST",200) THIS WORKS: I tried editing CTLD's crates in zone function as per below so that it adds to the flag value rather than just counting and replacing the value. I got that to work, so it is now adding onto a current flag value cumulatively. I had it pull the value and add 2 to it for every crate in the zone. NEED HELP: My attempts to have the crate despawn immediately following it being counted is not working. I have marked the line in bold in the code quote below. NEED HELP: The message to all to announce the delivery and supply count is also not working. I have marked the line in bold in the code quote below. Quote --Script File to add function: -- Continuously counts the number of crates in a zone and sets the value of the passed in flag -- to the count amount -- This means you can trigger actions based on the count and also trigger messages before the count is reached -- Just pass in the zone name and flag number like so as a single (NOT Continuous) Trigger -- This will now work for Mission Editor and Spawned Crates -- e.g. ctld.cratesInZone("DropZone1", 5) function ctld.cratesInZone(_zone, _flagNumber) local _triggerZone = trigger.misc.getZone(_zone) -- trigger to use as reference position if _triggerZone == nil then trigger.action.outText("CTLD.lua ERROR: Cant find zone called " .. _zone, 10) return end local _zonePos = mist.utils.zoneToVec3(_zone) --ignore side, if crate has been used its discounted from the count local _crateTables = { ctld.spawnedCratesRED, ctld.spawnedCratesBLUE, ctld.missionEditorCargoCrates } local _crateCount = trigger.misc.getUserFlag(_flagNumber) --Orignal value was 0, trying to set this to equal the current flag value for _, _crates in pairs(_crateTables) do for _crateName, _dontUse in pairs(_crates) do --get crate local _crate = ctld.getCrateObject(_crateName) --in air seems buggy with crates so if in air is true, get the height above ground and the speed magnitude if _crate ~= nil and _crate:getLife() > 0 and (ctld.inAir(_crate) == false) then local _dist = ctld.getDistance(_crate:getPoint(), _zonePos) if _dist <= _triggerZone.radius then _crateCount = _crateCount + 2 -- Crate addes value of 2 to the count which should be current flag value trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " delivered a Supply Crate. Supplies at " .. _zone .. ": " .. _crateCount, 10) --This will send a message confirming delivery and current new supply count at triggerzone --_crate.crateUnit:destroy() --Attempting to ADD IN THE DESPAWN CRATE LINE HERE, so crate will add 2 to flag value in line 810 but then disappear not be counted again end end end end --set flag stuff trigger.action.setUserFlag(_flagNumber, _crateCount) -- env.info("FLAG ".._flagNumber.." crates ".._crateCount) --retrigger in 5 seconds timer.scheduleFunction(function(_args) ctld.cratesInZone(_args[1], _args[2]) end, { _zone, _flagNumber }, timer.getTime() + 5) end If anyone can help me with the message line and the despawn line I would be really appreciative! If I can get the despawn(destroy) line to work and the message to work then I'll have the crate supply delivery functioning! I would love any help at all. Edited August 31, 2022 by RotorVR
Recommended Posts