Mikla Posted July 29, 2023 Posted July 29, 2023 Good day, I apologize if this is the wrong area to post this. I have a little LUA programming experience, but I just started dabbling with DCS scripting. I am trying to add an extension to rkusa's Scratchpad script to add the current aircraft type with a button. I believe it is something like this: addButton(0, 0, 50, 30, "CLR", function(text) local actype = Unit.getByName('myUnit'):getTypeName() local padtext = "Type:" .. actype log(padtext) text:setText(padtext) end) But I am unsure if I got the syntax right since nothing is added to the scratchpad or the log.
609_Relentov Posted July 30, 2023 Posted July 30, 2023 The syntax looks correct, i.e. local actype = Unit.getByName('myUnit'):getTypeName() The question is, how is "myUnit" populated. Not sure if there's a Mist method that gives you the name of the unit you (Player or Client) are currently flying/spawned in. Otherwise, you would need to add an onEvent method to track when a client spawned (e.g. world.event.S_EVENT_BIRTH), and then use the event's initiator to get the unit name.
cfrag Posted July 30, 2023 Posted July 30, 2023 There is no concept of 'I' or 'me' in DCS. If you design your mission so that there are multiple planes that can be controlled by the player, you will have to write your own code to iterate though all player-controlled planes that are currently active in-game. If there is only one player in the game, you can then access that unit, any that would be 'you', the player. Naturally, if there are more than one players active in the game, there is no such thing as "me".
Raisuli Posted July 30, 2023 Posted July 30, 2023 19 minutes ago, cfrag said: There is no concept of 'I' or 'me' in DCS. If you design your mission so that there are multiple planes that can be controlled by the player, you will have to write your own code to iterate though all player-controlled planes that are currently active in-game. If there is only one player in the game, you can then access that unit, any that would be 'you', the player. Naturally, if there are more than one players active in the game, there is no such thing as "me". So if a unit triggers an action ( Coalition in zone, 'BLUE', 'Aircraft' 'foobar') is there a way to identify the aircraft type that tripped that action in zone foobar?
cfrag Posted July 30, 2023 Posted July 30, 2023 15 minutes ago, Raisuli said: So if a unit triggers an action ( Coalition in zone, 'BLUE', 'Aircraft' 'foobar') is there a way to identify the aircraft type that tripped that action in zone foobar? From Lua it would be trivial, from ME not so much. As soon as you have the unit, you can (in Lua) do theUnit:getTypeName() and you have the type.
Raisuli Posted July 30, 2023 Posted July 30, 2023 1 hour ago, cfrag said: From Lua it would be trivial, from ME not so much. As soon as you have the unit, you can (in Lua) do theUnit:getTypeName() and you have the type. lua doesn't scare me any. Haven't done a ton with it for lack of application more than anything since I generally fly solo, but I'm sorely tempted to set the lead plane in my formation trainers based on whatever it is I'm flying. Thanks; if I get a few minutes I'll bang on that.
Recommended Posts