Need some help with AutoRewards Plugin PY

ice cold

Active Member
Trusted Member
Member
Oct 24, 2016
606
871
43
Canada
so i coded a TimedReward but it doesnt give us the stuff


Python:
__title__ = 'Timed Reward'
__author__ = 'ice cold'
__version__ = '1.0'

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


rose = "[color #ff4040"

class TimedReward:
    Timer = None
    Items = None

    def On_PluginInit(self):
        ini = self.Settings()
        enum = ini.EnumSection("Items")
        self.Items = Plugin.CreateList()
        self.Timer = int(ini.GetSetting("Settings", "Timer"))
        Plugin.CreateTimer("AutoReward", self.Timer).Start()
        for x in enum:
            self.Items.Add(ini.GetSetting("Items", x))

    def Settings(self):
        if not Plugin.IniExists("Settings"):
            ini = Plugin.CreateIni("Settings")
            ini.AddSetting("Settings", "Timer", "2600000")
            ini.AddSetting("Items", "Cloth Helmet", "1")
            ini.AddSetting("Items", "Cooked Chicken Breast", "10")
            ini.AddSetting("Items", "Hatchet", "1")
            ini.Save()
        return Plugin.GetIni("Settings")


    def AutoRewardCallback(self, timer):
        enum = ini.EnumSection("Items")
        for pl in Server.Players:
            for x in enum:
                pl.Notice("☢", "Auto Reward given")
                pl.Message(rose + "Auto Reward Given to all Players") 
                pl.Inventory.AddItem("Items", x)
            timer.Kill()
            Plugin.CreateTimer("AutoReward", self.Timer).Start()
 

salva

Friendly self-taught developer
Administrator
Jan 31, 2016
576
610
63
so i coded a TimedReward but it doesnt give us the stuff


Python:
__title__ = 'Timed Reward'
__author__ = 'ice cold'
__version__ = '1.0'

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


rose = "[color #ff4040"

class TimedReward:
    Timer = None
    Items = None

    def On_PluginInit(self):
        ini = self.Settings()
        enum = ini.EnumSection("Items")
        self.Items = Plugin.CreateList()
        self.Timer = int(ini.GetSetting("Settings", "Timer"))
        Plugin.CreateTimer("AutoReward", self.Timer).Start()
        for x in enum:
            self.Items.Add(ini.GetSetting("Items", x))

    def Settings(self):
        if not Plugin.IniExists("Settings"):
            ini = Plugin.CreateIni("Settings")
            ini.AddSetting("Settings", "Timer", "2600000")
            ini.AddSetting("Items", "Cloth Helmet", "1")
            ini.AddSetting("Items", "Cooked Chicken Breast", "10")
            ini.AddSetting("Items", "Hatchet", "1")
            ini.Save()
        return Plugin.GetIni("Settings")


    def AutoRewardCallback(self, timer):
        enum = ini.EnumSection("Items")
        for pl in Server.Players:
            for x in enum:
                pl.Notice("☢", "Auto Reward given")
                pl.Message(rose + "Auto Reward Given to all Players")
                pl.Inventory.AddItem("Items", x)
            timer.Kill()
            Plugin.CreateTimer("AutoReward", self.Timer).Start()
Maybe you need to use (Try) after foreach and add (continue, break or finally) depending on your needs, since if you try to give a reward to a dead player or not spawned the for cycle will break and will not continue, greetings
 

ice cold

Active Member
Trusted Member
Member
Oct 24, 2016
606
871
43
Canada
Maybe you need to use (Try) after foreach and add (continue, break or finally) depending on your needs, since if you try to give a reward to a dead player or not spawned the for cycle will break and will not continue, greetings
Python:
__title__ = 'Timed Reward'
__author__ = 'ice cold'
__version__ = '1.0'

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


rose = "[color #ff4040"

class TimedReward:
    Timer = None
    Items = None

    def On_PluginInit(self):
        ini = self.Settings()
        enum = ini.EnumSection("Items")
        self.Items = Plugin.CreateList()
        self.Timer = int(ini.GetSetting("Settings", "Timer"))
        Plugin.CreateTimer("AutoReward", self.Timer).Start()
        for x in enum:
            self.Items.Add(ini.GetSetting("Items", x))

    def Settings(self):
        if not Plugin.IniExists("Settings"):
            ini = Plugin.CreateIni("Settings")
            ini.AddSetting("Settings", "Timer", "2600000")
            ini.AddSetting("Items", "Cloth Helmet", "1")
            ini.AddSetting("Items", "Cooked Chicken Breast", "10")
            ini.AddSetting("Items", "Hatchet", "1")
            ini.Save()
        return Plugin.GetIni("Settings")


    def AutoRewardCallback(self, timer):
        try:
            enum = ini.EnumSection("Items")
            for pl in Server.Players:
                for x in enum:
                    pl.Notice("☢", "Auto Reward given")
                    pl.Message(rose + "Auto Reward Given to all Players") 
                    pl.Inventory.AddItem("Items", x)
                    continue
                timer.Kill()
                Plugin.CreateTimer("AutoReward", self.Timer).Start()
 

