try this,
Client:
local curTarget
local screenX , screenY = guiGetScreenSize ( )
addEvent('playCD', true)
addEventHandler('playCD', root,
function(cd)
playSound(cd..'.mp3', false)
end
)
addEvent ( "client:setPlayerFollowPlayer" , true )
addEventHandler ( "client:setPlayerFollowPlayer" , root ,
function ( bool , target )
if bool == true then
curTarget = target
addEventHandler ( "onClientRender" , root , setPlayerFollowPlayer )
else
showCursor(false)
toggleAllControls(true)
removeEventHandler ( "onClientRender" , root , setPlayerFollowPlayer )
end
end
)
function setPlayerFollowPlayer ( )
if isPedInVehicle ( curTarget ) then
local vehicle = getPedOccupiedVehicle ( curTarget )
local seat = getPedOccupiedVehicleSeat ( curTarget )
if not warpPedIntoVehicle ( source , vehicle , seat + 1 ) then
local posX , posY , posZ = getElementPosition ( vehicle )
setElementPosition ( source , posX , posY , posZ + 1 )
attachRotationAdjusted ( source , vehicle )
end
else
if isPedInVehicle ( source ) then
removePedFromVehicle ( source )
end
local posX , posY , posZ = getElementPosition ( source )
local posX2 , posY2 , posZ2 = getElementPosition ( curTarget )
local rotation = math.deg ( math.atan2 ( posX2 - posX , posY2 - posY ) ) % 360
setElementRotation ( source , 0 , 0 , 360 - rotation )
setCameraTarget ( source )
local distance = getDistanceBetweenPoints2D(posX2, posY2, posX, posY)
if distance > 22 then
setElementData(source, "Cuffed", false)
setElementData(source, "Handcuffer", "")
showCursor(false)
toggleAllControls(true)
removeEventHandler ( "onClientRender" , root , setPlayerFollowPlayer )
elseif distance > 12 then
setControlState("sprint", true)
setControlState("walk", false)
setControlState("forwards", true)
elseif distance > 6 then
setControlState("sprint", false)
setControlState("walk", false)
setControlState("forwards", true)
elseif distance > 1.5 then
setControlState("sprint", false)
setControlState("walk", true)
setControlState("forwards", true)
elseif distance < 1.5 then
setControlState("sprint", false)
setControlState("walk", false)
setControlState("forwards", false)
end
end
end
function Follow(target, player)
if not isPedInVehicle(player) then
local px, py, pz = getElementPosition(player)
local tx, ty, tz = getElementPosition(target)
local angle = ( 360 - math.deg ( math.atan2 ( ( px - tx ), ( py - ty ) ) ) ) % 360
setPedRotation(target, angle)
setCameraTarget(target)
local distance = getDistanceBetweenPoints2D(px, py, tx, ty)
if distance > 22 then
stopFollow(target, player)
setElementData(target, "Cuffed", false)
setElementData(target, "Handcuffer", "")
elseif distance > 12 then
setControlState(target, "sprint", true)
setControlState(target, "walk", false)
setControlState(target, "forwards", true)
followTimer[target] = setTimer(Follow, 500, 1, target, player)
elseif distance > 6 then
setControlState(target, "sprint", false)
setControlState(target, "walk", false)
setControlState(target, "forwards", true)
followTimer[target] = setTimer(Follow, 500, 1, target, player)
elseif distance > 1.5 then
setControlState(target, "sprint", false)
setControlState(target, "walk", true)
setControlState(target, "forwards", true)
followTimer[target] = setTimer(Follow, 500, 1, target, player)
elseif distance < 1.5 then
setControlState(target, "sprint", false)
setControlState(target, "walk", false)
setControlState(target, "forwards", false)
followTimer[target] = setTimer(Follow, 500, 1, target, player)
end
end
end
function attachRotationAdjusted ( from, to )
local frPosX, frPosY, frPosZ = getElementPosition( from )
local frRotX, frRotY, frRotZ = getElementRotation( from )
local toPosX, toPosY, toPosZ = getElementPosition( to )
local toRotX, toRotY, toRotZ = getElementRotation( to )
local offsetPosX = frPosX - toPosX
local offsetPosY = frPosY - toPosY
local offsetPosZ = frPosZ - toPosZ
local offsetRotX = frRotX - toRotX
local offsetRotY = frRotY - toRotY
local offsetRotZ = frRotZ - toRotZ
offsetPosX, offsetPosY, offsetPosZ = applyInverseRotation ( offsetPosX, offsetPosY, offsetPosZ, toRotX, toRotY, toRotZ )
attachElements( from, to, offsetPosX, offsetPosY, offsetPosZ, offsetRotX, offsetRotY, offsetRotZ )
end
function applyInverseRotation ( x,y,z, rx,ry,rz )
local DEG2RAD = (math.pi * 2) / 360
rx = rx * DEG2RAD
ry = ry * DEG2RAD
rz = rz * DEG2RAD
local tempY = y
y = math.cos ( rx ) * tempY + math.sin ( rx ) * z
z = -math.sin ( rx ) * tempY + math.cos ( rx ) * z
local tempX = x
x = math.cos ( ry ) * tempX - math.sin ( ry ) * z
z = math.sin ( ry ) * tempX + math.cos ( ry ) * z
tempX = x
x = math.cos ( rz ) * tempX + math.sin ( rz ) * y
y = -math.sin ( rz ) * tempX + math.cos ( rz ) * y
return x, y, z
end
addEventHandler ( "onClientRender" , root ,
function ( )
for index , player in ipairs ( getElementsByType ( "player" ) ) do
if not getElementData ( player , "Arrested" ) then
return
end
if getElementData(player, "Timeleft") < 1 then
return
end
dxDrawFramedText ( "Time left: " .. getElementData ( player , "Timeleft" ) , ( screenX / 1440 ) * 720 , ( screenY / 900 ) * 200 , ( screenX / 1440 ) * 1440 , ( screenY / 900 ) * 200 , tocolor ( 255 , 255 , 255 , 255 ) , ( screenX / 1440 ) * 3 , "default-bold" , "center" , "center" , false , false , true )
if getElementData ( player , "Timeleft" ) < 6 then
playSound ( getElementData ( player , "Timeleft" ) .. ".mp3" , false )
return
end
end
end
)
Server:
local LSPDColShape = createColTube ( 1544.599609375, -1675.6923828125, 13.558725357056 , 5 , 5 ) addEventHandler("onPlayerJoin", root, function() setElementData(source, "justDamaged", false) end ) addEventHandler ( "onPlayerDamage" , root , function ( attacker , attackerWeapon ) if getElementHealth ( source ) < 1 then return end if not getPlayerTeam( attacker, getTeamFromName("Police") ) then return end if not attacker or attacker == source then return end if getPlayerWantedLevel ( source ) < 1 then return end if getElementData ( source , "Cuffed" ) then return end if attackerWeapon ~= 3 then return end setElementData(source, "Cuffed", true) setElementData(source, "Handcuffer", getPlayerName(attacker)) outputChatBox("You have been handcuffed by " .. getPlayerName ( attacker ), source) outputChatBox("Take " .. getPlayerName ( source ) .. " to LSPD to arrest him" , attacker ) toggleAllControls(source, false) showCursor(source, true) setPlayerFollowPlayer ( source , attacker ) end ) function setPlayerFollowPlayer ( player , target ) triggerClientEvent ( player , "client:setPlayerFollowPlayer" , root , true , target ) end addCommandHandler("uncuff", function(player, _, name) if not getPlayerTeam( player, getTeamFromName("Police") ) then return outputChatBox("You are not a cop", player) end if not name then return outputChatBox("Syntax: /uncuff ", player) end local target = findPlayer(name, player) if not target then return end if target == player then return outputChatBox("You can't uncuff yourself", player) end if not getElementData(target, "Cuffed") then return outputChatBox(getPlayerName(target).." is not cuffed", player) end local tx, ty, tz = getElementPosition(target) if not isPlayerInRangeOfPoint(player, tx, ty, tz, 3) then return outputChatBox("You are too far from "..getPlayerName(target), player) end if not getElementData(target, "Handcuffer") == getPlayerName(player) then return outputChatBox("You didn't cuff "..getPlayerName(target), player) end setElementData(target, "Cuffed", false) setElementData(target, "Handcuffer", "") outputChatBox(getPlayerName(player).." has uncuffed you", target) triggerClientEvent ( target , "client:setPlayerFollowPlayer" , target , false , player ) end ) addEventHandler ( "onColShapeHit" , LSPDColShape , function ( hElement , mDim ) if not mDim then return end if getElementType ( hElement ) ~= player then return end if getPlayerWantedLevel ( hElement ) < 1 then return end if not getElementData ( hElement , "Cuffed" ) then return end local player = getPlayerFromName ( getElementData ( hElement , "Handcuffer" ) ) if not player then return end local wantedLevel = getPlayerWantedLevel ( hElement ) fadeCamera(hElement, false) setTimer(setElementInterior, 1000, 1, hElement, settingPrisonLocation [ 4 ]) setTimer(setElementPosition, 1000, 1, hElement, settingPrisonLocation [ 1 ] , settingPrisonLocation [ 2 ] , settingPrisonLocation [ 3 ] ) setTimer(setElementDimension, 1000, 1, hElement, settingPrisonLocation [ 5 ] ) setTimer(setElementRotation, 1000, 1, hElement, settingPrisonLocation [ 6 ]) setTimer(fadeCamera, 1000, 1, hElement, true) if settingTakePlayerWeaponsOnArrest then takeAllWeapons(hElement) end setElementData(hElement, "Arrested", true) setElementData(hElement, "Cuffed", false) setElementData(hElement, "Handcuffer", "") if wantedLevel == 1 then givePlayerMoney(player, 1000) takePlayerMoney(hElement, 5000) setElementData(hElement, "Timeleft", 30) setTimer ( releasePlayer , 30000 , 1 , hElement ) elseif wantedLevel == 2 then givePlayerMoney(player, 2000) takePlayerMoney(hElement, 8000) setElementData(hElement, "Timeleft", 60) setTimer ( releasePlayer , 60000 , 1 , hElement ) elseif wantedLevel == 3 then givePlayerMoney(player, 3000) takePlayerMoney(hElement, 10000) setElementData(hElement, "Timeleft", 120) setTimer ( releasePlayer , 120000 , 1 , hElement ) elseif wantedLevel == 4 then givePlayerMoney(player, 4000) takePlayerMoney(hElement, 12000) setElementData(hElement, "Timeleft", 180) setTimer ( releasePlayer , 180000 , 1 , hElement ) elseif wantedLevel == 5 then givePlayerMoney(player, 5000) takePlayerMoney(hElement, 15000) setElementData(hElement, "Timeleft", 200) setTimer ( releasePlayer , 200000 , 1 , hElement ) elseif wantedLevel == 6 then givePlayerMoney(player, 8000) takePlayerMoney(hElement, 20000) setElementData(hElement, "Timeleft", 240) setTimer ( releasePlayer , 240000 , 1 , hElement ) end setPlayerWantedLevel(hElement, 0) end ) function releasePlayer(player) fadeCamera(player, false) setTimer(setElementInterior, 1000, 1, player, 0) setTimer(setElementPosition, 1000, 1, player, 1544.0986328125, -1675.591796875, 13.557745933533) setTimer(setPedRotation, 1000, 1, player, 90) setTimer(setElementDimension, 1000, 1, player, 0) setTimer(fadeCamera, 1000, 1, player, true) setTimer(outputChatBox, 1000, 1, "You have been released from jail , try to be a better citizen", player) setTimer(setElementData, 1000, 1, player, "Arrested", false) toggleAllControls(player, true) showCursor(player, false) end addCommandHandler("release", function(player, _, name) if not getPlayerTeam( player, getTeamFromName("Police") ) then return outputChatBox("You are not a cop", player) end if not name then return outputChatBox("Syntax: /release ", player) end local target = findPlayer(name, player) if not target then return end if target == player then return outputChatBox("You can't release yourself", player) end if not getElementData(target, "Arrested") then return outputChatBox(getPlayerName(target).." is not arrested", player) end releasePlayer(player) end ) addCommandHandler("free", function(player, cmd, name, ...) if not getPlayerTeam( hitElement, getTeamFromName("Police") ) then return outputChatBox("You are not a cop", player) end if not name then return outputChatBox("Syntax: /free ", player) end if ... then local target = findPlayer(name, src) if not target then return end if target == player then return outputChatBox("You can't free yourself", player) end local reason = table.concat({...}, " ") setPlayerWantedLevel(target, 0) else local target = findPlayer(name, src) if not target then return end if target == player then return outputChatBox("You can't free yourself", player) end setPlayerWantedLevel(target, 0) end end ) local LSPEle = createMarker(1568.6572265625, -1689.9814453125, 7, "arrow", 1.5, 0, 255, 0, 255) local LSPREle = createMarker(1572.6884765625, -1675.5966796875, 29.09545249939, "arrow", 1.5, 0, 255, 0, 255) addEventHandler("onMarkerHit", LSPEle, function(hitElement, dim) if getElementType(hitElement) == "player" then if getPlayerTeam( hitElement, getTeamFromName("Police") ) then fadeCamera(hitElement, false) setTimer(setElementPosition, 1000, 1, hitElement, 1574.8115234375, -1675.4208984375, 28.39545249939) setTimer(setPedRotation, 1000, 1, hitElement, 270) setTimer(fadeCamera, 1000, 1, hitElement, true) playSoundFrontEnd(hitElement, 1) end end end ) addEventHandler("onMarkerHit", LSPREle, function(hitElement, dim) if getElementType(hitElement) == "player" then if getPlayerTeam( hitElement, getTeamFromName("Police") ) then fadeCamera(hitElement, false) setTimer(setElementPosition, 1000, 1, hitElement, 1568.447265625, -1692.6533203125, 5.890625) setTimer(setPedRotation, 1000, 1, hitElement, 175) setTimer(fadeCamera, 1000, 1, hitElement, true) playSoundFrontEnd(hitElement, 1) end end end ) addEventHandler("onResourceStart", resourceRoot, function() for i, v in ipairs(getElementsByType("player")) do setElementData(v, "RB", false) setElementFrozen(v, false) setElementData(v, "Cuffed", false) setElementData(v, "gotCuffs", false) setElementData(v, "Arrested", false) end end ) --WANTED addEventHandler("onPlayerWasted", root, function(ammo, attacker, weapon, bodypart) if getPlayerWantedLevel(source) > 0 and getPlayerTeam( attacker, getTeamFromName("Police") ) then setPlayerWantedLevel(source, 0) return takePlayerMoney(source, 200) end if getElementType(attacker) == "player" then if not isElement(attacker) or attacker == source then return end if getPlayerWantedLevel(attacker) < 6 then setPlayerWantedLevel(attacker, getPlayerWantedLevel(attacker) + 1) end elseif getElementType(attacker) == "vehicle" then local driver = getVehicleController(attacker) if not isElement(driver) then return end if getPlayerWantedLevel(driver) < 6 then setPlayerWantedLevel(driver, getPlayerWantedLevel(driver) + 1) end end end ) addEventHandler("onPlayerVehicleEnter", root,function(vehicle, seat, jacked) if getPlayerTeam( source, getTeamFromName("Police") ) then return end if getElementData(source, "Cuffed") then return end local model = getElementModel(vehicle) if model == 598 or model == 596 or model == 597 or model == 427 or model == 490 or model == 599 then if getPlayerWantedLevel(source) < 6 then setPlayerWantedLevel(source, getPlayerWantedLevel(source) + 1) end end end) addEventHandler("onPlayerDamage", root,function(attacker,weapon,bodypart,loss) if