Yuriks Posted April 16, 2022 Posted April 16, 2022 Mist noob here Trying to make respawn that would change skill level of new aircraft - random ore predefined. But at this point can not even display the skill level of a new unit.. if not Group.getByName('BadGuy1') then mist.respawnGroup('BadGuy1', 5) end local msg = {} msg.text = mist.message.add(mist.getUnitSkill('BadGuy1')) msg.displayTime = 20 mist.message.add(msg)
toutenglisse Posted April 16, 2022 Posted April 16, 2022 1 hour ago, Yuriks said: ...But at this point can not even display the skill level of a new unit... On the fly, I can see that you use same name for groupName functions and unitName function. Be sure to use unitName for mist.getUnitSkill(). 1
Yuriks Posted April 16, 2022 Author Posted April 16, 2022 @toutenglisse Probably that is it. Now on the new quest to get unit name I guess something with Group.getUnits()? Also, what is the best way to debug DCS scrips? insert brakes, see vars,
toutenglisse Posted April 16, 2022 Posted April 16, 2022 1 hour ago, Yuriks said: @toutenglisse Probably that is it. Now on the new quest to get unit name I guess something with Group.getUnits()? Also, what is the best way to debug DCS scrips? insert brakes, see vars, If your group is created with mission editor, the unit name is what is called "pilot name" (by default, if group name is for example "Plane-1" then the unit name is "Plane-1-1"). If I take your code example, what you need to get messages for USA players that will display skills of all units of group 'BadGuy1' is : Spoiler local units = Group.getByName('BadGuy1'):getUnits() for i, unit in pairs(units) do local msg = {} msg.text = '' .. mist.getUnitSkill(unit:getName()) msg.msgFor = {countries = {'USA'}} msg.displayTime = 20 mist.message.add(msg) end Spoil : units with 'random' skill will return 'random'... If you want skill to be random, but with you being able to know what the skill is, I assume you would need to use a random number to choose between available skills, and then dynamically spawn bandits with that skill so the messages won't return 'random', but 'Ace' or 'Vet' etc... 1
Yuriks Posted April 16, 2022 Author Posted April 16, 2022 Thank you, Finnaly I understand what Pilot Name is in ME
Yuriks Posted April 17, 2022 Author Posted April 17, 2022 @toutenglissestill not getting neither name or skills in the text box Also getting Unused local `i` Since using "pairs()" should i also be listed in the msg?
toutenglisse Posted April 17, 2022 Posted April 17, 2022 19 minutes ago, Yuriks said: @toutenglissestill not getting neither name or skills in the text box Also getting Unused local `i` Since using "pairs()" should i also be listed in the msg? I only checked that the little code I wrote to get units skills from 'BadGuy1' group works. (it just displays skills, not names. If you want them you could use : msg.text = unit:getName() .. ' : ' .. mist.getUnitSkill(unit:getName()) Looking back to your first post I suspect that your issue is that you try to access units at the time they spawn, and that usually doesn't work well. Run the "message" part a second later. "i" just means "value" (as "k" means key). "unit" is what to refer to in the msg. 1
Yuriks Posted April 18, 2022 Author Posted April 18, 2022 I must be doing something wrong. mist.message does not show, even though Mist respawn works. I have tried to run it as a separate scrip file and DO SCRIPT right from ME, same. Msgs set from ME:Actions:Text works though @toutenglisse thank you for patience if not Group.getByName('BadGuy1') then mist.respawnGroup('BadGuy1', true) end -- test msg, not working local msg = {} msg.text = "Test" msg.msgFor = {countries = {'all'}} msg.displayTime = 20 mist.message.add(msg) --msgs with skills, not working local units= Group.getByName('BadGuy1'):getUnits() for k, unit in pairs(units) do local msg = {} msg.text = unit:getName() .. ' : ' .. mist.getUnitSkill(unit:getName()) msg.msgFor = {countries = {'all'}} msg.displayTime = 20 mist.message.add(msg) end
toutenglisse Posted April 18, 2022 Posted April 18, 2022 (edited) 57 minutes ago, Yuriks said: I must be doing something wrong... No problem. I put it in a .miz file. 5 seconds after start, 'BadGuy1' group is destroyed / respawned and you get the skill messages. test-skill-message-respawn.miz Edited April 18, 2022 by toutenglisse 1
Yuriks Posted April 18, 2022 Author Posted April 18, 2022 Thank you, It does work. The only key difference with the exertion of 1sec delay is that you put this as skillmessage() function in a separate file while I run it as sequential commands in the same file. Could that be the reason?
toutenglisse Posted April 18, 2022 Posted April 18, 2022 Yes, you were trying to access (f.e. unit:getName()) unit's data at the same time it was created (respawn) - it must be delayed or issues happen. 1
Recommended Posts