Vote Day Time

justcyber

New Member
Member
Jan 3, 2015
13
0
1
56
Let There Be Light

Can you take this script and make it into Python so it can be ran on the server? I want to give the players the option to vote whether it should be day time or not. Here is the LUA file version
Code:
PLUGIN.Title = "Daytime Poll"
PLUGIN.Description = "Allows players to vote for daytime"
PLUGIN.Author = "GreenMan"
PLUGIN.Version = "2.2.1"


function PLUGIN:Init ()
    local b, res = config.Read ( "daytime" )
    self.Config = res or {}
    if (not b) then
        self:LoadDefaultConfig()
        if ( res ) then config.Save( "daytime" ) end
    end
    self:AddChatCommands()
    self:CheckPlugins()
end

function PLUGIN:LoadDefaultConfig ()
    self.Config.VoteCMD = "vote"
    self.Config.poll_timer = 30
    self.Config.start_time = 18.00
    self.Config.end_time = 5.00
    self.Config.denied_time = 300
    self.Config.percent_topass = 50
    self.Config.Poll_Cost = 500
    self.Config.disable_whendenied = true
    self.Config.PollEnabled = true
    self.Config.EnableEcon = false
end

function PLUGIN:AddChatCommands ()
    self:AddChatCommand( self.Config.VoteCMD, self.cmdvote )
    self:AddChatCommand( "daytime", self.cmddaytime )
    self:AddChatCommand( "gametime", self.cmdgametime )
    self:AddChatCommand( "daysettings", self.cmdSettings )
end

function PLUGIN:CheckPlugins ()
    if (self.Config.EnableEcon == true) then
        local bushy = plugins.Find( "bushycoin" )
        econ = plugins.Find( "econ" )
        if ( bushy ) and ( not econ ) then
            econ_loaded = "bushycoin"
            print( "Timed DayTime Poll Loaded with Bushy Coin Support" )
        elseif ( econ ) and ( not bushy ) then
            econ_loaded = "econ"
            print( "Timed DayTime Poll Loaded with Basic/Extended Economy Support" )
        elseif ( econ ) and ( bushy ) then
            print( "ERROR: Two Economy Plugins Found" )
            print( "Timed Daytime Poll Loaded with no Economy Support" )
        else
            print( "ERROR: No Economy Plugins Found" )
            print( "Timed Daytime Poll Loaded with no Economy Support" )
        end
    else
        print ( "Timed Daytime Poll Loaded." )
    end
end

function PLUGIN:cmdgametime ( netuser, cmd )
    local game_time = Rust.EnvironmentControlCenter.Singleton:GetTime()
    rust.Notice( netuser, "Current Game time is: " .. string.format("%.2f", game_time) )
end

function PLUGIN:cmdSettings( netuser, cmd, args )
    if (  netuser:CanAdmin() ) then
        if ( not args[1] ) then
            rust.SendChatToUser( netuser, "DayTime Poll", "*--------Daytime Settings--------*" )
            rust.SendChatToUser( netuser, "DayTime Poll", "/daysettings { OPTION } { VALUE }" )
            rust.SendChatToUser( netuser, "DayTime Poll", "enable { true|false }" )
            rust.SendChatToUser( netuser, "DayTime Poll", "percent { 1-100 }" )
            rust.SendChatToUser( netuser, "DayTime Poll", "starttime { 1 - 23 }" )
            rust.SendChatToUser( netuser, "DayTime Poll", "endtime { 1 - 23 }" )
            rust.SendChatToUser( netuser, "DayTime Poll", "deniedtime { SECONDS }" )
            rust.SendChatToUser( netuser, "DayTime Poll", "deniedcd { true | false }" )
            rust.SendChatToUser( netuser, "DayTime Poll", "poll_length { SECONDS }" )
            rust.SendChatToUser( netuser, "DayTime Poll", "econ { true | false }" )
            rust.SendChatToUser( netuser, "DayTime Poll", "cost { Number > 0 }" )
            return
        elseif ( args[1] == "enable" ) then
            if ( not args[2] ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Daytime Poll is currently set to: " .. tostring(self.Config.PollEnabled) )
                return
            elseif ( args[2] == "true" ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Daytime poll is now enabled" )
                self.Config.PollEnabled = true
                config.Save( "daytime" )
                return
            elseif ( args[2] == "false" ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Daytime poll is now disabled" )
                self.Config.PollEnabled = false
                config.Save( "daytime" )
                return       
            else rust.SendChatToUser( netuser, "DayTime Poll", "Must Enter True|False.") return end
        elseif ( args[1] == "percent" ) then
            if ( not args[2] ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Percent to Pass is currently set to: " .. tostring(self.Config.percent_topass) .. "%" )
                return
            elseif ( 0 < tonumber(args[2]) and tonumber(args[2]) <= 100 ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Percent of Yes Votes to Pass is now: " .. args[2] )
                self.Config.percent_topass = tonumber(args[2])
                config.Save( "daytime" )
                return
            else rust.SendChatToUser( netuser, "DayTime Poll", "Please enter a number between 1 and 100" ) return end
        elseif ( args[1] == "starttime" ) then
            if ( not args[2] ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Poll Start Time is currently set to: " .. tostring(self.Config.start_time) )
                return
            elseif ( 0 < tonumber(args[2]) and tonumber(args[2]) <= 23 ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Start Time is now set to: " .. args[2] )
                self.Config.start_time = tonumber(args[2])
                config.Save( "daytime" )
                return
            else rust.SendChatToUser( netuser, "DayTime Poll", "Please enter a number between 1 and 23" ) return end
        elseif ( args[1] == "endtime" ) then
            if ( not args[2] ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Poll End Time is currently set to: " .. tostring(self.Config.end_time) )
                return
            elseif ( 0 < tonumber(args[2]) and tonumber(args[2]) <= 23 ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "End Time is now set to: " .. args[2] )
                self.Config.end_time = tonumber(args[2])
                config.Save( "daytime" )
                return       
            else rust.SendChatToUser( netuser, "DayTime Poll", "Please enter a number between 1 and 23" ) return end
        elseif ( args[1] == "deniedtime" ) then
            if ( not args[2] ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Denied Timer is currently set to: " .. tostring(self.Config.denied_time) .. " seconds." )
                return
            elseif ( tonumber(args[2]) > 0 ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Denied Timer is now set to: " .. args[2] .. " seconds" )
                self.Config.denied_time = tonumber(args[2])
                config.Save( "daytime" )
                return       
            else rust.SendChatToUser( netuser, "DayTime Poll", "Please enter a number between Greater then 0. To Disable, change deniedcd to false." ) return end   
        elseif ( args[1] == "deniedcd") then
            if ( not args[2] ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Disable When Denied is currently set to: " .. tostring(self.Config.disable_whendenied) )
                return
            elseif ( args[2] == "true" ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Daytime poll will now be disabled when denied" )
                self.Config.disable_whendenied = true
                config.Save( "daytime" )
                return
            elseif ( args[2] == "false" ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Daytime poll will not be disabled when denied" )
                self.Config.disable_whendenied = false
                config.Save( "daytime" )
                return       
            else rust.SendChatToUser( netuser, "Must Enter True|False.") return end
        elseif ( args[1] == "poll_length") then
            if ( not args[2] ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Poll Length is currently set to: " .. tostring(self.Config.poll_timer) .. " seconds" )
                return
            elseif ( tonumber(args[2]) > 0 ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Poll Length is now set to: " .. args[2] .. " seconds" )
                self.Config.poll_timer = tonumber(args[2])
                config.Save( "daytime" )
                return       
            else rust.SendChatToUser( netuser, "DayTime Poll", "Please enter a number between Greater then 0. To Disable, change deniedcd to false." ) return end
        elseif ( args[1] == "cost") then
            if ( not args[2] ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Poll Cost is currently set to: $" .. tostring(self.Config.Poll_Cost) )
                return
            elseif ( tonumber(args[2]) > 0 ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Poll Cost is now set to: $" .. args[2] )
                self.Config.Poll_Cost = tonumber(args[2])
                config.Save( "daytime" )
                return       
            else rust.SendChatToUser( netuser, "DayTime Poll", "Please enter a number between Greater then 0. To Disable, change econ to false." ) return end
        elseif ( args[1] == "econ") then
            if ( not args[2] ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Use Economy is currently set to: " .. tostring(self.Config.disable_whendenied) )
                return
            elseif ( args[2] == "true" ) then
                self.Config.EnableEcon = true           
                if ( not econ_loaded ) then self:CheckPlugins() end
                rust.SendChatToUser( netuser, "DayTime Poll", "Daytime poll will now use Economy Plugins" )
                config.Save( "daytime" )
                return
            elseif ( args[2] == "false" ) then
                rust.SendChatToUser( netuser, "DayTime Poll", "Daytime Poll will no longer use Economy Plugins." )
                self.Config.EnableEcon = false
                config.Save( "daytime" )
                return       
            else rust.SendChatToUser( netuser, "Must Enter True|False.") return end
        else rust.SendChatToUser( netuser, "DayTime Poll", "Unknown Option" ) return end
    end
end


function PLUGIN:cmddaytime( netuser, cmd, args )
    local current_time = Rust.EnvironmentControlCenter.Singleton:GetTime()
    if ( args[1] == "help" ) then
        rust.SendChatToUser( netuser, "DayTime Poll", "*------Daytime Poll by GreenMan------*" )
        rust.SendChatToUser( netuser, "DayTime Poll", "Use /daytime to start a poll for Day" )
        rust.SendChatToUser( netuser, "DayTime Poll", "When a poll is active:" )
        rust.SendChatToUser( netuser, "DayTime Poll", "\"/" .. self.Config.VoteCMD .. " Y\" to vote FOR Day" )
        rust.SendChatToUser( netuser, "DayTime Poll", "\"/" .. self.Config.VoteCMD .. " N\" to vote AGAINST Day" )
        rust.SendChatToUser( netuser, "DayTime Poll", "Polls can be started between " .. string.format("%.2f",self.Config.start_time) .. " and " .. string.format("%.2f",self.Config.end_time) )
        rust.SendChatToUser( netuser, "DayTime Poll", "Type /gametime to see the current Time ingame" )
        if (  netuser:CanAdmin() ) then rust.SendChatToUser( netuser, "DayTime Poll", "Type /daysettings to Change Settings while in-game" ) end
        rust.SendChatToUser( netuser, "DayTime Poll", "*-------------------------------------------*" )
        return
    end
    if ( poll_denied and self.Config.disable_whendenied == true ) or ( self.Config.PollEnabled ~= true ) then
        rust.Notice( netuser, "Poll is Disabled" )
        return
    end
    if ( current_time  > tonumber(self.Config.start_time) ) or ( current_time < tonumber(self.Config.end_time) ) then
        if ( poll_on ) then
            rust.Notice( netuser, "A vote has already begun!" )
            return
        else
            if (self.Config.EnableEcon == true ) and ( econ_loaded ) then
                if (econ_loaded == "bushycoin") then
                    local call, req, res = api.Call( "bushycoin", "balance", netuser )
                    if ( res < tonumber(self.Config.Poll_Cost) ) then
                        rust.SendChatToUser( netuser, "DayTime Poll", "You don't have enough money to do this." )
                        return
                    else
                        local call, req, res = api.Call ( "bushycoin", "deduct", netuser, tonumber(self.Config.Poll_Cost) )
                        rust.SendChatToUser( netuser, "DayTime Poll", "You have successfully Started a Daytime Poll for $" .. self.Config.Poll_Cost )
                    end
                end
                if (econ_loaded == "econ") then
                    local player = rust.GetUserID( netuser )
                    if ( econ.Data[ player ].Money < tonumber(self.Config.Poll_Cost) ) then
                        rust.SendChatToUser( netuser, "DayTime Poll", "You don't have enough money to do this." )
                        return
                    else
                        econ.Data[ player ].Money = econ.Data[ player ].Money - tonumber(self.Config.Poll_Cost)
                        rust.SendChatToUser( netuser, "DayTime Poll", "You have successfully Started a Daytime Poll for $" .. self.Config.Poll_Cost )
                    end
                end
            end               
            poll_on = true
            yes_votes = 0
            no_votes = 0
            user_voted = rust.GetAllNetUsers()
            rust.RunServerCommand( "notice.popupall \"" .. self.Config.poll_timer .. " Second Poll for Daytime:  /" .. self.Config.VoteCMD .. " Y or N \"" )   
            endpolltimer = timer.Once( tonumber(self.Config.poll_timer), function() self:endpoll() end )
        end
    else
        rust.Notice( netuser, "Poll only available at Night!" )
    end
end

function PLUGIN:cmdvote ( netuser, cmd, args )
    local all_connected = tonumber(#rust.GetAllNetUsers())
    if ( not poll_on ) then
        rust.Notice( netuser, "There is no Active Poll!" )
        return
    end
    if ( user_voted[ netuser ] ~= true ) then
        if ( args[1] == "Y" ) or ( args[1] == "y") then
            rust.BroadcastChat( "DayTime Poll", netuser.DisplayName .. " votes Yes!" )
            yes_votes = yes_votes + 1
            user_voted[ netuser ] = true
        elseif ( args[1] == "N" ) or ( args[1] == "n" ) then
            rust.BroadcastChat( "DayTime Poll", netuser.DisplayName .. " votes No!" )
            no_votes = no_votes + 1
            user_voted[ netuser ] = true
        else
            rust.Notice( netuser, "Must be /vote Y or N" )
        end
    else
        rust.Notice( netuser, "You may only vote once!" )
        return
    end
    if ((yes_votes + no_votes) == all_connected) then
        endpolltimer:Destroy()
        self:endpoll()
    end
end   

function PLUGIN:SendHelpText ( netuser )
    rust.SendChatToUser( netuser, "DayTime Poll", "Use \"/daytime help\" for DayTime Poll Commands. " )
end

function PLUGIN:endpoll ()
    if ( yes_votes > 0 ) then
        local totalvotes = yes_votes + no_votes
        if ( (( yes_votes / totalvotes ) * 100 ) >= tonumber(self.Config.percent_topass) ) then
            rust.RunServerCommand( "notice.popupall \"Vote Has Passed!\"" )
            rust.RunServerCommand( "env.time 6" )
            rust.BroadcastChat( "DayTime Poll", "Time is now 6:00 am" )
        else
            rust.RunServerCommand( "notice.popupall \"Daytime has been denied!\"" )
            if (self.Config.disable_whendenied == true) then
                rust.BroadcastChat ( "DayTime Poll", "Poll will be disabled for " .. self.Config.denied_time .. " seconds." )
                poll_denied = true
                timer.Once( self.Config.denied_time, function() poll_denied = nil end )
            end
        end
    else
        rust.RunServerCommand( "notice.popupall \"Daytime has been denied!\"" )
        if (self.Config.disable_whendenied == true) then
            rust.BroadcastChat ( "DayTime Poll", "Poll will be disabled for " .. self.Config.denied_time .. " seconds." )
            poll_denied = true
            timer.Once( self.Config.denied_time, function() poll_denied = nil end )
        end
    end
    for k,v in pairs(user_voted) do user_voted[k]=nil end
    poll_on = nil
    yes_votes = nil
    no_votes = nil
end

I am pretty sure a lot of people will download this plugin!!!
 

justcyber

New Member
Member
Jan 3, 2015
13
0
1
56
I forgot to add that there does not need to be any kind of economy added to it, just a simple voting day system would be Awesome :)
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
Who knows if this works, Let me know :)

Player Commands:

/vote - Shows help
/vote start - Starts a vote
/vote day - Vote for day
/vote night - Vote for night
Admin/Moderator Commands:
/settime [time] - Set the servers time
/vote rig [day/night] - Rigs the vote

Python:
__title__ = 'TimeVoter'
__author__ = 'Jakkee'
__version__ = '1.0'

import clr
clr.AddReferenceByPartialName("Fougerite")
import Fougerite


class TimeVoter:
    def On_PluginInit(self):
        if not Plugin.IniExists("Settings"):
            Plugin.CreateIni("Settings")
            ini = Plugin.GetIni("Settings")
            ini.AddSetting("Config", "Enabled", "true")
            ini.AddSetting("Config", "ModeratorsCanUse", "true")
            ini.Save()

    def isMod(self, id):
        if DataStore.ContainsKey("Moderators", id):
            if Plugin.GetIni("Settings").GetSetting("Config", "ModeratorsCanUse") == "true":
                return True
            else:
                return False
        else:
            return False

    def stringtoint(self, arg):
        try:
            no = int(arg)
            no = float[no]
            return no
        except:
            return "string"

    def On_PlayerDisconnected(self, Player):
        if DataStore.Get("VoteNight", Player.SteamID) == "night":
            DataStore.Remove("VoteDay", Player.SteamID)
        elif DataStore.Get("VoteDay", Player.SteamID) == "day":
            DataStore.Remove("VoteDay", Player.SteamID)

    def VotingTimerCallBack(self):
        Plugin.KillTimer("VotingTimer")
        if DataStore.Get("RIGGED", "VOTER") == "day":
            World.Time = 8
            DataStore.Remove("RIGGED", "VOTER")
            Server.Broadcast("Voting has ending and the time has been set to Day!")
            self.removevotes()
        elif DataStore.Get("RIGGED", "VOTER") == "night":
            World.Time = 20
            DataStore.Remove("RIGGED", "VOTER")
            Server.Broadcast("Voting has ending and the time has been set to Night!")
            self.removevotes()
        else:
            day = DataStore.Count("VoteDay")
            night = DataStore.Count("VoteNight")
            if day > night:
                World.Time = 20
                Server.Broadcast("Voting has ending and the time has been set to Night!")
            elif day < night:
                World.Time = 8
                Server.Broadcast("Voting has ending and the time has been set to Day!")
            else:
                Server.Broadcast("50% of players voted for Night, The other 50% voted for Day!")
                Server.Broadcast("Time has not been changed!")
        self.removevotes()

    def removevotes(self):
        try:
            for Player in Server.Players:
                if DataStore.Get("VoteDay", Player.SteamID) == "true":
                    DataStore.Remove("VoteDay", Player.SteamID)
                elif DataStore.Get("VoteNight", Player.SteamID) == "night":
                    DataStore.Remove("VoteDay", Player.SteamID)
        except:
            return


    def On_Command(self, Player, cmd, args):
        if cmd == "vote":
            if len(args) == 0:
                Player.Message("--- TimeVoter ---")
                Player.Message("/vote - Shows help")
                Player.Message("/vote start - Starts a vote")
                Player.Message("/vote day - Votes for day")
                Player.Message("/vote night - votes for night")
                if Player.Admin or isMod(Player.SteamID):
                    Player.Message("-Admin Commands-")
                    Player.Message("/settime [time] - Sets the time")
                    Player.Message("/vote rig [day/night] - Rigs the voting")
            elif len(args) == 1:
                if args[0] == "start":
                    if DataStore.Get("Voter", "Started") == "true":
                        Player.Message("There is already a vote in progress")
                    else:
                        DataStore.Add("Voter", "Started", "true")
                        Server.Broadcast("----- [color green]TimeVoter[/color] -----")
                        Server.Broadcast(Player.Name + " has started a vote to change the servers time!")
                        Server.Broadcast("How to vote: /vote [day/night]")
                        Server.Broadcast("You have 60 seconds to vote")
                        Plugin.CreateTimer("VotingTimer", 60000).Start()
                elif args[0] == "day":
                    if DataStore.Get("Voter", "Started") == "true":
                        if DataStore.Get("VoteNight", Player.SteamID) == "night":
                            DataStore.Remove("VoteNight", Player.SteamID)
                            DataStore.Add("VoteDay", Player.SteamID, "day")
                            Player.Message("You have changed your vote to Day")
                        elif DataStore.Get("VoteDay", Player.SteamID) == "day":
                            Player.Message("You have already voted for Day")
                        else:
                            DataStore.Add("VoteDay", Player.SteamID, "day")
                            Player.Message("You have voted for Day!")
                    else:
                        Player.Message("There is no vote in progress!")
                        Player.Message("usage: /vote start")
                elif args[0] == "night":
                    if DataStore.Get("Voter", "Started") == "true":
                        if DataStore.Get("VoteDay", Player.SteamID) == "day":
                            DataStore.Remove("VoteDay", Player.SteamID)
                            DataStore.Add("VoteNight", Player.SteamID, "night")
                            Player.Message("You have changed your vote to Night")
                        elif DataStore.Get("VoteNight", Player.SteamID) == "night":
                            Player.Message("You have already voted for Night")
                        else:
                            DataStore.Add("VoteNight", Player.SteamID, "night")
                            Player.Message("You have voted for Night!")
                    else:
                        Player.Message("There is no vote in progress!")
                        Player.Message("usage: /vote start")
                elif args[0] == "rig day":
                    if Player.Admin or isMod(Player.SteamID):
                        if DataStore.Get("Voter", "Started") == "true":
                            if DataStore.Get("RIGGED", "VOTER") == "night":
                                DataStore.Remove("RIGGED", "VOTER")
                                DataStore.Add("RIGGED", "VOTER", "day")
                                Player.Message("You have rigged the vote to Day")
                            elif DataStore.Get("RIGGED", "VOTER") == "day":
                                Player.Message("The vote was already rigged to Day")
                            else:
                                DataStore.Add("RIGGED", "VOTER", "day")
                                Player.Message("The vote is now rigged to Day")
                        else:
                            Player.Message("There is no vote in progress!")
                            Player.Message("usage: /vote start")
                    else:
                        Player.Message("You are not allowed to use this command!")
                elif args[0] == "rig night":
                    if Player.Admin or isMod(Player.SteamID):
                        if DataStore.Get("Voter", "Started") == "true":
                            if DataStore.Get("RIGGED", "VOTER") == "day":
                                DataStore.Remove("RIGGED", "VOTER")
                                DataStore.Add("RIGGED", "VOTER", "night")
                                Player.Message("You have rigged the vote to Night")
                            elif DataStore.Get("RIGGED", "VOTER") == "night":
                                Player.Message("The vote was already rigged to Night")
                            else:
                                DataStore.Add("RIGGED", "VOTER", "night")
                                Player.Message("The vote is now rigged to Night")
                        else:
                            Player.Message("There is no vote in progress!")
                            Player.Message("usage: /vote start")
                    else:
                        Player.Message("You are not allowed to use this command!")
        elif cmd == "settime":
            if Player.Admin or isMod(Player.SteamID):
                if len(args) == 0:
                    Player.Message("usage: /settime [time]")
                elif len(args) == 1:
                    time = self.stringtoint((args[0]))
                    if time == "string":
                        Player.Message("You have not used a number, Try again")
                    else:
                        World.Time = time
                        Server.Broadcast("The servers time has been changed by an admin!")
                else:
                    Player.Message("usage: /settime [number]")
            else:
                Player.Message("You are not allowed to use this command!")
 

Attachments

Last edited:

Snake

Moderator
Moderator
Jul 13, 2014
288
174
28
Who knows if this works, Let me know :)

Player Commands:

/vote - Shows help
/vote start - Starts a vote
/vote day - Vote for day
/vote night - Vote for night
Admin/Moderator Commands:
/settime [time] - Set the servers time
/vote rig [day/night] - Rigs the vote

Python:
__title__ = 'TimeVoter'
__author__ = 'Jakkee'
__version__ = '1.0'

import clr
clr.AddReferenceByPartialName("Fougerite")
import Fougerite


class TimeVoter:
    def On_PluginInit(self):
        if not Plugin.IniExists("Settings"):
            Plugin.CreateIni("Settings")
            ini = Plugin.GetIni("Settings")
            ini.AddSetting("Config", "Enabled", "true")
            ini.AddSetting("Config", "ModeratorsCanUse", "true")
            ini.Save()

    def isMod(self, id):
        if DataStore.ContainsKey("Moderators", id):
            if Plugin.GetIni("Settings").GetSetting("Config", "ModeratorsCanUse") == "true":
                return True
            else:
                return False
        else:
            return False

    def stringtoint(self, arg):
        try:
            no = int(arg)
            no = float[no]
            return no
        except:
            return "string"

    def On_PlayerDisconnected(self, Player):
        if DataStore.Get("VoteNight", Player.SteamID) == "night":
            DataStore.Remove("VoteDay", Player.SteamID)
        elif DataStore.Get("VoteDay", Player.SteamID) == "day":
            DataStore.Remove("VoteDay", Player.SteamID)

    def VotingTimerCallBack(self):
        Plugin.KillTimer("VotingTimer")
        if DataStore.Get("RIGGED", "VOTER") == "day":
            World.Time = 8
            DataStore.Remove("RIGGED", "VOTER")
            Server.Broadcast("Voting has ending and the time has been set to Day!")
            self.removevotes()
        elif DataStore.Get("RIGGED", "VOTER") == "night":
            World.Time = 20
            DataStore.Remove("RIGGED", "VOTER")
            Server.Broadcast("Voting has ending and the time has been set to Night!")
            self.removevotes()
        else:
            day = DataStore.Count("VoteDay")
            night = DataStore.Count("VoteNight")
            if day > night:
                World.Time = 20
                Server.Broadcast("Voting has ending and the time has been set to Night!")
            elif day < night:
                World.Time = 8
                Server.Broadcast("Voting has ending and the time has been set to Day!")
            else:
                Server.Broadcast("50% of players voted for Night, The other 50% voted for Day!")
                Server.Broadcast("Time has not been changed!")
        self.removevotes()

    def removevotes(self):
        try:
            for Player in Server.Players:
                if DataStore.Get("VoteDay", Player.SteamID) == "true":
                    DataStore.Remove("VoteDay", Player.SteamID)
                elif DataStore.Get("VoteNight", Player.SteamID) == "night":
                    DataStore.Remove("VoteDay", Player.SteamID)
        except:
            return


    def On_Command(self, Player, cmd, args):
        if cmd == "vote":
            if len(args) == 0:
                Player.Message("--- TimeVoter ---")
                Player.Message("/vote - Shows help")
                Player.Message("/vote start - Starts a vote")
                Player.Message("/vote day - Votes for day")
                Player.Message("/vote night - votes for night")
                if Player.Admin or isMod(Player.SteamID):
                    Player.Message("-Admin Commands-")
                    Player.Message("/settime [time] - Sets the time")
                    Player.Message("/vote rig [day/night] - Rigs the voting")
            elif len(args) == 1:
                if args[0] == "start":
                    if DataStore.Get("Voter", "Started") == "true":
                        Player.Message("There is already a vote in progress")
                    else:
                        DataStore.Add("Voter", "Started", "true")
                        Server.Broadcast("----- [color green]TimeVoter[/color] -----")
                        Server.Broadcast(Player.Name + " has started a vote to change the servers time!")
                        Server.Broadcast("How to vote: /vote [day/night]")
                        Server.Broadcast("You have 60 seconds to vote")
                        Plugin.CreateTimer("VotingTimer", 60000).Start()
                elif args[0] == "day":
                    if DataStore.Get("Voter", "Started") == "true":
                        if DataStore.Get("VoteNight", Player.SteamID) == "night":
                            DataStore.Remove("VoteNight", Player.SteamID)
                            DataStore.Add("VoteDay", Player.SteamID, "day")
                            Player.Message("You have changed your vote to Day")
                        elif DataStore.Get("VoteDay", Player.SteamID) == "day":
                            Player.Message("You have already voted for Day")
                        else:
                            DataStore.Add("VoteDay", Player.SteamID, "day")
                            Player.Message("You have voted for Day!")
                    else:
                        Player.Message("There is no vote in progress!")
                        Player.Message("usage: /vote start")
                elif args[0] == "night":
                    if DataStore.Get("Voter", "Started") == "true":
                        if DataStore.Get("VoteDay", Player.SteamID) == "day":
                            DataStore.Remove("VoteDay", Player.SteamID)
                            DataStore.Add("VoteNight", Player.SteamID, "night")
                            Player.Message("You have changed your vote to Night")
                        elif DataStore.Get("VoteNight", Player.SteamID) == "night":
                            Player.Message("You have already voted for Night")
                        else:
                            DataStore.Add("VoteNight", Player.SteamID, "night")
                            Player.Message("You have voted for Night!")
                    else:
                        Player.Message("There is no vote in progress!")
                        Player.Message("usage: /vote start")
                elif args[0] == "rig day":
                    if Player.Admin or isMod(Player.SteamID):
                        if DataStore.Get("Voter", "Started") == "true":
                            if DataStore.Get("RIGGED", "VOTER") == "night":
                                DataStore.Remove("RIGGED", "VOTER")
                                DataStore.Add("RIGGED", "VOTER", "day")
                                Player.Message("You have rigged the vote to Day")
                            elif DataStore.Get("RIGGED", "VOTER") == "day":
                                Player.Message("The vote was already rigged to Day")
                            else:
                                DataStore.Add("RIGGED", "VOTER", "day")
                                Player.Message("The vote is now rigged to Day")
                        else:
                            Player.Message("There is no vote in progress!")
                            Player.Message("usage: /vote start")
                    else:
                        Player.Message("You are not allowed to use this command!")
                elif args[0] == "rig night":
                    if Player.Admin or isMod(Player.SteamID):
                        if DataStore.Get("Voter", "Started") == "true":
                            if DataStore.Get("RIGGED", "VOTER") == "day":
                                DataStore.Remove("RIGGED", "VOTER")
                                DataStore.Add("RIGGED", "VOTER", "night")
                                Player.Message("You have rigged the vote to Night")
                            elif DataStore.Get("RIGGED", "VOTER") == "night":
                                Player.Message("The vote was already rigged to Night")
                            else:
                                DataStore.Add("RIGGED", "VOTER", "night")
                                Player.Message("The vote is now rigged to Night")
                        else:
                            Player.Message("There is no vote in progress!")
                            Player.Message("usage: /vote start")
                    else:
                        Player.Message("You are not allowed to use this command!")
        elif cmd == "settime":
            if Player.Admin or isMod(Player.SteamID):
                if len(args) == 0:
                    Player.Message("usage: /settime [time]")
                elif len(args) == 1:
                    time = self.stringtoint((args[0]))
                    if time == "string":
                        Player.Message("You have not used a number, Try again")
                    else:
                        World.Time = time
                        Server.Broadcast("The servers time has been changed by an admin!")
                else:
                    Player.Message("usage: /settime [number]")
            else:
                Player.Message("You are not allowed to use this command!")
Add it as a plugin ! Maybe more people are interested in that :p
 
  • Agree
Reactions: Jakkee

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
So this keeps looping over and over. Even with the kill timer.
it does everything else but just loops over everything and broadcasts to the server the results even if there has been no voting.
Ideas?
Python:
    def VotingTimerCallback(self):
        Plugin.KillTimer("VotingTimer")
        day = DataStore.Count("VoteDay")
        night = DataStore.Count("VoteNight")
        if day > night:
            World.Time = 6
            Server.Broadcast("Voting has ending and the time has been set to Day!")
        elif day < night:
            World.Time = 18
            Server.Broadcast("Voting has ending and the time has been set to Night!")
        else:
            Server.Broadcast("50% of players voted for Night, The other 50% voted for Day!")
            Server.Broadcast("Time has not been changed!")
        self.removevotes()
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
So this keeps looping over and over. Even with the kill timer.
it does everything else but just loops over everything and broadcasts to the server the results even if there has been no voting.
Ideas?
Python:
    def VotingTimerCallback(self):
        Plugin.KillTimer("VotingTimer")
        day = DataStore.Count("VoteDay")
        night = DataStore.Count("VoteNight")
        if day > night:
            World.Time = 6
            Server.Broadcast("Voting has ending and the time has been set to Day!")
        elif day < night:
            World.Time = 18
            Server.Broadcast("Voting has ending and the time has been set to Night!")
        else:
            Server.Broadcast("50% of players voted for Night, The other 50% voted for Day!")
            Server.Broadcast("Time has not been changed!")
        self.removevotes()
So you run this timer only once and It doesn't stop?
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
So you run this timer only once and It doesn't stop?
Correct
Python:
__title__ = 'TimeVoter'
__author__ = 'Jakkee'
__version__ = '1.0'

import clr
clr.AddReferenceByPartialName("Fougerite")
import Fougerite


class TimeVoter:
    def On_PluginInit(self):
        if not Plugin.IniExists("Settings"):
            Plugin.CreateIni("Settings")
            ini = Plugin.GetIni("Settings")
            ini.AddSetting("Config", "Enabled", "true")
            ini.AddSetting("Config", "ModeratorsCanUse", "true")
            ini.Save()
        DataStore.Flush("VoteDay")
        DataStore.Flush("VoteNight")
        DataStore.Flush("Voter")
        DataStore.Flush("RIGGED")

    def isMod(self, id):
        if DataStore.ContainsKey("Moderators", id):
            if Plugin.GetIni("Settings").GetSetting("Config", "ModeratorsCanUse") == "true":
                return True
            else:
                return False
        else:
            return False

    def stringtoint(self, arg):
        try:
            b = int(arg)
            if b > 24 or b < 0:
                return a
            return b
        except:
            return c

    def On_PlayerDisconnected(self, Player):
        if DataStore.Get("VoteNight", Player.SteamID) == "night":
            DataStore.Remove("VoteDay", Player.SteamID)
        elif DataStore.Get("VoteDay", Player.SteamID) == "day":
            DataStore.Remove("VoteDay", Player.SteamID)

    def VotingTimerCallback(self):
        Plugin.KillTimer("VotingTimer")
        day = DataStore.Count("VoteDay")
        night = DataStore.Count("VoteNight")
        if day > night:
            World.Time = 8
            Server.Broadcast("Voting has ending and the time has been set to Day!")
        elif day < night:
            World.Time = 20
            Server.Broadcast("Voting has ending and the time has been set to Night!")
        else:
            Server.Broadcast("50% of players voted for Night, The other 50% voted for Day!")
            Server.Broadcast("Time has not been changed!")
        self.removevotes()

    def removevotes(self):
        DataStore.Flush("Voter")
        DataStore.Flush("VoteDay")
        DataStore.Flush("VoteNight")
        DataStore.Flush("RIGGED")

    def On_Command(self, Player, cmd, args):
        if cmd == "vote":
            if len(args) == 0:
                Player.Message("--- TimeVoter ---")
                Player.Message("/vote - Shows help")
                Player.Message("/vote start - Starts a vote")
                Player.Message("/vote day - Votes for day")
                Player.Message("/vote night - votes for night")
                if Player.Admin or isMod(Player.SteamID):
                    Player.Message("-Admin Commands-")
                    Player.Message("/vote stop - Stops the current vote (useful if something goes wrong)")
                    Player.Message("/vote rig [day/night] - Rigs the voting")
                    Player.Message("/settime [time] - Sets the time")
            elif len(args) == 1:
                if args[0] == "stop":
                    if Player.Admin or isMod(Player.SteamID):
                        if DataStore.Get("Voter", "Started") == "true":
                            DataStore.Remove("Voter", "Started")
                            Plugin.KillTimer("VotingTimer")
                            self.removevotes()
                            Server.Broadcast("A staff member has stopped the voting")
                        else:
                            Player.Message("There is no vote running!")
                    else:
                        Player.Message("You are not allowed to use that command!")
                elif args[0] == "start":
                    if DataStore.Get("Voter", "Started") == "true":
                        Player.Message("There is already a vote in progress")
                    else:
                        DataStore.Add("Voter", "Started", "true")
                        Server.Broadcast("----- [color green]TimeVoter[/color] -----")
                        Server.Broadcast(Player.Name + " has started a vote to change the servers time!")
                        Server.Broadcast("How to vote: /vote [day/night]")
                        Server.Broadcast("You have 60 seconds to vote")
                        Plugin.CreateTimer("VotingTimer", 10000).Start()
                elif args[0] == "day":
                    if DataStore.Get("Voter", "Started") == "true":
                        if DataStore.Get("VoteNight", Player.SteamID) == "night":
                            DataStore.Remove("VoteNight", Player.SteamID)
                            DataStore.Add("VoteDay", Player.SteamID, "day")
                            Player.Message("You have changed your vote to Day")
                        elif DataStore.Get("VoteDay", Player.SteamID) == "day":
                            Player.Message("You have already voted for Day")
                        else:
                            DataStore.Add("VoteDay", Player.SteamID, "day")
                            Player.Message("You have voted for Day!")
                    else:
                        Player.Message("There is no vote in progress!")
                        Player.Message("usage: /vote start")
                elif args[0] == "night":
                    if DataStore.Get("Voter", "Started") == "true":
                        if DataStore.Get("VoteDay", Player.SteamID) == "day":
                            DataStore.Remove("VoteDay", Player.SteamID)
                            DataStore.Add("VoteNight", Player.SteamID, "night")
                            Player.Message("You have changed your vote to Night")
                        elif DataStore.Get("VoteNight", Player.SteamID) == "night":
                            Player.Message("You have already voted for Night")
                        else:
                            DataStore.Add("VoteNight", Player.SteamID, "night")
                            Player.Message("You have voted for Night!")
                    else:
                        Player.Message("There is no vote in progress!")
                        Player.Message("usage: /vote start")
            elif len(args) == 2:
                if args[0] == "rig":
                    if Player.Admin or isMod(Player.SteamID):
                        if args[1] == "day":
                            if DataStore.Get("Voter", "Started") == "true":
                                if DataStore.Get("RIGGED", "VOTER") == "night":
                                    DataStore.Remove("RIGGED", "VOTER")
                                    DataStore.Add("RIGGED", "VOTER", "day")
                                    Player.Message("You have rigged the vote to Day")
                                elif DataStore.Get("RIGGED", "VOTER") == "day":
                                    Player.Message("The vote was already rigged to Day")
                                else:
                                    DataStore.Add("RIGGED", "VOTER", "day")
                                    Player.Message("The vote is now rigged to Day")
                            else:
                                Player.Message("There is no vote in progress!")
                                Player.Message("usage: /vote start")
                        elif args[1] == "night":
                            if DataStore.Get("Voter", "Started") == "true":
                                if DataStore.Get("RIGGED", "VOTER") == "day":
                                    DataStore.Remove("RIGGED", "VOTER")
                                    DataStore.Add("RIGGED", "VOTER", "night")
                                    Player.Message("You have rigged the vote to Night")
                                elif DataStore.Get("RIGGED", "VOTER") == "night":
                                    Player.Message("The vote was already rigged to Night")
                                else:
                                    DataStore.Add("RIGGED", "VOTER", "night")
                                    Player.Message("The vote is now rigged to Night")
                            else:
                                Player.Message("There is no vote in progress!")
                                Player.Message("usage: /vote start")
                        else:
                            Player.Message("usage: /vote rig [day/night]")
                    else:
                        Player.Message("You are not allowed to use this command!")
        elif cmd == "settime":
            if Player.Admin or isMod(Player.SteamID):
                if len(args) == 0:
                    Player.Message("usage: /settime [time]")
                elif len(args) == 1:
                    time = self.stringtoint((args[0]))
                    if time == c:
                        Player.Message("You have not used a number, Try again")
                    elif time == a:
                        Player.Message("You can only use a number from 0 - 24")
                    else:
                        World.Time = time
                        Server.Broadcast("The servers time has been changed by an admin!")
                else:
                    Player.Message("usage: /settime [number]")
            else:
                Player.Message("You are not allowed to use this command!")
EDIT: https://github.com/jakkee/FougeritePlugins/blob/JavaScript/Python/TimeVoter/TimeVoter.py
 
Last edited:

Snake

Moderator
Moderator
Jul 13, 2014
288
174
28
Correct
Python:
__title__ = 'TimeVoter'
__author__ = 'Jakkee'
__version__ = '1.0'

import clr
clr.AddReferenceByPartialName("Fougerite")
import Fougerite


class TimeVoter:
    def On_PluginInit(self):
        if not Plugin.IniExists("Settings"):
            Plugin.CreateIni("Settings")
            ini = Plugin.GetIni("Settings")
            ini.AddSetting("Config", "Enabled", "true")
            ini.AddSetting("Config", "ModeratorsCanUse", "true")
            ini.Save()
        DataStore.Flush("VoteDay")
        DataStore.Flush("VoteNight")
        DataStore.Flush("Voter")
        DataStore.Flush("RIGGED")

    def isMod(self, id):
        if DataStore.ContainsKey("Moderators", id):
            if Plugin.GetIni("Settings").GetSetting("Config", "ModeratorsCanUse") == "true":
                return True
            else:
                return False
        else:
            return False

    def stringtoint(self, arg):
        try:
            b = int(arg)
            if b > 24 or b < 0:
                return a
            return b
        except:
            return c

    def On_PlayerDisconnected(self, Player):
        if DataStore.Get("VoteNight", Player.SteamID) == "night":
            DataStore.Remove("VoteDay", Player.SteamID)
        elif DataStore.Get("VoteDay", Player.SteamID) == "day":
            DataStore.Remove("VoteDay", Player.SteamID)

    def VotingTimerCallback(self):
        Plugin.KillTimer("VotingTimer")
        day = DataStore.Count("VoteDay")
        night = DataStore.Count("VoteNight")
        if day > night:
            World.Time = 8
            Server.Broadcast("Voting has ending and the time has been set to Day!")
        elif day < night:
            World.Time = 20
            Server.Broadcast("Voting has ending and the time has been set to Night!")
        else:
            Server.Broadcast("50% of players voted for Night, The other 50% voted for Day!")
            Server.Broadcast("Time has not been changed!")
        self.removevotes()

    def removevotes(self):
        DataStore.Flush("Voter")
        DataStore.Flush("VoteDay")
        DataStore.Flush("VoteNight")
        DataStore.Flush("RIGGED")

    def On_Command(self, Player, cmd, args):
        if cmd == "vote":
            if len(args) == 0:
                Player.Message("--- TimeVoter ---")
                Player.Message("/vote - Shows help")
                Player.Message("/vote start - Starts a vote")
                Player.Message("/vote day - Votes for day")
                Player.Message("/vote night - votes for night")
                if Player.Admin or isMod(Player.SteamID):
                    Player.Message("-Admin Commands-")
                    Player.Message("/vote stop - Stops the current vote (useful if something goes wrong)")
                    Player.Message("/vote rig [day/night] - Rigs the voting")
                    Player.Message("/settime [time] - Sets the time")
            elif len(args) == 1:
                if args[0] == "stop":
                    if Player.Admin or isMod(Player.SteamID):
                        if DataStore.Get("Voter", "Started") == "true":
                            DataStore.Remove("Voter", "Started")
                            Plugin.KillTimer("VotingTimer")
                            self.removevotes()
                            Server.Broadcast("A staff member has stopped the voting")
                        else:
                            Player.Message("There is no vote running!")
                    else:
                        Player.Message("You are not allowed to use that command!")
                elif args[0] == "start":
                    if DataStore.Get("Voter", "Started") == "true":
                        Player.Message("There is already a vote in progress")
                    else:
                        DataStore.Add("Voter", "Started", "true")
                        Server.Broadcast("----- [color green]TimeVoter[/color] -----")
                        Server.Broadcast(Player.Name + " has started a vote to change the servers time!")
                        Server.Broadcast("How to vote: /vote [day/night]")
                        Server.Broadcast("You have 60 seconds to vote")
                        Plugin.CreateTimer("VotingTimer", 10000).Start()
                elif args[0] == "day":
                    if DataStore.Get("Voter", "Started") == "true":
                        if DataStore.Get("VoteNight", Player.SteamID) == "night":
                            DataStore.Remove("VoteNight", Player.SteamID)
                            DataStore.Add("VoteDay", Player.SteamID, "day")
                            Player.Message("You have changed your vote to Day")
                        elif DataStore.Get("VoteDay", Player.SteamID) == "day":
                            Player.Message("You have already voted for Day")
                        else:
                            DataStore.Add("VoteDay", Player.SteamID, "day")
                            Player.Message("You have voted for Day!")
                    else:
                        Player.Message("There is no vote in progress!")
                        Player.Message("usage: /vote start")
                elif args[0] == "night":
                    if DataStore.Get("Voter", "Started") == "true":
                        if DataStore.Get("VoteDay", Player.SteamID) == "day":
                            DataStore.Remove("VoteDay", Player.SteamID)
                            DataStore.Add("VoteNight", Player.SteamID, "night")
                            Player.Message("You have changed your vote to Night")
                        elif DataStore.Get("VoteNight", Player.SteamID) == "night":
                            Player.Message("You have already voted for Night")
                        else:
                            DataStore.Add("VoteNight", Player.SteamID, "night")
                            Player.Message("You have voted for Night!")
                    else:
                        Player.Message("There is no vote in progress!")
                        Player.Message("usage: /vote start")
            elif len(args) == 2:
                if args[0] == "rig":
                    if Player.Admin or isMod(Player.SteamID):
                        if args[1] == "day":
                            if DataStore.Get("Voter", "Started") == "true":
                                if DataStore.Get("RIGGED", "VOTER") == "night":
                                    DataStore.Remove("RIGGED", "VOTER")
                                    DataStore.Add("RIGGED", "VOTER", "day")
                                    Player.Message("You have rigged the vote to Day")
                                elif DataStore.Get("RIGGED", "VOTER") == "day":
                                    Player.Message("The vote was already rigged to Day")
                                else:
                                    DataStore.Add("RIGGED", "VOTER", "day")
                                    Player.Message("The vote is now rigged to Day")
                            else:
                                Player.Message("There is no vote in progress!")
                                Player.Message("usage: /vote start")
                        elif args[1] == "night":
                            if DataStore.Get("Voter", "Started") == "true":
                                if DataStore.Get("RIGGED", "VOTER") == "day":
                                    DataStore.Remove("RIGGED", "VOTER")
                                    DataStore.Add("RIGGED", "VOTER", "night")
                                    Player.Message("You have rigged the vote to Night")
                                elif DataStore.Get("RIGGED", "VOTER") == "night":
                                    Player.Message("The vote was already rigged to Night")
                                else:
                                    DataStore.Add("RIGGED", "VOTER", "night")
                                    Player.Message("The vote is now rigged to Night")
                            else:
                                Player.Message("There is no vote in progress!")
                                Player.Message("usage: /vote start")
                        else:
                            Player.Message("usage: /vote rig [day/night]")
                    else:
                        Player.Message("You are not allowed to use this command!")
        elif cmd == "settime":
            if Player.Admin or isMod(Player.SteamID):
                if len(args) == 0:
                    Player.Message("usage: /settime [time]")
                elif len(args) == 1:
                    time = self.stringtoint((args[0]))
                    if time == c:
                        Player.Message("You have not used a number, Try again")
                    elif time == a:
                        Player.Message("You can only use a number from 0 - 24")
                    else:
                        World.Time = time
                        Server.Broadcast("The servers time has been changed by an admin!")
                else:
                    Player.Message("usage: /settime [number]")
            else:
                Player.Message("You are not allowed to use this command!")
I don't know shit about how Timers work on Python but try stopping it with timer.Stop(); .
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
Last edited:

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
Saddly no good.
Tried a few similar to Timer.Stop()

EDIT#1:
When the plugin reads Plugin.KillTimer("VotingTimer") it doesn't throw an error and continues to carry on.

EDIT#2: https://github.com/jakkee/FougeritePlugins/blob/JavaScript/Python/TimeVoter/TimeVoter.py
Try this:

Python:
timer = Plugin.GetTimer(name)
if timer is None:
       return
timer.Kill()
Plugin.Timers.Remove(name)
Also, I think ur host didn't update Fougerite


http://fougerite.com/resources/fougerite-official.77/updates

You might be having the buggy IP module.
 
  • Like
Reactions: Snake

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
Last edited:
  • Like
Reactions: Snake

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
I asked for a quick compiled dll from balu, you are now also able to try this:

https://github.com/dretax/Python-Plugins/blob/master/IronPythonModule.dll
This module seems to have problems with the datastore and it remembers unloaded plugins even after a restart. Also String.Find(SubString) throws an error.
EDIT: You get randomly disconnected as well. No errors

Going through the logs it has said the timer was using 2 args when 1 men't to be used.
Python:
    def VotingTimerCallback(self):
        Plugin.KillTimer("VotingTimer")
        if DataStore.Get("RIGGED", "VOTER") == "night":
            DataStore.Remove("RIGGED", "VOTER")
            World.Time = 18
            Server.Broadcast("--------------------------- [color green]TimeVoter[/color] ---------------------------")
            Server.Broadcast("The results are in and the servers time has been changed to Night!")
            Server.Broadcast("45.0% voted for Day")
            Server.Broadcast("55.0% voted for Night")
            Server.Broadcast("--------------------------------------------------------------------")
            self.removevotes()
            return
        elif DataStore.Get("RIGGED", "VOTER") == "day":
            DataStore.Remove("RIGGED", "VOTER")
            World.Time = 6
            Server.Broadcast("--------------------------- [color green]TimeVoter[/color] ---------------------------")
            Server.Broadcast("The results are in and the servers time has been changed to Day!")
            Server.Broadcast("85.0% voted for Day")
            Server.Broadcast("15.0% voted for Night")
            Server.Broadcast("--------------------------------------------------------------------")
            self.removevotes()
            return
        else:
            day = DataStore.Count("VoteDay")
            night = DataStore.Count("VoteNight")
            total = day + night
            self.removevotes()
            if day > night:
                World.Time = 6
                Server.Broadcast("--------------------------- [color green]TimeVoter[/color] ---------------------------")
                Server.Broadcast("The results are in and the servers time has been changed to Day!")
                Server.Broadcast(str(round((day / total) * 100, 2)) + "% voted for Day")
                Server.Broadcast(str(round((night / total) * 100, 2)) + "% voted for Night")
                Server.Broadcast("--------------------------------------------------------------------")
            elif day < night:
                World.Time = 18
                Server.Broadcast("--------------------------- [color green]TimeVoter[/color] ---------------------------")
                Server.Broadcast("The results are in and the servers time has been changed to Night!")
                Server.Broadcast(str(round((day / total) * 100, 2)) + "% voted for Day")
                Server.Broadcast(str(round((night / total) * 100, 2)) + "% voted for Night")
                Server.Broadcast("--------------------------------------------------------------------")
            else:
                Server.Broadcast("--------------------------- [color green]TimeVoter[/color] ---------------------------")
                Server.Broadcast("The results are in and the servers time has not been changed!")
                Server.Broadcast(str(round((day / total) * 100, 2)) + "% voted for Day")
                Server.Broadcast(str(round((night / total) * 100, 2)) + "% voted for Night")
                Server.Broadcast("--------------------------------------------------------------------")

Code:
[1/18/2015 1:16:52 PM] [Error] [Modules] Module "IPModule" has thrown an exception while being deinitialized:
System.NullReferenceException: Object reference not set to an instance of an object
  at IronPythonModule.IPPlugin.KillTimers () [0x00000] in <filename unknown>:0
  at IronPythonModule.IPModule.UnloadPlugin (System.String name, Boolean removeFromDict) [0x00000] in <filename unknown>:0
  at IronPythonModule.IPModule.UnloadPlugins () [0x00000] in <filename unknown>:0
  at IronPythonModule.IPModule.DeInitialize () [0x00000] in <filename unknown>:0
  at Fougerite.ModuleContainer.DeInitialize () [0x00000] in <filename unknown>:0
  at Fougerite.ModuleManager.UnloadModules () [0x00000] in <filename unknown>:0
 
Last edited:

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
This module seems to have problems with the datastore and it remembers unloaded plugins even after a restart. Also String.Find(SubString) throws an error.
EDIT: You get randomly disconnected as well. No errors

Going through the logs it has said the timer was using 2 args when 1 men't to be used.
Python:
    def VotingTimerCallback(self):
        Plugin.KillTimer("VotingTimer")
        if DataStore.Get("RIGGED", "VOTER") == "night":
            DataStore.Remove("RIGGED", "VOTER")
            World.Time = 18
            Server.Broadcast("--------------------------- [color green]TimeVoter[/color] ---------------------------")
            Server.Broadcast("The results are in and the servers time has been changed to Night!")
            Server.Broadcast("45.0% voted for Day")
            Server.Broadcast("55.0% voted for Night")
            Server.Broadcast("--------------------------------------------------------------------")
            self.removevotes()
            return
        elif DataStore.Get("RIGGED", "VOTER") == "day":
            DataStore.Remove("RIGGED", "VOTER")
            World.Time = 6
            Server.Broadcast("--------------------------- [color green]TimeVoter[/color] ---------------------------")
            Server.Broadcast("The results are in and the servers time has been changed to Day!")
            Server.Broadcast("85.0% voted for Day")
            Server.Broadcast("15.0% voted for Night")
            Server.Broadcast("--------------------------------------------------------------------")
            self.removevotes()
            return
        else:
            day = DataStore.Count("VoteDay")
            night = DataStore.Count("VoteNight")
            total = day + night
            self.removevotes()
            if day > night:
                World.Time = 6
                Server.Broadcast("--------------------------- [color green]TimeVoter[/color] ---------------------------")
                Server.Broadcast("The results are in and the servers time has been changed to Day!")
                Server.Broadcast(str(round((day / total) * 100, 2)) + "% voted for Day")
                Server.Broadcast(str(round((night / total) * 100, 2)) + "% voted for Night")
                Server.Broadcast("--------------------------------------------------------------------")
            elif day < night:
                World.Time = 18
                Server.Broadcast("--------------------------- [color green]TimeVoter[/color] ---------------------------")
                Server.Broadcast("The results are in and the servers time has been changed to Night!")
                Server.Broadcast(str(round((day / total) * 100, 2)) + "% voted for Day")
                Server.Broadcast(str(round((night / total) * 100, 2)) + "% voted for Night")
                Server.Broadcast("--------------------------------------------------------------------")
            else:
                Server.Broadcast("--------------------------- [color green]TimeVoter[/color] ---------------------------")
                Server.Broadcast("The results are in and the servers time has not been changed!")
                Server.Broadcast(str(round((day / total) * 100, 2)) + "% voted for Day")
                Server.Broadcast(str(round((night / total) * 100, 2)) + "% voted for Night")
                Server.Broadcast("--------------------------------------------------------------------")

Code:
[1/18/2015 1:16:52 PM] [Error] [Modules] Module "IPModule" has thrown an exception while being deinitialized:
System.NullReferenceException: Object reference not set to an instance of an object
  at IronPythonModule.IPPlugin.KillTimers () [0x00000] in <filename unknown>:0
  at IronPythonModule.IPModule.UnloadPlugin (System.String name, Boolean removeFromDict) [0x00000] in <filename unknown>:0
  at IronPythonModule.IPModule.UnloadPlugins () [0x00000] in <filename unknown>:0
  at IronPythonModule.IPModule.DeInitialize () [0x00000] in <filename unknown>:0
  at Fougerite.ModuleContainer.DeInitialize () [0x00000] in <filename unknown>:0
  at Fougerite.ModuleManager.UnloadModules () [0x00000] in <filename unknown>:0
Okay, instead of the dll try this


Python:
timer = Plugin.GetTimer(name)
if timer is None:
       return
timer.Kill()
Plugin.Timers.Remove(name)
 
  • Like
Reactions: Jakkee