1 [
EntityEditorProps(
category:
"GameScripted/GameMode", description:
"Takes care of player penalties, kicks, bans etc.", color:
"0 0 255 255")]
27 protected static const int EVALUATION_PERIOD = 1000;
48 SCR_ChimeraCharacter victimChar = SCR_ChimeraCharacter.Cast(entity);
53 int killerPlayerId = instigator.GetInstigatorPlayerID();
54 int victimPlayerId =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(victimChar);
57 if (killerPlayerId == victimPlayerId)
64 Faction factionKiller =
Faction.Cast(factionManager.GetPlayerFaction(killerPlayerId));
69 if (!factionKiller.IsFactionFriendly(victimChar.GetFaction()))
74 if (victimPlayerId <= 0)
92 static SCR_ChimeraCharacter GetInstigatorFromVehicle(IEntity veh,
bool gunner =
false)
94 BaseCompartmentManagerComponent compartmentManager = BaseCompartmentManagerComponent.Cast(veh.FindComponent(BaseCompartmentManagerComponent));
96 if (!compartmentManager)
99 array<BaseCompartmentSlot> compartments =
new array <BaseCompartmentSlot>();
101 for (
int i = 0, cnt = compartmentManager.GetCompartments(compartments); i < cnt; i++)
103 BaseCompartmentSlot slot = compartments[i];
106 return SCR_ChimeraCharacter.Cast(slot.GetOccupant());
132 if (playerPenaltyData)
133 return playerPenaltyData;
136 PlayerController pc =
GetGame().GetPlayerManager().GetPlayerController(playerId);
140 Print(
string.Format(
"SCR_PlayerPenaltyComponent: No player with playerId %1 found.", playerId), LogLevel.ERROR);
146 playerPenaltyData.SetPlayerId(playerId);
149 return playerPenaltyData;
156 WorldTimestamp currentTime = world.GetServerTimestamp();
162 if (playerPenaltyData.GetPenaltyScore() > 0 && playerPenaltyData.GetNextPenaltySubtractionTimestamp().Less(currentTime))
167 forgivenScore = playerPenaltyData.GetPenaltyScore();
171 playerPenaltyData.AddPenaltyScore(-forgivenScore);
174 int playerId = playerPenaltyData.GetPlayerId();
199 void KickPlayer(
int playerId,
int duration, SCR_PlayerManagerKickReason reason)
203 if (playerPenaltyData)
204 playerPenaltyData.AddPenaltyScore(-playerPenaltyData.GetPenaltyScore());
206 GetGame().GetPlayerManager().KickPlayer(playerId, reason, duration);
224 void SCR_LocalPlayerPenalty(
int friendlyPlayerKillPenalty,
int friendlyAIKillPenalty,
int penaltyLimit,
int banDuration,
int penaltySubtractionPeriod,
int penaltySubtractionPoints)
234 Print(
"SCR_PlayerPenaltyComponent: Ban duration is shorter than Penalty substraction period. This will cause the player to remain banned until their penalty is substracted.", LogLevel.WARNING);
244 protected int m_iPlayerId;
245 protected int m_iPenaltyScore;
246 protected WorldTimestamp m_fNextPenaltySubtractionTimestamp;
247 protected SCR_PlayerManagerKickReason m_eKickReason = SCR_PlayerManagerKickReason.DISRUPTIVE_BEHAVIOUR;
251 void SetPlayerId(
int playerId)
266 void AddPenaltyScore(
int points)
268 m_iPenaltyScore += points;
272 WorldTimestamp currentTime = world.GetServerTimestamp();
273 if ((points > 0 && m_fNextPenaltySubtractionTimestamp.Less(currentTime)) || (points < 0 && m_iPenaltyScore > 0))
274 m_fNextPenaltySubtractionTimestamp = currentTime.PlusMilliseconds(
SCR_LocalPlayerPenalty.GetInstance().GetPenaltySubtractionPeriod());
279 float GetPenaltyScore()
281 return m_iPenaltyScore;
286 void SetNextPenaltySubstractionTimestamp(WorldTimestamp timestamp)
288 m_fNextPenaltySubtractionTimestamp = timestamp;
293 WorldTimestamp GetNextPenaltySubtractionTimestamp()
295 return m_fNextPenaltySubtractionTimestamp;