Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1. function startChooseItem(releaseCallback)
  2.   if not releaseCallback then
  3.     error("No mouse release callback parameter set.")
  4.   end
  5.   local mouseGrabberWidget = g_ui.createWidget('UIWidget')
  6.   mouseGrabberWidget:setVisible(false)
  7.   mouseGrabberWidget:setFocusable(false)
  8.  
  9.   connect(mouseGrabberWidget, { onMouseRelease = releaseCallback })
  10.  
  11.   mouseGrabberWidget:grabMouse()
  12.   g_mouse.pushCursor('target')
  13. end
  14.  
  15. function onClickWithMouse(self, mousePosition, mouseButton)
  16.   local item = nil
  17.   if mouseButton == MouseLeftButton then
  18.     local clickedWidget = modules.game_interface.getRootPanel():recursiveGetChildByPos(mousePosition, false)
  19.     if clickedWidget then
  20.       if clickedWidget:getClassName() == 'UIMap' then
  21.         local tile = clickedWidget:getTile(mousePosition)
  22.         if tile then
  23.           if currentSlot == 1 then
  24.              item = tile:getGround()
  25.           else
  26.               local thing = tile:getTopMoveThing()
  27.               if thing and thing:isItem() then
  28.                  item = thing
  29.               else
  30.                  item = tile:getTopCreature()
  31.               end
  32.           end
  33.         elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
  34.            item = clickedWidget:getItem()
  35.         end
  36.       end
  37.     end
  38.   end
  39.     if item then
  40.        if currentSlot == 4 and not item:isPlayer() then
  41.           modules.game_textmessage.displayFailureMessage('Use it only in players!')
  42.        else  
  43.           local player = g_game.getLocalPlayer()               --2  --6 pokedex
  44.           g_game.useInventoryItemWith(player:getInventoryItem(currentSlot):getId(), item)
  45.        end
  46.     end
  47.   g_mouse.popCursor()
  48.   self:ungrabMouse()
  49.   self:destroy()
  50.   mouseclick = false
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement