Need some help with AutoRewards Plugin PY

ice cold

Active Member
Trusted Member
Member
Oct 24, 2016
606
907
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()
 
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
 
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()
 
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()
 
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
 
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.
 
Well to start off, "Items" is not an item name :P
Python:
pl.Inventory.AddItem(x, ini.GetSetting("Items", x))
 
  • Agree
Reactions: salva
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))
 
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 ?
 
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
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
 
and i want it that it chooses 1 item from the list, could you make that please
 
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
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
 
@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

  • upload_2018-2-5_15-36-3.png
    upload_2018-2-5_15-36-3.png
    25 KB · Views: 4
@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)