Artisz Posted August 17, 2016 Share Posted August 17, 2016 Hi! How can I do that when I click on a ped(there are more ped, where can we talk with them), and after click, set the camera on him, so we can look at him. I create a ped, in x,y,z, and where I need put the camera that I can see the ped front? Sorry for my English! Link to comment
Wumbaloo Posted August 17, 2016 Share Posted August 17, 2016 Use addEventHandler ( "onClientClick", getRootElement(), clickOnPed) https://wiki.multitheftauto.com/wiki/OnClientClick to get the element and check if it's a ped using getElementType and then use setCameraTarget to set the camera target on the ped like function resourceStart() addEventHandler("onClientClick", getRootElement(), clickOnPed) end addEventHandler("onClientResourceStart", getRootElement(), resourceStart) function clickOnPed(button, state, x, y, z, worldX, worldY, worldZ, clickedWorld) if (button == "left" and state == "up") then if getElementType(clickedWorld) == "ped" then setCameraTarget(ped) end end end Link to comment
Artisz Posted August 17, 2016 Author Share Posted August 17, 2016 It's don't working. I create a ped: thePed = createPed(120, 1053.97461, 2096.96313, 10.82031) And I set the camera target: setCameraTarget (thePed) But nothing. And with the CameraTarget we can move the camera, no? I want to freeze the camera, that we can see the ped front side. Link to comment
Wumbaloo Posted August 17, 2016 Share Posted August 17, 2016 Should work with every ped function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z end function resourceStart() addEventHandler("onClientClick", getRootElement(), clickOnPed) thePed = createPed(120, 1053.97461, 2096.96313, 10.82031) end addEventHandler("onClientResourceStart", getRootElement(), resourceStart) function clickOnPed(button, state, x, y, z, worldX, worldY, worldZ, clickedWorld) if (button == "left" and state == "up") then if getElementType(clickedWorld) == "ped" then local pedX, pedY, pedZ = getElementPosition(clickedWorld) local x, y, z = getPositionFromElementOffset(clickedWorld, 0, 3, 0) setCameraMatrix(x, y, z, pedX, pedY, pedZ) end end end Link to comment
Artisz Posted August 17, 2016 Author Share Posted August 17, 2016 I copy your code, but It's still don't working. I put messages the code, and what is under these lines: local pedX, pedY, pedZ = getElementPosition(clickedWorld) local x, y, z = getPositionFromElementOffset(clickedWorld, 0, 3, 0) setCameraMatrix(x, y, z, pedX, pedY, pedZ) Dont working. Link to comment
Wumbaloo Posted August 17, 2016 Share Posted August 17, 2016 Sorry, forgot arguments of onClientClick function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z end function resourceStart() addEventHandler("onClientClick", getRootElement(), clickOnPed) thePed = createPed(120, 1053.97461, 2096.96313, 10.82031) end addEventHandler("onClientResourceStart", getRootElement(), resourceStart) function clickOnPed(button, state, x, y, worldX, worldY, worldZ, clickedWorld) if (button == "left" and state == "up") then if clickedWorld and getElementType(clickedWorld) == "ped" then local pedX, pedY, pedZ = getElementPosition(clickedWorld) local x, y, z = getPositionFromElementOffset(clickedWorld, 0, 3, 0) setCameraMatrix(x, y, z, pedX, pedY, pedZ) end end end Link to comment
Artisz Posted August 17, 2016 Author Share Posted August 17, 2016 Ah.. Thanks! You help me twice! You are awesome! And sorry Link to comment
Wumbaloo Posted August 17, 2016 Share Posted August 17, 2016 No problem! Don't be sorry, I like help peoples Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now