salva

Friendly self-taught developer
Administrator
Jan 31, 2016
576
610
63
Also put timer kill and create new timer out of circle for

Python:
 def AutoRewardCallback(self, timer):
        enum = ini.EnumSection("Items")
        timer.Kill()
        for pl in Server.Players:
            for x in enum:
                pl.Notice("☢", "Auto Reward given")
                pl.Message(rose + "Auto Reward Given to all Players")
                pl.Inventory.AddItem("Items", x)
        Plugin.CreateTimer("AutoReward", self.Timer).Start()
 

ice cold

Active Member
Trusted Member
Member
Oct 24, 2016
606
871
43
Canada
Also put timer kill and create new timer out of circle for

Python:
 def AutoRewardCallback(self, timer):
        enum = ini.EnumSection("Items")
        timer.Kill()
        for pl in Server.Players:
            for x in enum:
                pl.Notice("☢", "Auto Reward given")
                pl.Message(rose + "Auto Reward Given to all Players")
                pl.Inventory.AddItem("Items", x)
        Plugin.CreateTimer("AutoReward", self.Timer).Start()
thx but for some reason the plugin doesnt even try to give items
 

BogdanWDK

Administrator
Administrator
Jul 31, 2014
109
284
63
29
United Kingdom
It wont give the items because you first need to create a list with the items from .ini file then use another foreach to give the items.
 

Jakkee

Plugin Developer
Plugin Developer
Contributor
Jul 28, 2014
1,465
925
113
Australia
Well to start off, "Items" is not an item name :p
Python:
pl.Inventory.AddItem(x, ini.GetSetting("Items", x))
 
  • Agree
Reactions: salva

Jakkee

Plugin Developer
Plugin Developer
Contributor
Jul 28, 2014
1,465
925
113
Australia
Yet still he got more than one item , he have to get all of them into an array first then run a loop to give them away.
Thx for the help but i just wont make a ini file
That line will loop over all the items in the ini file, Might not be the best in performance but you’ll probably never notice it

Python:
pl.Inventory.AddItem(x, ini.GetSetting("Items", x))
 

BogdanWDK

Administrator
Administrator
Jul 31, 2014
109
284
63
29
United Kingdom
That line will loop over all the items in the ini file, Might not be the best in performance but you’ll probably never notice it

Python:
pl.Inventory.AddItem(x, ini.GetSetting("Items", x))
I think he'd need some optimised code , he might get some lag spikes if he's rewarding 50+ players at a time,don't you think ?
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,065
4,486
113
At your house.
github.com
Python:
__title__ = 'Timed Reward'
__author__ = 'ice cold'
__version__ = '1.0'

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


rose = "[color #ff4040"

class TimedReward:
    Timer = None
    Items = None

    def On_PluginInit(self):
        ini = self.Settings()
        enum = ini.EnumSection("Items")
        self.Items = Plugin.CreateList()
        self.Timer = int(ini.GetSetting("Settings", "Timer"))
        Plugin.CreateTimer("AutoReward", self.Timer).Start()
        for x in enum:
            self.Items.Add(ini.GetSetting("Items", x))

    def Settings(self):
        if not Plugin.IniExists("Settings"):
            ini = Plugin.CreateIni("Settings")
            ini.AddSetting("Settings", "Timer", "2600000")
            ini.AddSetting("Items", "Cloth Helmet", "1")
            ini.AddSetting("Items", "Cooked Chicken Breast", "10")
            ini.AddSetting("Items", "Hatchet", "1")
            ini.Save()
        return Plugin.GetIni("Settings")


    def AutoRewardCallback(self, timer):
        try:
            enum = ini.EnumSection("Items")
            for pl in Server.Players:
                for x in enum:
                    pl.Notice("☢", "Auto Reward given")
                    pl.Message(rose + "Auto Reward Given to all Players")
                    pl.Inventory.AddItem("Items", x)
                    continue
                timer.Kill()
                Plugin.CreateTimer("AutoReward", self.Timer).Start()
Here is your fixed code

Python:
__title__ = 'Timed Reward'
__author__ = 'ice cold'
__version__ = '1.0'

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


rose = "[color #ff4040]"

