Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VotingKick.c
Go to the documentation of this file.
3 {
4  [Attribute(desc: "When true, only players on the same faction as target of the vote can vote.")]
5  protected bool m_bFactionSpecific;
6 
7  //~ Used in voting to make sure there is a min kick duration (in seconds)
8  protected static const int PLAYER_VOTE_KICK_DURATION = 300;
9 
10  //------------------------------------------------------------------------------------------------
11  override void InitFromTemplate(SCR_VotingBase template, int value, float remainingDuration)
12  {
13  super.InitFromTemplate(template, value, remainingDuration);
14 
15  SCR_VotingKick votingKickTemplate = SCR_VotingKick.Cast(template);
16  m_bFactionSpecific = votingKickTemplate.isFactionSpecific();
17  }
18 
19  //------------------------------------------------------------------------------------------------
22  // TODO: fix casing
23  bool isFactionSpecific()
24  {
25  return m_bFactionSpecific;
26  }
27 
28  //------------------------------------------------------------------------------------------------
29  override bool IsAvailable(int value, bool isOngoing)
30  {
31  //--- Cannot kick yourself
32  if (value == SCR_PlayerController.GetLocalPlayerId())
33  return false;
34 
35  //--- Cannot kick admin
36  if (SCR_Global.IsAdmin(value))
37  return false;
38 
39  //--- When faction specific, allow voting only for players on the same faction as target of the vote
40  if (m_bFactionSpecific)
41  {
42  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
43  if (!factionManager)
44  return false;
45 
46  Faction targetFaction = factionManager.GetPlayerFaction(value); //--- value is ID of the player who is target of the vote
47  Faction playerFaction = factionManager.GetPlayerFaction(SCR_PlayerController.GetLocalPlayerId());
48  if (targetFaction != playerFaction || !targetFaction)
49  return false;
50  }
51 
52  //--- Cannot vote to kick out session host
53  SCR_VotingManagerComponent votingManager = SCR_VotingManagerComponent.GetInstance();
54  if (!votingManager)
55  return false;
56 
57  //~ Cannot kick if auto kick vote already active
58  if (m_Type == EVotingType.KICK && votingManager.IsVoting(EVotingType.AUTO_KICK, value))
59  return false;
60 
61  return votingManager && votingManager.GetHostPlayerID() != value;
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  override int GetPlayerCount()
66  {
67  int playerCount;
68  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
69 
70  Faction targetFaction;
71 
72  if (factionManager)
73  targetFaction = factionManager.GetPlayerFaction(m_iValue);
74 
75  if (m_bFactionSpecific && targetFaction)
76  {
77  //--- When faction specific, count only players on the same faction as target of the vote
78  //--- e.g., with 50% vote limit, only half of BLUFOR players will have to vote, not half of all players
79 
80  Faction playerFaction;
81  array<int> players = {};
82 
83  for (int i = 0, count = GetGame().GetPlayerManager().GetPlayers(players); i < count; i++)
84  {
85  //~ Ignore player that is the target of vote
86  if (players[i] != m_iValue)
87  {
88  //~ Check if player faction is the same as target faction
89  playerFaction = factionManager.GetPlayerFaction(players[i]);
90  if (targetFaction == playerFaction)
91  playerCount++;
92  }
93  }
94  }
95  else
96  {
97  //--- Ignore target player by subtracting 1
98  playerCount = super.GetPlayerCount() - 1;
99  }
100  //--- Limit to prevent instant completion in a session with less than limited participants
101  return Math.Max(playerCount, m_iMinVotes);
102  }
103 
104  //------------------------------------------------------------------------------------------------
105  override void OnVotingEnd(int value = DEFAULT_VALUE, int winner = DEFAULT_VALUE)
106  {
107  //~ Vote failed
108  if (winner == DEFAULT_VALUE)
109  return;
110 
112  //~ Kick using crime module
113  if (crimesModule)
114  {
115  switch(m_Type)
116  {
117  case EVotingType.KICK:
118  crimesModule.KickOrBanPlayer(winner, PlayerManagerKickReason.KICK_VOTED, PLAYER_VOTE_KICK_DURATION);
119  return;
120  case EVotingType.AUTO_KICK:
121  crimesModule.KickOrBanPlayer(winner, PlayerManagerKickReason.KICK, 0);
122  return;
123  case EVotingType.AUTO_LIGHTBAN:
124  crimesModule.KickOrBanPlayer(winner, PlayerManagerKickReason.TEMP_BAN, SCR_DataCollectorCrimesModule.MIN_AUTO_BAN_DURATION);
125  return;
126  case EVotingType.AUTO_HEAVYBAN:
127  crimesModule.KickOrBanPlayer(winner, PlayerManagerKickReason.BAN, SCR_DataCollectorCrimesModule.MIN_AUTO_BAN_DURATION);
128  return;
129  }
130  }
131  //~ For some reason the crime module does not exist so default kick/ban is called. Note that it can never heavy ban/backend ban only temp ban
132  else
133  {
134  if (m_Type == EVotingType.KICK)
135  GetGame().GetPlayerManager().KickPlayer(winner, PlayerManagerKickReason.KICK_VOTED, PLAYER_VOTE_KICK_DURATION);
136  else if (m_Type == EVotingType.AUTO_KICK)
137  GetGame().GetPlayerManager().KickPlayer(winner, PlayerManagerKickReason.KICK, 0);
138  else
139  {
140  //~ Ban for which ever time is longer
141  if (SCR_DataCollectorCrimesModule.MIN_AUTO_BAN_DURATION > PLAYER_VOTE_KICK_DURATION)
142  GetGame().GetPlayerManager().KickPlayer(winner, PlayerManagerKickReason.TEMP_BAN, SCR_DataCollectorCrimesModule.MIN_AUTO_BAN_DURATION);
143  else
144  GetGame().GetPlayerManager().KickPlayer(winner, PlayerManagerKickReason.TEMP_BAN, PLAYER_VOTE_KICK_DURATION);
145  }
146  }
147  }
148 }
SCR_VotingBase
Definition: SCR_VotingBase.c:5
SCR_PlayerController
Definition: SCR_PlayerController.c:31
GetPlayers
protected int GetPlayers(out notnull array< int > outPlayers)
Definition: SCR_DataCollectorComponent.c:233
SCR_BaseContainerCustomTitleEnum
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
Definition: SCR_CampaignHintStorage.c:22
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_iValue
protected int m_iValue
Definition: SCR_VotingBase.c:3
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_DataCollectorCrimesModule
Definition: SCR_DataCollectorCrimesModule.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_VotingReferendum
Definition: SCR_VotingBase.c:345
PlayerManagerKickReason
PlayerManagerKickReason
Definition: PlayerManagerKickReason.c:12
m_Type
protected EEditableEntityType m_Type
Definition: SCR_EntitiesToolbarEditorUIComponent.c:3
Faction
Definition: Faction.c:12
EVotingType
EVotingType
Definition: EVotingType.c:1
SCR_Global
Definition: Functions.c:6
SCR_VotingKick
Definition: SCR_VotingKick.c:2
SCR_VotingManagerComponent
void SCR_VotingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_VotingManagerComponent.c:878
GetDataCollector
SCR_DataCollectorComponent GetDataCollector()
Definition: game.c:90
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
FindModule
SCR_DataCollectorModule FindModule(typename type)
Definition: SCR_DataCollectorComponent.c:179
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468