Wumbaloo Posted July 24, 2015 Share Posted July 24, 2015 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
KariiiM Posted July 24, 2015 Share Posted July 24, 2015 I think i got your point,you've to use setVehicleRotation Check the example in wiki https://wiki.multitheftauto.com/wiki/SetVehicleRotation Link to comment
Wumbaloo Posted July 24, 2015 Author Share Posted July 24, 2015 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
KariiiM Posted July 24, 2015 Share Posted July 24, 2015 Ah sorry i didn't take attention, try this and tell me setCameraTarget(localPlayer) --Client side Link to comment
Wumbaloo Posted July 24, 2015 Author Share Posted July 24, 2015 idk what do you mean by setCameraTarget(localPlayer), it's already done. Look at that: I want this: http://www.noelshack.com/2015-30-143776 ... -09-34.png It's perfect, but when I look to the south, it do that: http://image.noelshack.com/fichiers/201 ... -09-44.png http://www.noelshack.com/2015-30-143776 ... -09-50.png I want the vehicle spawn at the player right, you understand? Link to comment
Seba500PLK Posted July 24, 2015 Share Posted July 24, 2015 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
Wumbaloo Posted July 24, 2015 Author Share Posted July 24, 2015 but I don't want to warp into the vehicle, i'm exigent lel Link to comment
Seba500PLK Posted July 24, 2015 Share Posted July 24, 2015 but I don't want to warp into the vehicle, i'm exigent lel ok getCameraMatrix Link to comment
Wumbaloo Posted July 24, 2015 Author Share Posted July 24, 2015 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
KariiiM Posted July 24, 2015 Share Posted July 24, 2015 It must be defined as localPlayer setCameraTarget(localPlayer) Link to comment
Wumbaloo Posted July 24, 2015 Author Share Posted July 24, 2015 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
Perfect Posted July 24, 2015 Share Posted July 24, 2015 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
Wumbaloo Posted July 24, 2015 Author Share Posted July 24, 2015 Not really, I want that: no matter where I am, the vehicle spawn at my right, look at that: I'm looking at one positionn the vehicle spawn at my right http://image.noelshack.com/fichiers/201 ... -15-08.png I'm looking at second position, the vehicle spawn at my right too http://image.noelshack.com/fichiers/201 ... -15-20.png Link to comment
n3wage Posted July 24, 2015 Share Posted July 24, 2015 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
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