Potato_Tomato420 Posted July 20, 2019 Share Posted July 20, 2019 I'm scripting a police job for my server, how can i force a player to follow a other player? Like arresting a criminal. Link to comment
HassoN Posted July 20, 2019 Share Posted July 20, 2019 (edited) Use setControlState -- forward, sprint, walk setPedRotation -- to obviously change player's rotation when the police officer changes his. With some calculations you may achieve your goal Edited July 20, 2019 by HassoN Link to comment
Casti Posted July 22, 2019 Share Posted July 22, 2019 --Example function followArrestor(player, cop) if (not isElement(player) or not isElement(cop)) then return end if (isPedInVehicle(player) or not isPlayerArrested(player)) then return end local cX, cY = getElementPosition(cop) local pX, pY = getElementPosition(player) local copangle = (360 - math.deg(math.atan2((cX - pX), (cY - pY)))) % 360 setPedRotation(player, copangle) setCameraTarget(player, player) setElementInterior(player, getElementInterior(cop)) setElementDimension(player, getElementDimension(cop)) local dist = getDistanceBetweenPoints2D(cX, cY, pX, pY) if (dist > 16) then -- Warp local x, y, z = getElementPosition(cop) setElementPosition(player, x, y, z) setTimer(followArrestor, 500, 1, player, cop) elseif (dist > 12) then -- Sprint setControlState(player, "sprint", true) setControlState(player, "walk", false) setControlState(player, "forwards", true) setTimer(followArrestor, 500, 1, player, cop) elseif (dist > 6) then -- Jog setControlState(player, "sprint", false) setControlState(player, "walk", false) setControlState(player, "forwards", true) setTimer(followArrestor, 500, 1, player, cop) elseif (dist > 1.5) then -- Walk setControlState(player, "sprint", false) setControlState(player, "walk", true) setControlState(player, "forwards", true) setTimer(followArrestor, 500, 1, player, cop) elseif (dist <= 1.5) then -- Stop setControlState(player, "sprint", false) setControlState(player, "walk", false) setControlState(player, "forwards", false) setTimer(followArrestor, 500, 1, player, cop) end end -- Vehicle Handlers -------------------->> addEventHandler("onVehicleStartEnter", root, function(player, seat) if (#getPlayerArrests(player) == 0) then return end local max_pass = getVehicleMaxPassengers(source) for _,plr in ipairs(getPlayerArrests(player)) do for i=1,max_pass do if (not getVehicleOccupant(source, i)) then warpPedIntoVehicle(plr, source, i) end end end end) addEventHandler("onVehicleExit",root, function(player,seat) if (#getPlayerArrests(player) == 0) then return end for k,v in ipairs(getPlayerArrests(player)) do local max_seats = getVehicleMaxPassengers(source) removePedFromVehicle(v) followArrestor(v,player) end 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