def Set_StackSizes(self): ini = Plugin.GetIni("ItemsList") for key in ini.EnumSection("StackSizes"): if ItemManager.FindItemDefinition(key) == None: Util.Log("Could not set stack size for: " + key) continue ItemManager.FindItemDefinition(key).stackable = int( ini.GetSetting("StackSizes", key))
def OnPlayerRespawned(self, BasePlayer): # Check if there is any group set on the configuration file. if self.Config['GroupItems']: # If at least one group is found on the configuration file then set the variable "_GroupItems" equals the group's dictionary. _GroupItems = self.Config['GroupItems'] # Set the variable "_Group" equals the list of groups the player belogs to. By default all players belog to the group "player". _Group = permission.GetUserGroups(BasePlayer.userID.ToString()) # Set the variable "_SetGroup" equals the last group the user was added from Oxide.Group. By default all players belog to the group "player". _SetGroup = _GroupItems.get(_Group[-1]) # Check if the group exists in the config file. if _SetGroup: try: # Catch the "KeyNotFoundException" error if "Container", "item_shortname" or "Amount" is not found on the config file. if _SetGroup[0]['Container'] and _SetGroup[0][ 'item_shortname'] and _SetGroup[0]['Amount']: # Set the variable "inv" equals the player's inventory. inv = BasePlayer.inventory # Empty the player's inventory. inv.Strip() # Iterate through the list of items for the specify group from the configuration file. for item in _SetGroup: # Add the items set on the configuration file to each container on the player's inventory. if item['Container'].lower() == 'main': inv.GiveItem( ItemManager.CreateByName( item['item_shortname'], item['Amount']), inv.containerMain) elif item['Container'].lower() == 'belt': inv.GiveItem( ItemManager.CreateByName( item['item_shortname'], item['Amount']), inv.containerBelt) elif item['Container'].lower() == 'wear': inv.GiveItem( ItemManager.CreateByName( item['item_shortname'], item['Amount']), inv.containerWear) else: return else: print False # Catch the "KeyNotFoundException" error if "Container", "item_shortname" or "Amount" is not found on the config file. except KeyError: return else: return else: return
def On_ServerInit(self): if not Plugin.IniExists("ItemsList"): Plugin.CreateIni("ItemsList") ini = Plugin.GetIni("ItemsList") items = ItemManager.GetItemDefinitions() for item in items: ini.AddSetting("StackSizes", item.shortname, str(item.stackable)) ini.Save() ini = Plugin.GetIni("ItemsList") for item in ItemManager.GetItemDefinitions(): if ini.GetSetting("StackSizes", item.shortname) == "" or None: ini.AddSetting("StackSizes", item.shortname, str(item.stackable)) ini.Save() self.Set_StackSizes()
def library_catalogue(libcon,infile): idnumb = NumbID() itemmanager = ItemManager.ItemManager() itemmanager.set_library_controller(libcon) file=open(infile,'r') for line in file: itemmanager.create_book(line.strip(), idnumb.new_id()) print 'Number of books added: ',idnumb.idnumber
def On_ServerInit(self): if not Plugin.IniExists("Items"): Plugin.CreateIni("Items") ini = Plugin.GetIni("Items") itemdef = ItemManager.GetItemDefinitions() for item in itemdef: ##ini.AddSetting("UID", item.shortname, str(item.uid)) ini.AddSetting("StackSizes", item.shortname, str(item.stackable)) ini.AddSetting("ConditionMax", item.shortname, str(item.condition.max)) ini.AddSetting("Flags", item.shortname, str(item.flags)) ##ini.AddSetting("Amount", item.shortname, str(item.amount)) ##ini.AddSetting("LockTime", item.shortname, str(item.locktime)) ##ini.AddSetting("RemoveTime", item.shortname, str(item.removetime)) ##ini.AddSetting("InstanceData", item.shortname, str(item.instanceData)) ##ini.AddSetting("IsBlueprint", item.shortname, str(item.isBlueprint)) ini.Save() ini = Plugin.GetIni("Items") for key in ini.EnumSection("StackSizes"): if itemkey(key) is None: Util.Log("Failed to set stack size for: " + key) continue itemkey.stackable = int(ini.GetSetting("StackSizes", key)) for key in ini.EnumSection("ConditionMax"): if itemkey(key) is None: Util.Log("Failed to set Max Condition for: " + key) continue itemkey(key).condition.max = float( ini.GetSetting("ConditionMax", key)) for key in ini.EnumSection("Flags"): if itemkey(key) is None: Util.Log("Failed to set Flags for: " + key) continue ##itemkey(key).flags = ItemDefinition.Flag.str(ini.GetSetting("Flags", key)) if itemkey(key).flags == "1": itemkey(key).flags = ItemDefinition.Flag.NoDropping
def On_Command(self, cmd): Player = cmd.User args = cmd.quotedArgs if cmd.cmd == "shop" or cmd.cmd == "s": if len(args) == 1: if args[0] == "lookup" or args[0] == "l": ini = Plugin.GetIni("Settings") keys = ini.EnumSection("Categories") for x in keys: Player.MessageFrom("Shop", x) elif args[0] == "buy" or args[0] == "b": Player.MessageFrom("Shop", "Usage: /shop buy [item] [amount]") elif args[0] == "sell" or args[0] == "s": Player.MessageFrom("Shop", "Usage: /shop sell [item] [amount]") else: Player.MessageFrom( "Shop", "/shop buy [item] [amount] - Buy an item") Player.MessageFrom( "Shop", "/shop sell [item] [amount] - Sell an item") Player.MessageFrom("Shop", "/shop lookup - Lists categories") Player.MessageFrom( "Shop", "/shop lookup [category/item] - Lists items buy / sell prices" ) elif len(args) == 2: if args[0] == "lookup" or args[0] == "l": ini = Plugin.GetIni("Settings") keys = ini.EnumSection(args[1]) count = 0 for x in keys: item = ItemManager.FindItemDefinition(x) if item is not None: buy = float(ini.GetSetting(args[1], x)) percent = float( ini.GetSetting("Settings", "SellPercentage").Replace( "%", "")) / 100 percentoff = (buy * percent) sell = (buy - percentoff) Player.MessageFrom( "Shop - " + args[1], item.shortname + " [Buy: " + DataStore.Get("iConomy", "MoneyMark") + str(buy) + ": Sell: " + DataStore.Get("iConomy", "MoneyMark") + str(sell) + "]") count += 1 else: continue if count == 0: item = ItemManager.FindItemDefinition(args[1]) if item is None: Player.MessageFrom( "Shop", "Could not find category or an item with that name!" ) return ini = Plugin.GetIni("Settings") keys = ini.EnumSection("Categories") price = None for x in keys: if not ini.GetSetting(x, item.shortname) == "": price = self.intcheck( ini.GetSetting(x, item.shortname)) if price is not None: buy = float( ini.GetSetting(x, item.shortname)) percent = float( ini.GetSetting( "Settings", "SellPercentage").Replace( "%", "")) / 100 percentoff = (buy * percent) sell = (buy - percentoff) Player.MessageFrom( "Shop - Lookup", item.shortname + " [Buy: " + DataStore.Get("iConomy", "MoneyMark") + str(buy) + ": Sell: " + DataStore.Get("iConomy", "MoneyMark") + str(sell) + "]") break else: Player.MessageFrom( "Shop", "Shop does not buy or sell this item!") break else: return elif args[0] == "buy" or args[0] == "b": oitem = args[1] amount = 1 item = ItemManager.FindItemDefinition(oitem) if item is None: Player.MessageFrom( "Shop", "Can not find: " + oitem + ". You have to use a shortname!") return ini = Plugin.GetIni("Settings") keys = ini.EnumSection("Categories") price = None for x in keys: if not ini.GetSetting(x, item.shortname) == "": price = self.intcheck( ini.GetSetting(x, item.shortname)) if price is not None: price = (price * amount) costs = float(DataStore.Get("iConomy", Player.SteamID)) - price if not costs < 0.0: DataStore.Add("iConomy", Player.SteamID, costs) Player.Inventory.Add(item.itemid, amount) Player.MessageFrom( "Shop", "You have brought " + str(amount) + " x " + item.shortname + " for " + DataStore.Get("iConomy", "MoneyMark") + str(price)) else: Player.MessageFrom( "Shop", "You do not have enough money to buy " + str(amount) + " x " + item.shortname) else: Player.MessageFrom( "Shop", "The shop does not sell: " + item.shortname) elif args[0] == "sell" or args[0] == "s": oitem = args[1] amount = 1 item = ItemManager.FindItemDefinition(oitem) if item is None: Player.MessageFrom( "Shop", "Can not find: " + oitem + ". You have to use a shortname!") return ini = Plugin.GetIni("Settings") keys = ini.EnumSection("Categories") price = None for x in keys: if not ini.GetSetting(x, item.shortname) == "": price = self.intcheck( ini.GetSetting(x, item.shortname)) if price is not None: playerAmount = Player.Inventory._inv.GetAmount( item.itemid) if playerAmount >= amount: percent = float( ini.GetSetting("Settings", "SellPercentage").Replace( "%", "")) / 100 percentoff = float(price) * percent costs = (float(price) - percentoff) * float(amount) Player.Inventory._inv.Take( Player.Inventory._inv.FindItemIDs(item.itemid), item.itemid, amount) DataStore.Add( "iConomy", Player.SteamID, float(DataStore.Get("iConomy", Player.SteamID)) + costs) Player.MessageFrom( "Shop", "You have sold " + item.shortname + " x " + str(amount) + " for " + DataStore.Get("iConomy", "MoneyMark") + str(costs)) Player.Inventory.Notice(" + " + str(costs)) else: Player.MessageFrom( "Shop", "You do not have " + str(amount) + " x " + item.shortname + " to sell!") else: Player.MessageFrom( "Shop", "The shop does not buy: " + item.shortname) else: Player.MessageFrom( "Shop", "/shop buy [item] [amount] - Buy an item") Player.MessageFrom( "Shop", "/shop sell [item] [amount] - Sell an item") Player.MessageFrom("Shop", "/shop lookup - Lists categories") Player.MessageFrom( "Shop", "/shop lookup [category/item] - Lists items buy / sell prices" ) elif len(args) == 3: if args[0] == "buy" or args[0] == "b": oitem = args[1] amount = self.intcheck(args[2]) if amount is None: Player.MessageFrom( "Shop", "The amount you have entered is not a number!") return item = ItemManager.FindItemDefinition(oitem) if item is None: Player.MessageFrom( "Shop", "Can not find: " + oitem + ". You have to use a shortname!") return ini = Plugin.GetIni("Settings") keys = ini.EnumSection("Categories") price = None for x in keys: if not ini.GetSetting(x, item.shortname) == "": price = self.intcheck( ini.GetSetting(x, item.shortname)) if price is not None: price = (price * amount) costs = float(DataStore.Get("iConomy", Player.SteamID)) - price if not costs < 0.0: DataStore.Add("iConomy", Player.SteamID, costs) Player.Inventory.Add(item.itemid, amount) Player.MessageFrom( "Shop", "You have brought " + str(amount) + " x " + item.shortname + " for " + DataStore.Get("iConomy", "MoneyMark") + str(price)) else: Player.MessageFrom( "Shop", "You do not have enough money to buy " + str(amount) + " x " + item.shortname) else: Player.MessageFrom( "Shop", "The shop does not sell: " + item.shortname) elif args[0] == "sell" or args[0] == "s": oitem = args[1] amount = self.intcheck(args[2]) if amount is None: Player.MessageFrom( "Shop", "The amount you have entered is not a number!") return item = ItemManager.FindItemDefinition(oitem) if item is None: Player.MessageFrom( "Shop", "Can not find: " + oitem + ". You have to use a shortname!") return ini = Plugin.GetIni("Settings") keys = ini.EnumSection("Categories") price = None for x in keys: if not ini.GetSetting(x, item.shortname) == "": price = self.intcheck( ini.GetSetting(x, item.shortname)) if price is not None: playerAmount = Player.Inventory._inv.GetAmount( item.itemid) if playerAmount >= amount: percent = float( ini.GetSetting("Settings", "SellPercentage").Replace( "%", "")) / 100 percentoff = float(price) * percent costs = (float(price) - percentoff) * float(amount) Player.Inventory._inv.Take( Player.Inventory._inv.FindItemIDs(item.itemid), item.itemid, amount) DataStore.Add( "iConomy", Player.SteamID, float(DataStore.Get("iConomy", Player.SteamID)) + costs) Player.MessageFrom( "Shop", "You have sold " + item.shortname + " x " + str(amount) + " for " + DataStore.Get("iConomy", "MoneyMark") + str(costs)) Player.Inventory.Notice(" + " + str(costs)) else: Player.MessageFrom( "Shop", "You do not have " + str(amount) + " x " + item.shortname + " to sell!") else: Player.MessageFrom( "Shop", "The shop does not buy: " + item.shortname) elif args[0] == "lookup" or args[0] == "l": Player.MessageFrom("Shop", "/shop lookup - Lists categories") Player.MessageFrom( "Shop", "/shop lookup [category/item] - Lists items buy / sell prices" ) else: Player.MessageFrom( "Shop", "/shop buy [item] [amount] - Buy an item") Player.MessageFrom( "Shop", "/shop sell [item] [amount] - Sell an item") Player.MessageFrom("Shop", "/shop lookup - Lists categories") Player.MessageFrom( "Shop", "/shop lookup [category/item] - Lists items buy / sell prices" ) else: Player.MessageFrom("Shop", "/shop buy [item] [amount] - Buy an item") Player.MessageFrom( "Shop", "/shop sell [item] [amount] - Sell an item") Player.MessageFrom("Shop", "/shop lookup - Lists categories") Player.MessageFrom( "Shop", "/shop lookup [category/item] - Lists items buy / sell prices" )
from src.library import LibraryController from src.user import User import datetime as dt import ItemManager as bob lc = LibraryController() im = bob.ItemManager() im.set_library_controller(lc) im.create_database('top100t.txt') JohnnyCodewarrior = User(666) lc.add_user(JohnnyCodewarrior) lc.user_checkout(666, 'Twilight', date=dt.datetime(2017, 3, 25)) lc.user_checkout(666, 'Document, Your job depends on it')
#! /usr/bin/env python ''' Created on Feb 1, 2012 @author: lbillon ''' if __name__ == '__main__': import sys import ItemManager, Item __im = ItemManager.ItemManager() def printUsage(): print( "Available commands:\n\ /+\t\tAdd new item definition\n\ /s filename\tSave item definitions to file\n\ /l filename\tLoad item definitions from file\n\ /h\t\tDisplay this help message\n\ \n\ Type a series of identifiers to register an order\n\ ") def __exitProgram(): print("terminating...") sys.exit() def __listItems():
def On_CombatEntityHurt(self, CombatEntityHurtEvent): try: Player = CombatEntityHurtEvent.Attacker.ToPlayer() BuildingPart = CombatEntityHurtEvent.Victim.ToBuildingPart() except: return if Player is not None: if DataStore.Get("Remove", Player.SteamID) == "normal": tcCount = 0 poCount = 0 for privlidge in UnityEngine.Object.FindObjectsOfType[ BuildingPrivlidge](): if Util.GetVectorsDistance( Player.Location, privlidge.transform.position) <= float(30.1): tcCount += 1 if privlidge.IsAuthed(Player.basePlayer): poCount += 1 if tcCount == 0: Player.MessageFrom("RemoveTool", DataStore.Get("RemoveTool", "NTC")) elif poCount < tcCount: Player.MessageFrom("RemoveTool", DataStore.Get("RemoveTool", "NBP")) else: if Util.GetVectorsDistance( CombatEntityHurtEvent.Victim.Location, Player.Location) <= float(3.5): try: for x in CombatEntityHurtEvent.Victim.ToBuildingPart( ).buildingBlock.currentGrade.costToBuild: Player.Inventory.Add(x.itemid, x.amount) CombatEntityHurtEvent.Victim.Kill() return except: try: name = CombatEntityHurtEvent.Victim.baseEntity.LookupShortPrefabName( ).replace('_', '.') name = name.replace('.deployed', '') name = name.replace('.prefab', '') item = ItemManager.FindItemDefinition(name) Player.Inventory.Add(item.itemid, 1) Util.DestroyEntity( CombatEntityHurtEvent.Victim.baseEntity) except: try: #Backup, Checks dictionary if above fails item = ItemManager.FindItemDefinition(Data[ CombatEntityHurtEvent.Victim. baseEntity.LookupShortPrefabName()]) if item is not None: Player.Inventory.Add(item.itemid, 1) Util.DestroyEntity( CombatEntityHurtEvent.Victim. baseEntity) else: Player.Message( "You can not remove this item!") except: Player.Message( "You can not remove this item!") return else: Player.MessageFrom("RemoveTool", DataStore.Get("RemoveTool", "OFR")) elif DataStore.Get("Remove", Player.SteamID) == "admin": try: for x in CombatEntityHurtEvent.Victim.ToBuildingPart( ).buildingBlock.currentGrade.costToBuild: Player.Inventory.Add(x.itemid, x.amount) CombatEntityHurtEvent.Victim.Kill() return except: try: name = CombatEntityHurtEvent.Victim.baseEntity.LookupShortPrefabName( ).replace('_', '.') name = name.replace('.deployed', '') name = name.replace('.prefab', '') item = ItemManager.FindItemDefinition(name) Player.Inventory.Add(item.itemid, 1) Util.DestroyEntity( CombatEntityHurtEvent.Victim.baseEntity) except: try: #Backup, Checks dictionary if above fails item = ItemManager.FindItemDefinition( self.Data[CombatEntityHurtEvent.Victim. baseEntity.LookupShortPrefabName()]) if item is not None: Player.Inventory.Add(item.itemid, 1) Util.DestroyEntity( CombatEntityHurtEvent.Victim.baseEntity) else: Player.Message("You can not remove this item!") except: Player.Message("You can not remove this item!")
def learn_bps(rows): if not rows: return for r in rows: player.blueprints.Learn( ItemManager.FindItemDefinition(r["bpid"]))