10 [
Attribute(
desc:
"When enabled, values are considered player IDs (e.g., a vote to KICK player).")]
13 [
Attribute(defvalue:
"1",
desc:
"Should vote be canceled when subject leaves the server.")]
16 [
Attribute(
"120",
desc:
"The voting will end after this duration (in seconds) and outcome will be evaluated.")]
19 [
Attribute(
"0.5",
UIWidgets.Slider,
"When percentual number of votes for single value is *larger* than this threshold, the voting will instantly end.\ne.g., in a session with 8 players and threshold 0.5, 5 votes are needed to win.",
params:
"0 1 0.01")]
22 [
Attribute(
"0.5",
UIWidgets.Slider,
"Winner can be declared only if this percentage of players participated in the vote.\nEvaluated together with 'Min Votes', at least one has to pass.",
params:
"0 1 0.01")]
25 [
Attribute(
"3",
desc:
"Winner can be declare only if at least this amount of players participated in the vote.\nEvaluated together with 'Min Participation', at least one has to pass.")]
31 [
Attribute(
"0",
desc:
"Delay in seconds between when the player joined the server and when they are able to start this specific vote. 0 means this is ignored",
params:
"0 inf")]
34 [
Attribute(
"0",
desc:
"If the server started fresh / restarted and players join it will check if the server was active for longer than this time (in seconds). If not it will not set the ServerVoteDelay time. Ignored if 0.",
params:
"0 inf")]
37 [
Attribute(
"0",
desc:
"Cooldown in seconds between instantiating votes. If a player has started a vote than they will no longer be able to do the same vote until the time has passed. Ignored if 0.",
params:
"0 inf")]
40 [
Attribute(
"0",
desc:
"When true, the subject of voting has voting timer always enabled during the voting progress.")]
43 [
Attribute(
"0",
desc:
"Makes the voting timer visible for the vote initiator throughout the voting process.")]
282 return value.ToString();
391 if (remainingDuration == -1)
411 int playersRequiredInt =
Math.Ceil(playersRequired);
414 if (playersRequired == playersRequiredInt)
415 playersRequiredInt++;
420 return playersRequiredInt;
477 if (!super.AddPlayerVotedServer(playerID))
482 if (playerMgr &&
System.GetCLIParam(
"logVoting", cliVal))
484 string serverLogMessage;
486 serverLogMessage +=
", where the vote subject is player '" + playerMgr.GetPlayerName(
m_iValue) +
"' (with player id = " +
m_iValue +
")";
488 serverLogMessage +=
", with vote value = " +
m_iValue;
490 Print(
"VOTING SYSTEM - Player '" + playerMgr.GetPlayerName(playerID) +
"' (with player id = " + playerID +
") voted in favor of the vote type = " +
typename.EnumToString(
EVotingType,
m_Type) + serverLogMessage,
LogLevel.NORMAL);
499 if (!super.RemovePlayerVotedServer(playerID))
504 if (playerMgr &&
System.GetCLIParam(
"logVoting", cliVal))
506 string serverLogMessage;
508 serverLogMessage +=
", where the vote subject is player '" + playerMgr.GetPlayerName(
m_iValue) +
"' (with player id = " +
m_iValue +
")";
510 serverLogMessage +=
", with vote value = " +
m_iValue;
512 Print(
"VOTING SYSTEM - Player '" + playerMgr.GetPlayerName(playerID) +
"' (with player id = " + playerID +
") voted against or retracted his vote for the vote type = " +
typename.EnumToString(
EVotingType,
m_Type) + serverLogMessage,
LogLevel.NORMAL);
595 super.InitFromTemplate(
template, startingPlayerID, value, remainingDuration);
607 protected int m_iHighestValue = DEFAULT_VALUE;
608 protected int m_iHighestCount;
611 protected void UpdateHighestValue()
615 set<int> winners =
new set<int>();
616 foreach (
int playerID,
int value: m_Votes)
619 if (tally.Find(value, count))
624 tally.Set(value, count);
626 if (count > m_iHighestCount)
628 m_iHighestCount = count;
630 winners.Insert(value);
632 else if (count == m_iHighestCount)
634 winners.Insert(value);
638 if (winners.IsEmpty())
639 m_iHighestValue = DEFAULT_VALUE;
642 m_iHighestValue = winners[
Math.RandomInt(0, winners.Count())];
646 override void SetVote(
int playerID,
int value = DEFAULT_VALUE)
648 m_Votes.Set(playerID, value);
649 UpdateHighestValue();
655 m_Votes.Remove(playerID);
656 UpdateHighestValue();
657 return m_Votes.IsEmpty();
663 for (
int i = m_Votes.Count() - 1; i >= 0; i--)
665 if (m_Votes.GetElement(i) == value)
666 m_Votes.RemoveElement(i);
668 UpdateHighestValue();
689 return m_iHighestValue;
691 return DEFAULT_VALUE;
698 if (m_Votes.Find(playerID, value))
701 return DEFAULT_VALUE;
708 PrintFormat(
" Leading value: %1 with %2 votes", m_iHighestValue, m_iHighestCount);
709 foreach (
int playerID,
int value: m_Votes)
ArmaReforgerScripted GetGame()
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_VotingReferendum SCR_VotingBase SCR_BaseContainerCustomTitleEnum(EVotingType, "m_Type")
SCR_VotingReferendum SCR_VotingBase BaseContainerProps()
bool Evaluate(out EVotingOutcome outcome)
bool AddPlayerVotedServer(int playerID)
void InitFromTemplate(SCR_VotingBase template, int startingPlayerID, int value, float remainingDuration)
SCR_VotingUIInfo GetInfo()
bool IsMatching(EVotingType type, int value=DEFAULT_VALUE)
ref SCR_VotingUIInfo m_Info
ref array< int > m_aPlayersVoted_Server
bool CanSendNotification(int value)
void SetVoteLocal(int value)
int GetCurrentVoteCount()
bool RemovePlayerVotedServer(int playerID)
int GetVoteCooldownTime()
float GetRemainingDuration()
int GetServerRuntimeIgnoreJoinServerCooldown()
static const int DEFAULT_VALUE
bool RemoveVote(int playerID)
bool m_bHasInitiatedVotingLocallyOnce
bool m_bAlwaysDisplayVoteSubjectVotingTimer
void SetLocalCooldownTimeStamp(float newTimeStamp)
float m_fVoteCooldownTimeStamp
int GetVoteCountRequired()
bool HasInitiatedVotingLocallyOnce()
void Update(float timeSlice)
int m_iJoinServerVoteCooldown
bool m_bAlwaysDisplayVoteInitiatorVotingTimer
int m_iServerRuntimeIgnoreJoinServerCooldown
void OnVotingEnd(int value=DEFAULT_VALUE, int winner=DEFAULT_VALUE)
int GetPlayerVote(int playerID)
void SetVote(int playerID, int value=DEFAULT_VALUE)
bool GetAlwaysDisplayVoteSubjectVotingTimer()
void SetCurrentVoteCount(int currentVoteCount)
bool IsAvailable(int value, bool isOngoing)
bool EvaluateParticipation(int voteCount)
void SetHasInitiatedVotingLocallyOnce()
Set Has initiated voting locally at least once to true.
string GetValueName(int value)
float m_iMinParticipation
bool GetAlwaysDisplayVoteInitiatorVotingTimer()
int GetJoinServerVoteCooldown()
bool RemoveValue(int value)
bool ShouldCancelWhenSubjectLeavesTheServer()
float GetLocalCooldownTimeStamp()
bool m_bCancelWhenSubjectLeavesTheServer
static const int ALTERNATIVE_VALUE
Value of the vote, that is used when vote ends in an alternative solution.
override bool Evaluate(out EVotingOutcome outcome)
override bool AddPlayerVotedServer(int playerID)
override void InitFromTemplate(SCR_VotingBase template, int startingPlayerID, int value, float remainingDuration)
override bool RemoveValue(int value)
override bool RemoveVote(int playerID)
override bool RemovePlayerVotedServer(int playerID)
override bool IsMatching(EVotingType type, int value=DEFAULT_VALUE)
override int GetPlayerVote(int playerID)
override void SetVote(int playerID, int value=DEFAULT_VALUE)
ref set< int > m_aPlayerIDs
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute