[python]I Face the problem

02/09/2014 08:28 ashraf6450#1
hi
todey During i design anti exp hack I have problems in def IsDivideAble
Reformed tried in different ways but I could not
Code:
import app
import ui
import player
import chr
import chat
import chrmgr
import time
import skill
import nonplayer
import net
import snd
import item
import math
import miniMap
import uiminimap
import background
import exception
import uiCommon
import grp
import os
import shop
import ServerInfo
import game
import chat
import thread
import pack
import uiPrivateShopBuilder
import sys
import ime
import uiTip
import interfacemodule
import messenger
import locale
import constInfo
import exchange
import textTail
import snd
import net
import effect
import wndMgr
import fly
import systemSetting
import quest
import guild
import dbg
class FarmToolsDialog(ui.ScriptWindow):

	Gui = []
	PotionBuffer = {}
	Taus = [50821, 50822, 50823, 50824, 50825, 50826]

	ExpBot = "off"

	PotionManagerGui = []
	PotionManager = [100, 5]
	PotionManagerState = "off"

	def __init__(self):
		ui.ScriptWindow.__init__(self)
		self.Gui = []
		self.AddGui()
		
	def __del__(self):
		self.Gui[0].Hide()
		try:
			self.PotionManagerGui[0].Hide()
		except:
			pass
		ui.ScriptWindow.__del__(self)
		
		
	def Destroy(self):
		self.Hide()
		return TRUE
		
	def CreateGuild(self):
		net.SendAnswerMakeGuildPacket(self.Gui[7].GetText())
		
		self.Gui[5].SetText("Erfahrungs-Grenze:")
		self.Gui[7].SetText("100")
		self.Gui[7].SetNumberMode()
		self.Gui[8].SetText("off")
		self.Gui[8].SetEvent(lambda : self.ToggleExpBot())
			
	def ToggleExpBot(self):
		if self.ExpBot == "off":
			self.Gui[8].SetText("on")
			self.ExpBot = "on"
			chat.AppendChat(1, "Der Exp-Spendebot wurde aktiviert.")
		else:
			self.Gui[8].SetText("off")
			self.ExpBot = "off"
			chat.AppendChat(1, "Der Exp-Spendebot wurde deaktiviert.")		
		
	def HidePotionManagement(self):
		self.PotionManagerGui[0].Hide()
		
	def SetConfig(self):
		Value, Time = self.PotionManager
		
		MinValue = int(self.PotionManagerGui[5].GetSliderPos() * 200)
		MinTime = int(self.PotionManagerGui[8].GetSliderPos() * 10)
		if MinValue != Value:
			self.PotionManagerGui[6].SetText("+ " + str(MinValue))
		if MinTime != Time:
			self.PotionManagerGui[9].SetText(str(MinTime) + " min")
			
		self.PotionManager = [MinValue, MinTime]
		
	def TogglePotionManager(self, state):
		if state == "Start":
			self.PotionManagerState = "on"
			chat.AppendChat(1, "Der Potion Manager wurde gestartet.")
		else:
			self.PotionManagerState = "off"
			chat.AppendChat(1, "Der Potion Manager wurde angehalten.")
			
	def OnRender(self):
		if self.PotionManagerState != "on" or player.GetStatus(player.HP) <= 0:
			return
			
		if not shop.IsOpen():
			chat.AppendChat(1, "Bitte öffne zuerst einen Shop.")
			self.TogglePotionManager("Stop")
			return
			
		MinValue, MinTime = self.PotionManager
		MinTime = MinTime * 60
		
		ItemIndex = self.PotionManagerGui[2].GetSelectedItem()
		if ItemIndex:
			pass
		else:
			chat.AppendChat(chat.CHAT_TYPE_INFO, "Bitte wähle ein Item aus!")
			return
		PotionValue = int(ItemIndex.GetText().split("	")[0])
	
		#Check Potions:
		for InventorySlot in xrange(player.INVENTORY_PAGE_SIZE*2):
			ItemIndex = player.GetItemIndex(InventorySlot)
			if PotionValue == ItemIndex:
				Value0, Value , Time = [player.GetItemMetinSocket(InventorySlot, i) for i in xrange(player.METIN_SOCKET_MAX_NUM)]
				if Value >= MinValue and Time >= MinTime:
					self.TogglePotionManager("Stop")
				else:
					net.SendShopSellPacket(InventorySlot)
	
		if self.PotionManagerState != "on":
			return
			
		#Buy Potions:
		for EachShopSlot in xrange(shop.SHOP_SLOT_COUNT):
			ShopItemValue = shop.GetItemID(EachShopSlot)
			if ShopItemValue == int(PotionValue):
				net.SendShopBuyPacket(EachShopSlot)
				break
		
	def OpenPotionManagement(self):
		self.PotionManagerGui = []
		self.PotionManager = [100, 5]
		self.PotionManagerState = "off"

		tmp = [
			[[ui.BoardWithTitleBar, ""], [200, 340], [0,0], [["SetCenterPosition", [""]], ["SetCloseEvent", [self.HidePotionManagement]], ["SetTitleName", ["Potion Manager"]]], ["movable", "float"]],			
			[[ui.SlotBar, 0], [170, 140], [10, 35], [], []],			
			[[ui.ListBoxEx, 0], [0, 0], [25, 50], [["SetViewItemCount", [6]]], []],			
			[[ui.ScrollBar, 0], [0, 0], [160, 40], [["SetScrollBarSize", [130]]], []],			
			[[ui.TextLine, 0], [0, 0], [70, 180], [["SetDefaultFontName", [""]], ["SetText", ["Mindest Wert"]],	["SetFontColor", [0.6, 0.7, 1.0]]], []],			
			[[ui.SliderBar, 0], [0, 0], [13, 200], [["SetEvent", [ui.__mem_func__(self.SetConfig)]], ["SetSliderPos", [0.5]]], []],			
			[[ui.TextLine, 0], [0, 0], [85, 215], [["SetDefaultFontName", [""]], ["SetText", ["+ 100"]],	], []],			
			[[ui.TextLine, 0], [0, 0], [85, 240], [["SetDefaultFontName", [""]], ["SetText", ["Dauer"]],	["SetFontColor", [0.6, 0.7, 1.0]]], []],			
			[[ui.SliderBar, 0], [0, 0], [13, 260], [["SetEvent", [ui.__mem_func__(self.SetConfig)]], ["SetSliderPos", [0.5]]], []],			
			[[ui.TextLine, 0], [0, 0], [87, 275], [["SetDefaultFontName", [""]], ["SetText", ["5 min"]],	], []],			
			[[ui.Button, 0], [0, 0], [35, 300], [['SetUpVisual', ["d:/ymir work/ui/public/middle_button_01.sub"]],['SetOverVisual', ["d:/ymir work/ui/public/middle_button_02.sub"]], ['SetDownVisual', ["d:/ymir work/ui/public/middle_button_03.sub"]], ["SetText", ["Start"]], ['SetEvent', [lambda : self.TogglePotionManager("Start")]]], []],			
			[[ui.Button, 0], [0, 0], [105, 300], [['SetUpVisual', ["d:/ymir work/ui/public/middle_button_01.sub"]],['SetOverVisual', ["d:/ymir work/ui/public/middle_button_02.sub"]], ['SetDownVisual', ["d:/ymir work/ui/public/middle_button_03.sub"]], ["SetText", ["Stop"]], ['SetEvent', [lambda : self.TogglePotionManager("Stop")]]], []],			
			]
		GuiParser(tmp, self.PotionManagerGui)
		
		self.PotionManagerGui[2].SetScrollBar(self.PotionManagerGui[3])
		for blaaa in self.Taus:
			self.PotionManagerGui[2].AppendItem(Item(str(blaaa) + "	" + str(item.GetItemName(item.SelectItem(blaaa)))))
		
	def AddGui(self):	
		Gui = [
			[[ui.ThinBoard, ""], [349, 537], [0,0], [["SetCenterPosition", [""]]], ["movable", "float"]],			
			[[ui.Button, 0], [0, 0], [313, 15], [['SetUpVisual', ["d:/ymir work/ui/public/close_button_01.sub"]],['SetOverVisual', ["d:/ymir work/ui/public/close_button_02.sub"]], ['SetDownVisual', ["d:/ymir work/ui/public/close_button_03.sub"]], ['SetToolTipText', ["Inchide", 0, - 23]], ['SetEvent', [lambda : self.__del__()]]], []],	
			[[ui.TextLine, 0], [0, 0], [113, 18], [["SetDefaultFontName", [""]],	["SetText", ["Farm Tools by DaRealFreak"]],	["SetFontColor", [0.1, 0.7, 1.0]]], []],
			[[ui.TextLine, 0], [0, 0], [129, 40], [["SetDefaultFontName", [""]],	["SetText", ["Auto Potion Usage"]],	["SetFontColor", [0.6, 0.7, 1.0]]], []],			
			[[ui.TextLine, 0], [0, 0], [134, 392], [["SetDefaultFontName", [""]],	["SetText", ["Guild Management"]],	["SetFontColor", [0.6, 0.7, 1.0]]], []],			
			[[ui.TextLine, 0], [0, 0], [137, 405], [["SetDefaultFontName", [""]],	["SetText", ["Enter Guildname:"]],	], []],
			[[ui.SlotBar, 0], [100, 18], [129, 425], [], []],			
			[[ui.EditLine, 6], [100, 17], [10, 2], [["SetMax", [12]], ["SetFocus", [""]]], []],			
			[[ui.Button, 0], [0, 0], [134, 450], [['SetUpVisual', ["d:/ymir work/ui/public/large_button_01.sub"]],['SetOverVisual', ["d:/ymir work/ui/public/large_button_02.sub"]], ['SetDownVisual', ["d:/ymir work/ui/public/large_button_03.sub"]], ["SetText", ["Create Guild"]], ['SetEvent', [lambda : self.CreateGuild()]]], []],			
			[[ui.TextLine, 0], [0, 0], [131, 482], [["SetDefaultFontName", [""]],	["SetText", ["Potion Management"]],	["SetFontColor", [0.6, 0.7, 1.0]]], []],			
			[[ui.Button, 0], [0, 0], [134, 500], [['SetUpVisual', ["d:/ymir work/ui/public/large_button_01.sub"]],['SetOverVisual', ["d:/ymir work/ui/public/large_button_02.sub"]], ['SetDownVisual', ["d:/ymir work/ui/public/large_button_03.sub"]], ["SetText", ["Potion Manager"]], ['SetEvent', [lambda : self.OpenPotionManagement()]]], []],			
			]
		GuiParser(Gui, self.Gui)
		
		#Guild System Fix:
		if player.GetGuildID() != 0:
			self.Gui[5].SetText("Erfahrungs-Grenze:")
			self.Gui[5].SetPosition(134, 405)
			self.Gui[7].SetText("100")
			self.Gui[7].SetNumberMode()
			self.Gui[8].SetText("off")
			self.Gui[8].SetEvent(lambda : self.ToggleExpBot())
		
		self.Potions = []
		for i in xrange(50813, 50827):
			self.Potions.append(i)
		self.Potions.remove(50815)
		self.Potions.remove(50816)
		self.Leftovers = [50801, 50802, 50107, 50108, 71027, 71028, 71029, 71030, 71044, 71045, 27102]
		for bla in self.Leftovers:
			self.Potions.append(bla)
			
		tmp = []
		x = 40
		y = 70
		for potion in self.Potions:
			Index = self.Potions.index(potion)
			if IsDivideAble(Index, 4):
				x = 40
				y += 50
			ItemName = item.GetItemName(item.SelectItem(potion))
			ItemIcon = item.GetIconImageFileName()
			button = [[ui.ExpandedImageBox, 0], [0, 0], [x, y], [['LoadImage', [ItemIcon]]], []]
			name = [[ui.Button, 0], [0, 0], [x - 15, y + 30], [['SetUpVisual', ["d:/ymir work/ui/public/middle_button_01.sub"]],['SetOverVisual', ["d:/ymir work/ui/public/middle_button_02.sub"]], ['SetDownVisual', ["d:/ymir work/ui/public/middle_button_03.sub"]], ["SetText", [ItemName]], ['SetEvent', [lambda arg = (self.Potions.index(potion)): self.AutoUsage(arg)]]], []]
			tmp.append(button)
			tmp.append(name)
			x += 78					
			
		GuiParser(tmp, self.Gui)
		
	def AutoUsage(self, ItemIndex):
		ItemValue = self.Potions[ItemIndex]
		
		try:
			del self.PotionBuffer[ItemValue]
			chat.AppendChat(1, item.GetItemName(item.SelectItem(ItemValue)) + " nicht mehr genutzt.")
		except KeyError:
			self.PotionBuffer[ItemValue] = app.GetGlobalTimeStamp()
			chat.AppendChat(1, item.GetItemName(item.SelectItem(ItemValue)) + " ab jetzt automatisch genutzt.")
	
	def UsePotion(self, ItemValue):
		if player.GetItemCountByVnum(ItemValue) == 0:
			return
			
		Firework = [50107, 50108]
		Berries = [50813, 50814, 50817, 50818, 50819, 50820, 50801, 50802]
		GodItems = [71027, 71028, 71029, 71030]
		HelpItems = [71044, 71045, 27102]

		if ItemValue in self.Taus:
			HighestValue = [0, 0]
			for InventorySlot in xrange(player.INVENTORY_PAGE_SIZE*2):
				ItemIndex = player.GetItemIndex(InventorySlot)
				if ItemValue == ItemIndex:
					Value0, Value , Time = [player.GetItemMetinSocket(InventorySlot, i) for i in xrange(player.METIN_SOCKET_MAX_NUM)]
					if HighestValue[0] < Value:
						HighestValue = [Value, InventorySlot, Time]
						self.PotionBuffer[ItemValue] = app.GetGlobalTimeStamp() + HighestValue[2] + 2
			net.SendItemUsePacket(HighestValue[1])

		elif ItemValue in Firework:
			for InventorySlot in xrange(player.INVENTORY_PAGE_SIZE*2):
				ItemIndex = player.GetItemIndex(InventorySlot)
				if ItemValue == ItemIndex:
					net.SendItemUsePacket(InventorySlot)
					self.PotionBuffer[ItemValue] = app.GetGlobalTimeStamp() + 482
					break
					
		elif ItemValue in Berries:
			for InventorySlot in xrange(player.INVENTORY_PAGE_SIZE*2):
				ItemIndex = player.GetItemIndex(InventorySlot)
				if ItemValue == ItemIndex:
					net.SendItemUsePacket(InventorySlot)
					self.PotionBuffer[ItemValue] = app.GetGlobalTimeStamp() + 362
					break
					
		elif ItemValue in GodItems:
			for InventorySlot in xrange(player.INVENTORY_PAGE_SIZE*2):
				ItemIndex = player.GetItemIndex(InventorySlot)
				if ItemValue == ItemIndex:
					net.SendItemUsePacket(InventorySlot)
					self.PotionBuffer[ItemValue] = app.GetGlobalTimeStamp() + 1802
					break
					
		elif ItemValue in HelpItems:
			for InventorySlot in xrange(player.INVENTORY_PAGE_SIZE*2):
				ItemIndex = player.GetItemIndex(InventorySlot)
				if ItemValue == ItemIndex:
					net.SendItemUsePacket(InventorySlot)
					self.PotionBuffer[ItemValue] = app.GetGlobalTimeStamp() + 603
					break
					
		chat.AppendChat(1, "Auto Usage: " + str(ItemValue))
	
	def OnUpdate(self):
		if player.GetGuildID() != 0 and self.ExpBot == "on":
			try:
				Exp = player.GetEXP()
				if Exp >= int(self.Gui[7].GetText()) and Exp >= 100:
					net.SendGuildOfferPacket(Exp)
			except:
				self.ToggleExpBot()
				chat.AppendChat(1, "Bitte gebe einen Wert an.")
	
		if self.PotionBuffer == {}:
			return
			
		for Potion in self.PotionBuffer:
			if app.GetGlobalTimeStamp() >= self.PotionBuffer[Potion]:
				self.UsePotion(Potion)
