From 0239098f305fc0474cdc13a02c3e387549372607 Mon Sep 17 00:00:00 2001 From: svenvandevelde Date: Thu, 21 Jan 2016 23:29:47 +0100 Subject: [PATCH] Fixed initialization of Cargo assigned to a client when a client spawns... --- Moose/Client.lua | 26 ++++++++++++++++++++++++-- Moose/Mission.lua | 5 +++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Moose/Client.lua b/Moose/Client.lua index 131fea85e..bc19ed666 100644 --- a/Moose/Client.lua +++ b/Moose/Client.lua @@ -134,6 +134,26 @@ trace.f(self.ClassName) end +--- InitCargo allows to initialize @{CARGO} on the CLIENT when the client initializes. +-- @tparam string InitCargoNames is a string or a table containing the names of the @{CARGO}s initialized in the Mission. +-- @treturn CLIENT +function CLIENT:InitCargo( InitCargoNames ) +trace.f(self.ClassName, { InitCargoNames } ) + + local Valid = true + + if Valid then + if type( InitCargoNames ) == "table" then + self.InitCargoNames = InitCargoNames + else + self.InitCargoNames = { InitCargoNames } + end + end + + return self + +end + --- AddCargo allows to add @{CARGO} on the CLIENT. -- @tparam string CargoName is the name of the @{CARGO}. -- @tparam string CargoGroupName is the name of an active Group defined within the Mission Editor or Dynamically Spawned. Note that this is only applicable for Unit @{CARGO} Types. @@ -150,13 +170,15 @@ trace.f(self.ClassName, { CargoName, CargoGroupName, CargoType, CargoWeight, Car Valid = routines.ValidateEnumeration( CargoType, "CargoType", CARGO_TYPE, Valid ) Valid = routines.ValidateNumber( CargoWeight, "CargoWeight", Valid ) - if Valid then + if Valid then local Cargo = {} Cargo.CargoName = CargoName Cargo.CargoGroupName = CargoGroupName Cargo.CargoType = CargoType Cargo.CargoWeight = CargoWeight - Cargo.CargoGroupTemplate = CargoGroupTemplate + if CargoGroupTemplate then + Cargo.CargoGroupTemplate = CargoGroupTemplate + end self._Cargos[CargoName] = Cargo self:ShowCargo() end diff --git a/Moose/Mission.lua b/Moose/Mission.lua index a1c1c56e9..2ead4c912 100644 --- a/Moose/Mission.lua +++ b/Moose/Mission.lua @@ -478,6 +478,11 @@ trace.scheduled("MISSIONSCHEDULER","Scheduler") Client._Tasks[TaskNumber].MissionTask = Mission._Tasks[TaskNumber] end Client._Cargos = {} + if Client.InitCargoNames then + for InitCargoID, InitCargoName in pairs( Client.InitCargoNames ) do + Client._Cargos[InitCargoName] = Mission._Cargos[InitCargoName] + end + end Mission:Ongoing() end