Jump to content

[Help] setElementPosition


Wumbaloo

Recommended Posts

Hey! I have a little problem, when I spawn a veh, or anything else like goto player, it take the position, add 5 and teleport me to this, but i don't want it, I want to spawn at the right of the player or spawn vehicle right

look at this:

function createVeh(player, commandName, model) 
        local x, y, z = getElementPosition(player) 
        local rx, ry, rz = getElementRotation(player) 
        x = x + 5 
        local createdVehicle = createVehicle(model, x, y, z, rx, ry, rz) 
        if (createdVehicle == false) then 
        outputChatBox("Error") 
        end 
end 
addCommandHandler("veh", createVeh) 

How can I spawn the vehicle at my right ? Thanks!

Link to comment

nah, setVehicleRotation is in the createVehicle, the arguments are: model, posX, posY, posZ, rotationX, rotationY, rotationZ

and i want to spawn the vehicle at my right, if I look at the North, it spawn at my right, but if i look to the South, it spawn at my left, do you understand? Sorry, i'm French.

Link to comment

maybe this :)

  
function createVeh(player, commandName, model) 
        local x, y, z = getElementPosition(player) 
        local rx, ry, rz = getElementRotation(player) 
        local createdVehicle = createVehicle(model, x, y, z, rx, ry, rz) 
        if (createdVehicle == false) then 
        outputChatBox("Error") 
        end 
warpPedIntoVehicle ( player, createdVehicle )  
end 
addCommandHandler("veh", createVeh) 
  

Link to comment

Can't test, error and idk why

function createVehicleForPlayer(player, commandName, model) 
        setCameraTarget(player) 
        -- local px, py, pz = getElementPosition(player) 
        local rx, ry, rz = getElementRotation(player) 
        local x, y, z = getCameraMatrix (player) 
        x = x + 5 
        local createdVehicle = createVehicle(model, x, y, z, rx, ry, rz) 
        if (createdVehicle == false) then 
        outputChatBox("Erreur lors de la création du véhicule") 
        end 
end 
addCommandHandler("veh", createVehicleForPlayer) 

Console:

script.lua:6: attempt to perform arithmetic on local 'x' (a boolean value) 

But, why, getCameraMatrix return 8 floats, the 3 first are x, y, z

Link to comment

Nah, it work, if i put localPlayer, some errors apparead, i said about the line 6, "x = x + 5"

i get that in the console: attempt to perform arithmetic on local x (a boolean value)

But I don't know why did the console put "a boolean value" because the first 3 floats are x, y, z

Link to comment

I think I got you.

Try this:

  
function getPointFromDistanceRotation(x, y, dist, angle) 
  
    local a = math.rad(90 - angle); 
  
    local dx = math.cos(a) * dist; 
    local dy = math.sin(a) * dist; 
  
    return x+dx, y+dy; 
  
end 
  
function createVeh(player, commandName, model) 
        local px, py, z = getElementPosition(player) 
        local x,y = getPointFromDistanceRotation(px, py, 5, 90) 
        local rx, ry, rz = getElementRotation(player) 
        local createdVehicle = createVehicle(model, x, y, z, rx, ry, rz) 
        if (createdVehicle == false) then 
        outputChatBox("Error") 
        end 
end 
addCommandHandler("veh", createVeh 

Link to comment

getElementMatrix

function getPositionFromElementOffset(element,offX,offY,offZ) 
    local m = getElementMatrix ( element )  -- Get the matrix 
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]  -- Apply transform 
    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                               -- Return the transformed point 
end 
  
function createVeh(player, commandName, model) 
    local x, y, z = getPositionFromElementOffset( player, 3, 0, 0 ) 
    local rx, ry, rz = getElementRotation(player) 
    local createdVehicle = createVehicle(model, x, y, z, rx, ry, rz) 
    if (createdVehicle == false) then 
        outputChatBox("Error") 
    end 
end 
addCommandHandler("veh", createVeh) 

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