Unit naming
Posted: Sat Aug 14, 2021 10:15 am
Setting up some random cargo ships to pop up on a non player side. I know that someone made a script for this a while back but for the life of me I cannot find it.
Anyway, this isn't that elaborate. The ships pop up on an event (%chance every XX hrs) the ships are one of three types and each type is assigned to a consistent mission. No problem and the script here works fine to a point:
-----Random cargo ships
a = math.random(1,3)
if a == 1 then
ScenEdit_AddUnit({type='ship', side='NATO Convoy Cmd', name='Panamax Container', dbid='2028', latitude='9.70632518352066', longitude='-79.9607376175008'})
ScenEdit_AssignUnitToMission('Panamax Container', 'Anegada Passage Assy')
elseif a == 2 then
ScenEdit_AddUnit({type='ship', side='NATO Convoy Cmd', name='Panamax Cargo', dbid='2774', latitude='9.70632518352066', longitude='-79.9607376175008'})
ScenEdit_AssignUnitToMission('Panamax Cargo', 'Mona Passage Assy')
elseif a == 3 then
ScenEdit_AddUnit({type='ship', side='NATO Convoy Cmd', name='Panamax Tanker', dbid='339', latitude='9.70632518352066', longitude='-79.9607376175008'})
ScenEdit_AssignUnitToMission('Panamax Tanker', 'Guadeloupe Passage Assy')
end
The problem of course is that the names are not unique, so the moment a second ship of the same type shows up it doesn't get assigned to the mission and just sits there. So I know there is a simple way of either adding something to the name string or using UnitX() -- but I fiddled with it for a while and decided to raise the white flag.
Any thoughts guys?
Anyway, this isn't that elaborate. The ships pop up on an event (%chance every XX hrs) the ships are one of three types and each type is assigned to a consistent mission. No problem and the script here works fine to a point:
-----Random cargo ships
a = math.random(1,3)
if a == 1 then
ScenEdit_AddUnit({type='ship', side='NATO Convoy Cmd', name='Panamax Container', dbid='2028', latitude='9.70632518352066', longitude='-79.9607376175008'})
ScenEdit_AssignUnitToMission('Panamax Container', 'Anegada Passage Assy')
elseif a == 2 then
ScenEdit_AddUnit({type='ship', side='NATO Convoy Cmd', name='Panamax Cargo', dbid='2774', latitude='9.70632518352066', longitude='-79.9607376175008'})
ScenEdit_AssignUnitToMission('Panamax Cargo', 'Mona Passage Assy')
elseif a == 3 then
ScenEdit_AddUnit({type='ship', side='NATO Convoy Cmd', name='Panamax Tanker', dbid='339', latitude='9.70632518352066', longitude='-79.9607376175008'})
ScenEdit_AssignUnitToMission('Panamax Tanker', 'Guadeloupe Passage Assy')
end
The problem of course is that the names are not unique, so the moment a second ship of the same type shows up it doesn't get assigned to the mission and just sits there. So I know there is a simple way of either adding something to the name string or using UnitX() -- but I fiddled with it for a while and decided to raise the white flag.
Any thoughts guys?
