Improved loot method
Posted: Sat Jul 24, 2010 5:34 pm
Well I made a new and improved loot method the only problem is it doesn't loot! It will walk up to the dead mob and then just move on to the next mob to fight. lootNearest is the method to actually loot where as findLoot locates dead mobs to loot.
Code: Select all
function findLoot(_id, ignore)
ignore = ignore or 0;
local bestTarget = nil;
local bestScore = 0;
local obj = nil;
local objectList = CObjectList();
objectList:update();
addMessage("Looking for lootable mobs");
-- The 'max' values that each scoring sub-part uses
local SCORE_DISTANCE = 60; -- closer = more score; actually score will usually be less than half
local SCORE_DEAD = 100; -- dead = possibly lootable
for i = 0,objectList:size() do
obj = objectList:getObject(i);
if( obj ~= nil ) then
if( obj.Type == PT_MONSTER and (_id == obj.Id or _id == nil) and obj.Address ~= ignore) then
local dist = distance(player.X, player.Z, obj.X, obj.Z);
local pawn = CPawn(obj.Address);
if( distance(player.X, player.Z, obj.X, obj.Z ) < settings.profile.options.MAX_TARGET_DIST and
(obj.Address ~= player.Address)) then
local currentScore = 0;
currentScore = currentScore + ( (settings.profile.options.MAX_TARGET_DIST - dist) / settings.profile.options.MAX_TARGET_DIST * SCORE_DISTANCE );
pawn:update();
if( pawn.Alive == false ) then
currentScore = currentScore + SCORE_DEAD;
else
currentScore = 0;
end
if( bestTarget == nil ) then
addMessage("Found lootable pawn named "..pawn.Name.."\n");
printf("Found lootable pawn named "..pawn.Name.."\n");
bestTarget = obj;
bestScore = currentScore;
elseif( currentScore > bestScore ) then
addMessage("Found better lootable pawn named "..pawn.Name.."\n");
printf("Found better lootable pawn named "..pawn.Name.."\n");
bestTarget = obj;
bestScore = currentScore;
end
end
end
end
end
if( bestTarget ) then
return CPawn(bestTarget.Address);
else
return nil;
end
end
function lootNearest()
local nearestLootable = nil;
nearestLootable = findLoot();
if( nearestLootable and nearestLootable.Lootable ) then
success, reason = player:moveTo(nearestLootable, true);
if( success ) then
addMessage("Successfully walked to the corpse\n");
printf("Successfully walked to the corpse\n");
if( player.LastTarget ~= nearestLootable.Address ) then
player.TargetPtr = nearestLootable.Address;
end
addMessage("Player Target = "..player.TargetPtr.."\n".."Nearest lootable address = "..nearestLootable.Address.."\n");
printf("Player Target = "..player.TargetPtr.."\n".."Nearest lootable address = "..nearestLootable.Address.."\n");
RoMScript("UseSkill(1,1);");
yrest(250);
RoMScript("BootyFrame:Hide()");
end
end
end