jingzhi Posted March 28, 2015 Share Posted March 28, 2015 Clientscript function cuffed() local copx, copy, copz = getElementPosition (arrester) local x, y, z = getElementPosition (localPlayer) local copangle = ( 360 - math.deg ( math.atan2 ( ( copx - x ), ( copy - y ) ) ) ) % 360 setElementRotation(localPlayer,_,_,copangle) local dist = getDistanceBetweenPoints2D (copx, copy, x, y) if dist < 2 then setControlState("forwards", false) setControlState("sprint", false ) else setControlState("forwards", true) setControlState("sprint", true ) end end addEvent("onPlayerArrested",true) addEventHandler("onPlayerArrested",root, function(arrester) arrester = arrester setCameraTarget(arrester) addEventHandler("onClientPreRender",root,cuffed) end) addEvent("onPlayerJailed",true) addEventHandler("onPlayerJailed",root, function() removeEventHandler("onClientPreRender",root,cuffed) end) Hey guys, I am having this problem, which I am trying to make the criminal follow the police, but they dont work, nothing happens, only the camera is following the police, nothing in debugscript, and its triggered, please help! TY Link to comment
xXMADEXx Posted March 28, 2015 Share Posted March 28, 2015 Try using this: function cuffed() local copx, copy, copz = getElementPosition (arrester) local x, y, z = getElementPosition (localPlayer) local copangle = ( 360 - math.deg ( math.atan2 ( ( copx - x ), ( copy - y ) ) ) ) % 360 local rx, ry, _ = getElementRotation ( localPlayer ); setElementRotation(localPlayer, rx, ry, copangle) local dist = getDistanceBetweenPoints2D (copx, copy, x, y) if dist < 2 then setControlState("forwards", false) setControlState("sprint", false ) else setControlState("forwards", true) setControlState("sprint", true ) end end _ isn't defined by MTA or Lua, so this could be causing the problem. Link to comment
jingzhi Posted March 30, 2015 Author Share Posted March 30, 2015 Try using this: function cuffed() local copx, copy, copz = getElementPosition (arrester) local x, y, z = getElementPosition (localPlayer) local copangle = ( 360 - math.deg ( math.atan2 ( ( copx - x ), ( copy - y ) ) ) ) % 360 local rx, ry, _ = getElementRotation ( localPlayer ); setElementRotation(localPlayer, rx, ry, copangle) local dist = getDistanceBetweenPoints2D (copx, copy, x, y) if dist < 2 then setControlState("forwards", false) setControlState("sprint", false ) else setControlState("forwards", true) setControlState("sprint", true ) end end _ isn't defined by MTA or Lua, so this could be causing the problem. Thank you very much, i will try out when i have a chance Link to comment
jingzhi Posted March 30, 2015 Author Share Posted March 30, 2015 Try using this: function cuffed() local copx, copy, copz = getElementPosition (arrester) local x, y, z = getElementPosition (localPlayer) local copangle = ( 360 - math.deg ( math.atan2 ( ( copx - x ), ( copy - y ) ) ) ) % 360 local rx, ry, _ = getElementRotation ( localPlayer ); setElementRotation(localPlayer, rx, ry, copangle) local dist = getDistanceBetweenPoints2D (copx, copy, x, y) if dist < 2 then setControlState("forwards", false) setControlState("sprint", false ) else setControlState("forwards", true) setControlState("sprint", true ) end end _ isn't defined by MTA or Lua, so this could be causing the problem. Here is the new script addEvent("onPlayerArrested",true) addEventHandler("onPlayerArrested",root, function(arrester) arrester = arrester setCameraTarget(arrester) addEventHandler("onClientPreRender",root,cuffed) end) function cuffed(arrester) local copx, copy, copz = getElementPosition (arrester) local x, y, z = getElementPosition (localPlayer) local copangle = ( 360 - math.deg ( math.atan2 ( ( copx - x ), ( copy - y ) ) ) ) % 360 local rx, ry, _ = getElementRotation ( localPlayer ) setElementRotation(localPlayer, rx, ry, copangle) local dist = getDistanceBetweenPoints2D (copx, copy, x, y) if dist < 2 then setControlState("forwards", false) setControlState("sprint", false ) else setControlState("forwards", true) setControlState("sprint", true ) end end addEvent("onPlayerJailed",true) addEventHandler("onPlayerJailed",root, function() removeEventHandler("onClientPreRender",root,cuffed) end) Unfortunately, its still not working Link to comment
JR10 Posted March 31, 2015 Share Posted March 31, 2015 Rename arrester parameter in onPlayerArrested function so it doesn't override the global one. Also, remove it from cuffed. Link to comment
jingzhi Posted March 31, 2015 Author Share Posted March 31, 2015 Rename arrester parameter in onPlayerArrested function so it doesn't override the global one. Also, remove it from cuffed. Hey JR10, thank you very much, the problem is fix. But there is a little bug, that if the cop is at the east or west of the arrested criminal, the criminal runs to the opposite direction, can you please help to fix? Thank you ! addEvent("onPlayerArrested",true) addEventHandler("onPlayerArrested",root, function(arrestercop) arrester = arrestercop setCameraTarget(arrester) toggleAllControls(localPlayer,true,true,false) addEventHandler("onClientRender",root,cuffed) end) function cuffed() local copx, copy, copz = getElementPosition (arrester) local x, y, z = getElementPosition (localPlayer) local copangle = ( 360 - math.deg ( math.atan2 ( ( copx - x ), ( copy - y ) ) ) ) % 360 local rx, ry, _ = getElementRotation (localPlayer) setElementRotation(localPlayer,_,_, copangle) local dist = getDistanceBetweenPoints2D (copx, copy, x, y) if dist < 2 then setControlState("forwards", false) setControlState("sprint", false ) else setControlState("forwards", true) setControlState("sprint", true ) end end addEvent("onPlayerJailed",true) addEventHandler("onPlayerJailed",root, function() removeEventHandler("onClientRender",root,cuffed) end) Link to comment
JR10 Posted March 31, 2015 Share Posted March 31, 2015 You can use the findRotation useful function. Link to comment
jingzhi Posted April 1, 2015 Author Share Posted April 1, 2015 You can use the findRotation useful function. Ty, i will try 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