GE Lua Documentation

Press F to search!

processOnEvent

Definition


-- @/lua/ge/extensions/core/inventory.lua:129

local function processOnEvent(onEventData, earnedMedal)
--[[
  OnEventData may contain keys for operations or items to assign directly
  Currently we have only Operations keys 'add' and 'remove'
  Add operation is a direct assignment from the value it points to
  Remove operation contains multiple tables. The value of the remove operation is another dictionary.
    the dictionary has keys for each possible medal - 'bronze', 'silver' and 'gold'. The value of any of these keys
    is the table to use for the remove operation. The one to use is determined by the 'earnedMedal' passed in.
    Examples:
      In this example, when the user wins a gold medal, the pickup would be removed from their inventory
        and 2500 units of currency
      "remove":{
        "gold": {
          "vehicles": [{"model":"pickup","config": "v8_4wd_rusty"}],
          "money" : 2500
        },
        "silver": {
        },
        "bronze": {
        }
      },

      In this example, the end medal does not matter, the pickup and money will always be removed
      "remove":{
          "vehicles": [{"model":"pickup","config": "v8_4wd_rusty"}],
          "money" : 2500
      },
  ]]
  log('I', logTag, 'processOnEvent called...   earnedMedal: '..tostring(earnedMedal))

  if onEventData then
    for key,entry in pairs(onEventData) do
      if key == 'remove' then
        for subKey,data in pairs(entry) do
          if subKey == 'gold' or subKey == 'silver' or subKey == 'bronze' then
            if earnedMedal and subKey == earnedMedal then
              for invType,value in pairs(data) do
                processTable('remove', invType, value)
              end
            end
          else
            processTable('remove', subKey, data)
          end
        end
      else
        processTable('add', key, entry)
      end
    end
  end
end

Callers

@/lua/ge/extensions/campaign/exploration.lua

local function processOnEvent(onEventData)
 if onEventData and onEventData.inventory then
 if onEventData and onEventData.inventory then
    core_inventory.processOnEvent(onEventData.inventory)
 end
      if locationData.onEvent and locationData.onEvent.onSucceed then
        processOnEvent(locationData.onEvent.onSucceed)
      end
@/lua/ge/extensions/campaign/campaigns.lua
  if onEventData and onEventData.inventory then
    core_inventory.processOnEvent(onEventData.inventory)
  end
  if onEventData and onEventData.inventory then
    core_inventory.processOnEvent(onEventData.inventory, scenario.stats.overall.medal)
  end