Home   Help Search Login Register  

Author Topic: Follow Script For Land Vehicles And Choppers  (Read 1949 times)

0 Members and 1 Guest are viewing this topic.

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
Follow Script For Land Vehicles And Choppers
« on: 01 Aug 2009, 15:45:04 »
This is a script :yes: and not a function :no:......
I wrote it yesterday as i got the idea just yesterday......i found it quite useful with my mission :cool2:
Not sure it will serve you good or bad....... :dunno:
As this is OFP,,i think you don't have much to worry about lag....no lag occured for me.........

Just beta testing................... :whistle:


Quote
?(_follower==player) or not (alive follower) : exit
_follower=_this select 0;
_target=_this select 1;
_meters=_this select 2;
_behaviour=_this select 3;
_mode=_this select 4;
_duration=_this select 5;
_unlimited=_this select 6;

;_follower follows _target
;_meters determine the distance at which _follower will stop from _target
;if _meters is +5 ("+" not needed),_follower will stop at 5 meters ;behind _target when _target is ;stopped,and _follower should follow ;_targetfrom 5 meters behind it.....
;when _unlimited is set to 1,_duration is NOT considered
;_unlimited must not exceed 1 or the script will exit and any number lower than 1 is considered 0
;the script exits if _unlimited is set to -1/-2 or so...
;if _duration is 60,the car will follow _target for 60 seconds
;behaviour is either "safe","aware","combat",or "stealth"
;mode is either "limited","normal",or "full" (don't forget to put quotes!)



_follower setbehaviour _behaviour
_follower setspeedmode _mode
_seconds=0

#checker
;----------------------
?_duration < 0 : exit
? _unlimited < 0 : exit
? _unlimited > 1 : exit
? _unlimited == 1 : goto "startfollowing"
? ! (alive _follower) : exit
? (_follower==player) : exit
?(_seconds > _duration) : goto "stopfollowing"
_seconds=_seconds + 1
;-------------------------------------------------------------------------------------
#startfollowing
;---------------------------
_follower domove [(getpos _target select 0)+(_meters),(getpos _target select 1),0]
~1

goto "checker"
;checker checks all the conditions to make follower follow,if one of them gone wrong,the follower no ;longer follows the target
;------------------------------------------------------------------------------
#stopfollowing
;--------------
_follower domove getpos _follower
exit

This script works perfect for me,especially when making a chopper follow another chopper.....

Syntax = [name of follower, name of to be followed, meters to follow behind or infront of target, behaviour of follower, speedmode of follower, seconds to follow, permenantly follow ]

NOTE : The script will exit immediately if the follower is PLAYER or the follower is not alive.....
          The script don't count on _duration if _unlimited is set to 1,but you still need to type a number to _duration (like 0 or something).........NOT < 0
« Last Edit: 02 Aug 2009, 12:14:14 by haroon1992 »
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(

Walter_E_Kurtz

  • Guest
Re: Follow Script For Land Vehicles And Choppers
« Reply #1 on: 01 Aug 2009, 16:52:01 »
1. Your message got cut off in the note.

2. It's not really following, as the follower aims to remain however many metres east of his target:
_follower domove [(getpos _target select 0)+(_meters),(getpos _target select 1),0]

You should use getDir on the target. Then you need to use trigonometry to apply the _metres correctly to each axis:
Code: [Select]
_bearing = getDir _target
_follower domove [(getpos _target select 0) - (_meters * (sin _bearing)), (getpos _target select 1) - (_meters * (cos _bearing)), 0]

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
Re: Follow Script For Land Vehicles And Choppers
« Reply #2 on: 02 Aug 2009, 12:10:40 »
I am not really good at trigonometry!
Have you tested this script ?

Yes,the follower sometimes don't follow that target exactly with the given meters but it followed it some how and it will follow behind the target(straight behind!)

I have tested it with OFP:CWC 1.3 and its definitely working.......
But as this is a beta test....i meant not to give anyone my script but to get some ideas from ones like you
So thanks you........
Anyway ,.i have no idea how to use Trigonometry :confused:
« Last Edit: 02 Aug 2009, 12:29:34 by haroon1992 »
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Follow Script For Land Vehicles And Choppers
« Reply #3 on: 02 Aug 2009, 23:33:00 »
You might add there a :
Code: [Select]
? !canMove _follower : exit

You might also enjoy with this (a bit brutal following way :D )

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
Re: Follow Script For Land Vehicles And Choppers
« Reply #4 on: 03 Aug 2009, 15:44:15 »
@Mandoble

I've already downloaded your chaser a few weeks ago,
but i am not satisfied with using other's scripts,(i always develop my own scripts and got my own errors :D)
(i saw the things about .sqf but it seems i have to practice a lot so i just remained with .sqs things as they are easy and i think they work faster in small amounts,also they save time)

But as you know,i am not an expert like you in scripting,i just wonder whether this script needs improvements or so.....

Haroon1992.................
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(