• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
In-Game Radar using Draw Text (now improved!)
#1
I accidentally removed the old thread, sorry about that.

Update: Improved outline and range indication. 

Two things still remains:
1. Correct the transformation from game coordinates to 2D pixel coordinates... Right now it works but its not optimal, see scaleX / scaleY.
2. Find a function/method of determine which direction we are facing

Other stuff is easy to add, such as displaying hostile players, friendly players etc. Or any object for that matter. You will get all objects within 100 yards of your character if you are alive. Right now I only display pull-able targets and players.

Code below:

function Radar()
        local radarOffsetX = 512; local radarOffsetY = 369; local radius = 200; local pi = 3.14;
       local numberOfValidTargets = 0; local numberOfPlayers = 0; local targets = {}; local players = {}; local localObj = GetLocalPlayer();
        local currentObj, typeObj = GetFirstObject();
        while currentObj ~= 0 do
        if typeObj == 3 then -- Save pull-able targets in an array
                   if CanAttack(currentObj) == 1 and IsDead(currentObj) == 0 and ((IsTapped(currentObj) == 0 or IsTappedByMe(currentObj) == 1)) then
                       numberOfValidTargets = numberOfValidTargets + 1;
                        targets[numberOfValidTargets] = currentObj;
                end
        elseif typeObj == 4 then -- Save players in an array
            numberOfPlayers = numberOfPlayers+1;
            players[numberOfPlayers]= currentObj;
        end
        currentObj, typeObj = GetNextObject(currentObj);
        end
    -- Draw the radar's outline        
        DrawText('*', radarOffsetX, radarOffsetY, 0, 255, 0);
        for i= 1, 360 do
            local cX = radarOffsetX + radius*math.cos(i/(2*pi)); local cY = radarOffsetY + radius*math.sin(i/(2*pi)); DrawLine(cX, cY, cX+1, cY+1, 0, 255, 0, 1);
        end
    -- Get the radar's center game coordinates
        local centerX, centerY, __ = GetPosition(localObj);
        -- Draw all the valid monster targets
        for i=1, numberOfValidTargets do
        -- Transform the game coordinates to 2D pixel coords.
        local cX, cY, __ = GetPosition(targets[i]);     
        -- X and Y coordinates are swapped dunno why
        local vectorLength = math.sqrt(cX^2 + cY^2);
        local scaleX = radius/85;
 local scaleY = radius/50;

        local distance = math.floor(GetDistance(targets[i]));
        local drawX = scaleX*(cY - centerY)*(centerY/vectorLength);
            
            local drawY = scaleY*(cX - centerX)*(centerX/vectorLength);
            if (GetTarget() == targets[i]) then
                DrawText('Target', radarOffsetX+drawX-10, radarOffsetY+drawY, 255, 0, 0);
        DrawText('(' .. distance .. ' yd)', radarOffsetX+drawX-9, radarOffsetY+drawY+10, 255, 0, 0);
            else
                DrawText('Monster', radarOffsetX+drawX-10, radarOffsetY+drawY, 0, 0, 255);
        DrawText('(' .. distance .. ' yd)', radarOffsetX+drawX-10, radarOffsetY+drawY+10, 0, 0, 255);
            end
        end

    -- Draw the players nearby
        for i=1, numberOfPlayers do
        -- Transform the game coordinates to 2D pixel coords.
        local cX, cY, __ = GetPosition(players[i]);     
        -- X and Y coordinates are swapped dunno why
        local vectorLength = math.sqrt(cX^2 + cY^2);
        local scaleX = radius/85;
 local scaleY = radius/50;

        local distance = math.floor(GetDistance(players[i]));
        local drawX = scaleX*(cY - centerY)*(centerY/vectorLength);
            
            local drawY = scaleY*(cX - centerX)*(centerX/vectorLength);
            if (GetTarget() == players[i] and players[i] ~= localObj) then
                DrawText('Target', radarOffsetX+drawX-10, radarOffsetY+drawY, 255, 0, 0);
        DrawText('(' .. distance .. ' yd)', radarOffsetX+drawX-9, radarOffsetY+drawY+10, 255, 0, 0);
            elseif (players[i] ~= localObj) then
                if (CanAttack(players[i]) == 1) then
                      DrawText('!PLAYER!', radarOffsetX+drawX-10, radarOffsetY+drawY, 255, 0, 0);
                      DrawText('(' .. distance .. ' yd)', radarOffsetX+drawX-10, radarOffsetY+drawY+10, 255, 0, 0);
                 else
                      DrawText('!PLAYER!', radarOffsetX+drawX-10, radarOffsetY+drawY, 0, 255, 0);
                      DrawText('(' .. distance .. ' yd)', radarOffsetX+drawX-10, radarOffsetY+drawY+10, 0, 255, 0);
                 end
           end
        end
 
end


Radar();


Attached Files Thumbnail(s)
   
  Reply
#2
(02-26-2017, 10:11 PM)Logitech Wrote: I accidentally removed the old thread, sorry about that.

Update: Improved outline and range indication.  ...
Sorry about the dumb qeustion, but, how does i run this script, i mean there it is a LUA tab where we can place this and try to run, cuz it wont work, not sure if there it is the right place tho! ty for helping and for the scripts development, they just look amazing!
  Reply
#3
Love the radar.. thanks!
  Reply
#4
The radar wasn't working properly for me: 
  • placement of players on radar was completely wrong
  • mobs were not displayed at all
I fixed few things and added some bells and whistles:
  • added more units (mobs and players) colors variations
  • fixed units positions
  • added UI menu
  • added on-screen units marking (script_nav style)
I didn't solve the rotation problem, but there is a work around - radar over large minimap (screenshot attached), simple and intuitive.


Attached Files Thumbnail(s)
   

.lua   script_radar.lua (Size: 6.96 KB / Downloads: 27)
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)