Jump to content

Rotate created ped onclick event


Recommended Posts

I'm trying to do if I click on a "left" or "right" button then rotate the created ped, if I click on the left button then rotate the ped -10 if I click on the right button then rotate the ped +10
 

defPed = createPed(1, pedPosition[1], pedPosition[2], pedPosition[3], pedPosition[4])

function createPed(key, state)
    local rotX, rotY, rotZ = getElementRotation(defPed)
	if state then
		if key == "mouse1" then
			if isInSlot(sx*0.3 + 275/myX*sx, startY+250, 40/myX*sx, 40/myX*sx) then
        		setElementRotation(defPed, rotX, rotY, rotZ - 10)
            end

            if isInSlot(sx*0.3 + 335/myX*sx, startY+250, 40/myX*sx, 40/myX*sx) then
                setElementRotation(defPed, rotX, rotY, rotZ + 10)
            end
      	end
    end
end

The problem is that if I click on the "right" button, it turns to the right and then if I click on it once more, it turns back, same situation with the "left" button.

Is it because I don't store rotX, rotY,rotZ after turning the ped to right/left? if so then where I need to store them?

Edited by thund3rbird23
Link to comment

Hey Bro Whats Up I Hope on This Script You Work Whit UseFull Any Functions , i Don't Know , i Write New Code For You 😄
And You Can Use And Enjoy ❤️

 

-- Script By ErroR (@FullOffeD)

-- Create Table To Insert Ped Pos And Rot 
pedPosition = {-2413.10327, -599.83673, 132.56250,60} -- {x,y,z,rotz}

defPed = createPed(1, pedPosition[1], pedPosition[2], pedPosition[3], pedPosition[4]) -- Createing Ped 

addEventHandler("onClientKey",getRootElement(),function(button, press) -- Add Event To When Click 
    if button == "mouse1" then 
        local rotx,roty,rotz = getElementRotation(defPed)
        setElementRotation(defPed,rotx,roty,rotz - 10) -- Set New Rotation
    elseif button == "mouse2" then 
        local rotx,roty,rotz = getElementRotation(defPed)
        setElementRotation(defPed,rotx,roty,rotz + 10) -- Set New Rotation
    end -- Close If
end)


I Test It Thats Work Successfully ❤️ 

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