Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when getting group name of a unit, leading to no stream kill events #209

Open
RobCollie opened this issue Jan 12, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@RobCollie
Copy link

The following is in our log:

2023-01-02 19:34:05.364 INFO Scripting (Main): event:type=kill,target_unit_type=BRDM-2,target_coalition=1,weapon=AGM-65L,t=5703.05,initiator_ws_type1=1,targetMissionID=1002613,initiator_unit_type=AV8BNA,target_ws_type1=2,initiator_object_id=16812805,initiator_coalition=2,target=BRDM-2,initiatorPilotName=TDCS | Pilot Pyles,initiatorMissionID=2166,target_object_id=17092097,
2023-01-02 19:34:05.364 ERROR SCRIPTING (Main): [GRPC] Error in event handler: [string "C:\Users\TacticalDCS\Saved Games\instance2\Scripts\DCS-gRPC\exporters\object.lua"]:45: attempt to index a nil value
stack traceback:
[string "C:\Users\TacticalDCS\Saved Games\instance2\Scripts\DCS-gRPC\exporters\object.lua"]:45: in function <[string "C:\Users\TacticalDCS\Saved Games\instance2\Scripts\DCS-gRPC\exporters\object.lua"]:27>
(tail call): ?
[string "C:\Users\TacticalDCS\Saved Games\instance2\Scripts\DCS-gRPC\methods\mission.lua"]:43: in function 'typed_exporter'
[string "C:\Users\TacticalDCS\Saved Games\instance2\Scripts\DCS-gRPC\methods\mission.lua"]:341: in function <[string "C:\Users\TacticalDCS\Saved Games\instance2\Scripts\DCS-gRPC\methods\mission.lua"]:63>
(tail call): ?
[C]: in function 'xpcall'
[string "C:\Users\TacticalDCS\Saved Games\instance2\Scripts\DCS-gRPC\grpc.lua"]:226: in function 'onEvent'
[string "Scripts/World/EventHandlers.lua"]:13: in function <[string "Scripts/World/EventHandlers.lua"]:11>

This links to this line in object.lua:

groupName = Unit.getGroup(unit):getName(),

@rurounijones
Copy link
Contributor

rurounijones commented Jan 14, 2023

Looks like ED broke something in the scripting... again. I will have a look at how to workaround this but please raise an issue on the ED forums and link it so we can track things their side as well.

@RobCollie
Copy link
Author

@soerenmeier
Copy link
Contributor

Not sure if this is the correct fix but to get the kill events i applied following patch:

 lua/DCS-gRPC/exporters/object.lua | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lua/DCS-gRPC/exporters/object.lua b/lua/DCS-gRPC/exporters/object.lua
index cc791e4..422be8c 100644
--- a/lua/DCS-gRPC/exporters/object.lua
+++ b/lua/DCS-gRPC/exporters/object.lua
@@ -17,6 +17,11 @@ GRPC.exporters.position = function(pos)
 end
 
 GRPC.exporters.unit = function(unit)
+  local group = Unit.getGroup(unit)
+  if group then
+    group = GRPC.exporters.group(group)
+  end
+
   return {
     id = tonumber(unit:getID()),
     name = unit:getName(),
@@ -24,7 +29,7 @@ GRPC.exporters.unit = function(unit)
     coalition = unit:getCoalition() + 1, -- Increment for non zero-indexed gRPC enum
     type = unit:getTypeName(),
     playerName = Unit.getPlayerName(unit),
-    group = GRPC.exporters.group(Unit.getGroup(unit)),
+    group = group,
     numberInGroup = unit:getNumber(),
     rawTransform = GRPC.exporters.rawTransform(unit),
   }

Should a unit always have a group?

@rurounijones
Copy link
Contributor

rurounijones commented Feb 4, 2023

Yes units always have groups. This issue is due to ED changing things and making units not units anymore, but statics, probably as an attempt to optimise things.

Making group optional is going to be a right pain for clients. Grimes suggested that there is a very hacky workaround to this bug of getting the group by mangling the unit name to remove the unit specific information and onyl leave the group then use GetGroupByName. We may need to add that as a backup method if unit.group lua returns nil.

@rurounijones
Copy link
Contributor

rurounijones commented Feb 23, 2023

Clarified with Grimes and it appears that what needs to happen is that lua scripters need to create a lookup table for units to groups which is a right pain in the arse to do since we now have to manage unit state in parallel with DCS's own unit state and risk desync.

so we have two crappy options to choose from... thanks ED

@RobCollie
Copy link
Author

sigh

@rurounijones rurounijones added the bug Something isn't working label Feb 24, 2023
martinco added a commit to strategic-dcs/rust-server that referenced this issue Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants