====== Comfort: Countdown and Peacetime ====== ===== Beschreibung ===== Mit diesem Code lassen sich Countdowns starten, die nach Ablauf bestimmte Funktionen aufrufen. \\ Ausserdem lässt sich eine Friedenszeit im Multiplayer setzen. \\ ===== Anwendung ===== Die Anwendung ist sehr einfach. Zunächst muss in der FirstMapAction() vor Anwendung der Code eingelesen werden: Countdown_and_Peacetime() Jetzt können folgende Funktionen verwendet werden ==== Countdown ==== _countdownId = StartCountdown (_Limit, _Callback, _Show) _countdownId: Id für spätere Verwendung _Limit: Ablauf des Countdowns in Sekunden _Callback: Funktion (ohne " ", also einfach der Name!) _Show: True, falls der Countdown gezeigt werden soll. Achtung! Es kann nur ein Countdown auf einmal angezeigt werden! StopCountdown(_Id) _Id: Id eines Countdowns wie in StartCountdown vermerkt ==== Peacetime (Multiplayer) ==== SetPeacetime = function ( _seconds ) _seconds: Dauer der Friedenszeit in Sekunden Sollen nach Ablauf der Friedenszeit noch andere Aktionen durchgeführt werden, muss noch die folgende Funktion bearbeitet werden. PeacetimeEnd = function() ... end ===== Code ===== function Countdown_and_Peacetime() PeacetimeEnd = function() -- sämtliche Aktionen bei Ende der Friedenszeit MultiplayerTools.SetUpDiplomacyOnMPGameConfig() -- Sound bei Ende der Friedenszeit Sound.PlayGUISound( Sounds.OnKlick_Select_kerberos, 127 ) -- Nachricht bei Ende der Friedenszeit Message( "@color:255,255,0 "..g_MC_Loc[gvRL].Wartimemsg ); end SetPeacetime = function ( _seconds ) ---hier wird die Funktion special peacetime gestartet SpecialPeacetime(); StartCountdown( _seconds, PeacetimeEnd, true ); end SpecialPeacetime = function() -- Anzahl der menschlichen Spieler wird hier ermittelt local _humenPlayer = XNetwork.GameInformation_GetMapMaximumNumberOfHumanPlayer() -- Abfrage ob Standardsituation gegeben ist das jeder sich mit jedem verbünden kann if XNetwork.GameInformation_GetFreeAlliancesFlag() == 1 then -- Feststellung wer mit wem verbündet ist und Festlegung des DiplomatiST für die Peacetime if _humenPlayer > 1 then for _teampId = 1, _humenPlayer do local _teamplayer = XNetwork.GameInformation_GetLogicPlayerTeam( _teampId ) for _oppopId = 1, _humenPlayer do if _teampId ~= OppoPlayer then local _oppoPlayer = XNetwork.GameInformation_GetLogicPlayerTeam( _oppopId ) if _teamplayer == _oppoPlayer then Logic.SetDiplomacyState( _oppopId, _teampId, Diplomacy.Friendly ) else Logic.SetDiplomacyState( _oppopId, _teampId, Diplomacy.Neutral ) end end end end end end end StartCountdown = function (_Limit, _Callback, _Show) assert(type(_Limit) == "number") Counter.Index = (Counter.Index or 0) + 1 if _Show and CountdownIsVisisble() then assert(false, "StartCountdown: A countdown is already visible") end Counter["counter" .. Counter.Index] = {Limit = _Limit, TickCount = 0, Callback = _Callback, Show = _Show, Finished = false} if _Show then MapLocal_StartCountDown(_Limit) end if Counter.JobId == nil then Counter.JobId = StartSimpleJob("CountdownTick") end return Counter.Index end StopCountdown = function(_Id) if Counter.Index == nil then return end if _Id == nil then for i = 1, Counter.Index do if Counter.IsValid("counter" .. i) then if Counter["counter" .. i].Show then MapLocal_StopCountDown() end Counter["counter" .. i] = nil end end else if Counter.IsValid("counter" .. _Id) then if Counter["counter" .. _Id].Show then MapLocal_StopCountDown() end Counter["counter" .. _Id] = nil end end end CountdownTick = function() local empty = true for i = 1, Counter.Index do if Counter.IsValid("counter" .. i) then if Counter.Tick("counter" .. i) then Counter["counter" .. i].Finished = true end if Counter["counter" .. i].Finished and not IsBriefingActive() then if Counter["counter" .. i].Show then MapLocal_StopCountDown() end -- callback function if type(Counter["counter" .. i].Callback) == "function" then Counter["counter" .. i].Callback() end Counter["counter" .. i] = nil end empty = false end end if empty then Counter.JobId = nil Counter.Index = nil return true end end CountdownIsVisisble = function() for i = 1, Counter.Index do if Counter.IsValid("counter" .. i) and Counter["counter" .. i].Show then return true end end return false end end ===== Anmerkungen ===== Der Autor der Funktionen ist mir unbekannt.