This repository has been archived by the owner on Nov 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VoteDay.py
85 lines (77 loc) · 3.32 KB
/
VoteDay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
__author__ = 'Corrosion X'
__version__ = '1.0.1'
__name__ = 'VoteDay'
import clr
import sys
clr.AddReferenceByPartialName("UnityEngine")
clr.AddReferenceByPartialName("Pluton")
import UnityEngine
import Pluton
class VoteDay:
votes = 0
GetConfig = Plugin.GetIni("VoteDay")
def On_PluginInit(self):
self.votingclearCallback(None)
Commands.Register("voteday")\
.setCallback("voteday")\
.setDescription("Initiate vote for day")\
.setUsage("use during night to start a vote for day")
ConfigFile = Plugin.CreateIni("VoteDay")
ConfigFile.AddSetting("Config", ";; Votes Required is a percent ;;")
ConfigFile.AddSetting("Config", "votesrequired", "51")
ConfigFile.AddSetting("Config", ";; Vote Timer - in milliseconds ;;")
ConfigFile.AddSetting("Config", "votetimer", "60000")
ConfigFile.AddSetting("Config", ";; Vote Timer - in milliseconds ;;")
ConfigFile.AddSetting("Config", "cooldown", "60000")
ConfigFile.Save()
def voteday(self, unused, player):
timerstarted = DataStore.Get("voteday", "timerstarted")
cooldown = DataStore.Get("voteday", "cooldown")
if cooldown:
player.Message("You must wait longer to start another vote!")
return
if not timerstarted or None:
if 17.5 < World.Time or World.Time < 5.5:
vtimer = int(self.GetConfig.GetSetting("Config", "votetimer", "60000"))
Server.Broadcast("A vote for day has been started by " + player.Name + " Use /voteday to cast your vote.")
Plugin.CreateTimer("votingtimer", vtimer).Start()
DataStore.Add("voteday", "timerstarted", True)
DataStore.Add("voteday", player.SteamID, True)
self.votes += 1
else:
player.Message("You have to wait until night before starting a vote.")
else:
if DataStore.ContainsKey("voteday", player.SteamID):
player.Message("You already voted!")
return
else:
self.votes += 1
DateStore.Add("voteday", player.SteamID, True)
player.Message("You're vote was added!")
result = self.domath()
result *= 100
Server.Broadcast("Current votes for day:" + str(result) + "%")
def votingtimerCallback(self, unused):
DataStore.Add("voteday", "timerstarted", False)
if DataStore.Get("voteday", "cooldown"):
return
result = self.domath() * 100
percent = int(self.GetConfig.GetSetting("Config", "votepercent", "51"))
if result >= percent:
Server.Broadcast("Vote for day Passed!")
World.Time = 7
self.votingclearCallback(None)
else:
Server.Broadcast("Vote for day failed!")
waittime = int(self.GetConfig.GetSetting("Config", "cooldown", "60000"))
Plugin.CreateTimer("votingclear", waittime).Start()
DataStore.Add("voteday", "cooldown", True)
def votingclearCallback(self, unused):
self.votes = 0
DataStore.Flush("voteday")
Plugin.KillTimers()
def domath(self):
votes = self.votes
count = Server.Players.Count
result = votes / count
return result