Timiimit Posted November 30, 2011 Share Posted November 30, 2011 Hi !!! I made 1 script but it looks like its not perfect. I want to make that when you would press left control [LCtrl] car of the driver would turn for 180 degrees with the same velocity(speed) and outputs in chatbox that you turned! This is what i have so far: function turn (thePlayer) speedx, speedy, speedz = getElementVelocity ( source ) pVehicle = getPedOccupiedVehicle(source) if isPedInVehicle ( source ) then actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) kmh = actualspeed * 180 mph = actualspeed * 111.847 setElementRotation(pVehicle,rX,rY,rZ+180) outputChatBox ( "You turned your Vehicle With " ..kph.. " km/h Or " ..mph.. " mph", source ) end end function bindKey ( thePlayer ) Bind( "LControl", turn ) outputChatBox( "#00FF00You can now press #0000FFLCtrl in vehicle to turn for 180 degrees!", source ) end addEventHandler( "onResourceStart", bindKey ) Thanks! Link to comment
Castillo Posted November 30, 2011 Share Posted November 30, 2011 (edited) This is total mess... function turn (thePlayer) local vehicle = getPedOccupiedVehicle(thePlayer) if (not vehicle) then return end local speedx, speedy, speedz = getElementVelocity ( vehicle ) local rX, rY, rZ = getElementRotation( vehicle ) local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) local kmh = actualspeed * 180 local mph = actualspeed * 111.847 setElementRotation(vehicle,rX,rY,rZ+180) outputChatBox ( "You turned your Vehicle With ".. tostring(kph) .." km/h Or ".. tostring(mph) .." mph", thePlayer) end function bindTheKey() for index, player in pairs(getElementsByType("player")) do bindKey(player, "lctrl", "down", turn ) outputChatBox( "#00FF00You can now press #0000FFLCtrl in vehicle to turn for 180 degrees!", player ) end end addEventHandler( "onResourceStart", resourceRoot, bindTheKey) addEventHandler("onPlayerJoin",root, function () bindKey(source, "lctrl", "down", turn ) end) Edited December 1, 2011 by Guest Link to comment
Timiimit Posted December 1, 2011 Author Share Posted December 1, 2011 this doent work it says that rZ is nil value! Link to comment
myonlake Posted December 1, 2011 Share Posted December 1, 2011 You didn't even try to find it out... function turn(thePlayer) local vehicle = getPedOccupiedVehicle(thePlayer) local rX, rY, rZ = getVehicleRotation(vehicle) if (not vehicle) then return end local speedx, speedy, speedz = getElementVelocity(vehicle) local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) local kmh = actualspeed * 180 local mph = actualspeed * 111.847 setElementRotation(vehicle, rX, rY, rZ + 180) outputChatBox("You turned your vehicle with " .. tostring(kph) .. " km/h | " .. tostring(mph) .. " mph", thePlayer) end function bindTheKey() for index, player in pairs(getElementsByType("player")) do bindKey(player, "lctrl", "down", turn) outputChatBox("#00FF00You can now press #0000FF'left ctrl' #00FF00in vehicle to turn for 180 degrees!", player, 255, 255, 255, true) end end addEventHandler("onResourceStart", resourceRoot, bindTheKey) addEventHandler("onPlayerJoin", root, function() bindKey(source, "lctrl", "down", turn) end) Link to comment
Castillo Posted December 1, 2011 Share Posted December 1, 2011 Yes, I forgot about the rotation. P.S: myonlake, you put getElementRotation before check if the vehicle exists. function turn(thePlayer) local vehicle = getPedOccupiedVehicle(thePlayer) if (not vehicle) then return end local speedx, speedy, speedz = getElementVelocity(vehicle) local rX, rY, rZ = getVehicleRotation(vehicle) local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) local kmh = actualspeed * 180 local mph = actualspeed * 111.847 setElementRotation(vehicle, rX, rY, rZ + 180) outputChatBox("You turned your vehicle with " .. tostring(kph) .. " km/h | " .. tostring(mph) .. " mph", thePlayer) end function bindTheKey() for index, player in pairs(getElementsByType("player")) do bindKey(player, "lctrl", "down", turn) outputChatBox("#00FF00You can now press #0000FF'left ctrl' #00FF00in vehicle to turn for 180 degrees!", player, 255, 255, 255, true) end end addEventHandler("onResourceStart", resourceRoot, bindTheKey) addEventHandler("onPlayerJoin", root, function() bindKey(source, "lctrl", "down", turn) end) Link to comment
Timiimit Posted December 1, 2011 Author Share Posted December 1, 2011 wait there is one more thing: i want to make opposite speed too! not that only car turnes!!!!! Link to comment
Castillo Posted December 1, 2011 Share Posted December 1, 2011 What are you talking about...? could you at least try to do it yourself before posting? Link to comment
12p Posted December 1, 2011 Share Posted December 1, 2011 then show your script! and stop using exclamations, it's annoying!!! Link to comment
Timiimit Posted December 1, 2011 Author Share Posted December 1, 2011 function turn(thePlayer) local vehicle = getPedOccupiedVehicle(thePlayer) if (not vehicle) then return end local speedx, speedy, speedz = getElementVelocity(vehicle) local rX, rY, rZ = getVehicleRotation(vehicle) local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) local kmh = actualspeed * 180 local mph = actualspeed * 111.847 setElementRotation(vehicle, rX, rY, rZ + 180) setElementVelocity ( getPlayerFromName ( source ), speedx, speedy, speedz - speedz^2 ) outputChatBox("You turned your vehicle with " .. tostring(kph) .. " km/h | " .. tostring(mph) .. " mph", thePlayer) end function bindTheKey() for index, player in pairs(getElementsByType("player")) do bindKey(player, "lctrl", "down", turn) outputChatBox("#00FF00You can now press #0000FF'left ctrl' #00FF00in vehicle to turn for 180 degrees!", player, 255, 255, 255, true) end end addEventHandler("onResourceStart", resourceRoot, bindTheKey) addEventHandler("onPlayerJoin", root, function() bindKey(source, "lctrl", "down", turn) end) Link to comment
50p Posted December 1, 2011 Share Posted December 1, 2011 You should use setElementVelocity on the vehicle, not the player. Link to comment
Timiimit Posted December 1, 2011 Author Share Posted December 1, 2011 (edited) function turn(thePlayer) local vehicle = getPedOccupiedVehicle(thePlayer) if (not vehicle) then return end local speedx, speedy, speedz = getElementVelocity(vehicle) local rX, rY, rZ = getVehicleRotation(vehicle) local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) local kmh = actualspeed * 180 local mph = actualspeed * 111.847 setElementRotation(vehicle, rX, rY, rZ + 180) setElementVelocity ( vehicle, speedx, speedy, speedz - speedz^2 ) outputChatBox("You turned your vehicle with " .. tostring(kph) .. " km/h | " .. tostring(mph) .. " mph", thePlayer) end function bindTheKey() for index, player in pairs(getElementsByType("player")) do bindKey(player, "lctrl", "down", turn) outputChatBox("#00FF00You can now press #0000FF'left ctrl' #00FF00in vehicle to turn for 180 degrees!", player, 255, 255, 255, true) end end addEventHandler("onResourceStart", resourceRoot, bindTheKey) addEventHandler("onPlayerJoin", root, function() bindKey(source, "lctrl", "down", turn) end) doesnt work Edited December 1, 2011 by Guest Link to comment
Timiimit Posted December 1, 2011 Author Share Posted December 1, 2011 no not like this. Link to comment
Timiimit Posted December 1, 2011 Author Share Posted December 1, 2011 now i just need to turn speed. setElementVelocity ( vehicle, speedx, speedy, speedz - speedz^2 ) how to? this doesnt work Link to comment
Castillo Posted December 1, 2011 Share Posted December 1, 2011 What's your f-*** problem? you have made 5 posts in 3 minutes! that's SPAM. Link to comment
Timiimit Posted December 1, 2011 Author Share Posted December 1, 2011 sorry didnt saw them in the forum. Link to comment
myonlake Posted December 1, 2011 Share Posted December 1, 2011 Use setVehicleHandling to edit speed. .. EDIT YOUR OLD MSGS!!! Link to comment
Timiimit Posted December 2, 2011 Author Share Posted December 2, 2011 No i want to make that not only car rotates. i want to make that car rotates and make oposite speed. Link to comment
Al3grab Posted December 2, 2011 Share Posted December 2, 2011 Hi , i used setElementSpeed + getElementSpeed from Useful Functions https://wiki.multitheftauto.com/wiki/SetElementSpeed https://wiki.multitheftauto.com/wiki/GetElementSpeed -- From Useful Functions ! function setElementSpeed(element, unit, speed) -- only work if element is moving! if (unit == nil) then unit = 0 end if (speed == nil) then speed = 0 end speed = tonumber(speed) local acSpeed = getElementSpeed(element, unit) if (acSpeed~=false) then -- if true - element is valid, no need to check again local diff = speed/acSpeed local x,y,z = getElementVelocity(element) setElementVelocity(element,x*diff,y*diff,z*diff) return true end return false end ----- function getElementSpeed(element,unit) if (unit == nil) then unit = 0 end if (isElement(element)) then local x,y,z = getElementVelocity(element) if (unit=="mph" or unit==1 or unit =='1') then return (x^2 + y^2 + z^2) ^ 0.5 * 100 else return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 end else outputDebugString("Not an element. Can't get speed") return false end end ------ function turn(thePlayer) local vehicle = getPedOccupiedVehicle(thePlayer) if (not vehicle) then return end local rX, rY, rZ = getVehicleRotation(vehicle) local Speeds = getElementSpeed(vehicle) setElementRotation(vehicle, rX, rY, rZ + 180) local Boost = 80 -- You Can set this to 0 if You Dont Need it ! setTimer(setElementSpeed,1100,1,vehicle,1,Speeds+Boost) -- i used timer to set the car speed after rotation 1 outputChatBox("You turned your vehicle with " .. tostring(Speeds) .. " mph", thePlayer) end function bindTheKey() for index, player in pairs(getElementsByType("player")) do bindKey(player, "lctrl", "down", turn) outputChatBox("#00FF00You can now press #0000FF'left ctrl' #00FF00in vehicle to turn for 180 degrees!", player, 255, 255, 255, true) end end addEventHandler("onResourceStart", resourceRoot, bindTheKey) addEventHandler("onPlayerJoin", root, function() bindKey(source, "lctrl", "down", turn) end) This Should Work !! Link to comment
Timiimit Posted December 2, 2011 Author Share Posted December 2, 2011 it doesnt work. I dont know how to fix. + if speed== nil(probably speed doesnt changes to 0) glitch happenes! Link to comment
Al3grab Posted December 3, 2011 Share Posted December 3, 2011 What do want to do exactly ?! Link to comment
TAPL Posted December 3, 2011 Share Posted December 3, 2011 -- From Useful Functions ! function setElementSpeed(element, unit, speed) -- only work if element is moving! if (unit == nil) then unit = 0 end if (speed == nil) then speed = 0 end speed = tonumber(speed) local acSpeed = getElementSpeed(element, unit) if (acSpeed~=false) then -- if true - element is valid, no need to check again local diff = speed/acSpeed local x,y,z = getElementVelocity(element) setElementVelocity(element,x*diff,y*diff,z*diff) return true end return false end ----- function getElementSpeed(element,unit) if (unit == nil) then unit = 0 end if (isElement(element)) then local x,y,z = getElementVelocity(element) if (unit=="mph" or unit==1 or unit =='1') then return (x^2 + y^2 + z^2) ^ 0.5 * 100 else return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 end else outputDebugString("Not an element. Can't get speed") return false end end ------ function turn(thePlayer) local vehicle = getPedOccupiedVehicle(thePlayer) if (not vehicle) then return end local rX, rY, rZ = getVehicleRotation(vehicle) local Speeds = getElementSpeed(vehicle, "mph") setElementRotation(vehicle, rX, rY, rZ + 180) local Boost = 0 -- You Can set this to 0 if You Dont Need it ! setTimer(setElementSpeed,50,1,vehicle,1,-Speeds+Boost) -- i used timer to set the car speed after rotation 1 outputChatBox("You turned your vehicle with " .. tostring(Speeds) .. " mph", thePlayer) end function bindTheKey() for index, player in pairs(getElementsByType("player")) do bindKey(player, "lctrl", "down", turn) outputChatBox("#00FF00You can now press #0000FF'left ctrl' #00FF00in vehicle to turn for 180 degrees!", player, 255, 255, 255, true) end end addEventHandler("onResourceStart", resourceRoot, bindTheKey) addEventHandler("onPlayerJoin", root, function() bindKey(source, "lctrl", "down", turn) end) 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