class TimedReward:
    Timer = None
    Items = None

    def On_PluginInit(self):
        ini = self.Settings()
        enum = ini.EnumSection("Items")
        self.Items = {}
        self.Timer = int(ini.GetSetting("Settings", "Timer"))
        Plugin.CreateTimer("AutoReward", self.Timer).Start()
        for x in enum:
            self.Items[x] = int(ini.GetSetting("Items", x))

    def Settings(self):
        if not Plugin.IniExists("Settings"):
            ini = Plugin.CreateIni("Settings")
            ini.AddSetting("Settings", "Timer", "2600000")
            ini.AddSetting("Items", "Cloth Helmet", "1")
            ini.AddSetting("Items", "Cooked Chicken Breast", "10")
            ini.AddSetting("Items", "Hatchet", "1")
            ini.Save()
        return Plugin.GetIni("Settings")


    def AutoRewardCallback(self, timer):
        timer.Kill()
        for pl in Server.Players:
            pl.Notice("☢", "Auto Reward given")
            pl.Message(rose + "Auto Reward Given to all Players") 
            for x in self.Items:
                pl.Inventory.AddItem("Items", x, self.Items[x])
        Plugin.CreateTimer("AutoReward", self.Timer).Start()
 
  • Winner
Reactions: ice cold

ice cold

Active Member
Trusted Member
Member
Oct 24, 2016
606
871
43
Canada
Here is your fixed code

Python:
__title__ = 'Timed Reward'
__author__ = 'ice cold'
__version__ = '1.0'

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


rose = "[color #ff4040]"

class TimedReward:
    Timer = None
    Items = None

    def On_PluginInit(self):
        ini = self.Settings()
        enum = ini.EnumSection("Items")
        self.Items = {}
        self.Timer = int(ini.GetSetting("Settings", "Timer"))
        Plugin.CreateTimer("AutoReward", self.Timer).Start()
        for x in enum:
            self.Items[x] = int(ini.GetSetting("Items", x))

    def Settings(self):
        if not Plugin.IniExists("Settings"):
            ini = Plugin.CreateIni("Settings")
            ini.AddSetting("Settings", "Timer", "2600000")
            ini.AddSetting("Items", "Cloth Helmet", "1")
            ini.AddSetting("Items", "Cooked Chicken Breast", "10")
            ini.AddSetting("Items", "Hatchet", "1")
            ini.Save()
        return Plugin.GetIni("Settings")


    def AutoRewardCallback(self, timer):
        timer.Kill()
        for pl in Server.Players:
            pl.Notice("☢", "Auto Reward given")
            pl.Message(rose + "Auto Reward Given to all Players")
            for x in self.Items:
                pl.Inventory.AddItem("Items", x, self.Items[x])
        Plugin.CreateTimer("AutoReward", self.Timer).Start()
Its not working
 

ice cold

Active Member
Trusted Member
Member
Oct 24, 2016
606
871
43
Canada
and i want it that it chooses 1 item from the list, could you make that please
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,065
4,486
113
At your house.
github.com
and i want it that it chooses 1 item from the list, could you make that please
Noticed the mistake.

Python:
__title__ = 'Timed Reward'
__author__ = 'ice cold'
__version__ = '1.0'

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

path = Util.GetRootFolder()
sys.path.append(path + "\\Save\\Lib\\")
try:
    import random
except ImportError:
    raise ImportError("Failed to import random! Download the lib!")

rose = "[color #ff4040]"


class TimedReward:
    Timer = None
    Items = None

    def On_PluginInit(self):
        ini = self.Settings()
        enum = ini.EnumSection("Items")
        self.Items = {}
        self.Timer = int(ini.GetSetting("Settings", "Timer"))
        for x in enum:
            self.Items[x] = int(ini.GetSetting("Items", x))
        Plugin.CreateTimer("AutoReward", self.Timer).Start()

    def Settings(self):
        if not Plugin.IniExists("Settings"):
            ini = Plugin.CreateIni("Settings")
            ini.AddSetting("Settings", "Timer", "2600000")
            ini.AddSetting("Items", "Cloth Helmet", "1")
            ini.AddSetting("Items", "Cooked Chicken Breast", "10")
            ini.AddSetting("Items", "Hatchet", "1")
            ini.Save()
        return Plugin.GetIni("Settings")


    def AutoRewardCallback(self, timer):
        timer.Kill()
        for pl in Server.Players:
            pl.Notice("☢", "Auto Reward given")
            pl.Message(rose + "Auto Reward Given to all Players")
            itemname = random.choice(self.Items.keys())
            pl.Inventory.AddItem(itemname, self.Items[itemname])
        Plugin.CreateTimer("AutoReward", self.Timer).Start()
 
  • Winner
Reactions: ice cold

ice cold

Active Member
Trusted Member
Member
Oct 24, 2016
606
871
43
Canada
Noticed the mistake.

Python:
__title__ = 'Timed Reward'
__author__ = 'ice cold'
__version__ = '1.0'

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

path = Util.GetRootFolder()
sys.path.append(path + "\\Save\\Lib\\")
try:
    import random
except ImportError:
    raise ImportError("Failed to import random! Download the lib!")

rose = "[color #ff4040]"


class TimedReward:
    Timer = None
    Items = None

    def On_PluginInit(self):
        ini = self.Settings()
        enum = ini.EnumSection("Items")
        self.Items = {}
        self.Timer = int(ini.GetSetting("Settings", "Timer"))
        for x in enum:
            self.Items[x] = int(ini.GetSetting("Items", x))
        Plugin.CreateTimer("AutoReward", self.Timer).Start()

    def Settings(self):
        if not Plugin.IniExists("Settings"):
            ini = Plugin.CreateIni("Settings")
            ini.AddSetting("Settings", "Timer", "2600000")
            ini.AddSetting("Items", "Cloth Helmet", "1")
            ini.AddSetting("Items", "Cooked Chicken Breast", "10")
            ini.AddSetting("Items", "Hatchet", "1")
            ini.Save()
        return Plugin.GetIni("Settings")


    def AutoRewardCallback(self, timer):
        timer.Kill()
        for pl in Server.Players:
            pl.Notice("☢", "Auto Reward given")
            pl.Message(rose + "Auto Reward Given to all Players")
            itemname = random.choice(self.Items.keys())
            pl.Inventory.AddItem(itemname, self.Items[itemname])
        Plugin.CreateTimer("AutoReward", self.Timer).Start()
Your are still the master XD
 

ice cold

Active Member
Trusted Member
Member
Oct 24, 2016
606
871
43
Canada
@DreTaX I'm trying to announce random messages in chat with the same code

Python:
__title__ = 'AutoAnnouncer'
__author__ = 'ice cold'
__version__ = '1.0'

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

path = Util.GetRootFolder()
sys.path.append(path + "\\Save\\Lib\\")
try:
    import random
except ImportError:
    raise ImportError("Failed to import random! Download the lib!")



rose = "[color #ff4040]"

class AutoAnnouncer:
    Timer = None
    Messages = None

    def On_PluginInit(self):
        ini = self.Settings()
        enum = ini.EnumSection("Messages")
        self.Messages = {}
        self.Timer = int(ini.GetSetting("Settings", "Timer"))
        Plugin.CreateTimer("AutoChat", self.Timer).Start()
        for x in enum:
            self.Messages[x] = int(ini.GetSetting("Messages", x))

    def Settings(self):
        if not Plugin.IniExists("Settings"):
            ini = Plugin.CreateIni("Settings")
            ini.AddSetting("Settings", "Timer", "2600000")
            ini.AddSetting("Messages", "1", "Welcome to uberrust")
            ini.AddSetting("Messages", "2", "[color orange]This plugin worked")
            ini.Save()
        return Plugin.GetIni("Settings")


    def AutoChatCallback(self, timer):
        timer.Kill()
        msg = random.choice(self.Messages.keys())
        Server.Broadcast("Messages", x, self.Messages[msg])
        Plugin.CreateTimer("AutoChat", self.Timer).Start()
_
i tried to fix it but it just doesnt work
 

Attachments

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,065
4,486
113
At your house.
github.com
@DreTaX I'm trying to announce random messages in chat with the same code

Python:
__title__ = 'AutoAnnouncer'
__author__ = 'ice cold'
__version__ = '1.0'

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

path = Util.GetRootFolder()
sys.path.append(path + "\\Save\\Lib\\")
try:
    import random
except ImportError:
    raise ImportError("Failed to import random! Download the lib!")



rose = "[color #ff4040]"

class AutoAnnouncer:
    Timer = None
    Messages = None

    def On_PluginInit(self):
        ini = self.Settings()
        enum = ini.EnumSection("Messages")
        self.Messages = {}
        self.Timer = int(ini.GetSetting("Settings", "Timer"))
        Plugin.CreateTimer("AutoChat", self.Timer).Start()
        for x in enum:
            self.Messages[x] = int(ini.GetSetting("Messages", x))

    def Settings(self):
        if not Plugin.IniExists("Settings"):
            ini = Plugin.CreateIni("Settings")
            ini.AddSetting("Settings", "Timer", "2600000")
            ini.AddSetting("Messages", "1", "Welcome to uberrust")
            ini.AddSetting("Messages", "2", "[color orange]This plugin worked")
            ini.Save()
        return Plugin.GetIni("Settings")


    def AutoChatCallback(self, timer):
        timer.Kill()
        msg = random.choice(self.Messages.keys())
        Server.Broadcast("Messages", x, self.Messages[msg])
        Plugin.CreateTimer("AutoChat", self.Timer).Start()
_
i tried to fix it but it just doesnt work
self.Messages[x]=int(ini.GetSetting("Messages", x))

??
self.Messages[x] = ini.GetSetting("Messages", x)