Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- * NosHook - Copyright (c) 2016 atom0s [atom0s@live.com]
- *
- * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
- * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to
- * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
- *
- * By using NosHook, you agree to the above license and its terms.
- *
- * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were
- * made. You must do so in any reasonable manner, but not in any way that suggests the licensor
- * endorses you or your use.
- *
- * Non-Commercial - You may not use the material (NosHook) for commercial purposes.
- *
- * No-Derivatives - If you remix, transform, or build upon the material (NosHook), you may not distribute the
- * modified material. You are, however, allowed to submit the modified works back to the original
- * NosHook project in attempt to have it added to the original project.
- *
- * You may not apply legal terms or technological measures that legally restrict others
- * from doing anything the license permits.
- *
- * No warranties are given.
- ]]--
- require 'common'
- require 'timer'
- _addon.author = 'Trojan';
- _addon.name = 'Nostale4DE Pii Bot';
- _addon.version = '0.02';
- piiSchoten = {};
- piiMobs = {};
- piiRange = 10;
- skillsUsed = {};
- selectedID = 0;
- me = {name=nil,x=nil,y=nil,id=nil};
- hook.register_event('load', function()
- print('~ Pii Bot Loaded ~');
- end);
- hook.register_event('unload', function()
- end);
- hook.register_event('command', function(cmd)
- return false;
- end);
- hook.register_event('incoming_packet', function(packet, blocked)
- local packetArray = packet:split(" "); --split the incomming packet
- if packetArray ~= nil then
- lastPacket = packetArray; --set lastPacket
- end
- if not isMeSet() then --waits for c_info on Mapchange
- if (packetArray[1] == "c_info") then
- me.name = packetArray[2];
- me.id = packetArray[7]; --saves id and name from c_info
- end
- if (packetArray[1] == "at") then
- if (packetArray[2] == me.id) then
- me.x = packetArray[4]; --gets current location on map
- me.y = packetArray[3];
- print('Hi,' .. me.name .. '!'); -- got id name and pos
- print('Looking for Piis now...');
- end
- end
- else -- if id name and pos is set
- if (packetArray[1] == "st") then --wait st packet (if you select a creep)
- mobType = tonumber(packetArray[4]); -- the 4th arg is mobtype
- if mobType ~= nil then
- selectedID = tonumber(packetArray[3]);
- if piiSchoten[selectedID] ~= nil then -- check if we already selected this creep
- if piiSchoten[selectedID].mystate ~= nil then -- check which state it has
- if piiSchoten[selectedID].mystate == "wanttoattack" then -- if we want to attack try it
- if distance(piiSchoten[selectedID].x,piiSchoten[selectedID].y,me.x,me.y) > 8 then --check distance (you should change 8 to cur skill range)
- print("Target to far away!"); -- handle the to far away. calc the needed distance and the coords and move there then try again
- piiSchoten[selectedID].mystate = nil;
- else
- local skillNum = 0; -- this is const change it to current skill
- if skillsUsed[skillNum] == nil then -- check for cooldown
- skillsUsed[skillNum] = {cooldown=false}; -- same
- end
- if (tonumber(packetArray[6]) => 0) then -- if creep health is not zero
- if (skillsUsed[skillNum].cooldown ~= true) then -- check cooldown again
- SendPacket('u_s '.. skillNum .. ' 3 '.. selectedID); --attack
- end
- else
- piiSchoten[selectedID].mystate = "dead"; -- hp less than zero or zero
- killNext(selectedID); -- kill next
- end
- end
- end
- end
- end
- end
- end
- if (packetArray[1] == "at") then -- update players position
- if (packetArray[2] == me.id) then
- me.x = packetArray[4];
- me.y = packetArray[3];
- end
- end
- 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
- mobType = tonumber(packetArray[3]);
- if mobType ~= nil then
- if ((mobType >= 45 and mobType <= 53 )) then
- piiSchoten[tonumber(packetArray[4])] = { ["x"] = packetArray[5], ["y"] = packetArray[6], ["rot"] = packetArray[7], ["selected"] = false,["mystate"] = false};
- elseif ((mobType >= 36 and mobType <= 44 )) and (distance(me.x,me.y,tonumber(packetArray[5]),tonumber(packetArray[6])) < piiRange) then
- piiMobs[tonumber(packetArray[4])] = { ["x"] = packetArray[5], ["y"] = packetArray[6], ["rot"] = packetArray[7], ["selected"] = false,["mystate"] = false};
- end
- end
- end
- end
- if (packetArray[1] == "sr") then -- wait for cooldown packets and update the table if needed
- local skillNum = tonumber(packetArray[2]);
- skillsUsed[skillNum] = {cooldown=false};
- print('Skill: '..skillNum..' is not cooldown');
- end
- return false;
- end);
- hook.register_event('outgoing_packet', function(packet, blocked)
- local packetArray = packet:split(" ");
- if isMeSet() then
- if (packetArray[1] == "walk") then -- update my position
- me.x = packetArray[2];
- me.y = packetArray[3];
- end
- end
- if (packetArray[1] == "u_s") then
- local skillNum = tonumber(packetArray[2]); -- update the cooldown
- skillsUsed[skillNum] = {cooldown=true}
- print('Skill: '..skillNum..' is on cooldown');
- end
- return false;
- end);
- hook.register_event('keyboard', function(code, wparam, lparam)
- if wparam == 34 and lparam > 0 then -- if Pos1 is pressed
- --SendPacket('u_s 0 3 4013');
- print(pairs(piiSchotenSelected)); --select a pii
- end
- if wparam == 35 and lparam > 0 then -- if pos1 is pressed
- if selectedID ~= 0 and piiSchoten[selectedID] ~= nil then --select a pii ( a x will pear on the ground)
- if piiSchoten[selectedID].selected == true then
- 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');
- piiSchoten[selectedID].selected = false;
- else
- 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');
- piiSchoten[selectedID].selected = true;
- end
- end
- end
- return false;
- end);
- hook.register_event('mouse', function(code, wparam, lparam)
- return false;
- end);
- hook.register_event('prerender', function()
- end);
- hook.register_event('render', function()
- end);
- function killSchoten()
- for variable, k in pairs(piiSchoten) do
- if k.selected == true
- print( variable, k.x )
- killMob(variable)
- end
- end
- end
- function killNext(id)
- end
- function getMobInfo(id)
- SendPacket('ncif 3 ' .. id);
- piiSchoten[id].mystate = true;
- end
- function killMob(id,x,y)
- piiSchoten[id].mystate = "wanttoattack";
- end
- function distance ( x1, y1, x2, y2 )
- local dx = x1 - x2
- local dy = y1 - y2
- return math.sqrt ( dx * dx + dy * dy )
- end
- function isMeSet()
- if me.name == nil or me.x == nil or me.y == nil or me.id == nil then
- return false;
- else
- return true;
- end
- end
- function string:split( inSplitPattern, outResults )
- if not outResults then
- outResults = { }
- end
- local theStart = 1
- local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
- while theSplitStart do
- table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
- theStart = theSplitEnd + 1
- theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
- end
- table.insert( outResults, string.sub( self, theStart ) )
- return outResults
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement