diff --git a/Moose Development/Moose/Core/Base.lua b/Moose Development/Moose/Core/Base.lua index d6f61b293..c36ea3405 100644 --- a/Moose Development/Moose/Core/Base.lua +++ b/Moose Development/Moose/Core/Base.lua @@ -198,13 +198,17 @@ BASE = { ClassID = 0, Events = {}, States = {}, - _ = {}, } --- @field #BASE.__ BASE.__ = {} +--- @field #BASE._ +BASE._ = { + Schedules = {} --- Contains the Schedulers Active +} + --- The Formation Class -- @type FORMATION -- @field Cone A cone formation. @@ -654,6 +658,86 @@ function BASE:onEvent(event) end end +do -- Scheduling + + --- Schedule a new time event. Note that the schedule will only take place if the scheduler is *started*. Even for a single schedule event, the scheduler needs to be started also. + -- @param #BASE self + -- @param #number Start Specifies the amount of seconds that will be waited before the scheduling is started, and the event function is called. + -- @param #function SchedulerFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments. + -- @param #table ... Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }. + -- @return #number The ScheduleID of the planned schedule. + function BASE:ScheduleOnce( Start, SchedulerFunction, ... ) + self:F2( { Start } ) + self:T3( { ... } ) + + local ObjectName = "-" + ObjectName = self.ClassName .. self.ClassID + + self:F3( { "ScheduleOnce: ", ObjectName, Start } ) + self.SchedulerObject = self + + local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule( + self, + SchedulerFunction, + { ... }, + Start, + nil, + nil, + nil + ) + + self._.Schedules[#self.Schedules+1] = ScheduleID + + return self._.Schedules + end + + --- Schedule a new time event. Note that the schedule will only take place if the scheduler is *started*. Even for a single schedule event, the scheduler needs to be started also. + -- @param #BASE self + -- @param #number Start Specifies the amount of seconds that will be waited before the scheduling is started, and the event function is called. + -- @param #number Repeat Specifies the interval in seconds when the scheduler will call the event function. + -- @param #number RandomizeFactor Specifies a randomization factor between 0 and 1 to randomize the Repeat. + -- @param #number Stop Specifies the amount of seconds when the scheduler will be stopped. + -- @param #function SchedulerFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments. + -- @param #table ... Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }. + -- @return #number The ScheduleID of the planned schedule. + function BASE:ScheduleRepeat( Start, Repeat, RandomizeFactor, Stop, SchedulerFunction, ... ) + self:F2( { Start } ) + self:T3( { ... } ) + + local ObjectName = "-" + ObjectName = self.ClassName .. self.ClassID + + self:F3( { "ScheduleRepeat: ", ObjectName, Start, Repeat, RandomizeFactor, Stop } ) + self.SchedulerObject = self + + local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule( + self, + SchedulerFunction, + { ... }, + Start, + Repeat, + RandomizeFactor, + Stop + ) + + self._.Schedules[SchedulerFunction] = ScheduleID + + return self._.Schedules + end + + --- Stops the Schedule. + -- @param #BASE self + -- @param #function SchedulerFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments. + function BASE:ScheduleStop( SchedulerFunction ) + + self:F3( { "ScheduleStop:" } ) + + _SCHEDULEDISPATCHER:Stop( self, self._.Schedules[SchedulerFunction] ) + end + +end + + --- Set a state or property of the Object given a Key and a Value. -- Note that if the Object is destroyed, nillified or garbage collected, then the Values and Keys will also be gone. -- @param #BASE self diff --git a/Moose Development/Moose/Functional/AirbasePolice.lua b/Moose Development/Moose/Functional/AirbasePolice.lua index 1d628db80..ac7d1d0ba 100644 --- a/Moose Development/Moose/Functional/AirbasePolice.lua +++ b/Moose Development/Moose/Functional/AirbasePolice.lua @@ -181,8 +181,21 @@ function AIRBASEPOLICE_BASE:_AirbaseMonitor() Client:Message( "You are speeding on the taxiway! Slow down or you will be removed from this airbase! Your current velocity is " .. string.format( "%2.0f km/h", Velocity ), 5, "Warning " .. SpeedingWarnings .. " / 3" ) Client:SetState( self, "Warnings", SpeedingWarnings + 1 ) else - MESSAGE:New( "Player " .. Client:GetPlayerName() .. " has been removed from the airbase, due to a speeding violation ...", 10, "Airbase Police" ):ToAll() - Client:Destroy() + MESSAGE:New( "Player " .. Client:GetPlayerName() .. " is being damaged at the airbase, due to a speeding violation ...", 10, "Airbase Police" ):ToAll() + --- @param Wrapper.Client#CLIENT Client + local function DestroyUntilHeavilyDamaged( Client ) + local ClientCoord = Client:GetCoordinate() + ClientCoord:Explosion( 100 ) + local Damage = Client:GetLife() + local InitialLife = Client:GetLife0() + MESSAGE:New( "Player " .. Client:GetPlayerName() .. " Damage ... " .. Damage, 5, "Airbase Police" ):ToAll() + if ( Damage / InitialLife ) * 100 < 80 then + Client:ScheduleStop( DestroyUntilHeavilyDamaged ) + end + end + Client:ScheduleOnce( 1, DestroyUntilHeavilyDamaged, Client ) + --Client:ScheduleRepeat( 1, 1, 0, nil, DestroyUntilHeavilyDamaged, Client ) + --Client:Destroy() trigger.action.setUserFlag( "AIRCRAFT_"..Client:GetID(), 100) Client:SetState( self, "Speeding", false ) Client:SetState( self, "Warnings", 0 )