function CPlayer:target_Object(_objname, _waittime, _harvestall, _donotignore, evalFunc) _waittime = _waittime or 0 local minWaitTime = 1000 -- minimum time to wait for castbar to come up. _harvestall = (_harvestall == true) if type(_donotignore) ~= "boolean" then _donotignore = (_harvestall == false) end -- default value depends on _harvestall if( not _objname ) then cprintf(cli.yellow, language[181]); -- Please give an Object name return end -- Make sure we come to a stop before attempting to harvest. self:waitTillStopMoving() local objFound = false; while(true) do repeat interrupted = false if _donotignore == false then obj = self:findNearestNameOrId(_objname, self.LastTargetPtr, evalFunc) else obj = self:findNearestNameOrId(_objname, nil, evalFunc) end -- Check if too far if obj and ( distance(self.X, self.Z, self.Y, obj.X, obj.Z, obj.Y ) > settings.profile.options.HARVEST_DISTANCE ) then obj = nil end if obj then -- object found, target if self.LastTargetPtr ~= obj.Address then cprintf(cli.yellow, language[95], obj.Name); -- We found object and will harvest it self.LastTargetPtr = obj.Address; -- remember target address to avoid msg spam end objFound = true self:target(obj.Address); if( distance(self.X, self.Z, obj.X, obj.Z) > 39 ) then self:moveInRange(CWaypoint(obj.X, obj.Z), 39, true); end --yrest(100) Attack() local timeStart = getTime() --Wait minimum time repeat yrest(100) self:updateCasting() self:updateBattling() if self.Casting or self.Battling then break end until deltaTime(getTime(),timeStart) >= minWaitTime if self.Casting == false and _waittime > 0 then -- Was expecting castingbar so try again, 2nd try. Attack(); yrest(100); timeStart = getTime() end self:updateXYZ() repeat yrest(10); self:updateBattling(); while( self.Battling ) do if self:target(self:findEnemy(true, nil, evalTargetDefault)) then self:fight(); interrupted = true else break end self:updateBattling(); end self:updateCasting() until interrupted or (deltaTime(getTime(),timeStart) > _waittime and self.Casting == false) end until interrupted == false if obj then -- harvest again if _donotignore ~= true then self.LastTargetPtr = obj.Address -- Default ignore this address in next search end if _harvestall == false then -- No more harvesting return objFound end else return objFound end end end function CPlayer:target_NPC(_npcname) if( not _npcname ) then cprintf(cli.yellow, language[133]); -- Please give a NPC name return end cprintf(cli.green, language[135], _npcname); -- We try to find NPC if type(_npcname) == "string" and bot.ClientLanguage == "RU" then _npcname = utf82oem_russian(_npcname); -- language conversations for Russian Client end local npc = self:findNearestNameOrId(_npcname) if npc then -- we successfully found NPC if RoMScript("SpeakFrame:IsVisible()") then RoMScript("CloseWindows()"); end cprintf(cli.green, language[136], npc.Name); -- we successfully target NPC if( distance(self.X, self.Z, npc.X, npc.Z) > 39 ) then self:moveInRange(CWaypoint(npc.X, npc.Z), 39, true); end if npc.Id == 110986 or npc.Id == 122097 or npc.Id == 110538 or npc.Id == 110694 or npc.Id == 113136 or npc.Id == 117407 then -- target NPC self:target(npc.Address) Attack(); yrest(50); Attack(); -- 'click' again to be sure else self:target(npc.Address) local starttime = os.clock() while(not RoMScript("SpeakFrame:IsVisible()") and os.clock() - starttime <= 5000)do Attack() yrest(50) end if not RoMScript("SpeakFrame:IsVisible()") then cprintf(cli.green,"NPC dialog failed to open!") return false end end --yrest(500); return true else cprintf(cli.green, language[137], _npcname); -- we can't find NPC return false end end function CPlayer:useMenu_NPC(_target,_choiceList,_conditonList) local maxtries = 5-- Should be a global value /setting local tries = 0; if type(_choiceList) == "number" or type(_choiceList) == "string" then _choiceList = {_choiceList} end if type(_conditonList) == "number" then _conditonList = {_conditonList} end repeat tries = maxtries + 1; until self:target_NPC(_target) or tries > maxtries local option1; local option2; local condition = true; if(#choiceList == 1)then if _conditonList[1] and RoMScript("GetNumSpeakOption()") < _conditonList[1] then return false; end if(type(_choiceList[1]) == "string")then ChoiceOptionByName(_choiceList[1]) else --option1 = RoMScript("GetSpeakOption(".._choiceList[1]..")") RoMScript("ChoiceOption(".._choiceList[1]..");"); -- repeat -- option2 = RoMScript("GetSpeakOption(".._choiceList[1]..")") -- -- no menu -- if not option2 and not RoMScript("SpeakFrame:IsVisible()") then -- break; -- end -- -- next menu -- if(option2 and option2 ~= option1 )then -- break; -- end -- -- next Menu but nil option(out of index) -- if(not option2 and RoMScript("SpeakFrame:IsVisible()"))then -- break; -- end -- yrest(50) -- until true end else for index, element in pairs(_choiceList) do local starttime = os.clock() option1 = nil; option2 = nil; while(not RoMScript("SpeakFrame:IsVisible()") and os.clock() - starttime <= 5000)do yrest(50) end if(not RoMScript("SpeakFrame:IsVisible()"))then return false; end if _conditonList and _conditonList[index] and RoMScript("GetNumSpeakOption()") < _conditonList[index] then return false; end if(type(element) == "string")then ChoiceOptionByName(element) else starttime = os.clock() repeat option1 = RoMScript("GetSpeakOption("..element..")") until option1 or os.clock() - starttime > 5000 if( option1 == nil)then return false; end RoMScript("ChoiceOption("..element..");"); -- repeat -- option2 = RoMScript("GetSpeakOption("..element..")") -- -- no menu -- if not option2 and not RoMScript("SpeakFrame:IsVisible()") then -- break; -- end -- -- next menu -- if(option2 and option2 ~= option1 )then -- break; -- end -- -- next Menu but nil option(out of index) -- if(not option2 and RoMScript("SpeakFrame:IsVisible()"))then -- break; -- end -- --yrest(50) -- until true end end end return true; end -- Thanks to JackBlonder for his work on the QuestByName functions function AcceptQuestByName(_nameorid, _questgroup) local DEBUG = false if settings.options.DEBUGGING == true then DEBUG = true end -- Check for valid _nameorid local questToAccept if _nameorid == nil then questToAccept = "all" elseif type(_nameorid) == "number" then questToAccept = GetIdName(_nameorid) else questToAccept = _nameorid end if type(questToAccept) ~= "string" then error("Invalid name or id used in AcceptQuestByName") end if DEBUG then printf("questToAccept: %s\n",questToAccept) end -- Check if already accepted if questToAccept ~= "all" and getQuestStatus(questToAccept, _questgroup) ~= "not accepted" then printf("Quest already accepted: %s\n", questToAccept) return end -- Check for valid _questgroup if _questgroup ~= nil then if type(_questgroup) == "string" then _questgroup = string.lower(_questgroup) _questgroup = string.gsub(_questgroup,"s$","") -- remove 's' at end if user used plural end if _questgroup == "normal" then _questgroup = 0 elseif _questgroup == "daily" then _questgroup = 2 elseif _questgroup == "public" then _questgroup = 3 else _questgroup = nil end end -- If no _questgroup specified and Id used, get quest group from memory. if _questgroup == nil and type(_nameorid) == "number" then local baseaddress = GetItemAddress(_nameorid) if baseaddress then _questgroup = memoryReadInt(getProc(), baseaddress + addresses.questGroup_offset) end end -- Check if we have target player:updateTargetPtr() yrest(50) if (player.TargetPtr == 0 or player.TargetPtr == nil) then print("No target! Target NPC before using AcceptQuestByName") return end -- Target NPC again to get updated questlist local starttime = os.clock() while(not RoMScript("SpeakFrame:IsVisible()") and os.clock() - starttime <= 5000)do Attack() yrest(100) end if not RoMScript("SpeakFrame:IsVisible()") then error("NPC dialog failed to open!") end local questOnBoard local availableQuests = RoMScript("GetNumQuest(1)") -- Get number of available quests if DEBUG then printf("Number of available quests: %d\n",availableQuests) end local matchFound = false -- For each quest for i=1,availableQuests do -- Check to see if we have room to accept quests if (30 > RoMScript("GetNumQuestBookButton_QuestBook()")) then -- Get quest name questOnBoard, daily, qgroup = RoMScript("GetQuestNameByIndex(1, "..i..")") if DEBUG then printf("questOnBoard: %s \n",questOnBoard) end if ((questToAccept == "" or questToAccept == "all") or -- Accept all FindNormalisedString(questOnBoard,questToAccept)) and -- Or match name (_questgroup == nil or _questgroup == qgroup) then -- And match quest group matchFound = true repeat RoMScript("OnClick_QuestListButton(1,"..i..")") -- Clicks the quest -- yrest(100) RoMScript("AcceptQuest()") -- Accepts the quest -- yrest(100) until (getQuestStatus(questOnBoard, qgroup)=="incomplete" or getQuestStatus(questOnBoard, qgroup)=="complete") -- Try again if accepting didn't work printf("Quest accepted: %s\n",questOnBoard) -- break if name matched if (questToAccept ~= "" and questToAccept ~= "all") then break end -- yrest(200) elseif questToAccept ~= "" and questToAccept ~= "all" and i==availableQuests then -- Didn't find name match printf("Questname not found: %s\n",questToAccept) -- Quest not found end else print("Maxim number of quests in questbook!") end end RoMScript("SpeakFrame:Hide()") -- yrest(750) return matchFound end function CompleteQuestByName(_nameorid, _rewardnumberorname, _questgroup) local DEBUG = false if settings.options.DEBUGGING == true then DEBUG = true end -- Check for valid _nameorid local questToComplete if _nameorid == nil then questToComplete = "all" elseif type(_nameorid) == "number" then questToComplete = GetIdName(_nameorid) else questToComplete = _nameorid end if type(questToComplete) ~= "string" then error("Invalid name or id used in CompleteQuestByName") end if DEBUG then printf("questToComplete: %s\n",questToComplete) end -- Check if user put questgroup in second argument if type(_rewardnumberorname) == "string" and (string.lower(_rewardnumberorname) == "normal" or string.lower(_rewardnumberorname) == "daily" or string.lower(_rewardnumberorname) == "public") then _questgroup = _rewardnumberorname _rewardnumberorname = nil end -- Check if not complete if questToComplete ~= "all" and getQuestStatus(questToComplete, _questgroup) ~= "complete" then printf("Quest not ready to be completed: %s\n",questToComplete) return end -- Check for valid _questgroup if _questgroup ~= nil then if type(_questgroup) == "string" then _questgroup = string.lower(_questgroup) _questgroup = string.gsub(_questgroup,"s$","") -- remove 's' at end if user used plural end if _questgroup == "normal" then _questgroup = 0 elseif _questgroup == "daily" then _questgroup = 2 elseif _questgroup == "public" then _questgroup = 3 else _questgroup = nil end end -- If no _questgroup specified and Id used, get quest group from memory. if _questgroup == nil and type(_nameorid) == "number" then local baseaddress = GetItemAddress(_nameorid) if baseaddress then _questgroup = memoryReadInt(getProc(), baseaddress + addresses.questGroup_offset) end end -- Check if we have target player:updateTargetPtr() -- yrest(100) if (player.TargetPtr == 0 or player.TargetPtr == nil) then print("No target! Target NPC before using CompleteQuestByName") return end -- Target NPC again to get updated questlist local starttime = os.clock() while(not RoMScript("SpeakFrame:IsVisible()") and os.clock() - starttime <= 5000)do Attack() yrest(100) end if not RoMScript("SpeakFrame:IsVisible()") then error("NPC dialog failed to open!") end local questOnBoard = "" local availableQuests = RoMScript("GetNumQuest(3)") if DEBUG then printf("Number of available quests: %d\n",availableQuests) end -- For each quest for i=1,availableQuests do -- Get quest name questOnBoard, daily, qgroup = RoMScript("GetQuestNameByIndex(3, "..i..")") if DEBUG then printf("questOnBoard / Index: %s \t %d\n",questOnBoard,i) end if ((questToComplete == "" or questToComplete == "all") or -- Complete all FindNormalisedString(questOnBoard,questToComplete)) and -- Or match name (_questgroup == nil or _questgroup == qgroup) then -- And match quest group local _counttime = os.time() repeat RoMScript("OnClick_QuestListButton(3, "..i..")") -- Clicks the quest -- yrest(100) if _rewardnumberorname then if DEBUG then printf("_rewardnumberorname: %s \n",_rewardnumberorname) end if type(_rewardnumberorname) == "number" then RoMScript("SpeakFrame_ClickQuestReward(SpeakQuestReward1_Item".._rewardnumberorname..")") -- yrest(100) elseif type(_rewardnumberorname) == "string" then -- Search for reward name local found = false for rewardNum = 1, RoMScript("SpeakQuestReward1.itemcount") do -- rewardID = RoMScript("SpeakQuestReward1_Item"..rewardNum..".ID") -- rewardType = RoMScript("SpeakQuestReward1_Item"..rewardNum..".Type") -- set Tooltip -- RoMScript("GameTooltip:SetQuestItem("..rewardType..","..rewardID..")") -- get Tooltip data local rewardName = RoMScript("SpeakQuestReward1_Item"..rewardNum.."_Desc:GetText()") if FindNormalisedString(rewardName, _rewardnumberorname) then found = true RoMScript("SpeakFrame_ClickQuestReward(SpeakQuestReward1_Item"..rewardNum..")") -- yrest(100) break end end if not found then printf("Invalid reward name or number, \"%s\"\n", _rewardnumberorname) return end else printf("Invalid reward type specified. Expected \"number\" or \"string\", got \""..type(_rewardnumberorname).."\".\n") return end elseif (os.time() - _counttime) >= 2 then -- quest still there because of reward item needs choosing RoMScript("SpeakFrame_ClickQuestReward(SpeakQuestReward1_Item1)") -- yrest(100) end RoMScript("CompleteQuest()") -- Completes the quest -- yrest(100) until (getQuestStatus(questOnBoard,qgroup)~="complete") printf("Quest completed: %s\n",questOnBoard) -- break if name matched if (questToComplete ~= "" and questToComplete ~= "all") then break end -- yrest(200) elseif questToComplete ~= "" and questToComplete ~= "all" and i==availableQuests then printf("Questname not found: %s\n",questToComplete) end end RoMScript("SpeakFrame:Hide()") -- yrest(750) end function CancelQuest(nameorid) local index = 1 local questId = RoMScript("GetQuestId(1)") while questId ~= nil do if questId == nameorid or string.find(GetIdName(questId), nameorid, 1, true) then -- match found, delete RoMCode("g_SelectedQuest = "..index) RoMScript("ViewQuest_QuestBook( g_SelectedQuest )") --yrest(500) RoMScript("DeleteQuest()") --yrest(1000) return else index = index + 1 questId = RoMScript("GetQuestId("..index..")") end end end function PressMenu( _option ) if (player.TargetPtr == 0 or player.TargetPtr == nil) then print("No target! Target NPC before using PressMenu") return false; end local starttime = os.clock() while(not RoMScript("SpeakFrame:IsVisible()") and os.clock() - starttime <= 1500)do yrest(50) end --secound try to avoid use Attack() on the first place. if(not RoMScript("SpeakFrame:IsVisible()"))then local starttime2 = os.clock() while(not RoMScript("SpeakFrame:IsVisible()") and os.clock() - starttime2 <= 2500)do Attack() yrest(50) end -- all eforts failed if(not RoMScript("SpeakFrame:IsVisible()"))then return false; end end if(type( _option) == "string")then ChoiceOptionByName( _option) else RoMScript("ChoiceOption(".._option..");"); end return true; end