Jump to content

Get list of rendered elements in MTA SA in client


Emre_

Recommended Posts

Hi,

I want to get list of visible elements (in my case pickups) to player in client-side code so I can loop through these elements. By visible, I mean literally player can "see" with their own eyes. You can also think it as loaded/rendered elements within given range. eg. element list of in 400.0 meters radius with player in center. I couldn't find proper function for it. 

Thank you for your further helps.

Edit: these pickups are created server-side

Edited by Emre_
Link to comment

I made a example, go to coords 0,0,0 and test the command:

server:

createPickup(0,0,10, 3, 1247)
createPickup(0,5,20, 3, 1254)
createPickup(10,0,10, 3, 1248)

client:

function pks()
    for i,p in ipairs(getElementsByType("pickup")) do
    
        local x,y,z=getElementPosition(localPlayer)
        local xb,yb,zb=getElementPosition(p)
        local sx,sy=getScreenFromWorldPosition(x,y,z+0.7)
        local sxb,syb=getScreenFromWorldPosition(xb,yb,zb)
        
        if isElement(p) and isElementOnScreen(p) and isLineOfSightClear(x,y,z+0.7,xb,yb,zb) and getDistanceBetweenPoints3D(x,y,z,xb,yb,zb)<400 then
            dxDrawLine(sx,sy,sxb,syb,tocolor(255, 255, 255))
            dxDrawText("pickup id: "..getElementModel(p),sxb,syb,_,_,tocolor(255, 255, 0))
        end
    end
end
function pksr()
addEventHandler("onClientRender", root, pks)
end
addCommandHandler("pkps",pksr)

I will list pickup ids within 400m, in camera angle and not blocked by objects (from skin position) I tested and its working but its just a test code, not checked for warnings or exception handling

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...