joaosilva099 Posted September 19, 2014 Share Posted September 19, 2014 Hi all.I am making my own cop arrest system. I know how to do it but w en the criminal get arrested what should i use to force im to fpllow the cop? attachElements ?? Help me pls Link to comment
Anubhav Posted September 19, 2014 Share Posted September 19, 2014 Instead of following cop, you can attach the elements and make them collidable by using setElementCollidableWith. Link to comment
joaosilva099 Posted September 19, 2014 Author Share Posted September 19, 2014 Im not understanding u. Can u explain better? Or example Link to comment
Anubhav Posted September 19, 2014 Share Posted September 19, 2014 Example: client only function arrestPlayer(criminal, cop) attachElements(criminal, cop) setElementFrozen(criminal, true) setElementCollidableWith(criminal, cop, false) setElementCollidableWith(cop, criminal, false) end Link to comment
Saml1er Posted September 19, 2014 Share Posted September 19, 2014 (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 September 20, 2014 by Guest Link to comment
joaosilva099 Posted September 20, 2014 Author Share Posted September 20, 2014 I dont testes yet but i think it should be setPedRotation(criminal, followRotation) Instead of criminal, cop no? AnD why use math.Random? Link to comment
Saml1er Posted September 20, 2014 Share Posted September 20, 2014 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. Link to comment
joaosilva099 Posted September 20, 2014 Author Share Posted September 20, 2014 Aah OK. Can i try to improve the script by adding ifs to check if is in Walter AMD other situations? Link to comment
Saml1er Posted September 21, 2014 Share Posted September 21, 2014 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. Link to comment
joaosilva099 Posted September 21, 2014 Author Share Posted September 21, 2014 i will put if the distance betwen cop aand crim is bigger than 5 then setElementPosition(crim, copx, copy, copz) do u agree? Link to comment
Saml1er Posted September 21, 2014 Share Posted September 21, 2014 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. 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