SHARE
TWEET

Untitled

a guest Sep 30th, 2016 173 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2. * NosHook - Copyright (c) 2016 atom0s [atom0s@live.com]
  3. *
  4. * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
  5. * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to
  6. * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
  7. *
  8. * By using NosHook, you agree to the above license and its terms.
  9. *
  10. *      Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were
  11. *                    made. You must do so in any reasonable manner, but not in any way that suggests the licensor
  12. *                    endorses you or your use.
  13. *
  14. *   Non-Commercial - You may not use the material (NosHook) for commercial purposes.
  15. *
  16. *   No-Derivatives - If you remix, transform, or build upon the material (NosHook), you may not distribute the
  17. *                    modified material. You are, however, allowed to submit the modified works back to the original
  18. *                    NosHook project in attempt to have it added to the original project.
  19. *
  20. * You may not apply legal terms or technological measures that legally restrict others
  21. * from doing anything the license permits.
  22. *
  23. * No warranties are given.
  24. ]]--
  25.  
  26. require 'common'
  27. require 'timer'
  28. _addon.author   = 'Trojan';
  29. _addon.name     = 'Nostale4DE Pii Bot';
  30. _addon.version  = '0.02';
  31.  
  32. piiSchoten = {};
  33. piiMobs = {};
  34. piiRange = 10;
  35. skillsUsed = {};
  36. selectedID = 0;
  37.  
  38. me = {name=nil,x=nil,y=nil,id=nil};
  39.  
  40. hook.register_event('load', function()
  41.  
  42. print('~ Pii Bot Loaded ~');
  43. end);
  44.  
  45.  
  46. hook.register_event('unload', function()
  47.  
  48.  
  49.  
  50. end);
  51.  
  52. hook.register_event('command', function(cmd)
  53.  
  54. return false;
  55. end);
  56.  
  57.  
  58. hook.register_event('incoming_packet', function(packet, blocked)
  59.  
  60.  
  61. local packetArray = packet:split(" "); --split the incomming packet
  62. if packetArray ~= nil then
  63.   lastPacket = packetArray; --set lastPacket
  64. end
  65.  
  66. if not isMeSet() then --waits for c_info on Mapchange
  67.  
  68.   if (packetArray[1] == "c_info") then
  69.     me.name = packetArray[2];
  70.     me.id = packetArray[7]; --saves id and name from c_info
  71.   end
  72.  
  73.   if (packetArray[1] == "at") then
  74.  
  75.     if (packetArray[2] == me.id) then
  76.       me.x = packetArray[4]; --gets current location on map
  77.       me.y = packetArray[3];
  78.  
  79.       print('Hi,' .. me.name .. '!'); -- got id name and pos
  80.       print('Looking for Piis now...');
  81.     end
  82.   end
  83.  
  84. else -- if id name and pos is set
  85.  
  86.  
  87.   if (packetArray[1] == "st") then --wait st packet (if you select a creep)
  88.     mobType = tonumber(packetArray[4]); -- the 4th arg is mobtype
  89.     if mobType ~= nil then
  90.       selectedID = tonumber(packetArray[3]);
  91.       if piiSchoten[selectedID] ~= nil then -- check if we already selected this creep
  92.         if piiSchoten[selectedID].mystate ~= nil then -- check which state it has
  93.  
  94.           if piiSchoten[selectedID].mystate == "wanttoattack" then -- if we want to attack try it
  95.             if distance(piiSchoten[selectedID].x,piiSchoten[selectedID].y,me.x,me.y) > 8 then --check distance (you should change 8 to cur skill range)
  96.               print("Target to far away!"); -- handle the to far away. calc the needed distance and the coords and move there then try again
  97.               piiSchoten[selectedID].mystate = nil;
  98.             else
  99.               local skillNum = 0; -- this is const change it to current skill
  100.               if skillsUsed[skillNum] == nil then -- check for cooldown
  101.                 skillsUsed[skillNum] = {cooldown=false}; -- same
  102.               end
  103.               if (tonumber(packetArray[6]) => 0) then -- if creep health is not zero
  104.                 if (skillsUsed[skillNum].cooldown ~= true) then -- check cooldown again
  105.                     SendPacket('u_s '.. skillNum .. ' 3 '.. selectedID); --attack
  106.                 end
  107.                 else
  108.                
  109.                 piiSchoten[selectedID].mystate = "dead"; -- hp less than zero or zero
  110.                 killNext(selectedID); -- kill next
  111.               end
  112.             end
  113.           end
  114.         end
  115.       end
  116.     end
  117.   end
  118.  
  119.   if (packetArray[1] == "at") then -- update players position
  120.     if (packetArray[2] == me.id) then
  121.       me.x = packetArray[4];
  122.       me.y = packetArray[3];
  123.     end
  124.   end
  125.  
  126.  
  127.   if (packetArray[1] == "in") then -- this gets all creeps and looks for their mobtype. if they are piis put a table in piiSchoten or piiMobs
  128.     mobType = tonumber(packetArray[3]);
  129.     if mobType ~= nil then
  130.       if ((mobType >= 45 and mobType <= 53 )) then
  131.         piiSchoten[tonumber(packetArray[4])] =  { ["x"] = packetArray[5], ["y"] = packetArray[6],  ["rot"] = packetArray[7], ["selected"] = false,["mystate"] = false};
  132.     elseif ((mobType >= 36 and mobType <= 44 )) and (distance(me.x,me.y,tonumber(packetArray[5]),tonumber(packetArray[6])) < piiRange) then
  133.         piiMobs[tonumber(packetArray[4])] =  { ["x"] = packetArray[5], ["y"] = packetArray[6],  ["rot"] = packetArray[7], ["selected"] = false,["mystate"] = false};
  134.       end
  135.     end
  136.   end
  137.  
  138.  
  139. end
  140.  
  141.  
  142. if (packetArray[1] == "sr") then -- wait for cooldown packets and update the table if needed
  143.   local skillNum = tonumber(packetArray[2]);
  144.   skillsUsed[skillNum] = {cooldown=false};
  145.   print('Skill: '..skillNum..' is not cooldown');
  146. end
  147.  
  148. return false;
  149. end);
  150.  
  151.  
  152. hook.register_event('outgoing_packet', function(packet, blocked)
  153.  
  154. local packetArray = packet:split(" ");
  155. if isMeSet() then
  156.   if (packetArray[1] == "walk") then -- update my position
  157.     me.x = packetArray[2];
  158.     me.y = packetArray[3];
  159.   end
  160. end
  161.  
  162. if (packetArray[1] == "u_s") then
  163.   local skillNum = tonumber(packetArray[2]); -- update the cooldown
  164.   skillsUsed[skillNum] = {cooldown=true}
  165.   print('Skill: '..skillNum..' is on cooldown');
  166. end
  167.  
  168. return false;
  169. end);
  170.  
  171. hook.register_event('keyboard', function(code, wparam, lparam)
  172.  
  173. if wparam == 34 and lparam > 0 then -- if Pos1 is pressed
  174.   --SendPacket('u_s 0 3 4013');
  175.   print(pairs(piiSchotenSelected)); --select a pii
  176.  
  177.  
  178. end
  179.  
  180. if wparam == 35 and lparam > 0 then -- if pos1 is pressed
  181.  
  182.   if selectedID ~= 0 and piiSchoten[selectedID] ~= nil then --select a pii ( a x will pear on the ground)
  183.  
  184.     if piiSchoten[selectedID].selected == true then
  185.       RecvPacket('in 3 53 ' .. selectedID .. ' '.. piiSchoten[selectedID].x ..' ' .. piiSchoten[selectedID].y .. ' ' .. piiSchoten[selectedID].rot ..' 100 100 0 0 0 -1 1 0 -1 0 0 -1 0 0 0 0 0 0 0 0');
  186.       piiSchoten[selectedID].selected = false;
  187.     else
  188.       RecvPacket('in 3 53 ' .. selectedID .. ' '.. piiSchoten[selectedID].x ..' ' .. piiSchoten[selectedID].y .. ' ' .. piiSchoten[selectedID].rot ..' 100 100 0 0 -1 -1 1 0 -1 0 0 -1 0 0 0 0 0 0 0 0');
  189.       piiSchoten[selectedID].selected = true;
  190.     end
  191.   end
  192. end
  193.  
  194. return false;
  195. end);
  196.  
  197. hook.register_event('mouse', function(code, wparam, lparam)
  198.  
  199.  
  200.  
  201. return false;
  202. end);
  203.  
  204.  
  205. hook.register_event('prerender', function()
  206.  
  207. end);
  208.  
  209.  
  210. hook.register_event('render', function()
  211.  
  212. end);
  213.  
  214.  
  215. function killSchoten()
  216.  
  217.   for variable, k in pairs(piiSchoten) do
  218.    if k.selected == true
  219.     print( variable, k.x )
  220.     killMob(variable)
  221.   end
  222. end
  223. end
  224.  
  225. function killNext(id)
  226.  
  227. end
  228.  
  229.  
  230. function getMobInfo(id)
  231.   SendPacket('ncif 3 ' .. id);
  232.   piiSchoten[id].mystate = true;
  233. end
  234.  
  235. function killMob(id,x,y)
  236.   piiSchoten[id].mystate = "wanttoattack";
  237. end
  238.  
  239. function distance ( x1, y1, x2, y2 )
  240.   local dx = x1 - x2
  241.   local dy = y1 - y2
  242.   return math.sqrt ( dx * dx + dy * dy )
  243. end
  244.  
  245. function isMeSet()
  246.   if me.name == nil or me.x == nil or me.y == nil or me.id == nil then
  247.     return false;
  248.   else
  249.     return true;
  250.   end
  251. end
  252.  
  253.  
  254. function string:split( inSplitPattern, outResults )
  255.   if not outResults then
  256.     outResults = { }
  257.   end
  258.   local theStart = 1
  259.   local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
  260.   while theSplitStart do
  261.     table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
  262.     theStart = theSplitEnd + 1
  263.     theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
  264.   end
  265.   table.insert( outResults, string.sub( self, theStart ) )
  266.   return outResults
  267. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top