Skip to content

Commit

Permalink
Add outSound*() support to Gremlin
Browse files Browse the repository at this point in the history
  • Loading branch information
danhunsaker committed Apr 3, 2024
1 parent 1e32f18 commit 3d8b756
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 120 deletions.
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [Setup](./gremlin/setup.md)
- [Usage](./gremlin/usage.md)
- [Functions](./gremlin/functions.md)
- [Comms](./gremlin/functions/comms.md)
- [Events](./gremlin/functions/events.md)
- [Log](./gremlin/functions/log.md)
- [Menu](./gremlin/functions/menu.md)
Expand Down
12 changes: 12 additions & 0 deletions docs/gremlin/functions/comms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- markdownlint-disable MD041 -->
### Comms

#### `Gremlin.comms.displayMessageTo(_name, _text, _time)`

Displays a message to a named Unit, Group, Country, or Coalition, or to everyone with the special name `all`

---

#### `Gremlin.comms.playClipTo(_name, _path)`

Plays a clip to a named Unit, Group, Country, or Coalition, or to everyone with the special name `all`
6 changes: 0 additions & 6 deletions docs/gremlin/functions/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ Counts the number of entries in a table, regardless of type

---

#### `Gremlin.utils.displayMessageTo(_name, _text, _time)`

Displays a message to a named Unit, Group, Country, or Coalition, or to everyone with the special name `all`

---

#### `Gremlin.utils.getUnitZones(_unit)`

Looks up a list of all the zones a unit is currently in
Expand Down
2 changes: 1 addition & 1 deletion docs/gremlin/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Gremlin:setup()
Gremlin.log.info('My Cool DCS Script', 'Starting up!')
Gremlin.utils.displayMessageTo('test', 'Hullabaloo!', timer.getTime() + 1)
Gremlin.comms.displayMessageTo('test', 'Hullabaloo!', timer.getTime() + 1)
local myArgs = Gremlin.utils.parseFuncArgs({ '{unit}:test', '{group}:test', timer.getTime() }, {
unit = {
Expand Down
5 changes: 5 additions & 0 deletions mocks/DCS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,11 @@ require("Scripts.ScriptingSystem")
trigger.action.activateGroup = Mock()
trigger.action.deactivateGroup = Mock()
trigger.action.smoke = Mock()
trigger.action.outSound = Mock()
trigger.action.outSoundForCoalition = Mock()
trigger.action.outSoundForCountry = Mock()
trigger.action.outSoundForGroup = Mock()
trigger.action.outSoundForUnit = Mock()
trigger.action.outText = Mock()
trigger.action.outTextForCoalition = Mock()
trigger.action.outTextForCountry = Mock()
Expand Down
30 changes: 15 additions & 15 deletions src/evac.lua
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,19 @@ Evac.units = {
if _unitObj ~= nil then
local _free = Evac.carryLimits[_unitObj:getTypeName()] or 0
if _free == 0 then
Gremlin.utils.displayMessageTo(_unit, "Your aircraft isn't rated for evacuees in this mission!", 1)
Gremlin.comms.displayMessageTo(_unit, "Your aircraft isn't rated for evacuees in this mission!", 1)
return
end

_free = _free - Evac._internal.aircraft.countEvacuees(_unit)
if _free <= 0 then
Gremlin.utils.displayMessageTo(_unit, 'Already full! Unload, first!', 1)
Gremlin.comms.displayMessageTo(_unit, 'Already full! Unload, first!', 1)
return
end

Evac._internal.aircraft.loadEvacuees(_unit, _free)
else
Gremlin.utils.displayMessageTo(_unit, "Your aircraft isn't rated for evacuees in this mission!", 1)
Gremlin.comms.displayMessageTo(_unit, "Your aircraft isn't rated for evacuees in this mission!", 1)
end
end,
-- Starts the evacuee unloading process for a unit
Expand All @@ -351,7 +351,7 @@ Evac.units = {

local _count = Evac._internal.aircraft.countEvacuees(_unit)

Gremlin.utils.displayMessageTo(_unit, 'You are currently carrying ' .. _count .. ' evacuees.', 1)
Gremlin.comms.displayMessageTo(_unit, 'You are currently carrying ' .. _count .. ' evacuees.', 1)
end,
-- Count the number of units in a given zone
count = function(_zone)
Expand Down Expand Up @@ -513,20 +513,20 @@ Evac._internal.aircraft = {

if Evac._state.extractableNow[_zone] == nil or ((Evac._state.zones.evac[_zone] == nil or Evac._state.zones.evac[_zone].active == false) and (Evac._state.zones.relay[_zone] == nil or Evac._state.zones.relay[_zone].active == false)) then
Gremlin.log.debug(Evac.Id, string.format('Loading Evacuees : %s is not an active or registered zone\nextractable - %s\nevac zone - %s\nrelay zone - %s', _zone, mist.utils.tableShowSorted(Evac._state.extractableNow[_zone]), mist.utils.tableShowSorted(Evac._state.zones.evac[_zone]), mist.utils.tableShowSorted(Evac._state.zones.relay[_zone])))
Gremlin.utils.displayMessageTo(_unit, 'Not in an active evac or relay zone! Try looking elsewhere.', 5)
Gremlin.comms.displayMessageTo(_unit, 'Not in an active evac or relay zone! Try looking elsewhere.', 5)
return
end

if Evac._internal.aircraft.inAir(_unit) then
Gremlin.log.debug(Evac.Id, string.format('Loading Evacuees : %s is not on the ground', _unit))
Gremlin.utils.displayMessageTo(_unit, 'You need to land, first! Unless you have some magic way to teleport them up? And no, these folks are in no condition for the hoist, so put that back up.', 5)
Gremlin.comms.displayMessageTo(_unit, 'You need to land, first! Unless you have some magic way to teleport them up? And no, these folks are in no condition for the hoist, so put that back up.', 5)
return
end

_number = math.min(_number, Gremlin.utils.countTableEntries(Evac._state.extractableNow[_zone]))
if _number < 1 then
Gremlin.log.debug(Evac.Id, string.format('Loading Evacuees : %s is empty', _zone))
Gremlin.utils.displayMessageTo(_unit, 'No evacuees to load here, pilot! Try looking elsewhere.', 5)
Gremlin.comms.displayMessageTo(_unit, 'No evacuees to load here, pilot! Try looking elsewhere.', 5)
return
end

Expand Down Expand Up @@ -577,7 +577,7 @@ Evac._internal.aircraft = {
Gremlin.log.debug(Evac.Id, string.format('Loading Evacuees : Sending %s to %s', _message, tostring(_unit)))

Gremlin.events.fire({ id = 'Evac:UnitLoaded', zone = _zone, unit = _unit, number = _number })
Gremlin.utils.displayMessageTo(_unit, _message, _displayFor)
Gremlin.comms.displayMessageTo(_unit, _message, _displayFor)
end, {_timeNow + 0.01}, _timeNow + 0.01, 1, _timeNow + _timeout + 0.02)
end,
countEvacuees = function(_unit)
Expand Down Expand Up @@ -634,20 +634,20 @@ Evac._internal.aircraft = {

if (Evac._state.zones.safe[_zone] == nil or Evac._state.zones.safe[_zone].active == false) and (Evac._state.zones.relay[_zone] == nil or Evac._state.zones.relay[_zone].active == false) then
Gremlin.log.debug(Evac.Id, string.format('Unloading Evacuees : %s is not an active or registered zone\nrelay zone - %s\nsafe zone - %s', _zone, mist.utils.tableShowSorted(Evac._state.zones.relay[_zone]), mist.utils.tableShowSorted(Evac._state.zones.safe[_zone])))
Gremlin.utils.displayMessageTo(_unit, 'Not in an active relay or safe zone! Try looking elsewhere.', 5)
Gremlin.comms.displayMessageTo(_unit, 'Not in an active relay or safe zone! Try looking elsewhere.', 5)
return
end

if Evac._internal.aircraft.inAir(_unit) then
Gremlin.log.debug(Evac.Id, string.format('Unloading Evacuees : %s is not on the ground', _unit))
Gremlin.utils.displayMessageTo(_unit, "You need to land, first! Fastrope doesn't work with stretchers.", 5)
Gremlin.comms.displayMessageTo(_unit, "You need to land, first! Fastrope doesn't work with stretchers.", 5)
return
end

local _number = Evac._internal.aircraft.countEvacuees(_unit)
if _number < 1 then
Gremlin.log.debug(Evac.Id, string.format('Unloading Evacuees : %s is empty', _unit))
Gremlin.utils.displayMessageTo(_unit, 'No evacuees to unload?! Why are you even here, pilot?!', 5)
Gremlin.comms.displayMessageTo(_unit, 'No evacuees to unload?! Why are you even here, pilot?!', 5)
return
end

Expand Down Expand Up @@ -697,7 +697,7 @@ Evac._internal.aircraft = {
Gremlin.log.debug(Evac.Id, string.format('Unloading Evacuees : Sending %s to %s', _message, tostring(_unit)))

Gremlin.events.fire({ id = 'Evac:UnitUnloaded', zone = _zone, unit = _unit, number = _number })
Gremlin.utils.displayMessageTo(_unit, _message, _displayFor)
Gremlin.comms.displayMessageTo(_unit, _message, _displayFor)
Evac._internal.utils.endIfEnoughGotOut()
end, { _timeNow + 0.01 }, _timeNow + 0.01, 1, _timeNow + _timeout + 0.02)
end
Expand Down Expand Up @@ -834,9 +834,9 @@ Evac._internal.beacons = {
Gremlin.log.debug(Evac.Id, string.format('Got Beacon List For Unit : %s, %s', tostring(_unit), _message or 'none'))

if _message ~= nil and _message ~= '' then
Gremlin.utils.displayMessageTo(_unitObj:getGroup(), 'Evacuation Beacons:\n' .. _message, 15)
Gremlin.comms.displayMessageTo(_unitObj:getGroup(), 'Evacuation Beacons:\n' .. _message, 15)
else
Gremlin.utils.displayMessageTo(_unitObj:getGroup(), 'No Active Evacuation Beacons', 15)
Gremlin.comms.displayMessageTo(_unitObj:getGroup(), 'No Active Evacuation Beacons', 15)
end
end
end
Expand Down Expand Up @@ -1658,7 +1658,7 @@ Evac._internal.handlers = {

Gremlin.log.debug(Evac.Id, string.format('Lost Evacuee(s)! : %s', Evac._internal.aircraft.countEvacuees(_name)))

Gremlin.utils.displayMessageTo(Gremlin.SideToText[_side], string.format('We just lost %i evacuee(s)! Step it up, pilots!', Evac._internal.aircraft.countEvacuees(_name)), 15)
Gremlin.comms.displayMessageTo(Gremlin.SideToText[_side], string.format('We just lost %i evacuee(s)! Step it up, pilots!', Evac._internal.aircraft.countEvacuees(_name)), 15)

Evac._state.extractionUnits[_name] = {
[0] = Evac._state.extractionUnits[_name][0],
Expand Down
59 changes: 40 additions & 19 deletions src/gremlin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,46 @@ Gremlin = {
},

-- Methods
comms = {
displayMessageTo = function(_name, _text, _time)
if _name == 'all' or _name == 'Neutral' or _name == nil then
trigger.action.outText(_text, _time)
elseif type(_name) == 'string' and coalition.side[string.upper(_name)] ~= nil then
trigger.action.outTextForCoalition(coalition.side[string.upper(_name)], _text, _time)
elseif type(_name) == 'string' and country[string.upper(_name)] ~= nil then
trigger.action.outTextForCountry(country[string.upper(_name)], _text, _time)
elseif type(_name) == 'table' and _name.className_ == 'Group' then
trigger.action.outTextForGroup(_name:getID(), _text, _time)
elseif type(_name) == 'string' and Group.getByName(_name) ~= nil then
trigger.action.outTextForGroup(Group.getByName(_name):getID(), _text, _time)
elseif type(_name) == 'table' and _name.className_ == 'Unit' then
trigger.action.outTextForUnit(_name:getID(), _text, _time)
elseif type(_name) == 'string' and Unit.getByName(_name) ~= nil then
trigger.action.outTextForUnit(Unit.getByName(_name):getID(), _text, _time)
else
Gremlin.log.error(Gremlin.Id, string.format("Can't find object named %s to display message to!\nMessage was: %s", tostring(_name), _text))
end
end,
playClipTo = function(_name, _path)
if _name == 'all' or _name == 'Neutral' or _name == nil then
trigger.action.outSound(_path)
elseif type(_name) == 'string' and coalition.side[string.upper(_name)] ~= nil then
trigger.action.outSoundForCoalition(coalition.side[string.upper(_name)], _path)
elseif type(_name) == 'string' and country[string.upper(_name)] ~= nil then
trigger.action.outSoundForCountry(country[string.upper(_name)], _path)
elseif type(_name) == 'table' and _name.className_ == 'Group' then
trigger.action.outSoundForGroup(_name:getID(), _path)
elseif type(_name) == 'string' and Group.getByName(_name) ~= nil then
trigger.action.outSoundForGroup(Group.getByName(_name):getID(), _path)
elseif type(_name) == 'table' and _name.className_ == 'Unit' then
trigger.action.outSoundForUnit(_name:getID(), _path)
elseif type(_name) == 'string' and Unit.getByName(_name) ~= nil then
trigger.action.outSoundForUnit(Unit.getByName(_name):getID(), _path)
else
Gremlin.log.error(Gremlin.Id, string.format("Can't find object named %s to play clip to!\nClip was: %s", tostring(_name), _path))
end
end,
},
events = {
_globalHandlers = {
logEvents = {
Expand Down Expand Up @@ -187,25 +227,6 @@ Gremlin = {
end
return _count
end,
displayMessageTo = function(_name, _text, _time)
if _name == 'all' or _name == 'Neutral' or _name == nil then
trigger.action.outText(_text, _time)
elseif type(_name) == 'string' and coalition.side[string.upper(_name)] ~= nil then
trigger.action.outTextForCoalition(coalition.side[string.upper(_name)], _text, _time)
elseif type(_name) == 'string' and country[string.upper(_name)] ~= nil then
trigger.action.outTextForCountry(country[string.upper(_name)], _text, _time)
elseif type(_name) == 'table' and _name.className_ == 'Group' then
trigger.action.outTextForGroup(_name:getID(), _text, _time)
elseif type(_name) == 'string' and Group.getByName(_name) ~= nil then
trigger.action.outTextForGroup(Group.getByName(_name):getID(), _text, _time)
elseif type(_name) == 'table' and _name.className_ == 'Unit' then
trigger.action.outTextForUnit(_name:getID(), _text, _time)
elseif type(_name) == 'string' and Unit.getByName(_name) ~= nil then
trigger.action.outTextForUnit(Unit.getByName(_name):getID(), _text, _time)
else
Gremlin.log.error(Gremlin.Id, string.format("Can't find object named %s to display message to!\nMessage was: %s", tostring(_name), _text))
end
end,
getUnitZones = function(_unit)
Gremlin.log.trace(Gremlin.Id, string.format('Grabbing Unit Zone Names : %s', _unit))

Expand Down
2 changes: 1 addition & 1 deletion src/urgency.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Urgency._internal.doCountdowns = function()
for _time, _message in pairs(_countdown.messages) do
if (_time >= 0 and _time + _countdown.startedAt <= _now) or (_endTime ~= nil and _time < 0 and _time + _endTime <= _now) then
Urgency._state.countdowns.active[_name].messages[_time] = nil
Gremlin.utils.displayMessageTo(_message.to, _message.text, _message.duration)
Gremlin.comms.displayMessageTo(_message.to, _message.text, _message.duration)
Gremlin.log.trace(Urgency.Id, string.format('Sent Message : %s', _message.text))
end
end
Expand Down
Loading

0 comments on commit 3d8b756

Please sign in to comment.