[Release]Drag command

Thanks for the share, Frazzle!

Happy to see this script coming out :stuck_out_tongue:

Hey folks, iā€™ve tried to edit the script so there is no need to enter an ID but just the need to press a key to attach/detach with the nearest player. Itā€™s crashing FiveM as soon as i push the key. Any idea whatā€™s going wrong please ? Iā€™m pretty sure this is a GetPlayers() but why ?

function GetNearPlayer(distance)
  local players = GetPlayers()
  local nearPlayerDistance = distance or -1
  local nearPlayer = -1
  local playerCd = GetEntityCoords(GetPlayerPed(-1), 0)
  for i,v in ipairs(players) do
    local target = GetPlayerPed(v)
    if(target ~= GetPlayerPed(-1)) then
      local targetCoords = GetEntityCoords(GetPlayerPed(v), 0)
      local distance = GetDistanceBetweenCoords(targetCoords["x"], targetCoords["y"], targetCoords["z"], playerCd["x"], playerCd["y"], playerCd["z"], true)
      if(nearPlayerDistance == -1 or nearPlayerDistance > distance) then
        nearPlayer = v
      end
    end
  end
  return nearPlayer
end

function GetPlayers()
    local players = {}
    for i = 0, 31 do
        if NetworkIsPlayerActive(i) then
            table.insert(players, i)
        end
    end
    return players
end

function ShowNotif(text)
	SetNotificationTextEntry("STRING")
	AddTextComponentString3(text)
	DrawNotification(true, true)
end

Citizen.CreateThread(function()
	while true do
	local ped = GetPlayerPed(GetNearPlayer(2))
	local myped = GetPlayerPed(-1)
		if IsEntityAttached(myped) and IsControlJustPressed(1, 70) then -- Right Ctrl
			ShowNotif('Right Ctrl pressed')
			DetachEntity(GetPlayerPed(-1), true, false)
		elseif IsControlJustPressed(1, 70) then
			AttachEntityToEntity(myped, ped, 11816, 0.54, 0.54, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
		end
		Citizen.Wait(0)
	end
end)

@Lyrad if you managed to realed it, you are my god =O ^^

ps : Hmm can i talk with you to help me for 2 police scripts ?

Wait some days, itā€™s already working with Cops_FiveM v1.2 ^^

Can this work without essential?

Hey! Do you find a solution?

Can someone help me? I have put the drag folder in my resourses folder. Put ā€œdragā€ in my citmp. And /drag (id) doesnā€™t workā€¦ So is there something wrong I didā€¦ Cause the description is very tiny and has no info.

1 Like

^^^ Same, can someone help?

Can someone tell me if I can add this to a vRP framework? It involves .lua files and most of the cop animations are in one section, the police.lua

I would love you forever if i could just copy and paste, if so, what should i copy and paste into the police.lua?

-- this module define some police tools and functions

local handcuffed = false
local cop = false

-- set player as cop (true or false)
function tvRP.setCop(flag)
  cop = flag
  SetPedAsCop(GetPlayerPed(-1),flag)
end

-- HANDCUFF

function tvRP.toggleHandcuff()
  handcuffed = not handcuffed

  SetEnableHandcuffs(GetPlayerPed(-1), handcuffed)
  if handcuffed then
    tvRP.playAnim(true,{{"mp_arresting","idle",1}},true)
  else
    tvRP.stopAnim(true)
    SetPedStealthMovement(GetPlayerPed(-1),false,"") 
  end
end

function tvRP.setHandcuffed(flag)
  if handcuffed ~= flag then
    tvRP.toggleHandcuff()
  end
end

function tvRP.isHandcuffed()
  return handcuffed
end

-- (experimental, based on experimental getNearestVehicle)
function tvRP.putInNearestVehicleAsPassenger(radius)
  local veh = tvRP.getNearestVehicle(radius)

  if IsEntityAVehicle(veh) then
    for i=1,math.max(GetVehicleMaxNumberOfPassengers(veh),3) do
      if IsVehicleSeatFree(veh,i) then
        SetPedIntoVehicle(GetPlayerPed(-1),veh,i)
        return true
      end
    end
  end
  
  return false
end

function tvRP.putInNetVehicleAsPassenger(net_veh)
  local veh = NetworkGetEntityFromNetworkId(net_veh)
  if IsEntityAVehicle(veh) then
    for i=1,GetVehicleMaxNumberOfPassengers(veh) do
      if IsVehicleSeatFree(veh,i) then
        SetPedIntoVehicle(GetPlayerPed(-1),veh,i)
        return true
      end
    end
  end
end

function tvRP.putInVehiclePositionAsPassenger(x,y,z)
  local veh = tvRP.getVehicleAtPosition(x,y,z)
  if IsEntityAVehicle(veh) then
    for i=1,GetVehicleMaxNumberOfPassengers(veh) do
      if IsVehicleSeatFree(veh,i) then
        SetPedIntoVehicle(GetPlayerPed(-1),veh,i)
        return true
      end
    end
  end
end

-- keep handcuffed animation
Citizen.CreateThread(function()
  while true do
    Citizen.Wait(15000)
    if handcuffed then
      tvRP.playAnim(true,{{"mp_arresting","idle",1}},true)
    end
  end
end)

-- force stealth movement while handcuffed (prevent use of fist and slow the player)
Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
    if handcuffed then
      SetPedStealthMovement(GetPlayerPed(-1),true,"")
      DisableControlAction(0,21,true) -- disable sprint
      DisableControlAction(0,24,true) -- disable attack
      DisableControlAction(0,25,true) -- disable aim
      DisableControlAction(0,47,true) -- disable weapon
      DisableControlAction(0,58,true) -- disable weapon
      DisableControlAction(0,263,true) -- disable melee
      DisableControlAction(0,264,true) -- disable melee
      DisableControlAction(0,257,true) -- disable melee
      DisableControlAction(0,140,true) -- disable melee
      DisableControlAction(0,141,true) -- disable melee
      DisableControlAction(0,142,true) -- disable melee
      DisableControlAction(0,143,true) -- disable melee
      DisableControlAction(0,75,true) -- disable exit vehicle
      DisableControlAction(27,75,true) -- disable exit vehicle
    end
  end
end)

-- JAIL

local jail = nil

-- jail the player in a no-top no-bottom cylinder 
function tvRP.jail(x,y,z,radius)
  tvRP.teleport(x,y,z) -- teleport to center
  jail = {x+0.0001,y+0.0001,z+0.0001,radius+0.0001}
end

-- unjail the player
function tvRP.unjail()
  jail = nil
end

function tvRP.isJailed()
  return jail ~= nil
end

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(5)
    if jail then
      local x,y,z = tvRP.getPosition()

      local dx = x-jail[1]
      local dy = y-jail[2]
      local dist = math.sqrt(dx*dx+dy*dy)

      if dist >= jail[4] then
        local ped = GetPlayerPed(-1)
        SetEntityVelocity(ped, 0.0001, 0.0001, 0.0001) -- stop player

        -- normalize + push to the edge + add origin
        dx = dx/dist*jail[4]+jail[1]
        dy = dy/dist*jail[4]+jail[2]

        -- teleport player at the edge
        SetEntityCoordsNoOffset(ped,dx,dy,z,true,true,true)
      end
    end
  end
end)

-- WANTED

-- wanted level sync
local wanted_level = 0

function tvRP.applyWantedLevel(new_wanted)
  Citizen.CreateThread(function()
    local old_wanted = GetPlayerWantedLevel(PlayerId())
    local wanted = math.max(old_wanted,new_wanted)
    ClearPlayerWantedLevel(PlayerId())
    SetPlayerWantedLevelNow(PlayerId(),false)
    Citizen.Wait(10)
    SetPlayerWantedLevel(PlayerId(),wanted,false)
    SetPlayerWantedLevelNow(PlayerId(),false)
  end)
end

-- update wanted level
Citizen.CreateThread(function()
  while true do
    Citizen.Wait(2000)

    -- if cop, reset wanted level
    if cop then
      ClearPlayerWantedLevel(PlayerId())
      SetPlayerWantedLevelNow(PlayerId(),false)
    end
    
    -- update level
    local nwanted_level = GetPlayerWantedLevel(PlayerId())
    if nwanted_level ~= wanted_level then
      wanted_level = nwanted_level
      vRPserver.updateWantedLevel({wanted_level})
    end
  end
end)

-- detect vehicle stealing
Citizen.CreateThread(function()
  while true do
    Citizen.Wait(1)
    local ped = GetPlayerPed(-1)
    if IsPedTryingToEnterALockedVehicle(ped) or IsPedJacking(ped) then
      Citizen.Wait(2000) -- wait x seconds before setting wanted
      local ok,vtype,name = tvRP.getNearestOwnedVehicle(5)
      if not ok then -- prevent stealing detection on owned vehicle
        for i=0,4 do -- keep wanted for 1 minutes 30 seconds
          tvRP.applyWantedLevel(2)
          Citizen.Wait(15000)
        end
      end
      Citizen.Wait(15000) -- wait 15 seconds before checking again
    end
  end
end)

I really wish vRP would die in a fire.

1 Like

VRP is a lot better than most frameworks, at least it works and has a lot of content

does this drag command work?

IDK I havenā€™t tested it, but if its in LUA format it just might? I donā€™t see why it shouldnā€™tā€¦ Which is why I asked in the first place lol. Also @Frazzle I have tried FX based servers and they constantly kick you from the games, vRP my friends and I can play for hours and hours with no issues. Making it better than most.

1 Like

Having a problem getting this to work. Wanted EMS to be able to drag a downed player, or have people be able to drag a player who they k.oed to perhaps hide them from police.

Make RP a bit more interesting.

This does not work for me

can you make the drag command not use es and be a standalone script and be button based so it attaches the person in front of you

if u took 10 mins to research the forums, u would know how to do it yourself

1 Like

@Frazzle btw i was eating these the other day

SX342

have u heard of esx? its like vrp but 10 times better just look at ttheir github
https://github.com/ESX-Org