def IsMobAlive(vid):
	global LastCheck
	global MatchCount
	global HookedVid
	chr.SelectInstance(vid)
	BoundBox = chr.GetBoundBoxOnlyXY(vid)
	Distance = player.GetCharacterDistance(vid)
	if chr.GetInstanceType(vid) == chr.INSTANCE_TYPE_ENEMY:
	
		if HookedVid[0] == vid and HookedVid[1] <= 0 and Distance <= 200:
			return 0
	
		if LastCheck == str(BoundBox):
			MatchCount += 1
		else:
			MatchCount = 0
		LastCheck = str(BoundBox)
		
		if Distance >= 975:
			return 1
			
		if MatchCount >= 9:
			MatchCount = 0
			return 0
		else:
			return 1
	else:
		if BoundBox[3] >= 175:
			return 0
		else:
			return 1	
	
def IsBetween(x, y, z):
	tmp = []
	for i in xrange(x, y):
		tmp.append(i)
		
	try:
		tmp.index(z)
		return 1
	except:
		pass

def GuiParser(guiobjects, list):
	#[Type, Parentindex],[Sizex, Sizey], [Posx, Posy], [commands], [flags]
	for object in guiobjects:
		Object = object[0][0]()
		if object[0][1] != "":
			Object.SetParent(list[object[0][1]])
		if object[1][0] + object[1][1] != 0:
			Object.SetSize(object[1][0], object[1][1])
		if object[2][0] + object[2][1] != 0:
			Object.SetPosition(object[2][0], object[2][1])
				
		for command in object[3]:
			cmd = command[0]	
			attr = getattr(Object,cmd)			
			if callable(attr):
				argument = command[1]
				lenght = len(argument)
				if lenght == 1:
					if argument[0] == "":
						attr()
					else:
						attr(argument[0])
				elif lenght == 2:
					attr(argument[0], argument[1])
				elif lenght == 3:
					attr(argument[0], argument[1], argument[2])
				elif lenght == 4:
					attr(argument[0], argument[1], argument[2], argument[3])
		for flag in object[4]:
			Object.AddFlag(str(flag))
		Object.Show()
	
		list.append(Object)
		
def IsDivideAble(x, y):
	if x == 0:
		return
	if float(x/y) == DivideToFloat(x, y):
		return 1
	
def DivideToFloat(x, y):
	try:
		return x * (y**-1)
	except:
		return 0
	

	def Show(self):
		ui.ThinBoard.Show(self)

start = FarmToolsDialog()
start.Show()
When I try to show the problem batch
(no selected item data)
please
Please help me