Advertisement
nvp777

Untitled

May 15th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.88 KB | None | 0 0
  1. #=================================================================================================#
  2. # Script Name: AutoPush
  3. # Tibia Version: 8.6+
  4. # TibiaAuto: 2.5.1+
  5. # Python Version:
  6. # Language: English
  7. # Platform: All Windows
  8. # Author: Ascer (visit: https://github.com/Ascer1/LachyZone)
  9. # Requirements: pywin32-210 for load dlls (win32gui, win32api, win32con, struct)
  10. # Can be download here: https://sourceforge.net/projects/pywin32/files/pywin32/
  11. #=================================================================================================#
  12.  
  13.  
  14. #=================================================================================================#
  15. # Config Class: Here you can change all script settings.
  16. #=================================================================================================#
  17.  
  18. TIBIA_WINDOW_X = [836, 916]; # [start, end] position X on screen where stay your character.
  19. TIBIA_WINDOW_Y = [405, 485]; # [start, end] position Y on screen where stay your character.
  20. SQUARE_UPDATE = 80 # square length in pixels. (Length X + Length Y)/2
  21.  
  22.  
  23. EXECUTION_DELAY = 0 # loop time in miliseconds (0 means run fast as possible around 20-50ms)
  24. USE_RUNE_DELAY = 1000 # how fast we will use destroy trash rune on ground default 1000ms to avoid spam
  25. PUSH_DELAY = 150 # time in miliseconds between pushing player, default 150ms to avoid spam
  26.  
  27. MAGIC_WALL_GROUND_ID = 2129 # 2129 id magic wall on ground square
  28. WILD_GROWTH_GROUND_ID = 2128 # 2128 or 2130 id of wooden bush on ground square
  29.  
  30. MAGIC_WALL_TIME = 20.0 # time of magic wall effct on ground square
  31. WILD_GROWTH_TIME = 45.0 # time of wooden bush effct on ground square
  32.  
  33. 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
  34.  
  35. DEAD_BODIES = [4240, 4241, 4247, 4248, 3492] # open browse field and remove this items before push
  36.  
  37. DESTROY_TRASH_RUNE_ID = 3197 # 3197 id of rune to destory trash under player, default=disinegrate
  38. COVER_TRASH_RUNE_ID = 3164 # 3164 id of rune to cover trash when bodies detected, default=energy field rune
  39. 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)
  40.  
  41.  
  42. #=================================================================================================#
  43. # Include List: Load Windows Libraries for later usage.
  44. #=================================================================================================#
  45.  
  46. import time
  47. import signal
  48. import win32gui, win32api, win32con, struct
  49.  
  50. #=================================================================================================#
  51. # TibiaAuto Class: Creating platform in memory for run code in loop.
  52. #=================================================================================================#
  53.  
  54. class ModuleMachine:
  55.  
  56. modTime = 0
  57. pushTime = 0
  58. dropTime = 0
  59. walls = [[0, 0, 0, 0, 0]]
  60. lastF = 0
  61. lastT = 0
  62. lastMyPos = [0, 0, 0]
  63. autoPush = False
  64. lastPlayer = 0
  65. pushPos = [0, 0, 0]
  66.  
  67. def getName(self):
  68. return "AutoPush"
  69.  
  70. def getVersion(self):
  71. return "1.0"
  72.  
  73. def getFunDef(self, nr):
  74. if (nr==0): return (0, EXECUTION_DELAY, self.engine)
  75. return ()
  76.  
  77. def getConfigParam(self, nr):
  78. return ()
  79.  
  80.  
  81. #=================================================================================================#
  82. # Functions Class: Stored functions to calculate values and read memory.
  83. #=================================================================================================#
  84.  
  85. #=================================================================================================
  86. # Function: console(self, message):
  87. # Description: Write message to Tibia Chat on by blue text.
  88. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  89. # message - message to write.
  90. #
  91. # Return Value(s): Nothing.
  92. #=================================================================================================
  93. def console(self, message):
  94. tasender.sendTAMessage(message)
  95.  
  96.  
  97. #=================================================================================================
  98. # Function: mapGetTopUseItem(self, x, y, z):
  99. # Description: Get Top Item ID on map position x, y, z
  100. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  101. # x, y, z - Coordines on map.
  102. #
  103. # Return Value(s):
  104. # On Success: ID of map postion.
  105. # On Failure: 0
  106. #=================================================================================================
  107. def mapGetTopUseItem(self, x, y, z):
  108. return tareader.mapGetPointItemId(x, y, z, tareader.mapGetPointTopPos(x, y, z))
  109.  
  110.  
  111. #=================================================================================================
  112. # Function: readMe(self):
  113. # Description: Read self characters for all known informations.
  114. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  115. #
  116. # Return Value(s):
  117. # On Success: An array with self informations
  118. # On Failure: 0
  119. #=================================================================================================
  120. def readMe(self):
  121. return tareader.readSelfCharacter()
  122.  
  123.  
  124. #=================================================================================================
  125. # Function: isPressed(self, key):
  126. # Description: Read win32api for key state.
  127. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  128. # key - Hex value of key on keyboard, example F9 = 0x78
  129. #
  130. # Return Value(s):
  131. # On Success: True
  132. # On Failure: False
  133. #=================================================================================================
  134. def isPressed(self, key):
  135. if win32api.GetAsyncKeyState(key) == 0: return False
  136. return True
  137.  
  138. #=================================================================================================
  139. # Function: getMousePos(self):
  140. # Description: Read win32api for mouse coordines.
  141. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  142. #
  143. # Return Value(s):
  144. # On Success: x, y mouse
  145. # On Failure: Null
  146. #=================================================================================================
  147. def getMouse(self):
  148. return win32api.GetCursorPos()
  149.  
  150.  
  151. #=================================================================================================
  152. # Function: getGround(self, x, y, z, stackNr):
  153. # Description: Browse tibia title for each item id.
  154. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  155. # x, y, z - Coordines on map.
  156. # stackNr - Place item in stack.
  157. # Return Value(s):
  158. # On Success: itemID
  159. # On Failure: 0
  160. #=================================================================================================
  161. def getGround(self, x, y, z, stackNr):
  162. if tareader.mapGetPointItemsCount(x, y, z) - 1 >= stackNr: return tareader.mapGetPointItemExtraInfo(x, y, z, stackNr, 0)
  163. return 0
  164.  
  165.  
  166. #=================================================================================================
  167. # Function: mapIsWalkable(self, x, y, z):
  168. # Description: Read Tibia map for walkable position
  169. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  170. # x, y, z - Coordines on map.
  171. # Return Value(s):
  172. # On Success: True
  173. # On Failure: False
  174. #=================================================================================================
  175. def mapIsWalkable(self, x, y, z):
  176. for i in range(0, 8):
  177. mapID = self.getGround(x, y, z, i)
  178. if mapID == 99 or tareader.getTibiaTile(mapID)['blocking'] == 1: return False
  179. return True
  180.  
  181.  
  182. #=================================================================================================
  183. # Function: itemIsMoveable(self, itemid):
  184. # Description: Check if item is possible to move
  185. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  186. # itemid - id of item to check
  187. # Return Value(s):
  188. # On Success: True
  189. # On Failure: False
  190. #=================================================================================================
  191. def itemIsMoveable(self, itemid):
  192. if itemid == 99: return False
  193. if tareader.getTibiaTile(itemid)['notMoveable'] == 0: return True
  194. return False
  195.  
  196.  
  197. #=================================================================================================
  198. # Function: tableContains(self, table, argumenet):
  199. # Description: Research table for special argument
  200. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  201. # table - An array to search.
  202. # argument - element to find
  203. # Return Value(s):
  204. # On Success: table [0] - True, [1] - element
  205. # On Failure: False
  206. #=================================================================================================
  207. def tableContains(self, table, argumenet):
  208. for i in range(0, len(table)):
  209. if table[i] == argumenet:
  210. return [True, table[i]]
  211. return [False, 0]
  212.  
  213.  
  214. #=================================================================================================
  215. # Function: wallInTable(self, x, y, z):
  216. # Description: Check if wall on ground position is already in self.walls table
  217. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  218. # x, y, z - Coordines on map.
  219. # Return Value(s):
  220. # On Success: Table [0] - True, [1] - Wall table
  221. # On Failure: False
  222. #=================================================================================================
  223. def wallInTable(self, x, y, z):
  224. for i in range(0, len(self.walls)):
  225. if self.walls[i][0] == x and self.walls[i][1] == y and self.walls[i][2] == z:
  226. return [True, self.walls[i]]
  227. return [False, 0]
  228.  
  229.  
  230. #=================================================================================================
  231. # Function: catchWallTimers(self):
  232. # Description: Collect all wall timers into table.
  233. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  234. #
  235. # Return Value(s): Nothing.
  236. #=================================================================================================
  237. def catchWallTimers(self):
  238. 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]
  239. if len(self.walls) == 0: self.walls.append([0, 0, 0, 0, 0])
  240. for ox in range(0, len(xT)):
  241. for oy in range(0, len(yT)):
  242. me = self.readMe()
  243. x, y, z = me['x']+xT[ox], me['y']+yT[oy], me['z']
  244. contains = self.tableContains([MAGIC_WALL_GROUND_ID, WILD_GROWTH_GROUND_ID], self.mapGetTopUseItem(xT[ox], yT[oy], 0))
  245. if contains[0] and not self.wallInTable(x, y, z)[0]:
  246. self.walls.append([x, y, z, time.time(), contains[1]])
  247.  
  248.  
  249. #=================================================================================================
  250. # Function: removeWallTimers(self):
  251. # Description: Remove wrong timers from table.
  252. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  253. # me - table with self informations returned by self.readMe()
  254. #
  255. # Return Value(s): Nothing.
  256. #=================================================================================================
  257. def removeWallTimers(self):
  258. for i in range(0, len(self.walls)):
  259. if self.walls[i][1] == 0: continue
  260. me = self.readMe()
  261. x, y, z = me['x'], me['y'], me['z']
  262. if self.walls[i][4] == MAGIC_WALL_GROUND_ID:
  263. 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)):
  264. self.walls.pop(i)
  265. else:
  266. 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)):
  267. self.walls.pop(i)
  268.  
  269.  
  270. #=================================================================================================
  271. # Function: targetID(self):
  272. # Description: Read memory for current target id.
  273. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  274. #
  275. # Return Value(s):
  276. # On Success: id of creature
  277. # On Failure: 0
  278. #=================================================================================================
  279. def targetID(self):
  280. return tareader.getAttackedCreature()
  281.  
  282.  
  283. #=================================================================================================
  284. # Function: followID(self):
  285. # Description: Read memory for current followed id.
  286. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  287. #
  288. # Return Value(s):
  289. # On Success: id of creature
  290. # On Failure: 0
  291. #=================================================================================================
  292. def followID(self):
  293. return tareader.getFollowedCreature()
  294.  
  295.  
  296. #=================================================================================================
  297. # Function: lastFollowID(self):
  298. # Description: Calculate last followed creature.
  299. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  300. #
  301. # Return Value(s):
  302. # On Success: id of creature
  303. # On Failure: 0
  304. #=================================================================================================
  305. def lastFollowID(self):
  306. f = self.followID()
  307. if f != 0:
  308. self.lastF = f
  309. return self.lastF
  310. else:
  311. if self.lastF != 0: return self.lastF
  312. return 0
  313.  
  314.  
  315. #=================================================================================================
  316. # Function: lastTargetID(self):
  317. # Description: Calculate last attacked creature.
  318. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  319. #
  320. # Return Value(s):
  321. # On Success: id of creature
  322. # On Failure: 0
  323. #=================================================================================================
  324. def lastTargetID(self):
  325. t = self.targetID()
  326. if t != 0:
  327. self.lastT = t
  328. return self.lastT
  329. else:
  330. if self.lastT != 0: return self.lastT
  331. return 0
  332.  
  333.  
  334. #=================================================================================================
  335. # Function: getPlayerToPush(self):
  336. # Description: Choose last target id or last followed id
  337. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  338. #
  339. # Return Value(s):
  340. # On Success: id of creature
  341. # On Failure: 0
  342. #=================================================================================================
  343. def getPlayerToPush(self):
  344. lt = self.lastTargetID()
  345. if lt > 0 and self.followID() == 0:
  346. self.lastF = 0
  347. return lt
  348. lf = self.lastFollowID()
  349. if lf > 0:
  350. self.lastT = 0
  351. return lf
  352. return 0
  353.  
  354.  
  355. #=================================================================================================
  356. # Function: mapContainsBody(self, x, y, z):
  357. # Description: Read ground square x, y, z to get information about body
  358. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  359. # x, y, z - Coordines on map.
  360. #
  361. # Return Value(s):
  362. # On Success: contNr
  363. # On Failure: -1
  364. #=================================================================================================
  365. def mapContainsBody(self, x, y, z):
  366. for i in range(8):
  367. if self.tableContains(DEAD_BODIES, self.getGround(x, y, z, i))[0]: return True
  368. return False
  369.  
  370.  
  371. #=================================================================================================
  372. # Function: getItem(self, itemid):
  373. # Description: Get container pos and slot by item id
  374. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  375. # itemid - id of item to find
  376. #
  377. # Return Value(s):
  378. # On Success: table [0] - contNr, [1] - contPos, [2] = True, [3] - quantity
  379. # On Failure: False
  380. #=================================================================================================
  381. def getItem(self, itemid):
  382. info = [0, 0, False, 0]
  383. for contNr in range(16):
  384. cont=tareader.readContainer(contNr);
  385. if cont['flagOnOff'] == 1:
  386. for contPos in range(cont['itemsInside']):
  387. if tareader.readContainerItem(contNr, contPos)['objectId'] == itemid:
  388. return [0x40+contNr, contPos, True, tareader.readContainerItem(contNr, contPos)['quantity']]
  389. return info
  390.  
  391.  
  392. #=================================================================================================
  393. # Function: untrash(self):
  394. # Description: Remove trash from creature
  395. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  396. # x, y, z - Coordines on map.
  397. #
  398. # Return Value(s):
  399. # On Success: True
  400. # On Failure: False
  401. #=================================================================================================
  402. def untrash(self, x, y, z):
  403. count = 0
  404. rune = DESTROY_TRASH_RUNE_ID
  405. for i in range(0, 8):
  406. me = self.readMe()
  407. mapID = self.getGround((x - me['x']), (y - me['y']), 0, i)
  408. if mapID > 100 and self.itemIsMoveable(mapID):
  409. count += 1
  410. if count > 1:
  411. if self.tableContains(DEAD_BODIES, mapID)[0]: rune = COVER_TRASH_RUNE_ID
  412. return tasender.useWithObjectOnFloor(rune, 0, x, y, z, 2)
  413. tasender.moveObjectFromFloorToFloor(mapID, x, y, z, me['x'], me['y'], me['z'], tareader.mapGetPointItemExtraInfo((x - me['x']), (y - me['y']), 0, i, 1))
  414. if count == 0: return self.trash()
  415.  
  416.  
  417. #=================================================================================================
  418. # Function: trash(self):
  419. # Description: Drop item under your character
  420. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  421. #
  422. # Return Value(s):
  423. # On Success: True
  424. # On Failure: False
  425. #=================================================================================================
  426. def trash(self):
  427. if not TRASH_MYSELF_ITEM[2]: return
  428. g = self.mapGetTopUseItem(0, 0, 0)
  429. if g != 0 and self.itemIsMoveable(g): return
  430. t = time.time()
  431. if t - self.dropTime < 0.1: return
  432. item = self.getItem(TRASH_MYSELF_ITEM[0])
  433. if item[0] == 0: return
  434. amount = TRASH_MYSELF_ITEM[1]
  435. if item[3] < amount:
  436. amount = item[3]
  437. me = self.readMe()
  438. self.dropTime = t
  439. return tasender.moveObjectFromContainerToFloor(TRASH_MYSELF_ITEM[0], item[0], item[1], me['x'], me['y'], me['z'], amount)
  440.  
  441.  
  442.  
  443. #=================================================================================================
  444. # Function: pushMax(self):
  445. # Description: Push player on magic wall
  446. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  447. # Return Value(s): Nothing.
  448. #=================================================================================================
  449. def pushMax(self):
  450. 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()
  451. cursorX, cursorY = self.getMouse()
  452. if not key: return
  453. if time.time() - self.pushTime <= (PUSH_DELAY / 1000) or creatureID == 0: return
  454. me, player = self.readMe(), tareader.getCharacterByTibiaId(creatureID)
  455. for ox in range(0, len(xT)):
  456. for oy in range(0, len(yT)):
  457. posX, posY = xT[ox], yT[oy]
  458. 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):
  459. x, y, z, px, py, pz = me['x'] + posX, me['y'] + posY, me['z'], player['x'], player['y'], player['z']
  460. 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
  461. self.pushPos = [x, y, z]
  462. wall = self.wallInTable(self.pushPos[0], self.pushPos[1], self.pushPos[2])
  463. contains = self.tableContains([MAGIC_WALL_GROUND_ID, WILD_GROWTH_GROUND_ID], self.mapGetTopUseItem(posX, posY, 0))
  464. if contains[0]:
  465. var = (not wall[0] or (wall[0] and MAGIC_WALL_TIME - (time.time() - wall[1][3])) > PUSH_ON_MW_TIME)
  466. if contains[1] == WILD_GROWTH_GROUND_ID:
  467. var = (not wall[0] or (wall[0] and WILD_GROWTH_TIME - (time.time() - wall[1][3])) > PUSH_ON_MW_TIME)
  468. if var:
  469. self.autoPush = True
  470. self.pushTime = time.time()
  471. return
  472.  
  473.  
  474. #=================================================================================================
  475. # Function: pushMax(self):
  476. # Description: Push player on magic wall
  477. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  478. # Return Value(s): Nothing.
  479. #=================================================================================================
  480. def autoPushOnMw(self):
  481. if not self.autoPush: return
  482. leftTime = MAGIC_WALL_TIME - (time.time() - self.wallInTable(self.pushPos[0], self.pushPos[1], self.pushPos[2])[1][3])
  483. if leftTime > PUSH_ON_MW_TIME: return
  484. self.autoPush = False
  485. me, player = self.readMe(), tareader.getCharacterByTibiaId(self.getPlayerToPush())
  486. 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
  487. 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
  488. tasender.useWithObjectFromContainerOnFloor(3197,0,0,player['tibiaId'], player['x'], player['y'], player['z'],2)
  489. tasender.moveObjectFromFloorToFloor(99, player['x'], player['y'], player['z'], self.pushPos[0], self.pushPos[1], self.pushPos[2], player['tibiaId'])
  490.  
  491.  
  492. #=================================================================================================
  493. # Function: engine(self, callback):
  494. # Description: Run our all functions in this script
  495. # Parameter(s): self - The Handle of class do not insert argumnet in this place.
  496. # callback - An empty value need to store loop timers.
  497. #
  498. # Return Value(s): Nothing.
  499. #=================================================================================================
  500. def engine(self, callback):
  501. self.catchWallTimers()
  502. self.removeWallTimers()
  503. self.pushMax()
  504. self.autoPushOnMw()
  505.  
  506.  
  507. #=================================================================================================#
  508. # Module Class: Register specific class for reading functions by Python.
  509. #=================================================================================================#
  510.  
  511. tibiaauto.registerPlugin(ModuleMachine);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement