Jump to content

Clicking on Ped


Axel

Recommended Posts

function onPedClick(button, state, absX, absY, wx, wy, wz, element) 
    if element and getElementType(element) == "ped" and state=="down" then 
        local x, y, z = getElementPosition(getLocalPlayer()) 
            if getDistanceBetweenPoints3D(x, y, z, wx, wy, wz)<=3 then 
            guiSetVisible(myGUIElement, true) 
        end 
    end 
end 
addEventHandler("onClientClick", getRootElement(), onPedClick) 

Link to comment
  • 1 month later...
I made 2 of those for 2 peds and now it shows the both gui's when i click on one of them..
--Made by Jesseunit 
--skin, name, x, y, z, rotationZ 
peds = { 
{115, "John", 0, 0, 3, 180} 
} 
  
for i = 1, #peds do 
ped = createPed(peds[i][1], peds[i][3], peds[i][4], peds[i][5]) 
setElementRotation(ped, 0, 0, peds[i][6]) 
setElementData(ped, "name", peds[i][2], true) 
end 
  

Then, when the player clicks on it, get his elementData and trigger the event by using triggerEvent/triggerServerEvent/triggerClientEvent.

-- Made by Jesseunit 
function clickPed(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
if (clickedElement) and (getElementType(clickedElement) == "ped" ) then 
            local x, y, z = getElementPosition(getLocalPlayer()) 
            local wx, wy, wz = getElementPosition(clickedElement) 
            local jij = getLocalPlayer() 
             
            if (getDistanceBetweenPoints3D(x, y, z, wx, wy, wz)<=3) and (button == "right") and (state == "down" ) then 
                         
                        local ped = getElementData(clickedElement, "name") 
                        if (ped=="John") then 
                        triggerEvent("showBarWnd", getLocalPlayer()) 
                        end 
            end 
else 
return 
end 
end 
addEventHandler("onClientClick", getRootElement(), clickPed, true) 

Thats a part of my script. Please correct me if there is something wrong.

EDIT: I'm in a good mood today, please dont ruin it by removing my tags.

Link to comment
  • 5 years later...

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