Jump to content

[HELP] Arrest system


joaosilva099

Recommended Posts

Posted

Example:

client only

  
function arrestPlayer(criminal, cop) 
     attachElements(criminal, cop) 
     setElementFrozen(criminal, true) 
     setElementCollidableWith(criminal, cop, false) 
     setElementCollidableWith(cop, criminal, false) 
end 
  

Posted (edited)

If you use attachElements then it will simply attach the element to player. Nothing more. Criminal won't follow the cop. So to make it right, you must use

setControlState 

This is how you're gonna use it.

  
  
  
local function Follow(criminal,cop )  
if cop and criminal and isElement ( cop ) and isElement ( criminal ) then 
local ax,ay,az= getElementPosition ( cop )  
local jx,jy,jz = getElementPosition ( criminal )  
    local followRotation =  ( 360 - math.deg ( math.atan2 ( (  ax- jx ), ( ay - jy ) ) ) ) % 360 
              setPedRotation (criminal , cop ) --- making the criminal to look at cop  
            --- now we need to make him follow  
local distance = getDistanceBetweenPoints3D( ax,ay,az,jx,jy,jz ) 
if distance > 0.8 then  
local WhatToDo = math.random (1,5)  
if WhatToDo == 1 then  
  
  setControlState ( criminal, "forwards", true)  
    setTimer (  
    function (criminal)  
         if isElement ( criminal ) then 
           setControlState ( criminal, "forwards", false)  
         end  
             end, 2000, 1, criminal ) 
  
   elseif WhatToDo == 3 then  
  setControlState ( criminal, "jump", true )  
    setTimer (  
    function (criminal)  
         if  isElement ( criminal ) then 
           setControlState ( criminal, "jump", false)  
         end  
             end, 2000, 1, criminal ) 
         
end  
     end 
      
     local data = getElementData(criminal,"follow" ) or false 
     if data  == true then  
        setTimer (  Follow,3000,1,criminal,cop  )  
        end 
           end 
              end 
               
--------- USAGE 
local criminal =   --- define criminal 
toggleAllControls (criminal,false,false,false)  
--enable all controls which we disabled  
setElementData(criminal,"follow",true ) 
local cop =  --- define cop 
Follow ( criminal, cop ) --- now call the function 
  

now once you call the function then you don't need to call it again

because the timer will keep repeating, if you want to stop criminal from following the ped then use this

then simply use an element data

  
local criminal =   ---- define criminal  
toggleAllControls (criminal,true) --- enable all controls which we disabled  
setElementData(criminal,"follow",nil ) -- this will stop the criminal from following the cop 
  

NOT TESTED. This is just an example.

Edited by Guest
Posted
I dont testes yet but i think it should be
setPedRotation(criminal, followRotation) 

Instead of criminal, cop no?

AnD why use math.Random?

Yes, sorry for typo.

  
      setPedRotation (criminal , followRotation )  

We are using math.random cause we also want the player to jump because sometimes the player is in water and he can't get out of it.

Posted
Aah OK. Can i try to improve the script by adding ifs to check if is in Walter AMD other situations?

Yes but you never know when the player gets stuck so he has to jump. :P

Posted
i will put if the distance betwen cop aand crim is bigger than 5 then setElementPosition(crim, copx, copy, copz) do u agree?

Well depends on you but anyone who joins your server will think that if player ( criminal ) is lagging.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...