Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=================================================================================================#
- # Script Name: AutoPush
- # Tibia Version: 8.6+
- # TibiaAuto: 2.5.1+
- # Python Version:
- # Language: English
- # Platform: All Windows
- # Author: Ascer (visit: https://github.com/Ascer1/LachyZone)
- # Requirements: pywin32-210 for load dlls (win32gui, win32api, win32con, struct)
- # Can be download here: https://sourceforge.net/projects/pywin32/files/pywin32/
- #=================================================================================================#
- #=================================================================================================#
- # Config Class: Here you can change all script settings.
- #=================================================================================================#
- TIBIA_WINDOW_X = [836, 916]; # [start, end] position X on screen where stay your character.
- TIBIA_WINDOW_Y = [405, 485]; # [start, end] position Y on screen where stay your character.
- SQUARE_UPDATE = 80 # square length in pixels. (Length X + Length Y)/2
- EXECUTION_DELAY = 0 # loop time in miliseconds (0 means run fast as possible around 20-50ms)
- USE_RUNE_DELAY = 1000 # how fast we will use destroy trash rune on ground default 1000ms to avoid spam
- PUSH_DELAY = 150 # time in miliseconds between pushing player, default 150ms to avoid spam
- MAGIC_WALL_GROUND_ID = 2129 # 2129 id magic wall on ground square
- WILD_GROWTH_GROUND_ID = 2128 # 2128 or 2130 id of wooden bush on ground square
- MAGIC_WALL_TIME = 20.0 # time of magic wall effct on ground square
- WILD_GROWTH_TIME = 45.0 # time of wooden bush effct on ground square
- PUSH_ON_MW_TIME = 1.5 # [HERE YOU NEED TO TEST BEST TIMER FOR YOU PC] push player when this amount of seconds left to end of magic wall
- DEAD_BODIES = [4240, 4241, 4247, 4248, 3492] # open browse field and remove this items before push
- DESTROY_TRASH_RUNE_ID = 3197 # 3197 id of rune to destory trash under player, default=disinegrate
- COVER_TRASH_RUNE_ID = 3164 # 3164 id of rune to cover trash when bodies detected, default=energy field rune
- TRASH_MYSELF_ITEM = [3031, 2, True] # [0] - item id to drop under your character before push, [1] - item quantity, [2] - trash True/False (when false, increase speed of push a little)
- #=================================================================================================#
- # Include List: Load Windows Libraries for later usage.
- #=================================================================================================#
- import time
- import signal
- import win32gui, win32api, win32con, struct
- #=================================================================================================#
- # TibiaAuto Class: Creating platform in memory for run code in loop.
- #=================================================================================================#
- class ModuleMachine:
- modTime = 0
- pushTime = 0
- dropTime = 0
- walls = [[0, 0, 0, 0, 0]]
- lastF = 0
- lastT = 0
- lastMyPos = [0, 0, 0]
- autoPush = False
- lastPlayer = 0
- pushPos = [0, 0, 0]
- def getName(self):
- return "AutoPush"
- def getVersion(self):
- return "1.0"
- def getFunDef(self, nr):
- if (nr==0): return (0, EXECUTION_DELAY, self.engine)
- return ()
- def getConfigParam(self, nr):
- return ()
- #=================================================================================================#
- # Functions Class: Stored functions to calculate values and read memory.
- #=================================================================================================#
- #=================================================================================================
- # Function: console(self, message):
- # Description: Write message to Tibia Chat on by blue text.
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # message - message to write.
- #
- # Return Value(s): Nothing.
- #=================================================================================================
- def console(self, message):
- tasender.sendTAMessage(message)
- #=================================================================================================
- # Function: mapGetTopUseItem(self, x, y, z):
- # Description: Get Top Item ID on map position x, y, z
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # x, y, z - Coordines on map.
- #
- # Return Value(s):
- # On Success: ID of map postion.
- # On Failure: 0
- #=================================================================================================
- def mapGetTopUseItem(self, x, y, z):
- return tareader.mapGetPointItemId(x, y, z, tareader.mapGetPointTopPos(x, y, z))
- #=================================================================================================
- # Function: readMe(self):
- # Description: Read self characters for all known informations.
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- #
- # Return Value(s):
- # On Success: An array with self informations
- # On Failure: 0
- #=================================================================================================
- def readMe(self):
- return tareader.readSelfCharacter()
- #=================================================================================================
- # Function: isPressed(self, key):
- # Description: Read win32api for key state.
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # key - Hex value of key on keyboard, example F9 = 0x78
- #
- # Return Value(s):
- # On Success: True
- # On Failure: False
- #=================================================================================================
- def isPressed(self, key):
- if win32api.GetAsyncKeyState(key) == 0: return False
- return True
- #=================================================================================================
- # Function: getMousePos(self):
- # Description: Read win32api for mouse coordines.
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- #
- # Return Value(s):
- # On Success: x, y mouse
- # On Failure: Null
- #=================================================================================================
- def getMouse(self):
- return win32api.GetCursorPos()
- #=================================================================================================
- # Function: getGround(self, x, y, z, stackNr):
- # Description: Browse tibia title for each item id.
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # x, y, z - Coordines on map.
- # stackNr - Place item in stack.
- # Return Value(s):
- # On Success: itemID
- # On Failure: 0
- #=================================================================================================
- def getGround(self, x, y, z, stackNr):
- if tareader.mapGetPointItemsCount(x, y, z) - 1 >= stackNr: return tareader.mapGetPointItemExtraInfo(x, y, z, stackNr, 0)
- return 0
- #=================================================================================================
- # Function: mapIsWalkable(self, x, y, z):
- # Description: Read Tibia map for walkable position
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # x, y, z - Coordines on map.
- # Return Value(s):
- # On Success: True
- # On Failure: False
- #=================================================================================================
- def mapIsWalkable(self, x, y, z):
- for i in range(0, 8):
- mapID = self.getGround(x, y, z, i)
- if mapID == 99 or tareader.getTibiaTile(mapID)['blocking'] == 1: return False
- return True
- #=================================================================================================
- # Function: itemIsMoveable(self, itemid):
- # Description: Check if item is possible to move
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # itemid - id of item to check
- # Return Value(s):
- # On Success: True
- # On Failure: False
- #=================================================================================================
- def itemIsMoveable(self, itemid):
- if itemid == 99: return False
- if tareader.getTibiaTile(itemid)['notMoveable'] == 0: return True
- return False
- #=================================================================================================
- # Function: tableContains(self, table, argumenet):
- # Description: Research table for special argument
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # table - An array to search.
- # argument - element to find
- # Return Value(s):
- # On Success: table [0] - True, [1] - element
- # On Failure: False
- #=================================================================================================
- def tableContains(self, table, argumenet):
- for i in range(0, len(table)):
- if table[i] == argumenet:
- return [True, table[i]]
- return [False, 0]
- #=================================================================================================
- # Function: wallInTable(self, x, y, z):
- # Description: Check if wall on ground position is already in self.walls table
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # x, y, z - Coordines on map.
- # Return Value(s):
- # On Success: Table [0] - True, [1] - Wall table
- # On Failure: False
- #=================================================================================================
- def wallInTable(self, x, y, z):
- for i in range(0, len(self.walls)):
- if self.walls[i][0] == x and self.walls[i][1] == y and self.walls[i][2] == z:
- return [True, self.walls[i]]
- return [False, 0]
- #=================================================================================================
- # Function: catchWallTimers(self):
- # Description: Collect all wall timers into table.
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- #
- # Return Value(s): Nothing.
- #=================================================================================================
- def catchWallTimers(self):
- xT, yT = [-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7], [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
- if len(self.walls) == 0: self.walls.append([0, 0, 0, 0, 0])
- for ox in range(0, len(xT)):
- for oy in range(0, len(yT)):
- me = self.readMe()
- x, y, z = me['x']+xT[ox], me['y']+yT[oy], me['z']
- contains = self.tableContains([MAGIC_WALL_GROUND_ID, WILD_GROWTH_GROUND_ID], self.mapGetTopUseItem(xT[ox], yT[oy], 0))
- if contains[0] and not self.wallInTable(x, y, z)[0]:
- self.walls.append([x, y, z, time.time(), contains[1]])
- #=================================================================================================
- # Function: removeWallTimers(self):
- # Description: Remove wrong timers from table.
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # me - table with self informations returned by self.readMe()
- #
- # Return Value(s): Nothing.
- #=================================================================================================
- def removeWallTimers(self):
- for i in range(0, len(self.walls)):
- if self.walls[i][1] == 0: continue
- me = self.readMe()
- x, y, z = me['x'], me['y'], me['z']
- if self.walls[i][4] == MAGIC_WALL_GROUND_ID:
- if (time.time() - self.walls[i][3] >= MAGIC_WALL_TIME or (abs(x - self.walls[i][0]) <= 7 and abs(y - self.walls[i][1]) <= 5 and z == self.walls[i][2] and self.mapGetTopUseItem(self.walls[i][0] - x, self.walls[i][1] - y, 0) != MAGIC_WALL_GROUND_ID)):
- self.walls.pop(i)
- else:
- if (time.time() - self.walls[i][3] >= WILD_GROWTH_TIME or (abs(x - self.walls[i][0]) <= 7 and abs(y - self.walls[i][1]) <= 5 and z == self.walls[i][2] and self.mapGetTopUseItem(self.walls[i][0] - x, self.walls[i][1] - y, 0) != WILD_GROWTH_GROUND_ID)):
- self.walls.pop(i)
- #=================================================================================================
- # Function: targetID(self):
- # Description: Read memory for current target id.
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- #
- # Return Value(s):
- # On Success: id of creature
- # On Failure: 0
- #=================================================================================================
- def targetID(self):
- return tareader.getAttackedCreature()
- #=================================================================================================
- # Function: followID(self):
- # Description: Read memory for current followed id.
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- #
- # Return Value(s):
- # On Success: id of creature
- # On Failure: 0
- #=================================================================================================
- def followID(self):
- return tareader.getFollowedCreature()
- #=================================================================================================
- # Function: lastFollowID(self):
- # Description: Calculate last followed creature.
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- #
- # Return Value(s):
- # On Success: id of creature
- # On Failure: 0
- #=================================================================================================
- def lastFollowID(self):
- f = self.followID()
- if f != 0:
- self.lastF = f
- return self.lastF
- else:
- if self.lastF != 0: return self.lastF
- return 0
- #=================================================================================================
- # Function: lastTargetID(self):
- # Description: Calculate last attacked creature.
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- #
- # Return Value(s):
- # On Success: id of creature
- # On Failure: 0
- #=================================================================================================
- def lastTargetID(self):
- t = self.targetID()
- if t != 0:
- self.lastT = t
- return self.lastT
- else:
- if self.lastT != 0: return self.lastT
- return 0
- #=================================================================================================
- # Function: getPlayerToPush(self):
- # Description: Choose last target id or last followed id
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- #
- # Return Value(s):
- # On Success: id of creature
- # On Failure: 0
- #=================================================================================================
- def getPlayerToPush(self):
- lt = self.lastTargetID()
- if lt > 0 and self.followID() == 0:
- self.lastF = 0
- return lt
- lf = self.lastFollowID()
- if lf > 0:
- self.lastT = 0
- return lf
- return 0
- #=================================================================================================
- # Function: mapContainsBody(self, x, y, z):
- # Description: Read ground square x, y, z to get information about body
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # x, y, z - Coordines on map.
- #
- # Return Value(s):
- # On Success: contNr
- # On Failure: -1
- #=================================================================================================
- def mapContainsBody(self, x, y, z):
- for i in range(8):
- if self.tableContains(DEAD_BODIES, self.getGround(x, y, z, i))[0]: return True
- return False
- #=================================================================================================
- # Function: getItem(self, itemid):
- # Description: Get container pos and slot by item id
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # itemid - id of item to find
- #
- # Return Value(s):
- # On Success: table [0] - contNr, [1] - contPos, [2] = True, [3] - quantity
- # On Failure: False
- #=================================================================================================
- def getItem(self, itemid):
- info = [0, 0, False, 0]
- for contNr in range(16):
- cont=tareader.readContainer(contNr);
- if cont['flagOnOff'] == 1:
- for contPos in range(cont['itemsInside']):
- if tareader.readContainerItem(contNr, contPos)['objectId'] == itemid:
- return [0x40+contNr, contPos, True, tareader.readContainerItem(contNr, contPos)['quantity']]
- return info
- #=================================================================================================
- # Function: untrash(self):
- # Description: Remove trash from creature
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # x, y, z - Coordines on map.
- #
- # Return Value(s):
- # On Success: True
- # On Failure: False
- #=================================================================================================
- def untrash(self, x, y, z):
- count = 0
- rune = DESTROY_TRASH_RUNE_ID
- for i in range(0, 8):
- me = self.readMe()
- mapID = self.getGround((x - me['x']), (y - me['y']), 0, i)
- if mapID > 100 and self.itemIsMoveable(mapID):
- count += 1
- if count > 1:
- if self.tableContains(DEAD_BODIES, mapID)[0]: rune = COVER_TRASH_RUNE_ID
- return tasender.useWithObjectOnFloor(rune, 0, x, y, z, 2)
- tasender.moveObjectFromFloorToFloor(mapID, x, y, z, me['x'], me['y'], me['z'], tareader.mapGetPointItemExtraInfo((x - me['x']), (y - me['y']), 0, i, 1))
- if count == 0: return self.trash()
- #=================================================================================================
- # Function: trash(self):
- # Description: Drop item under your character
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- #
- # Return Value(s):
- # On Success: True
- # On Failure: False
- #=================================================================================================
- def trash(self):
- if not TRASH_MYSELF_ITEM[2]: return
- g = self.mapGetTopUseItem(0, 0, 0)
- if g != 0 and self.itemIsMoveable(g): return
- t = time.time()
- if t - self.dropTime < 0.1: return
- item = self.getItem(TRASH_MYSELF_ITEM[0])
- if item[0] == 0: return
- amount = TRASH_MYSELF_ITEM[1]
- if item[3] < amount:
- amount = item[3]
- me = self.readMe()
- self.dropTime = t
- return tasender.moveObjectFromContainerToFloor(TRASH_MYSELF_ITEM[0], item[0], item[1], me['x'], me['y'], me['z'], amount)
- #=================================================================================================
- # Function: pushMax(self):
- # Description: Push player on magic wall
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # Return Value(s): Nothing.
- #=================================================================================================
- def pushMax(self):
- xT, yT, key, creatureID = [-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7], [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], self.isPressed(0xBE), self.getPlayerToPush()
- cursorX, cursorY = self.getMouse()
- if not key: return
- if time.time() - self.pushTime <= (PUSH_DELAY / 1000) or creatureID == 0: return
- me, player = self.readMe(), tareader.getCharacterByTibiaId(creatureID)
- for ox in range(0, len(xT)):
- for oy in range(0, len(yT)):
- posX, posY = xT[ox], yT[oy]
- if cursorX >= TIBIA_WINDOW_X[0]+(posX * SQUARE_UPDATE) and cursorX <= TIBIA_WINDOW_X[1] + (posX * SQUARE_UPDATE) and cursorY >= TIBIA_WINDOW_Y[0] + (posY * SQUARE_UPDATE) and cursorY <= TIBIA_WINDOW_Y[1] + (posY * SQUARE_UPDATE):
- x, y, z, px, py, pz = me['x'] + posX, me['y'] + posY, me['z'], player['x'], player['y'], player['z']
- if (x == px and y == py) or abs(x - px) > 1 or abs(y - py) > 1 or abs(me['x'] - px) > 1 or abs(me['y'] - py) > 1 or pz != me['z']: return
- self.pushPos = [x, y, z]
- wall = self.wallInTable(self.pushPos[0], self.pushPos[1], self.pushPos[2])
- contains = self.tableContains([MAGIC_WALL_GROUND_ID, WILD_GROWTH_GROUND_ID], self.mapGetTopUseItem(posX, posY, 0))
- if contains[0]:
- var = (not wall[0] or (wall[0] and MAGIC_WALL_TIME - (time.time() - wall[1][3])) > PUSH_ON_MW_TIME)
- if contains[1] == WILD_GROWTH_GROUND_ID:
- var = (not wall[0] or (wall[0] and WILD_GROWTH_TIME - (time.time() - wall[1][3])) > PUSH_ON_MW_TIME)
- if var:
- self.autoPush = True
- self.pushTime = time.time()
- return
- #=================================================================================================
- # Function: pushMax(self):
- # Description: Push player on magic wall
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # Return Value(s): Nothing.
- #=================================================================================================
- def autoPushOnMw(self):
- if not self.autoPush: return
- leftTime = MAGIC_WALL_TIME - (time.time() - self.wallInTable(self.pushPos[0], self.pushPos[1], self.pushPos[2])[1][3])
- if leftTime > PUSH_ON_MW_TIME: return
- self.autoPush = False
- me, player = self.readMe(), tareader.getCharacterByTibiaId(self.getPlayerToPush())
- if abs(me['x'] - self.pushPos[0]) > 2 or abs(me['y'] - self.pushPos[1]) > 2 or me['z'] != self.pushPos[2] or (me['x'] == self.pushPos[0] and me['y'] == self.pushPos[1]): return
- if (self.pushPos[0] == player['x'] and self.pushPos[1] == player['y']) or abs(self.pushPos[0] - player['x']) > 1 or abs(self.pushPos[1] - player['y']) > 1 or me['z'] != self.pushPos[2]: return
- tasender.useWithObjectFromContainerOnFloor(3197,0,0,player['tibiaId'], player['x'], player['y'], player['z'],2)
- tasender.moveObjectFromFloorToFloor(99, player['x'], player['y'], player['z'], self.pushPos[0], self.pushPos[1], self.pushPos[2], player['tibiaId'])
- #=================================================================================================
- # Function: engine(self, callback):
- # Description: Run our all functions in this script
- # Parameter(s): self - The Handle of class do not insert argumnet in this place.
- # callback - An empty value need to store loop timers.
- #
- # Return Value(s): Nothing.
- #=================================================================================================
- def engine(self, callback):
- self.catchWallTimers()
- self.removeWallTimers()
- self.pushMax()
- self.autoPushOnMw()
- #=================================================================================================#
- # Module Class: Register specific class for reading functions by Python.
- #=================================================================================================#
- tibiaauto.registerPlugin(ModuleMachine);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement