Describe the continuous tracking of an enemy submarine for more than an hour?

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
hanzawa1991
Posts: 71
Joined: Tue Apr 05, 2022 9:05 am

Describe the continuous tracking of an enemy submarine for more than an hour?

Post by hanzawa1991 »

has anyone can help me?
How to write the codes like this :
Describe the continuous tracking of an enemy submarine for more than an hour,then the tracking camp add 50 points.
I considered that for underwater targets sustained tracking is losing targets within a minute.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Describe the continuous tracking of an enemy submarine for more than an hour?

Post by KnightHawk75 »

Build a scheduled contact monitor\tracker that runs at regular time every minute or 30 seconds for it.

Assuming this is for tracking a specific underlying sub (and not any sub) the following comes to mind broadly.

Maybe not most efficient but would work...
Basically scan side contactsby( sub category), for each look for matching underlying unitguid of sub to be tracked, if exists... flip a marker and break; if not continue.. if not found in the pass...reset a tracked time var to 0; otherwise add seconds(based on whatever interval your monitor function runs at), if seconds >= 3600 award points\message player. Optionally per what it seems you want add logic in there to check contact objects age, if age grows too large reset if you want to count it as lost track, similar age checking could\should be done scanning detection\lastdetections tables making sure the last detections age say isn't more than a minute or so old before incrementing continuous tracked seconds var.

May be more efficient probably if you already know the sub unit(s) ahead of time, scan the units .ascontact table on sub unit to be tracked's unit object, looking for a side match against side you are checking for having a track on it, then grab that contact if exists and investigate and process as mentioned above however you need.

Some of this depends as alluded too if you're trying to count how long the contact itself exists, vs how long since the contact has been last updated\detected etc. Ie a contact obj could exist for an hour but be way out of date, what you consider out of date, and lost track, is up to you, but that's where age and detection tables on the contact object will help you.

--comments based on 114x.xx builds (new 12xx.x beta builds may enable other methods)
Let me know if that helps point you in the right direction.
hanzawa1991
Posts: 71
Joined: Tue Apr 05, 2022 9:05 am

Re: Describe the continuous tracking of an enemy submarine for more than an hour?

Post by hanzawa1991 »

KnightHawk75 wrote: Sun Sep 25, 2022 5:57 am Build a scheduled contact monitor\tracker that runs at regular time every minute or 30 seconds for it.

Assuming this is for tracking a specific underlying sub (and not any sub) the following comes to mind broadly.

Maybe not most efficient but would work...
Basically scan side contactsby( sub category), for each look for matching underlying unitguid of sub to be tracked, if exists... flip a marker and break; if not continue.. if not found in the pass...reset a tracked time var to 0; otherwise add seconds(based on whatever interval your monitor function runs at), if seconds >= 3600 award points\message player. Optionally per what it seems you want add logic in there to check contact objects age, if age grows too large reset if you want to count it as lost track, similar age checking could\should be done scanning detection\lastdetections tables making sure the last detections age say isn't more than a minute or so old before incrementing continuous tracked seconds var.

May be more efficient probably if you already know the sub unit(s) ahead of time, scan the units .ascontact table on sub unit to be tracked's unit object, looking for a side match against side you are checking for having a track on it, then grab that contact if exists and investigate and process as mentioned above however you need.

Some of this depends as alluded too if you're trying to count how long the contact itself exists, vs how long since the contact has been last updated\detected etc. Ie a contact obj could exist for an hour but be way out of date, what you consider out of date, and lost track, is up to you, but that's where age and detection tables on the contact object will help you.

--comments based on 114x.xx builds (new 12xx.x beta builds may enable other methods)
Let me know if that helps point you in the right direction.

Thanks for your reply, I tried to write some code, there are still some problems, but it should be close to the correct answer :
1.when scenario is loaded , load the function:
flag_sub=0 -- whether a submarine has been spotted
time_r=0 -- the spotting duration time
points=0 -- the scores

2.Check every minute for a submarine:
local loc =ScenEdit_GetContacts("B")
for i,v in ipairs(loc) do
if(loc.type == 'Submarine') then
flag_sub=1
time_r=time_r+1
break
end
flag_sub=0
time_r=0
end

3. Bonus points for finding the sub for more than an hour:
if(time_r >60) then
points=50+points
time_r=0
end
hanzawa1991
Posts: 71
Joined: Tue Apr 05, 2022 9:05 am

Re: Describe the continuous tracking of an enemy submarine for more than an hour?

Post by hanzawa1991 »

KnightHawk75 wrote: Sun Sep 25, 2022 5:57 am Build a scheduled contact monitor\tracker that runs at regular time every minute or 30 seconds for it.

Assuming this is for tracking a specific underlying sub (and not any sub) the following comes to mind broadly.

Maybe not most efficient but would work...
Basically scan side contactsby( sub category), for each look for matching underlying unitguid of sub to be tracked, if exists... flip a marker and break; if not continue.. if not found in the pass...reset a tracked time var to 0; otherwise add seconds(based on whatever interval your monitor function runs at), if seconds >= 3600 award points\message player. Optionally per what it seems you want add logic in there to check contact objects age, if age grows too large reset if you want to count it as lost track, similar age checking could\should be done scanning detection\lastdetections tables making sure the last detections age say isn't more than a minute or so old before incrementing continuous tracked seconds var.

May be more efficient probably if you already know the sub unit(s) ahead of time, scan the units .ascontact table on sub unit to be tracked's unit object, looking for a side match against side you are checking for having a track on it, then grab that contact if exists and investigate and process as mentioned above however you need.

Some of this depends as alluded too if you're trying to count how long the contact itself exists, vs how long since the contact has been last updated\detected etc. Ie a contact obj could exist for an hour but be way out of date, what you consider out of date, and lost track, is up to you, but that's where age and detection tables on the contact object will help you.

--comments based on 114x.xx builds (new 12xx.x beta builds may enable other methods)
Let me know if that helps point you in the right direction.
about"check contact objects age, if age grows too large reset if you want to count it as lost track, similar age checking could\should be done scanning detection\lastdetections tables making sure the last detections age say isn't more than a minute or so old before incrementing continuous tracked seconds var"
It's a little difficult for me . Could you tell me how to write this part?
Post Reply

Return to “Lua Legion”