From b222395d891b64d35ab979e6225fc7bc9961fd77 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Fri, 18 Mar 2016 11:02:29 +0100 Subject: [PATCH 1/3] Updated score mechanism When no category is given, the MESSAGE class will not show the title in the message. The scores are now showing between 2 and 5 seconds, and no title is given. This will be better visually. --- Moose/Database.lua | 29 +++++++++++++++++++---------- Moose/Message.lua | 34 ++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/Moose/Database.lua b/Moose/Database.lua index 3b30557bd..4b0393607 100644 --- a/Moose/Database.lua +++ b/Moose/Database.lua @@ -291,15 +291,15 @@ function DATABASE:OnDeadOrCrash( event ) PlayerData.Kill[TargetCategory][TargetType].Penalty = PlayerData.Kill[TargetCategory][TargetType].Penalty + 25 PlayerData.Kill[TargetCategory][TargetType].PenaltyKill = PlayerData.Kill[TargetCategory][TargetType].PenaltyKill + 1 MESSAGE:New( "Player '" .. PlayerName .. "' killed a friendly " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. - PlayerData.Kill[TargetCategory][TargetType].PenaltyKill .. " times. Penalty: -" .. PlayerData.Kill[TargetCategory][TargetType].Penalty, - "Game Status: Penalty", 20, "/PENALTY" .. PlayerName .. "/" .. InitUnitName ):ToAll() + PlayerData.Kill[TargetCategory][TargetType].PenaltyKill .. " times. Penalty: -" .. PlayerData.Kill[TargetCategory][TargetType].Penalty, + "", 5, "/PENALTY" .. PlayerName .. "/" .. InitUnitName ):ToAll() self:ScoreAdd( PlayerName, "KILL_PENALTY", 1, -125, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) else PlayerData.Kill[TargetCategory][TargetType].Score = PlayerData.Kill[TargetCategory][TargetType].Score + 10 PlayerData.Kill[TargetCategory][TargetType].ScoreKill = PlayerData.Kill[TargetCategory][TargetType].ScoreKill + 1 MESSAGE:New( "Player '" .. PlayerName .. "' killed an enemy " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. - PlayerData.Kill[TargetCategory][TargetType].ScoreKill .. " times. Score: " .. PlayerData.Kill[TargetCategory][TargetType].Score, - "Game Status: Score", 20, "/SCORE" .. PlayerName .. "/" .. InitUnitName ):ToAll() + PlayerData.Kill[TargetCategory][TargetType].ScoreKill .. " times. Score: " .. PlayerData.Kill[TargetCategory][TargetType].Score, + "", 5, "/SCORE" .. PlayerName .. "/" .. InitUnitName ):ToAll() self:ScoreAdd( PlayerName, "KILL_SCORE", 1, 10, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) end end @@ -373,8 +373,11 @@ function DATABASE:_AddPlayerFromUnit( UnitData ) self.Players[PlayerName].Penalty = self.Players[PlayerName].Penalty + 50 self.Players[PlayerName].PenaltyCoalition = self.Players[PlayerName].PenaltyCoalition + 1 MESSAGE:New( "Player '" .. PlayerName .. "' changed coalition from " .. DATABASECoalition[self.Players[PlayerName].UnitCoalition] .. " to " .. DATABASECoalition[UnitCoalition] .. - "(changed " .. self.Players[PlayerName].PenaltyCoalition .. " times the coalition). 50 Penalty points added.", - "Game Status: Penalty", 20, "/PENALTYCOALITION" .. PlayerName ):ToAll() + "(changed " .. self.Players[PlayerName].PenaltyCoalition .. " times the coalition). 50 Penalty points added.", + "", + 2, + "/PENALTYCOALITION" .. PlayerName + ):ToAll() self:ScoreAdd( PlayerName, "COALITION_PENALTY", 1, -50, self.Players[PlayerName].UnitName, DATABASECoalition[self.Players[PlayerName].UnitCoalition], DATABASECategory[self.Players[PlayerName].UnitCategory], self.Players[PlayerName].UnitType, UnitName, DATABASECoalition[UnitCoalition], DATABASECategory[UnitCategory], UnitData:getTypeName() ) end @@ -407,7 +410,7 @@ function DATABASE:_AddMissionTaskScore( PlayerUnit, MissionName, Score ) MESSAGE:New( "Player '" .. PlayerName .. "' has finished another Task in Mission '" .. MissionName .. "'. " .. Score .. " Score points added.", - "Game Status: Task Completion", 20, "/SCORETASK" .. PlayerName ):ToAll() + "", 20, "/SCORETASK" .. PlayerName ):ToAll() _Database:ScoreAdd( PlayerName, "TASK_" .. MissionName:gsub( ' ', '_' ), 1, Score, PlayerUnit:getName() ) end @@ -423,7 +426,7 @@ function DATABASE:_AddMissionScore( MissionName, Score ) PlayerData.Mission[MissionName].ScoreMission = PlayerData.Mission[MissionName].ScoreMission + Score MESSAGE:New( "Player '" .. PlayerName .. "' has finished Mission '" .. MissionName .. "'. " .. Score .. " Score points added.", - "Game Status: Mission Completion", 20, "/SCOREMISSION" .. PlayerName ):ToAll() + "", 20, "/SCOREMISSION" .. PlayerName ):ToAll() _Database:ScoreAdd( PlayerName, "MISSION_" .. MissionName:gsub( ' ', '_' ), 1, Score ) end end @@ -541,14 +544,20 @@ function DATABASE:OnHit( event ) self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].PenaltyHit = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].PenaltyHit + 1 MESSAGE:New( "Player '" .. InitPlayerName .. "' hit a friendly " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].PenaltyHit .. " times. Penalty: -" .. self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Penalty, - "Game Status: Penalty", 20, "/PENALTY" .. InitPlayerName .. "/" .. InitUnitName ):ToAll() + "", + 2, + "/PENALTY" .. InitPlayerName .. "/" .. InitUnitName + ):ToAll() self:ScoreAdd( InitPlayerName, "HIT_PENALTY", 1, -25, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) else self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score + 1 self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit + 1 MESSAGE:New( "Player '" .. InitPlayerName .. "' hit a target " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit .. " times. Score: " .. self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score, - "Game Status: Score", 20, "/SCORE" .. InitPlayerName .. "/" .. InitUnitName ):ToAll() + "", + 2, + "/SCORE" .. InitPlayerName .. "/" .. InitUnitName + ):ToAll() self:ScoreAdd( InitPlayerName, "HIT_SCORE", 1, 1, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) end end diff --git a/Moose/Message.lua b/Moose/Message.lua index b93fc4690..a544998ce 100644 --- a/Moose/Message.lua +++ b/Moose/Message.lua @@ -37,11 +37,17 @@ MESSAGE = { -- MessageClient1 = MESSAGE:New( "Congratulations, you've just hit a target", "Score", 25, "Score" ) -- MessageClient2 = MESSAGE:New( "Congratulations, you've just killed a target", "Score", 25, "Score" ) function MESSAGE:New( MessageText, MessageCategory, MessageDuration, MessageID ) -trace.f(self.ClassName, { MessageText, MessageCategory, MessageDuration, MessageID } ) +self:T( { MessageText, MessageCategory, MessageDuration, MessageID } ) local self = BASE:Inherit( self, BASE:New() ) - - self.MessageCategory = MessageCategory + + -- When no messagecategory is given, we don't show it as a title... + if MessageCategory or MessageCategory ~= "" then + self.MessageCategory = MessageCategory .. "\n" + else + self.MessageCategory = "" + end + self.MessageDuration = MessageDuration self.MessageID = MessageID self.MessageTime = timer.getTime() @@ -73,13 +79,13 @@ end -- MessageClient1:ToClient( ClientGroup ) -- MessageClient2:ToClient( ClientGroup ) function MESSAGE:ToClient( Client ) -trace.f(self.ClassName ) + self:T( Client ) if Client and Client:GetClientGroupID() then local ClientGroupID = Client:GetClientGroupID() - trace.i( self.ClassName, self.MessageCategory .. '\n' .. self.MessageText:gsub("\n$",""):gsub("\n$","") .. " / " .. self.MessageDuration ) - trigger.action.outTextForGroup( ClientGroupID, self.MessageCategory .. '\n' .. self.MessageText:gsub("\n$",""):gsub("\n$",""), self.MessageDuration ) + trace.i( self.ClassName, self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$","") .. " / " .. self.MessageDuration ) + trigger.action.outTextForGroup( ClientGroupID, self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$",""), self.MessageDuration ) end return self @@ -96,7 +102,7 @@ end -- MessageBLUE = MESSAGE:New( "To the BLUE Players: You receive a penalty because you've killed one of your own units", "Penalty", 25, "Score" ) -- MessageBLUE:ToBlue() function MESSAGE:ToBlue() -trace.f(self.ClassName ) + self:T() self:ToCoalition( coalition.side.BLUE ) @@ -114,7 +120,7 @@ end -- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", "Penalty", 25, "Score" ) -- MessageRED:ToRed() function MESSAGE:ToRed( ) -trace.f(self.ClassName ) + self:T() self:ToCoalition( coalition.side.RED ) @@ -133,11 +139,11 @@ end -- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", "Penalty", 25, "Score" ) -- MessageRED:ToCoalition( coalition.side.RED ) function MESSAGE:ToCoalition( CoalitionSide ) -trace.f(self.ClassName ) + self:T( CoalitionSide ) if CoalitionSide then - trace.i(self.ClassName, self.MessageCategory .. '\n' .. self.MessageText:gsub("\n$",""):gsub("\n$","") .. " / " .. self.MessageDuration ) - trigger.action.outTextForCoalition( CoalitionSide, self.MessageCategory .. '\n' .. self.MessageText:gsub("\n$",""):gsub("\n$",""), self.MessageDuration ) + trace.i(self.ClassName, self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$","") .. " / " .. self.MessageDuration ) + trigger.action.outTextForCoalition( CoalitionSide, self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$",""), self.MessageDuration ) end return self @@ -154,7 +160,7 @@ end -- MessageAll = MESSAGE:New( "To all Players: BLUE has won! Each player of BLUE wins 50 points!", "End of Mission", 25, "Win" ) -- MessageAll:ToAll() function MESSAGE:ToAll() -trace.f(self.ClassName ) + self:T() self:ToCoalition( coalition.side.RED ) self:ToCoalition( coalition.side.BLUE ) @@ -172,9 +178,9 @@ MESSAGEQUEUE = { } function MESSAGEQUEUE:New( RefreshInterval ) -trace.f( self.ClassName, { RefreshInterval } ) - local self = BASE:Inherit( self, BASE:New() ) + + self:T( { RefreshInterval } ) self.RefreshInterval = RefreshInterval From 8c46f7c7f26ce7e3c61b9ce7ce064902dd755716 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Fri, 18 Mar 2016 12:45:21 +0100 Subject: [PATCH 2/3] Updated scoring and made it better. Implemented also a fracitide function. Anybody committing fracitide above 150 penalty points, gets destroyed and cannot join anymore. --- Embedded/Moose_Embedded.lua | 124 +++++++++++++++++++++++++++--------- Moose/Database.lua | 43 +++++++++++-- Moose/Group.lua | 22 ++++++- Moose/Message.lua | 6 +- 4 files changed, 154 insertions(+), 41 deletions(-) diff --git a/Embedded/Moose_Embedded.lua b/Embedded/Moose_Embedded.lua index 43d771fd5..73d4157cb 100644 --- a/Embedded/Moose_Embedded.lua +++ b/Embedded/Moose_Embedded.lua @@ -3289,7 +3289,7 @@ function GROUP:New( DCSGroup ) end ---- Create a new GROUP from an existing DCSGroup in the mission. +--- Create a new GROUP from an existing group name. -- @param self -- @param GroupName The name of the DCS Group. -- @return #GROUP self @@ -3301,12 +3301,30 @@ function GROUP:NewFromName( GroupName ) if self.DCSGroup then self.GroupName = self.DCSGroup:getName() self.GroupID = self.DCSGroup:getID() - self.Controller = DCSGroup:getController() + self.Controller = self.DCSGroup:getController() end return self end +--- Create a new GROUP from an existing DCSUnit in the mission. +-- @param self +-- @param DCSUnit The DCSUnit. +-- @return #GROUP self +function GROUP:NewFromDCSUnit( DCSUnit ) + local self = BASE:Inherit( self, BASE:New() ) + self:T( DCSUnit ) + + self.DCSGroup = DCSUnit:getGroup() + if self.DCSGroup then + self.GroupName = self.DCSGroup:getName() + self.GroupID = self.DCSGroup:getID() + self.Controller = self.DCSGroup:getController() + end + + return self +end + --- Gets the DCSGroup of the GROUP. -- @param self -- @return #Group The DCSGroup. @@ -4138,18 +4156,22 @@ function DATABASE:OnDeadOrCrash( event ) end if InitCoalition == TargetCoalition then + PlayerData.Penalty = PlayerData.Penalty + 25 PlayerData.Kill[TargetCategory][TargetType].Penalty = PlayerData.Kill[TargetCategory][TargetType].Penalty + 25 PlayerData.Kill[TargetCategory][TargetType].PenaltyKill = PlayerData.Kill[TargetCategory][TargetType].PenaltyKill + 1 MESSAGE:New( "Player '" .. PlayerName .. "' killed a friendly " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. - PlayerData.Kill[TargetCategory][TargetType].PenaltyKill .. " times. Penalty: -" .. PlayerData.Kill[TargetCategory][TargetType].Penalty, - "Game Status: Penalty", 20, "/PENALTY" .. PlayerName .. "/" .. InitUnitName ):ToAll() + PlayerData.Kill[TargetCategory][TargetType].PenaltyKill .. " times. Penalty: -" .. PlayerData.Kill[TargetCategory][TargetType].Penalty .. + ". Score Total:" .. PlayerData.Score - PlayerData.Penalty, + "", 5, "/PENALTY" .. PlayerName .. "/" .. InitUnitName ):ToAll() self:ScoreAdd( PlayerName, "KILL_PENALTY", 1, -125, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) else + PlayerData.Score = PlayerData.Score + 10 PlayerData.Kill[TargetCategory][TargetType].Score = PlayerData.Kill[TargetCategory][TargetType].Score + 10 PlayerData.Kill[TargetCategory][TargetType].ScoreKill = PlayerData.Kill[TargetCategory][TargetType].ScoreKill + 1 MESSAGE:New( "Player '" .. PlayerName .. "' killed an enemy " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. - PlayerData.Kill[TargetCategory][TargetType].ScoreKill .. " times. Score: " .. PlayerData.Kill[TargetCategory][TargetType].Score, - "Game Status: Score", 20, "/SCORE" .. PlayerName .. "/" .. InitUnitName ):ToAll() + PlayerData.Kill[TargetCategory][TargetType].ScoreKill .. " times. Score: " .. PlayerData.Kill[TargetCategory][TargetType].Score .. + ". Score Total:" .. PlayerData.Score - PlayerData.Penalty, + "", 5, "/SCORE" .. PlayerName .. "/" .. InitUnitName ):ToAll() self:ScoreAdd( PlayerName, "KILL_SCORE", 1, 10, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) end end @@ -4212,8 +4234,10 @@ function DATABASE:_AddPlayerFromUnit( UnitData ) -- end self.Players[PlayerName].HitPlayers = {} self.Players[PlayerName].HitUnits = {} + self.Players[PlayerName].Score = 0 self.Players[PlayerName].Penalty = 0 self.Players[PlayerName].PenaltyCoalition = 0 + self.Players[PlayerName].PenaltyWarning = 0 end if not self.Players[PlayerName].UnitCoalition then @@ -4223,8 +4247,11 @@ function DATABASE:_AddPlayerFromUnit( UnitData ) self.Players[PlayerName].Penalty = self.Players[PlayerName].Penalty + 50 self.Players[PlayerName].PenaltyCoalition = self.Players[PlayerName].PenaltyCoalition + 1 MESSAGE:New( "Player '" .. PlayerName .. "' changed coalition from " .. DATABASECoalition[self.Players[PlayerName].UnitCoalition] .. " to " .. DATABASECoalition[UnitCoalition] .. - "(changed " .. self.Players[PlayerName].PenaltyCoalition .. " times the coalition). 50 Penalty points added.", - "Game Status: Penalty", 20, "/PENALTYCOALITION" .. PlayerName ):ToAll() + "(changed " .. self.Players[PlayerName].PenaltyCoalition .. " times the coalition). 50 Penalty points added.", + "", + 2, + "/PENALTYCOALITION" .. PlayerName + ):ToAll() self:ScoreAdd( PlayerName, "COALITION_PENALTY", 1, -50, self.Players[PlayerName].UnitName, DATABASECoalition[self.Players[PlayerName].UnitCoalition], DATABASECategory[self.Players[PlayerName].UnitCategory], self.Players[PlayerName].UnitType, UnitName, DATABASECoalition[UnitCoalition], DATABASECategory[UnitCategory], UnitData:getTypeName() ) end @@ -4233,8 +4260,29 @@ function DATABASE:_AddPlayerFromUnit( UnitData ) self.Players[PlayerName].UnitCoalition = UnitCoalition self.Players[PlayerName].UnitCategory = UnitCategory self.Players[PlayerName].UnitType = UnitTypeName - end + if self.Players[PlayerName].Penalty > 100 then + if self.Players[PlayerName].PenaltyWarning < 1 then + MESSAGE:New( "Player '" .. PlayerName .. "': WARNING! If you continue to commit FRATRICIDE and have a PENALTY score higher than 150, you will be COURT MARTIALED and DISMISSED from this mission! \nYour total penalty is: " .. self.Players[PlayerName].Penalty, + "", + 30, + "/PENALTYCOALITION" .. PlayerName + ):ToAll() + self.Players[PlayerName].PenaltyWarning = self.Players[PlayerName].PenaltyWarning + 1 + end + end + + if self.Players[PlayerName].Penalty > 150 then + ClientGroup = GROUP:NewFromDCSUnit( UnitData ) + ClientGroup:Destroy() + MESSAGE:New( "Player '" .. PlayerName .. "' committed FRATRICIDE, he will be COURT MARTIALED and is DISMISSED from this mission!", + "", + 10, + "/PENALTYCOALITION" .. PlayerName + ):ToAll() + end + + end end @@ -4253,11 +4301,12 @@ function DATABASE:_AddMissionTaskScore( PlayerUnit, MissionName, Score ) self:T( PlayerName ) self:T( self.Players[PlayerName].Mission[MissionName] ) + self.Players[PlayerName].Score = self.Players[PlayerName].Score + Score self.Players[PlayerName].Mission[MissionName].ScoreTask = self.Players[PlayerName].Mission[MissionName].ScoreTask + Score MESSAGE:New( "Player '" .. PlayerName .. "' has finished another Task in Mission '" .. MissionName .. "'. " .. Score .. " Score points added.", - "Game Status: Task Completion", 20, "/SCORETASK" .. PlayerName ):ToAll() + "", 20, "/SCORETASK" .. PlayerName ):ToAll() _Database:ScoreAdd( PlayerName, "TASK_" .. MissionName:gsub( ' ', '_' ), 1, Score, PlayerUnit:getName() ) end @@ -4270,10 +4319,11 @@ function DATABASE:_AddMissionScore( MissionName, Score ) for PlayerName, PlayerData in pairs( self.Players ) do if PlayerData.Mission[MissionName] then + PlayerData.Score = PlayerData.Score + Score PlayerData.Mission[MissionName].ScoreMission = PlayerData.Mission[MissionName].ScoreMission + Score MESSAGE:New( "Player '" .. PlayerName .. "' has finished Mission '" .. MissionName .. "'. " .. Score .. " Score points added.", - "Game Status: Mission Completion", 20, "/SCOREMISSION" .. PlayerName ):ToAll() + "", 20, "/SCOREMISSION" .. PlayerName ):ToAll() _Database:ScoreAdd( PlayerName, "MISSION_" .. MissionName:gsub( ' ', '_' ), 1, Score ) end end @@ -4387,18 +4437,28 @@ function DATABASE:OnHit( event ) end local Score = 0 if InitCoalition == TargetCoalition then + self.Players[InitPlayerName].Penalty = self.Players[InitPlayerName].Penalty + 10 self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Penalty = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Penalty + 10 self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].PenaltyHit = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].PenaltyHit + 1 MESSAGE:New( "Player '" .. InitPlayerName .. "' hit a friendly " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. - self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].PenaltyHit .. " times. Penalty: -" .. self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Penalty, - "Game Status: Penalty", 20, "/PENALTY" .. InitPlayerName .. "/" .. InitUnitName ):ToAll() + self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].PenaltyHit .. " times. Penalty: -" .. self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Penalty .. + ". Score Total:" .. self.Players[InitPlayerName].Score - self.Players[InitPlayerName].Penalty, + "", + 2, + "/PENALTY" .. InitPlayerName .. "/" .. InitUnitName + ):ToAll() self:ScoreAdd( InitPlayerName, "HIT_PENALTY", 1, -25, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) else + self.Players[InitPlayerName].Score = self.Players[InitPlayerName].Score + 10 self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score + 1 self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit + 1 MESSAGE:New( "Player '" .. InitPlayerName .. "' hit a target " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. - self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit .. " times. Score: " .. self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score, - "Game Status: Score", 20, "/SCORE" .. InitPlayerName .. "/" .. InitUnitName ):ToAll() + self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit .. " times. Score: " .. self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score .. + ". Score Total:" .. self.Players[InitPlayerName].Score - self.Players[InitPlayerName].Penalty, + "", + 2, + "/SCORE" .. InitPlayerName .. "/" .. InitUnitName + ):ToAll() self:ScoreAdd( InitPlayerName, "HIT_SCORE", 1, 1, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) end end @@ -6124,11 +6184,16 @@ MESSAGE = { -- MessageClient1 = MESSAGE:New( "Congratulations, you've just hit a target", "Score", 25, "Score" ) -- MessageClient2 = MESSAGE:New( "Congratulations, you've just killed a target", "Score", 25, "Score" ) function MESSAGE:New( MessageText, MessageCategory, MessageDuration, MessageID ) -trace.f(self.ClassName, { MessageText, MessageCategory, MessageDuration, MessageID } ) - local self = BASE:Inherit( self, BASE:New() ) - - self.MessageCategory = MessageCategory + self:T( { MessageText, MessageCategory, MessageDuration, MessageID } ) + + -- When no messagecategory is given, we don't show it as a title... + if MessageCategory and MessageCategory ~= "" then + self.MessageCategory = MessageCategory .. "\n" + else + self.MessageCategory = "" + end + self.MessageDuration = MessageDuration self.MessageID = MessageID self.MessageTime = timer.getTime() @@ -6160,13 +6225,13 @@ end -- MessageClient1:ToClient( ClientGroup ) -- MessageClient2:ToClient( ClientGroup ) function MESSAGE:ToClient( Client ) -trace.f(self.ClassName ) + self:T( Client ) if Client and Client:GetClientGroupID() then local ClientGroupID = Client:GetClientGroupID() - trace.i( self.ClassName, self.MessageCategory .. '\n' .. self.MessageText:gsub("\n$",""):gsub("\n$","") .. " / " .. self.MessageDuration ) - trigger.action.outTextForGroup( ClientGroupID, self.MessageCategory .. '\n' .. self.MessageText:gsub("\n$",""):gsub("\n$",""), self.MessageDuration ) + trace.i( self.ClassName, self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$","") .. " / " .. self.MessageDuration ) + trigger.action.outTextForGroup( ClientGroupID, self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$",""), self.MessageDuration ) end return self @@ -6183,7 +6248,7 @@ end -- MessageBLUE = MESSAGE:New( "To the BLUE Players: You receive a penalty because you've killed one of your own units", "Penalty", 25, "Score" ) -- MessageBLUE:ToBlue() function MESSAGE:ToBlue() -trace.f(self.ClassName ) + self:T() self:ToCoalition( coalition.side.BLUE ) @@ -6201,7 +6266,7 @@ end -- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", "Penalty", 25, "Score" ) -- MessageRED:ToRed() function MESSAGE:ToRed( ) -trace.f(self.ClassName ) + self:T() self:ToCoalition( coalition.side.RED ) @@ -6220,11 +6285,11 @@ end -- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", "Penalty", 25, "Score" ) -- MessageRED:ToCoalition( coalition.side.RED ) function MESSAGE:ToCoalition( CoalitionSide ) -trace.f(self.ClassName ) + self:T( CoalitionSide ) if CoalitionSide then - trace.i(self.ClassName, self.MessageCategory .. '\n' .. self.MessageText:gsub("\n$",""):gsub("\n$","") .. " / " .. self.MessageDuration ) - trigger.action.outTextForCoalition( CoalitionSide, self.MessageCategory .. '\n' .. self.MessageText:gsub("\n$",""):gsub("\n$",""), self.MessageDuration ) + trace.i(self.ClassName, self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$","") .. " / " .. self.MessageDuration ) + trigger.action.outTextForCoalition( CoalitionSide, self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$",""), self.MessageDuration ) end return self @@ -6241,7 +6306,7 @@ end -- MessageAll = MESSAGE:New( "To all Players: BLUE has won! Each player of BLUE wins 50 points!", "End of Mission", 25, "Win" ) -- MessageAll:ToAll() function MESSAGE:ToAll() -trace.f(self.ClassName ) + self:T() self:ToCoalition( coalition.side.RED ) self:ToCoalition( coalition.side.BLUE ) @@ -6259,9 +6324,8 @@ MESSAGEQUEUE = { } function MESSAGEQUEUE:New( RefreshInterval ) -trace.f( self.ClassName, { RefreshInterval } ) - local self = BASE:Inherit( self, BASE:New() ) + self:T( { RefreshInterval } ) self.RefreshInterval = RefreshInterval diff --git a/Moose/Database.lua b/Moose/Database.lua index 4b0393607..d20f79f23 100644 --- a/Moose/Database.lua +++ b/Moose/Database.lua @@ -288,17 +288,21 @@ function DATABASE:OnDeadOrCrash( event ) end if InitCoalition == TargetCoalition then + PlayerData.Penalty = PlayerData.Penalty + 25 PlayerData.Kill[TargetCategory][TargetType].Penalty = PlayerData.Kill[TargetCategory][TargetType].Penalty + 25 PlayerData.Kill[TargetCategory][TargetType].PenaltyKill = PlayerData.Kill[TargetCategory][TargetType].PenaltyKill + 1 MESSAGE:New( "Player '" .. PlayerName .. "' killed a friendly " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. - PlayerData.Kill[TargetCategory][TargetType].PenaltyKill .. " times. Penalty: -" .. PlayerData.Kill[TargetCategory][TargetType].Penalty, + PlayerData.Kill[TargetCategory][TargetType].PenaltyKill .. " times. Penalty: -" .. PlayerData.Kill[TargetCategory][TargetType].Penalty .. + ". Score Total:" .. PlayerData.Score - PlayerData.Penalty, "", 5, "/PENALTY" .. PlayerName .. "/" .. InitUnitName ):ToAll() self:ScoreAdd( PlayerName, "KILL_PENALTY", 1, -125, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) else + PlayerData.Score = PlayerData.Score + 10 PlayerData.Kill[TargetCategory][TargetType].Score = PlayerData.Kill[TargetCategory][TargetType].Score + 10 PlayerData.Kill[TargetCategory][TargetType].ScoreKill = PlayerData.Kill[TargetCategory][TargetType].ScoreKill + 1 MESSAGE:New( "Player '" .. PlayerName .. "' killed an enemy " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. - PlayerData.Kill[TargetCategory][TargetType].ScoreKill .. " times. Score: " .. PlayerData.Kill[TargetCategory][TargetType].Score, + PlayerData.Kill[TargetCategory][TargetType].ScoreKill .. " times. Score: " .. PlayerData.Kill[TargetCategory][TargetType].Score .. + ". Score Total:" .. PlayerData.Score - PlayerData.Penalty, "", 5, "/SCORE" .. PlayerName .. "/" .. InitUnitName ):ToAll() self:ScoreAdd( PlayerName, "KILL_SCORE", 1, 10, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) end @@ -362,8 +366,10 @@ function DATABASE:_AddPlayerFromUnit( UnitData ) -- end self.Players[PlayerName].HitPlayers = {} self.Players[PlayerName].HitUnits = {} + self.Players[PlayerName].Score = 0 self.Players[PlayerName].Penalty = 0 self.Players[PlayerName].PenaltyCoalition = 0 + self.Players[PlayerName].PenaltyWarning = 0 end if not self.Players[PlayerName].UnitCoalition then @@ -386,8 +392,29 @@ function DATABASE:_AddPlayerFromUnit( UnitData ) self.Players[PlayerName].UnitCoalition = UnitCoalition self.Players[PlayerName].UnitCategory = UnitCategory self.Players[PlayerName].UnitType = UnitTypeName - end + if self.Players[PlayerName].Penalty > 100 then + if self.Players[PlayerName].PenaltyWarning < 1 then + MESSAGE:New( "Player '" .. PlayerName .. "': WARNING! If you continue to commit FRATRICIDE and have a PENALTY score higher than 150, you will be COURT MARTIALED and DISMISSED from this mission! \nYour total penalty is: " .. self.Players[PlayerName].Penalty, + "", + 30, + "/PENALTYCOALITION" .. PlayerName + ):ToAll() + self.Players[PlayerName].PenaltyWarning = self.Players[PlayerName].PenaltyWarning + 1 + end + end + + if self.Players[PlayerName].Penalty > 150 then + ClientGroup = GROUP:NewFromDCSUnit( UnitData ) + ClientGroup:Destroy() + MESSAGE:New( "Player '" .. PlayerName .. "' committed FRATRICIDE, he will be COURT MARTIALED and is DISMISSED from this mission!", + "", + 10, + "/PENALTYCOALITION" .. PlayerName + ):ToAll() + end + + end end @@ -406,6 +433,7 @@ function DATABASE:_AddMissionTaskScore( PlayerUnit, MissionName, Score ) self:T( PlayerName ) self:T( self.Players[PlayerName].Mission[MissionName] ) + self.Players[PlayerName].Score = self.Players[PlayerName].Score + Score self.Players[PlayerName].Mission[MissionName].ScoreTask = self.Players[PlayerName].Mission[MissionName].ScoreTask + Score MESSAGE:New( "Player '" .. PlayerName .. "' has finished another Task in Mission '" .. MissionName .. "'. " .. @@ -423,6 +451,7 @@ function DATABASE:_AddMissionScore( MissionName, Score ) for PlayerName, PlayerData in pairs( self.Players ) do if PlayerData.Mission[MissionName] then + PlayerData.Score = PlayerData.Score + Score PlayerData.Mission[MissionName].ScoreMission = PlayerData.Mission[MissionName].ScoreMission + Score MESSAGE:New( "Player '" .. PlayerName .. "' has finished Mission '" .. MissionName .. "'. " .. Score .. " Score points added.", @@ -540,20 +569,24 @@ function DATABASE:OnHit( event ) end local Score = 0 if InitCoalition == TargetCoalition then + self.Players[InitPlayerName].Penalty = self.Players[InitPlayerName].Penalty + 10 self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Penalty = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Penalty + 10 self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].PenaltyHit = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].PenaltyHit + 1 MESSAGE:New( "Player '" .. InitPlayerName .. "' hit a friendly " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. - self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].PenaltyHit .. " times. Penalty: -" .. self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Penalty, + self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].PenaltyHit .. " times. Penalty: -" .. self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Penalty .. + ". Score Total:" .. self.Players[InitPlayerName].Score - self.Players[InitPlayerName].Penalty, "", 2, "/PENALTY" .. InitPlayerName .. "/" .. InitUnitName ):ToAll() self:ScoreAdd( InitPlayerName, "HIT_PENALTY", 1, -25, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) else + self.Players[InitPlayerName].Score = self.Players[InitPlayerName].Score + 10 self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score + 1 self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit + 1 MESSAGE:New( "Player '" .. InitPlayerName .. "' hit a target " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. - self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit .. " times. Score: " .. self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score, + self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit .. " times. Score: " .. self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score .. + ". Score Total:" .. self.Players[InitPlayerName].Score - self.Players[InitPlayerName].Penalty, "", 2, "/SCORE" .. InitPlayerName .. "/" .. InitUnitName diff --git a/Moose/Group.lua b/Moose/Group.lua index 5a025c918..1103b13be 100644 --- a/Moose/Group.lua +++ b/Moose/Group.lua @@ -46,7 +46,7 @@ function GROUP:New( DCSGroup ) end ---- Create a new GROUP from an existing DCSGroup in the mission. +--- Create a new GROUP from an existing group name. -- @param self -- @param GroupName The name of the DCS Group. -- @return #GROUP self @@ -58,12 +58,30 @@ function GROUP:NewFromName( GroupName ) if self.DCSGroup then self.GroupName = self.DCSGroup:getName() self.GroupID = self.DCSGroup:getID() - self.Controller = DCSGroup:getController() + self.Controller = self.DCSGroup:getController() end return self end +--- Create a new GROUP from an existing DCSUnit in the mission. +-- @param self +-- @param DCSUnit The DCSUnit. +-- @return #GROUP self +function GROUP:NewFromDCSUnit( DCSUnit ) + local self = BASE:Inherit( self, BASE:New() ) + self:T( DCSUnit ) + + self.DCSGroup = DCSUnit:getGroup() + if self.DCSGroup then + self.GroupName = self.DCSGroup:getName() + self.GroupID = self.DCSGroup:getID() + self.Controller = self.DCSGroup:getController() + end + + return self +end + --- Gets the DCSGroup of the GROUP. -- @param self -- @return #Group The DCSGroup. diff --git a/Moose/Message.lua b/Moose/Message.lua index a544998ce..d17c07053 100644 --- a/Moose/Message.lua +++ b/Moose/Message.lua @@ -37,12 +37,11 @@ MESSAGE = { -- MessageClient1 = MESSAGE:New( "Congratulations, you've just hit a target", "Score", 25, "Score" ) -- MessageClient2 = MESSAGE:New( "Congratulations, you've just killed a target", "Score", 25, "Score" ) function MESSAGE:New( MessageText, MessageCategory, MessageDuration, MessageID ) -self:T( { MessageText, MessageCategory, MessageDuration, MessageID } ) - local self = BASE:Inherit( self, BASE:New() ) + self:T( { MessageText, MessageCategory, MessageDuration, MessageID } ) -- When no messagecategory is given, we don't show it as a title... - if MessageCategory or MessageCategory ~= "" then + if MessageCategory and MessageCategory ~= "" then self.MessageCategory = MessageCategory .. "\n" else self.MessageCategory = "" @@ -179,7 +178,6 @@ MESSAGEQUEUE = { function MESSAGEQUEUE:New( RefreshInterval ) local self = BASE:Inherit( self, BASE:New() ) - self:T( { RefreshInterval } ) self.RefreshInterval = RefreshInterval From 9912f9720915e6a98a8369296993874af32dc13e Mon Sep 17 00:00:00 2001 From: FlightControl Date: Fri, 18 Mar 2016 19:18:44 +0100 Subject: [PATCH 3/3] Fix Rename of Essential API of the SPAWN class back to public. --- Moose/Spawn.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Moose/Spawn.lua b/Moose/Spawn.lua index 711d2d490..00d4b0d74 100644 --- a/Moose/Spawn.lua +++ b/Moose/Spawn.lua @@ -831,7 +831,7 @@ end --- Get the index from a given group. -- The function will search the name of the group for a #, and will return the number behind the #-mark. -function SPAWN:_GetGroupIndexFromGroup( SpawnGroup ) +function SPAWN:GetSpawnIndexFromGroup( SpawnGroup ) self:T( { self.SpawnTemplatePrefix, self.SpawnAliasPrefix, SpawnGroup } ) local IndexString = string.match( SpawnGroup:GetName(), "#.*$" ):sub( 2 ) @@ -1137,7 +1137,7 @@ function SPAWN:_OnLand( event ) self.Landed = true self:T( "self.Landed = true" ) if self.Landed and self.RepeatOnLanding then - local SpawnGroupIndex = self:_GetGroupIndexFromGroup( SpawnGroup ) + local SpawnGroupIndex = self:GetSpawnIndexFromGroup( SpawnGroup ) self:T( { "Landed:", "ReSpawn:", SpawnGroup:GetName(), SpawnGroupIndex } ) self:ReSpawn( SpawnGroupIndex ) end @@ -1158,7 +1158,7 @@ function SPAWN:_OnLand( event ) if SpawnGroup then self:T( { "EngineShutDown event: " .. event.initiator:getName(), event } ) if self.Landed and self.RepeatOnEngineShutDown then - local SpawnGroupIndex = self:_GetGroupIndexFromGroup( SpawnGroup ) + local SpawnGroupIndex = self:GetSpawnIndexFromGroup( SpawnGroup ) self:T( { "EngineShutDown: ", "ReSpawn:", SpawnGroup:GetName(), SpawnGroupIndex } ) self:ReSpawn( SpawnGroupIndex ) end