Jump to content

Some questions about peds


Malganys23

Recommended Posts

Hi, I'm trying to make a mission system and other stuff with peds but I've a limited idea how to do it on scripting, basically what functions to use. My idea is to detect if player is near ped dynamically, I tried to use onClientRender but is it the best way?

Thanks in advance for any answer.

Link to comment

To detect if a player is near a ped, you can use the isElementWithinColShape function. This function takes two arguments: the first is the element you want to check (in this case, the player), and the second is the colshape you want to check if the element is within (in this case, the ped). If the player is within the colshape of the ped, the function will return true, otherwise it will return false.

Here is an example of how you might use this function in your script:

 

function onClientRender()
    local player = getLocalPlayer() -- get the local player
    local ped = getPedOccupiedVehicle(player) -- get the ped the player is in
    if ped then -- if the player is in a ped
        local pedColShape = createColCircle(getElementPosition(ped), 5) -- create a colshape around the ped
        if isElementWithinColShape(player, pedColShape) then -- check if the player is within the colshape
            -- player is within 5 units of the ped, so do something here
        end
    end
end

 

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...