Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.00 KB | None | 0 0
  1. AllowSummonFromNames = {};
  2. AcceptSummonFromAll = false;
  3. DeclineUnAllowedPlayersSummons = true;
  4.  
  5. function CheckIfInsideList(Smsg,Rmsglist)
  6.     if (Rmsglist ~= nil) then
  7.         for x=1,#Rmsglist do
  8.             if (Rmsglist[x] == Smsg) then
  9.                 return true;
  10.             end;
  11.         end;
  12.     end;
  13.     return false;  
  14. end;
  15.  
  16. function OnCreate()
  17.     -- from summoner plugin
  18.     Event_PacketUnBlock(0xF3,0xFF,1); --0x0732  0x732
  19.  
  20.     this:RegisterCommand("chatbot", CommandChatType.CHAT_ALLY, CommandAccessLevel.ACCESS_ME);
  21.     ENABLED = false;
  22.     DEFAULT_BUFFING_MAX_RANGE = 300;
  23.  
  24.     admins = {
  25.                 "Zanfas",
  26.                 "xwlx",
  27.                 "xbpx",  
  28.                 "Bezbel",
  29.                 "Mekinjar",
  30.                 "xbdx",
  31.                 "xswsx",
  32.                 "xppx",
  33.                 "Isus",
  34.                 "Yeeeea",
  35.                 "HurtMe",
  36.                 "Farbeyonddriven",
  37.                 "Onomad",
  38.                 "Decartes",
  39.                 "Newton",
  40.                 "Pascal",
  41.                 "Leibniz",
  42.                 "Ramanujan",
  43.                 "Gauss"
  44.             }
  45.  
  46.     commands = {};
  47.     commands['follow'] = {}
  48.     commands['follow']['type'] = "misc"
  49.     commands['leave'] = {}
  50.     commands['leave']['type'] = "leave"
  51.     commands['invite'] = {}
  52.     commands['invite']['type'] = "invite"
  53.     commands['buff'] = {}
  54.     commands['buff']['type'] = "buff"
  55.     commands['command'] = {}
  56.     commands['command']['type'] = "command"
  57.     commands['-c'] = {}
  58.     commands['-c']['type'] = "ccommand"
  59.     commands['-s'] = {}
  60.     commands['-s']['type'] = "say"
  61.     commands['sstart'] = {}
  62.     commands['sstart']['type'] = "scriptstart"
  63.     commands['sstop'] = {}
  64.     commands['sstop']['type'] = "scriptstop"
  65.     commands['stop'] = {}
  66.     commands['stop']['type'] = "stop"
  67.  
  68.     skills = {};
  69.     skills[1] = {};
  70.     skills[1]['id'] = 1393
  71.     skills[1]['name'] = 'Unholy Resistance';
  72.     skills[1]['alias'] = 'ur';
  73.     skills[1]['requireParty'] = false;
  74.     skills[1]['requireTarget'] = true;
  75.     skills[2] = {};
  76.     skills[2]['id'] = 1191
  77.     skills[2]['name'] = 'Resist Fire';
  78.     skills[2]['alias'] = 'rf';
  79.     skills[2]['requireParty'] = false;
  80.     skills[2]['requireTarget'] = true;
  81.     skills[3] = {};
  82.     skills[3]['id'] = 1189
  83.     skills[3]['name'] = 'Resist Wind';
  84.     skills[3]['alias'] = 'rw';
  85.     skills[3]['requireParty'] = false;
  86.     skills[3]['requireTarget'] = true;
  87.     skills[4] = {};
  88.     skills[4]['id'] = 1182
  89.     skills[4]['name'] = 'Resist Aqua';
  90.     skills[4]['alias'] = 'ra';
  91.     skills[4]['requireParty'] = false;
  92.     skills[4]['requireTarget'] = true;
  93.     skills[5] = {};
  94.     skills[5]['id'] = 1352
  95.     skills[5]['name'] = 'Elemental Protection';
  96.     skills[5]['alias'] = 'ep';
  97.     skills[5]['requireParty'] = false;
  98.     skills[5]['requireTarget'] = true;
  99.     skills[6] = {};
  100.     skills[6]['id'] = 307
  101.     skills[6]['name'] = 'Dance of Aqua Guard';
  102.     skills[6]['alias'] = 'doa';
  103.     skills[6]['requireParty'] = true;
  104.     skills[6]['requireTarget'] = false;
  105.     skills[7] = {};
  106.     skills[7]['id'] = 306
  107.     skills[7]['name'] = 'Song of Flame Guard';
  108.     skills[7]['alias'] = 'sof';
  109.     skills[7]['requireParty'] = true;
  110.     skills[7]['requireTarget'] = false;
  111.     skills[8] = {};
  112.     skills[8]['id'] = 308
  113.     skills[8]['name'] = 'Song of Storm Guard';
  114.     skills[8]['alias'] = 'sos';
  115.     skills[8]['requireParty'] = true;
  116.     skills[8]['requireTarget'] = false;
  117.     skills[9] = {};
  118.     skills[9]['id'] = 1397
  119.     skills[9]['name'] = 'Clarity';
  120.     skills[9]['alias'] = 'cl';
  121.     skills[9]['requireParty'] = false;
  122.     skills[9]['requireTarget'] = true;
  123.     skills[10] = {};
  124.     skills[10]['id'] = 1353
  125.     skills[10]['name'] = 'Divine Protection';
  126.     skills[10]['alias'] = 'dp';
  127.     skills[10]['requireParty'] = false;
  128.     skills[10]['requireTarget'] = true;
  129.     skills[11] = {};
  130.     skills[11]['id'] = 1354
  131.     skills[11]['name'] = 'Arcane Protection';
  132.     skills[11]['alias'] = 'ap';
  133.     skills[11]['requireParty'] = false;
  134.     skills[11]['requireTarget'] = true;
  135.     skills[12] = {};
  136.     skills[12]['id'] = 270
  137.     skills[12]['name'] = 'Song of Invocation';
  138.     skills[12]['alias'] = 'soi';
  139.     skills[12]['requireParty'] = true;
  140.     skills[12]['requireTarget'] = false;
  141.     skills[13] = {};
  142.     skills[13]['id'] = 1303
  143.     skills[13]['name'] = 'Wild Magic';
  144.     skills[13]['alias'] = 'wm';
  145.     skills[13]['requireParty'] = false;
  146.     skills[13]['requireTarget'] = true;
  147.     skills[14] = {};
  148.     skills[14]['id'] = 1388
  149.     skills[14]['name'] = 'Greater Might';
  150.     skills[14]['alias'] = 'gm';
  151.     skills[14]['requireParty'] = true;
  152.     skills[14]['requireTarget'] = true;
  153.     skills[15] = {};
  154.     skills[15]['id'] = 1389
  155.     skills[15]['name'] = 'Greater Shield';
  156.     skills[15]['alias'] = 'gs';
  157.     skills[15]['requireParty'] = true;
  158.     skills[15]['requireTarget'] = true;
  159.  
  160.     function getSkillId(sknm)
  161.        local Skills = GetSkills();
  162.        for Skill in Skills.list do
  163.           if (Skill.name == sknm) then
  164.              return Skill.skillId;
  165.           end;
  166.        end;
  167.        return nil
  168.     end;
  169.  
  170.     function useSkill(skillId, requireTarget, requireParty, requestSender, targetName, maxRange, cType)
  171.         ready = isSkillReady(skillId);
  172.         if ready ~= nil then
  173.             if ready then
  174.                 ok  = true
  175.                 target = nil
  176.                 if isTargetInRange(targetName, maxRange) then
  177.                     if requireTarget then
  178.                         target = getTarget(targetName)
  179.                     end
  180.                     if (requireParty) then
  181.                         if GetUserByName(targetName):IsMyPartyMember() == false then
  182.                             if(requestSender ~= targetName) then
  183.                                 SendPM(requestSender, targetName.." is not member of my party!")
  184.                             else
  185.                                 SendPM(requestSender, "You are not member of my party!")
  186.                             end
  187.                             ok = false;
  188.                         end
  189.                     end
  190.                 else
  191.                     if(requestSender ~= targetName) then
  192.                         SendPM(requestSender, targetName.." is too far!")
  193.                     else
  194.                         SendPM(requestSender, "You are too far!")
  195.                     end
  196.                     ok = false;
  197.                 end
  198.                 if ok then
  199.                     UseSkillRaw(skillId, false, false) 
  200.                 else
  201.                     ShowToClient("error", "error")
  202.                 end
  203.             else
  204.                 SendPM(requestSender, "That skill is on reuse.")
  205.             end
  206.         else
  207.             if cType == 2 then
  208.                 SendPM(requestSender, "I don't have such skill.")
  209.             end
  210.         end
  211.     end
  212.  
  213.     function getTarget(targetName)
  214.         Command("/target "..targetName);
  215.         return GetTarget();
  216.     end
  217.  
  218.     function isTargetInRange(targetName, maxRange)
  219.         return GetMe():GetRangeTo(GetUserByName(targetName)) <= maxRange
  220.     end
  221.  
  222.     function isSkillReady(skillId)
  223.         local skills = GetSkills();
  224.         for skill in skills.list do
  225.             if (skill.skillId == skillId) then
  226.                 return skill:CanBeUsed();
  227.             end;
  228.         end;
  229.         return nil
  230.     end;
  231.     function trimr(s)
  232.         return s:find'^%s*$' and '' or s:match'^(.*%S)'
  233.     end
  234.  
  235.     function buff(playerName, buffName, cType)
  236.         skillIndex = 0;
  237.         for i = 1, table.getn(skills) do
  238.             if skills[i]['alias'] == buffName or skills[i]['name'] == buffName then
  239.                 skillIndex = i;
  240.                 break;
  241.             end
  242.         end
  243.         if skillIndex == 0 then
  244.             if cType == 2 then
  245.                 SendPM(playerName, "That buff is unknown to me.")
  246.             end
  247.         else
  248.             useSkill(skills[skillIndex]['id'], skills[skillIndex]['requireTarget'], skills[skillIndex]['requireParty'], playerName, playerName, 300, cType)
  249.         end
  250.     end
  251. end;
  252.  
  253. function stop()
  254.     loc = GetMe():GetLocation();
  255.     x = loc.X - 1;
  256.     y = loc.Y;
  257.     z = loc.Z;
  258.     MoveToNoWait(x, y, z)
  259.     ClearTargets();
  260.     CancelTarget(false);
  261.     CancelTarget(false);
  262.     CancelTarget(false);
  263. end
  264.  
  265. -- function OnCommand_chatbot(vCommandChatType, vNick, vCommandParam)
  266. --  if (ENABLED) then
  267. --      ENABLED = false;
  268. --      ShowToClient("ChatBot","DISABLED");
  269. --  else
  270. --      ENABLED = true;
  271. --      ShowToClient("ChatBot","ENABLED"); 
  272. --  end;
  273. -- end;
  274.  
  275. function OnChatUserMessage(chatType, nick, msg)
  276.     pcall(protectedOnChatUserMessage, chatType, nick, msg);
  277. end;
  278.  
  279. function protectedOnChatUserMessage(cType, cNm, cMsg)
  280.  
  281.     -- ShowToClient(tostring(cType), "asd");
  282.     -- ShowToClient("chatbot", tostring(ENABLED))
  283.     -- if ENABLED then
  284.         -- ShowToClient("chatbot", "chating is enabled")
  285.     if cNm ~= GetMe():GetName() then
  286.         if cType ==2 or cType == 3 then
  287.             for i, admin in ipairs(admins) do
  288.                 if admin == cNm then
  289.                     words = {}
  290.                     local command = ""
  291.                     i = 0
  292.                     params = {}
  293.                     params[1] = ""
  294.                     paramsString = ""
  295.                     for w in cMsg:gmatch("%S+") do
  296.  
  297.                         if i > 0 then
  298.                             params[i] = w
  299.                             paramsString = paramsString..w.." "
  300.                         else
  301.                             command = w
  302.                         end
  303.                         i = i + 1
  304.                     end
  305.                     if command ~= "" then
  306.                         if commands[command] ~= nil then
  307.                             if commands[command]['type'] == "command" then
  308.                                 if paramsString ~= "" then
  309.                                     Command(paramsString)
  310.                                 else
  311.                                     SendPM(admin, "I need atleast one parameter!")
  312.                                 end
  313.                             elseif commands[command]['type'] == "invite" then
  314.                                 Command("/invite "..cNm)
  315.                             elseif commands[command]['type'] == "leave" then
  316.                                 Command("/leave")
  317.                             elseif commands[command]['type'] == "stop" then
  318.                                 stop();
  319.                             elseif commands[command]['type'] == "scriptstart" then
  320.                                 Command(".scriptstart "..trimr(paramsString)..".lua")
  321.                             elseif commands[command]['type'] == "scriptstop" then
  322.                                 Command(".scriptstop "..trimr(paramsString)..".lua")
  323.                             elseif commands[command]['type'] == "ccommand" then
  324.                                 Command("/"..paramsString)
  325.                             elseif commands[command]['type'] == "say" then
  326.                                 Command(paramsString)
  327.                             elseif command == "buff" then
  328.                                 buff(cNm, trimr(paramsString), cType)
  329.                                 stop();
  330.                             end
  331.                         end
  332.                     end
  333.                 end
  334.             end
  335.         end
  336.     end
  337. end;
  338.  
  339. function OnIncomingPacket(packet)
  340.         ShowToClient("asd", "asd")
  341.         --F3 (packet id) confirm dlg
  342.         --32 07 00 00 -- (type) in this case its summoning accept/decline window
  343.         --02 00 00 00 -- how many data will be provided for this window
  344.         --0C 00 00 00 -- type of data of first (in this case 0C is string)
  345.         --4A 00 55 00 3E 00 70 00 71 00 6C 00 65 00 00 00 -- (the data as name of user summoning(string))
  346.         --07 00 00 00 -- type of data of second (in this case 7 is coordinates(3 int variables x,y,z))
  347.         --83 3F 01 00 -- X
  348.         --17 47 02 00 -- Y
  349.         --78 F2 FF FF -- Z
  350.         --30 75 00 00 -- Time in mille seconds until the window automaticaly closes with a decline answer if no response
  351.         --8D 99 70 4A -- Message Id which is needed to be added in the DLG answer to indicate the answer for this message.
  352.     packet:SetOffset(0)
  353.     if (packet:GetID() == 0xF3 and packet:ReadInt(4) == 1842) then
  354.         packet:SetOffset(12)
  355.         local SummonerName = packet:ReadString();
  356.         --ShowToClient("Summoner Name",tostring(SummonerName))
  357.         packet:Move(20);
  358.         local MsgId = packet:ReadInt(4);
  359.         --ShowToClient("Message Id",tostring(MsgId))
  360.         if AcceptSummonFromAll or CheckIfInsideList(SummonerName,AllowSummonFromNames) then
  361.             packet:BlockMe();
  362.             AnswerDlg(1842,true,MsgId);
  363.             ShowToClient("Summon Plugin","Summon from " .. SummonerName .. " has been Accepted.");
  364.         elseif DeclineUnAllowedPlayersSummons then
  365.             packet:BlockMe();
  366.             AnswerDlg(1842,false,MsgId);
  367.             ShowToClient("Summon Plugin","Summon from " .. SummonerName .. " has been Rejected.");
  368.         end;
  369.     end;
  370. end;
  371.  
  372.  
  373. function AnswerDlg(dlgtype,answer,messageid)
  374.     -- C6 (DlgAnswer packetId)
  375.     -- (MessageID):Int
  376.     -- (Answer):Int
  377.     -- (Messgae Id):Int
  378.     pb = PacketBuilder();
  379.     pb:AppendInt(0xC6,1);
  380.     pb:AppendInt(dlgtype,4);
  381.     if answer then
  382.         pb:AppendInt(1,4);
  383.     else
  384.         pb:AppendInt(0,4);
  385.     end;
  386.     pb:AppendInt(messageid,4);
  387.     SendPacket(pb);
  388. end;
  389.  
  390. -- function OnMagicSkillUse(user, target, skillId)
  391. --  if user:IsPlayer() and target:IsMe() then
  392. --          ShowToClient("SKILL ID",tostring(skillId));
  393. --  end
  394. -- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement