OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: haroon1992 on 14 Jul 2009, 14:07:40

Title: House Patrol Script (need help!)(arma scripts)
Post by: haroon1992 on 14 Jul 2009, 14:07:40
Can someone convert the following to .sqf format(version) :D
I indeed need that format because .sqs is annoying the fps when over 20 of that scripts was used in a single mission!
Code: [Select]
#loop
tourguide setbehaviour "safe"
tourguide setspeedmode "limited"
{_x domove getpos (hotel1 buildingpos random 256)} foreach units travellers;
~15
?!(alive tourguide):hint "The tourguide is dead";exit
?tourguide distance helipad1 > 25 :goto "loop"

tourguide=name of the leader of the group "travellers"

helipad1=used an invisilbe helipad.(script will continue looping if tourguide is more than 25 meters far away from helipad1

hotel1=name of the hotel (get this by using "hotel1=nearestbuilding gamelogic1")

This script makes the group of travellers to roam in the hotel.
The hotel has 256 max available pos for the roamers so you will get a complete active hotel. :)
Just need to know that it can be converted to .sqf or not?? ???
Title: Re: House Patrol Script (need help!)(arma scripts)
Post by: Luke on 08 Aug 2009, 18:15:36
Here ya go!!

Code: [Select]
_dist = tourguide distance helipad1;
while {((tourguide distance helipad1) < 25)&&(alive tourguide)} do
   {
   tourguide setbehaviour "safe";
   tourguide setspeedmode "limited";
   {_x domove getpos (hotel1 buildingpos random 256)} foreach units travellers;
   sleep 15;
   };

Hope that helps!

Luke
Title: Re: House Patrol Script (need help!)(arma scripts)
Post by: haroon1992 on 09 Aug 2009, 07:02:19
Thank you for the help!.....
Long time no reply....! hUh....!
At least i got it now!

Thank you :clap:
Title: Re: House Patrol Script (need help!)(arma scripts)
Post by: savedbygrace on 09 Aug 2009, 14:55:24
Just for the sake of my sanity,( I am not very comfortable with SQF either) but shouldn't the local variable "_dist" replace the full line of text inside the braces on the second line? Otherise, why declare that variable? Just trying to understand is all.
Example:
Code: [Select]
while {((_dist) < 25)&&(alive tourguide)} do
Title: Re: House Patrol Script (need help!)(arma scripts)
Post by: Worldeater on 09 Aug 2009, 17:56:12
No. The loop would check an outdated value on every iteration. The only purpose of _dist is to confuse you... :)
Title: Re: House Patrol Script (need help!)(arma scripts)
Post by: Luke on 10 Aug 2009, 00:19:48
{S}houldn't the local variable "_dist" replace the full line of text inside the braces on the second line? Otherise, why declare that variable? Just trying to understand is all.

No. The loop would check an outdated value on every iteration. The only purpose of _dist is to confuse you... :)

Nice, WE!  :D

No, Grace is right, my bad.

New Script:
Code: [Select]
_dist = tourguide distance helipad1;
while {(_dist < 25)&&(alive tourguide)} do
   {
   tourguide setbehaviour "safe";
   tourguide setspeedmode "limited";
   {_x domove getpos (hotel1 buildingpos random 256)} foreach units travellers;
   _dist = tourguide distance helipad1;
   sleep 15;
   };

Sorry about that!

Luke
Title: Re: House Patrol Script (need help!)(arma scripts)
Post by: haroon1992 on 10 Aug 2009, 11:38:37
Yes , i have got the correct one,,,,but how do i call that from the game?

script=[] exec "housepatrol.sqf" , is this right ?
Or
script = [] execVM "housepatrol.sqf"?????
Title: Re: House Patrol Script (need help!)(arma scripts)
Post by: savedbygrace on 10 Aug 2009, 11:45:55
I believe the latter one for sqf.

@Luke
Thanks for clearing that up Luke.

@Worldeater
What are you refering to when you say outdated value? A condition satisfied already?
Title: Re: House Patrol Script (need help!)(arma scripts)
Post by: Luke on 11 Aug 2009, 05:44:28
Yes , i have got the correct one,,,,but how do i call that from the game?

That might require some modification to the script,
at least, in my eyes.

All right One Final Effort (http://www.youtube.com/watch?v=fX63z4acmUo&annotation_id=annotation_370279&feature=iv). (Because its so uplifting)

Code: (Housepatrol.sqf) [Select]
tourguide= _this select 0;
helipad1 = _this select 1;
hotel1 = _this select 2;
travellers = _this select 3;

_dist = tourguide distance helipad1;
while {(_dist < 25)&&(alive tourguide)} do
   {
   tourguide setbehaviour "safe";
   tourguide setspeedmode "limited";
   {_x domove getpos (hotel1 buildingpos random 256)} foreach units travellers;
   _dist = tourguide distance helipad1;
   sleep 15;
   };


Can be called in one of the two following ways;
[tourguide, helipad1, hotel1, travellers] execvm "Housepatrol.sqf";

or if you want specific units in the group 'travellers' rather than a set group use this:
[tourguide, helipad1, hotel1, [traveller1, traveller2, ... travellerN]] execvm "Housepatrol.sqf";

Where traveller1 through travellerN are the names of individual.

So if Dan and Dave are the travellers then:
[tourguide, helipad1, hotel1, [Dan, Dave]] execvm "Housepatrol.sqf";

or if its Dan, Dave, & Phil then:
[tourguide, helipad1, hotel1, [Dan, Dave, Phil]] execvm "Housepatrol.sqf";

Hope this helps.

Luke
Title: Re: House Patrol Script (need help!)(arma scripts)
Post by: Worldeater on 11 Aug 2009, 08:33:42
What are you refering to when you say outdated value? A condition satisfied already?

No, the value of _dist would not have been updated. So the script would have used the initial(!) distance for the check until the end of the mission. Luke's current version almost solves this problem:
Quote
   ...
   _dist = tourguide distance helipad1;
   sleep 15;
   };
In this version the value of _dist is updated regularly. The problem is that the value in _dist is still 15s old when while checks it. ;)

To solve this you could switch the bold line and the sleep (so _dist is updated right before while checks it again). But if you do this and look at the code again then you might realize that all this _dist stuff looks pretty confusing and that the first while construct (http://www.ofpec.com/forum/index.php?topic=33734.msg233486#msg233486) was the most readable... :)
Title: Re: House Patrol Script (need help!)(arma scripts)
Post by: haroon1992 on 11 Aug 2009, 16:06:12
Thank all of you for the replies....but i saw something like PRELOADING the .sqf script or STORING it in the CACHE before use
Is this done automatically? Or do i need something to do that?
I've seen many examples,including Mr.Murray's and got confused by what they mean!  :weeping:


Title: Re: House Patrol Script (need help!)(arma scripts)
Post by: Luke on 11 Aug 2009, 17:39:47
No, the value of _dist would not have been updated. So the script would have used the initial(!) distance for the check until the end of the mission. Luke's current version almost solves this problem:
Quote
   ...
   _dist = tourguide distance helipad1;
   sleep 15;
   };
In this version the value of _dist is updated regularly. The problem is that the value in _dist is still 15s old when while checks it. ;)

Good God, You're Right!

Oops. :dry:

Sorry! :whistle:

Code: (housepatrol.sqf) [Select]
]
tourguide= _this select 0;
helipad1 = _this select 1;
hotel1 = _this select 2;
travellers = _this select 3;

_dist = tourguide distance helipad1;
while {(_dist < 25)&&(alive tourguide)} do
   {
   tourguide setbehaviour "safe";
   tourguide setspeedmode "limited";
   {_x domove getpos (hotel1 buildingpos random 256)} foreach units travellers;
   _dist = tourguide distance helipad1;
   sleep 1;
   };

Thanks for catching that.

Luke
Title: Re: House Patrol Script (need help!)(arma scripts)
Post by: haroon1992 on 07 Sep 2009, 13:22:47
Sorry for replying so lately [I may be even digging my old - thread! :D]

When its :
sleep 1;
Then how do i make the unit wait for a random time(eg  ~2 +random 10)in .sqf???
And also, can loops be created with .sqf?

And this may be a little OFFTOPIC :

 ???what is :
private ["_thisisone","_thisistwo","_thisisthree"]
Is that used to define the local variables?
Also,I don't see them in your script????
Haroon1992..........