PDA

View Full Version : Randomwatch for searchlights



Blanco
Dec 26 2006, 17:05
Hi, I always wanted a searchglight in OFP and I'm pleased we got a full working example in Arma. Thx BIS.

I've wrote a simple watchscript for the searchlight.

- slow moving to make it realistic. clockwise & counterclockwise
- random bearing
- random pitch (min 2m, max 45m above sealevel, we don't want him to spot planes)
- Searchlight stays on when the "gunner" got killed, but turns out when the lens got shot.

Here it is :


Quote[/b] ]
;watch script for searchlights 0.2
;written by Blanco


_unit = _this select 0
_dis = 200

#loop
?!alive _unit : exit
_dir = random 360

_steps = random 350 + 10
_steps = _steps - _steps %1
;hint format ["Dir is %1 in %2 steps",_dir,_steps]

~2
;hint "Heading for a new direction"
_x = 0
_i = -1

_maxheight = 45
_minheight = 2

_inc = -0.2

_height = (2 + random 43)
;hint format ["height = %1",_height]
~1
?random 2 < 1 : _i = 1
?random 2 < 1 : _inc = 0.2

#steps

?&#33;alive gunner _unit : goto "unitdied"
_dir = _dir + _i

?_dir < 0: _dir = _dir +360
?_dir > 360: _dir = _dir -360


_upos = getpos _unit
_cposx = _upos select 0
_cposy = _upos select 1
_cposz = _upos select 2

_height = (_height - _inc)

?(_height > _maxheight) : _inc = 0.2
?(_height < _minheight) : _inc = -0.2

?alive _unit : _unit doWatch [_cposx + ((sin _dir) * _dis), _cposy + ((cos _dir) * _dis),(_height - _inc)]

;hint format ["Direction is %1&#92;n%2 Steps to go&#92;nHeight is %3",_dir,_steps,(_height - _inc)]

~0.2
_steps = _steps - 1

?_steps > 0 : goto "steps"
goto "loop"

#unitdied
;hint "unitdied"
_gl = "logic" createvehicle [0,0,0]
_gl moveingunner _unit
@<hidden>&#33;alive _unit
deletevehicle _gl
exit


Run it with :


Quote[/b] ] [name of the searchlight] exec "randomwatch.sqs"

You may also put the searchlight in a tower with this line in the initialisation field of the searchlight


Quote[/b] ] this setpos [(getpos this select 0),(getpos this select 1),3.8]

3.8 is the height, adjust it when necessary

Here&#39;s a demomission : http://rapidshare.com/files/9033990/Searchlight_watch_script.Sara.zip

Hope you like it. http://forums.bistudio.com/oldsmileys/wink_o.gif

Sickboy
Dec 26 2006, 18:36
Heya m8, very nice job, very useful for many ppl...
If you don&#39;t mind me suggesting... I would suggest to write everything in SQF format for ArmA, as that&#39;s the new / optimized way of coding, aswell as that there are preload and process functions etc. etc. Again, only a suggestion m8, nice job either way&#33;

Blanco
Dec 26 2006, 19:02
I have to learn that stuff first, I&#39;m not familiar with sqf.
Any good tutorials around yet?
Or can someone convert my script into the new format so I can see how it&#39;s done?

Glad you like it.

Sickboy
Dec 26 2006, 19:10
I have to learn that stuff first, I&#39;m not familiar with sqf.
Any good tutorials around yet?
Or can someone convert my script into the new format so I can see how it&#39;s done?

Glad you like it.
Based on my current knowledge http://forums.bistudio.com/oldsmileys/biggrin_o.gif:
Basicly, every line that&#39;s not comment, the returning result of a function or the opening of a while, if, etc, needs a ; at the end.
@<hidden> is replaced by waituntil{...};
~.. is replaced by sleep ..;
;... comment is replaced by // ... comment
? ... : ... is replaced by if (...) then { .. }; and you can use else, this will be ran when the first condition=false instead of true: if (...) then { .. } else { .. };
goto ".." and #.. is replaced by while {..} do { .. }; together with if and else you can recreate the same loop possibilities as before but probably more efficient&#33;
Switch is also awesome to use, More info about Control Structures (http://community.bistudio.com/wiki/switch)
You need to define the used private (not global) variables by: private ["_var1","_var2","_var3"]; you do not have to define _this as that&#39;s always private.
Instead of running scripts with exec you need to use execVM if you wish to run SQF scripts...


Functions work the same as scripts, altough you call the functions instead of execVM them:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">randomInt = compile preprocessfile &#34;functions&#92;randomint.sqf&#34;;[/QUOTE]
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_i = &#91;1,5&#93; call RandomInt;[/QUOTE]
The difference between scripts (execVM/Spawn) and functions (call) is that scripts can be running parallel, while a function (call) is first completing the function and is usually receiving a returned value, before it continues the script in which you called the function. So you can load different variables in your script, with the output of different functions called with their own parameters. Or the function could just run some code without returned value, while the script will wait for it to complete before continueing the script.


What I do is preload the used scripts into variables (like functions):
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">six_scr_misinit = compile preprocessFile &#34;scripts&#92;misinit.sqf&#34;;[/QUOTE]
And then when I need the script, I spawn it (as with functions you would call them):
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">&#91;&#93; spawn six_scr_misinit;[/QUOTE]
The main reason I use this personally, is that the scripts are all compiled and loaded before, and you can keep spawning them as many times as you want without the game reloading the script every single time from file, plus that you find problems with the scripts(syntax) right away as they are processed at the start.

You can of coarse preload and spawn things only nececairy for lets say client or server, by creating a gamelogic that&#39;s named server (which could actually be named anything), by testing if it&#39;s local: if(local server) then { .1. } else { .2. }; if the script is ran on the server, it will run the code at 1, and if it&#39;s ran on the client it will run the code at 2.

Loaded functions/scripts are global if they are loaded in global variables (without _ in front of them), as such you can initiate (most of) them at the start in init.sqs etc, while using them throughout any script. While more specific scripts or functions can be loaded later, when they are needed.

OFPEC has loads of functions in SQF, so you could have a look there and see if there is smth you can use as a base to understand the syntax. http://www.ofpec.com/ed_depot/functions.php The BIS Community WIKI also has some SQF scripting basics afaik: http://community.bistudio.com


If you don&#39;t get it converted somehow, just let me know, if I got some spare time here and there I will convert it as an example for you http://forums.bistudio.com/oldsmileys/smile_o.gif


Examples: (BTW the forum messes up the tabs etc, so they are replaced by spaces)
While and waituntil (this script waits for six_bc to become true, then puts it back to false, executes some code, and then waits again till six_bc = true, until a certain condition is met and then _run is set to false and as such ends the loop):<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">///////////////////////////////////////////////////////////
// ArmA - loop_cl.sqf by Sickboy &#40;sb_at_6thSense.eu&#41;
///////////////////////////////////////////////////////////
private &#91;&#34;_run&#34;,&#34;_obj1f&#34;,&#34;_obj2f&#34;,&#34;_obj3f&#34;,&#34;obj4f&#34;&#93;;
_obj1f=false; _obj2f=false; _obj3f=false; _obj4f=false;
_run = true;
while{_run} do
{
waitUntil {six_bc};
six_bc = false;
if&#40;overcast &#33;= six_overcast&#41; then { 0 setOvercast six_overcast };
if&#40;fog &#33;= six_fog&#41; then { 0 setFog six_fog };
if&#40;six_daci&#41; then
{
if&#40;six_obj1act && six_obj1d && &#33;_obj1f&#41; then { _obj1f=true; hint &#34;Objective 1&#58; Done&#34; };
if&#40;six_obj2act && six_obj2d && &#33;_obj2f&#41; then { _obj2f=true; hint &#34;Objective 2&#58; Done&#34; };
if&#40;six_obj3act && six_obj3d && &#33;_obj3f&#41; then { _obj3f=true; hint &#34;Objective 3&#58; Done&#34; };
if&#40;six_obj4act && six_obj4d && &#33;_obj4f&#41; then { _obj4f=true; hint &#34;Objective 4&#58; Done&#34; };
if&#40;six_obj1d && six_obj2d && six_obj3d && six_obj4d&#41; then { &#34;outro&#34; spawn six_scr_cam; _run = false};
};
};[/QUOTE]

A function, for returning valid players (Alive and not null) as an array of objects, from an array of strings. I define all the possible players=["s1","s2","s3"....] and use a script loop that uses this function to update a currentplayer array according to current alive and valid players, and possibly added players through JIP:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">///////////////////////////////////////////////////////////
// ArmA - fnPlayers.sqf by Sickboy &#40;sb_at_6thSense.eu&#41;
// Input - Array with players as strings
// Output - Array with alive players as objects
///////////////////////////////////////////////////////////
private &#91;&#34;_y&#34;,&#34;_f&#34;,&#34;_r&#34;&#93;;
_r = &#91;&#93;;
{
_y = call compile _x; _f = format&#91;&#34;%1&#34;,_y&#93;;
if &#40;&#40;_f &#33;= &#34;scalar bool array string 0xe0ffffef&#34;&#41; && &#40;_f &#33;= &#34;&#60;NULL-object&#62;&#34;&#41;&#41; then{if &#40;alive _y&#41; then { _r = _r + &#91;_y&#93; }};
} foreach _this;
_r[/QUOTE]

Blanco
Dec 26 2006, 23:05
Thx, but I need time to understand the new syntax. It&#39;s still Chinese for me.
I&#39;m kind of familiar with if, then & else statements but while, do, from, switch are new to me.

I &#39;ve started with OFP scripting without any scripting knowledge, except for a little BASIC from school. I&#39;ve learned a lot by watching other people&#39;s scripts.
I extracted the whole ArmA campaign and I couldn&#39;t find one sqf script. At this moment I can&#39;t even make the examples on the wiki work...

Sickboy
Dec 27 2006, 11:08
Well, how do you think most of us learned? I haven&#39;t had a single computer lesson in my whole life, altough I have been busy with computers at home since I was 10 http://forums.bistudio.com/oldsmileys/smile_o.gif)

This is the converted script... I did not try it yet, as that needs to wait until at least tonight... but it should work, might even use some optimizations here.. Kegetys posted some nice examples of how to use breakout and breakto... I might update if I feel like it http://forums.bistudio.com/oldsmileys/smile_o.gif

Remember, you must use execVM to run it, or if you preprocessed it into a variable, Spawn.

Again... the forum messes my tabs, so I replaced tabs by spaces http://forums.bistudio.com/oldsmileys/smile_o.gif
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">//watch script for searchlights 0.2
//written by Blanco
//converted to SQF by Sickboy &#40;sb_at_6thSense.eu&#41;
private &#91;&#34;_run&#34;,&#34;_unit&#34;,&#34;_dis&#34;,&#34;_steps&#34;,&#34;_x&#34;,&#34;_i&#34;,&#34;_maxheight&#34;,&#34;_minheight&#34;,&#34;_inc&#34;,&#34;_height&#34;,&#34;_upos&#34;,&#34;_cposx&#34;,&#34;_cposy&#34;,&#34;_cposz&#34;&#93;;
_unit = _this select 0;
_dis = 200;

_run = true;
while{_run} do
{
    if &#40;not alive _unit&#41; then
    {
         _run = false;
    } else {
         _dir = random 360;
         _steps = random 350 + 10;
         _steps = _steps - _steps %1;
         //hint format &#91;&#34;Dir is %1 in %2 steps&#34;,_dir,_steps&#93;;
         sleep 2;
         //hint &#34;Heading for a new direction&#34;;
         _x = 0;
         _i = -1;
         _maxheight = 45;
         _minheight = 2;
         _inc = -0.2;
         _height = &#40;2 + random 43&#41;;
         //hint format &#91;&#34;height = %1&#34;,_height&#93;;
         sleep 1;
         if &#40;random 2 &#60; 1&#41; then { _i = 1; _inc = 0.2 };
         while{_steps &#62; 0} do
         {
              if&#40;not alive gunner _unit&#41; then
              {
                   _run = false;
              } else {
                   _upos = getpos _unit; _cposx = _upos select 0; _cposy = _upos select 1;     _cposz = _upos select 2; _height = &#40;_height - _inc&#41;;
                   _dir = _dir + _i;
                   if&#40;_dir &#60; 0&#41; then { _dir = _dir + 360 };
                   if&#40;_dir &#62; 360&#41; then { _dir = _dir - 360 };
                   if&#40;_height &#62; _maxheight&#41; then { _inc = 0.2 };
                   if&#40;_height &#60; _minheight&#41; then { _inc = -0.2 };
                   if&#40;alive _unit&#41; then { _unit doWatch &#91;_cposx + &#40;&#40;sin _dir&#41; * _dis&#41;, _cposy + &#40;&#40;cos _dir&#41; * _dis&#41;,&#40;_height - _inc&#41;&#93; };
                   //hint format &#91;&#34;Direction is %1&#92;n%2 Steps to go&#92;nHeight is %3&#34;,_dir,_steps,&#40;_height - _inc&#41;&#93;;
                   _steps = _steps - 1;
                   sleep 0.2;
              };
         };
    };
};

//hint &#34;unitdied&#34;;
if&#40;alive _unit&#41; then
{
    _gl = &#34;logic&#34; createvehicle &#91;0,0,0&#93;;
    _gl moveingunner _unit;
    waituntil{not alive _unit};
    deletevehicle _gl;
};
[/QUOTE]

redface
Dec 27 2006, 12:28
terrific script Blanco&#33;

this converts one of your many pioneering OFP scripts (need I recall e.g. LogicCam to anyone?) to Armed Assault http://forums.bistudio.com/oldsmileys/notworthy.gif

MattXR
Dec 27 2006, 12:28
Sickboy how do i get it to work in the editor it never lets me run

[this] execVM "script.sqf" or any other way?? how can i get it to work http://forums.bistudio.com/oldsmileys/wink_o.gif

Sickboy
Dec 27 2006, 12:31
Sickboy how do i get it to work in the editor it never lets me run

[this] execVM "script.sqf" or any other way?? how can i get it to work  http://forums.bistudio.com/oldsmileys/wink_o.gif
Do you get some kind of error while you try to run it like that?
I usually load everything in my scripts and use the init fields etc as less as possible, but just give names to all the objects I wish to use in scripts.

Please post the contents of script.sqf (if it isn&#39;t the sqf that I posted above) if you had an error.
I think I read somewhere that "call" could not be used in the mission editor, but afaik execVM should work just as fine as exec..
Just checked, im actually using an execVM in the onActivation of a trigger for displaying some debug info, and that at least works, now im not sure about the init fields...

Blanco
Dec 27 2006, 19:12
Thx, sickboy. It all looks so obvious when I see the conversion, it definitly helps me to understand the syntax.

I did some tests with enemy AI and it seems that AI tries to kill the gamelogic when the original gunner got killed; Good luck http://forums.bistudio.com/oldsmileys/wink_o.gif

I had to add a _gl setcaptive true line at the end to prevent this and I was really suprised it worked. (afaik see)
I always thought Setcaptive had no effect on gamelogics but it seems it does.

@<hidden> : I already tried logiccam and It doesn&#39;t seems to work anymore in ArmA,I dunno why.

Blanco
Dec 28 2006, 14:23
I tried you conversion Sickboy and it doesn&#39;t work or I don&#39;t know how to run it.

I&#39;ve made an init with


Quote[/b] ]
watchscript=compile preprocessfile "watch.sqf";
sleep 1;
[SL1] call watchscript;

That gave me an error.
http://img.photobucket.com/albums/v228/blanco2/CAtafgan/error.jpg

Then I tried it via execVM...


Quote[/b] ][SL1] execVM "watch.sqf"
or

Quote[/b] ]SL1 execVM "watch.sqf"

No succes...
Can you tell me how to run this, cause I don&#39;t have a clue...

How can I use parameters? Same way as in sqs scripts?

Sickboy
Dec 28 2006, 14:26
...
Please share the error, as that will help me understand what&#39;s wrong http://forums.bistudio.com/oldsmileys/smile_o.gif)

I can take a look tonight if we don&#39;t get it debugged by the error report. You can read your errors back in your arma.rpt folder in %USERPROFILE%&#92;local settings&#92;application data&#92;arma
%USERPROFILE% is usually C:&#92;Documents and Settings&#92;yourname

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">watchscript=compile preprocessfile &#34;watch.sqf&#34;;
sleep 1;
&#91;SL1&#93; call watchscript;[/QUOTE]
is wrong, as it is no function, in this case you should use spawn:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">watchscript=compile preprocessfile &#34;watch.sqf&#34;;
sleep 1;
&#91;SL1&#93; spawn watchscript;[/QUOTE]

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">&#91;SL1&#93; execVM &#34;watch.sqf&#34;[/QUOTE]
Is fine

Blanco
Dec 28 2006, 14:42
the error (http://img.photobucket.com/albums/v228/blanco2/CAtafgan/error.jpg)

here&#39;s what I found in that rpt file


Quote[/b] ]
if (not alive _unit) th>
Error position: <while{_run} do
{
if (not alive _unit) th>
Error Missing ;
Error in expression <this select 0;
_dis = 200;

_run = true
while{_run} do


When I run it with [SL1] execVM "watch.sqf" I got :
type script expected nothing, i&#39;m not allowed to press the ok button.

Sickboy
Dec 28 2006, 14:44
When I run it with [SL1] execVM "watch.sqf" I got :
type script expected nothing, i&#39;m not allowed to press the ok button.Try with: dummy=[SL1] execVM "watch.sqf"   dummy can be anything. (thanks to raedor for the tip), altough I prefer using the loading of the script in a variable and spawning it, especially handy/optimized when using multiple search lights&#33; Will check error and update in a sec...

update: _run = true was missing ; so: _run = true;

Blanco
Dec 28 2006, 15:01
huh..in what line? The 9th?

Sickboy
Dec 28 2006, 15:20
huh..in what line? The 9th?
yes, I already updated my post with the fix aswell
im gonna take a look at the script within a mission, brb will update

Blanco
Dec 28 2006, 15:59
Ok, take your time, no need to hurry http://forums.bistudio.com/oldsmileys/wink_o.gif

BadAss [Mapfact.net]
Dec 28 2006, 18:30
I&#39;m sorry if i&#39;m messing up your efforts.

But I&#39;ve experienced or suffered some strange behaviour with my own searchlight script. What I wanted to do is a script to let your guard search a defined angle. The script looks just like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">comment &#34;Script by BadAss, Feel free to use and modify
visit www.mapfact.net and www.mapfact.net/forum_arma
contact&#58; badass@<hidden>&#34;;

private&#91;&#34;_sl&#34;,&#34;_ang&#34;,&#34;_del&#34;,&#34;_dir&#34;,&#34;_dirneg&#34;,&#34;_dirpos&#34;&#93;;

_sl=_this select 0;
_ang=_this select 1;
_del=_this select 2;

_dir=getDir _sl;_dirneg=_dir-_ang/2;_dirpos=_dir+_ang/2;

while {alive gunner _sl} do
{
while {&#40;alive gunner _sl&#41;&&&#40;_dir&#62;_dirneg&#41;} do
{
_dir=_dir - 1;
_sl setDir _dir;gunner _sl setFormDir _dir;
sleep _del;
};

sleep &#40;_del*5&#41;;

while {&#40;alive gunner _sl&#41;&&&#40;_dir&#60;_dirpos&#41;} do
{
_dir=_dir + 1;
_sl setDir _dir;gunner _sl setFormDir _dir;
sleep _del;
};
};[/QUOTE]

In theory it works pretty okay but - and that&#39;s my pain - not always. In my little test mission only one of three guards is turning his rounds.
The two lazy guards will eventually start when you get near enough - not exactly the way a searchlight is expected to work.

Sometimes the searchlights are nervously twitching at their turning points. I don&#39;t have any clue why. Bad thing: they don&#39;t do it regularily.

Here&#39;s the little testing mission (http://mapfact.net/Material/Betatest/BadAss/MAP_Misc_Searchlight.Intro.rar) that I&#39;ve made.

Any help and ideas are appreciated, so take my thanks in advance.

Sickboy
Dec 28 2006, 18:47
@<hidden> Dec. 28 2006,20:30)]...
Roger, looking at both.

Had to remove MAP_misc from the addon arrays and the map_misc_logic --&#62; just logic http://forums.bistudio.com/oldsmileys/wink_o.gif

BadAss [Mapfact.net]
Dec 28 2006, 18:55
Sorry, you&#39;re right. It&#39;s just because we&#39;re making our first little ArmA ad... erm. Wait and see. http://forums.bistudio.com/oldsmileys/tounge2.gif

And thanks for having a look at it. http://forums.bistudio.com/oldsmileys/smile_o.gif

Sickboy
Dec 28 2006, 19:00
@<hidden> Dec. 28 2006,20:55)]Sorry, you&#39;re right. It&#39;s just because we&#39;re making our first little ArmA ad... erm. Wait and see. http://forums.bistudio.com/oldsmileys/tounge2.gif
As if I didn&#39;t know http://forums.bistudio.com/oldsmileys/tounge2.gif

Still on it, it&#39;s indeed weird, but I have at least found that if you remove the _sl setdir&#39;s the movement is a lot more smooth.

BadAss Update: This seems to work fine&#33;
Tabs replaced by 4x space for [ code ] block, added extra while loop for 10.000x10.000 loops
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">comment &#34;Script by BadAss, Feel free to use and modify
visit www.mapfact.net and www.mapfact.net/forum_arma
contact&#58; badass@<hidden>
Edited by Sickboy &#40;sb_at_6thSense.eu&#41; with dowatch-direction code from Blanco&#34;;

private&#91;&#34;_sl&#34;,&#34;_ang&#34;,&#34;_del&#34;,&#34;_dir&#34;,&#34;_dirneg&#34;,&#34;_dirpos&#34;,&#34;_dis&#34;,&#34;_upos&#34;,&#34;_cposx&#34;,&#34;_cposy&#34;,&#34;_cposz&#34;,&#34;_run&#34;&#93;;

_sl=_this select 0;
_ang=_this select 1;
_del=_this select 2;

_dir=getDir _sl;_dirneg=_dir-_ang/2;_dirpos=_dir+_ang/2;
_dis=200;_upos=getpos _sl; _cposx=_upos select 0; _cposy=_upos select 1; _cposz=_upos select 2;
_run=true;
while {_run} do
{
   while {alive gunner _sl} do
   {
       while {&#40;alive gunner _sl&#41;&&&#40;_dir&#62;_dirneg&#41;} do
       {
           _dir=_dir - 1;
           _sl doWatch &#91;_cposx + &#40;&#40;sin _dir&#41; * _dis&#41;, _cposy + &#40;&#40;cos _dir&#41; * _dis&#41;,_cposz&#93;;
           sleep _del;
       };
       sleep &#40;_del*5&#41;;
       while {&#40;alive gunner _sl&#41;&&&#40;_dir&#60;_dirpos&#41;} do
       {
           _dir=_dir + 1;
           _sl doWatch &#91;_cposx + &#40;&#40;sin _dir&#41; * _dis&#41;, _cposy + &#40;&#40;cos _dir&#41; * _dis&#41;,_cposz&#93;;
           sleep _del;
       };
   };
};[/QUOTE]The problem seems to be an engine bug or by design?? when an unit is turned with setformdir it doesn&#39;t relate properly when ur far away from it :S Can&#39;t do better at the moment http://forums.bistudio.com/oldsmileys/smile_o.gif

Blanco:
When I used the SQF script as I posted it a few posts ago, it works fine when using: dummy=[this] execVM "script.sqf"   in the init line of the light, should also work for you I guess http://forums.bistudio.com/oldsmileys/smile_o.gif

BadAss [Mapfact.net]
Dec 28 2006, 20:28
Great work&#33; Now they&#39;re real guards. Thank you&#33; http://forums.bistudio.com/oldsmileys/biggrin_o.gif I&#39;ve never been into that sin and cos stuff, but i&#39;ll try and see if i get it someday... http://forums.bistudio.com/oldsmileys/tounge2.gif



Btw. maybe you&#39;ve noticed? The searchlight guys are really wearing NVGoggles by default. http://forums.bistudio.com/oldsmileys/huh.gif

raedor
Dec 28 2006, 21:03
@<hidden>: Instead of using (and computing everytime) sin dir and cos dir, check the "similarities" to vectorDir http://forums.bistudio.com/oldsmileys/wink_o.gif

Sickboy
Dec 28 2006, 21:06
@<hidden> Dec. 28 2006,22:28)]Great work&#33; Now they&#39;re real guards. Thank you&#33; http://forums.bistudio.com/oldsmileys/biggrin_o.gif I&#39;ve never been into that sin and cos stuff, but i&#39;ll try and see if i get it someday... http://forums.bistudio.com/oldsmileys/tounge2.gif



Btw. maybe you&#39;ve noticed? The searchlight guys are really wearing NVGoggles by default. http://forums.bistudio.com/oldsmileys/huh.gifNo biggie, and im no star with the cos etc either http://forums.bistudio.com/oldsmileys/smile_o.gif
About the NVG, I actually didn&#39;t notice, was concentrating on getting the stuff fixed asap, share it and get on with my own stuff http://forums.bistudio.com/oldsmileys/biggrin_o.gif but too bad they dont put it down auto http://forums.bistudio.com/oldsmileys/smile_o.gif But I guess you solved that already? http://forums.bistudio.com/oldsmileys/smile_o.gif


@<hidden>: Instead of using (and computing everytime) sin dir and cos dir, check the "similarities" to vectorDir http://forums.bistudio.com/oldsmileys/wink_o.gifThanks for the tip m8&#33; Will take a look at it, but was merely fixing and converting to sqf (for Blanco) without really bothering about the structures or used functions.. That&#39;s for another day http://forums.bistudio.com/oldsmileys/smile_o.gif  http://forums.bistudio.com/oldsmileys/goodnight.gif

BadAss [Mapfact.net]
Dec 28 2006, 21:10
@<hidden>: Instead of using (and computing everytime) sin dir and cos dir, check the "similarities" to vectorDir http://forums.bistudio.com/oldsmileys/wink_o.gif
What would it look like then?



But I guess you solved that already? Just ignored it so far, but why not. Good idea. http://forums.bistudio.com/oldsmileys/wink_o.gif

raedor
Dec 29 2006, 08:56
Here you go. I&#39;m sorry, but the vectorDir solution was not possible (as you have to step the dir). Well, I took vb&#39;s idea to save a lot performance anyway (if you know how a computer computes sin/cos, you know why it saves a lot http://forums.bistudio.com/oldsmileys/tounge2.gif ). I hope the 10.000 while do limit is fixed within the next patch, that&#39;s why I didn&#39;t add more while do&#39;s. I added a new argument for the up/down angle of the searchlight.<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private&#91;&#34;_sl&#34;,&#34;_ang&#34;,&#34;_del&#34;,&#34;_dir&#34;,&#34;_h&#34;,&#34;_dis&#34;,&#34;_px&#34;,&#34;_py&#34;,&#34;_sin&#34;,&#34;_cos&#34;,&#34;_i&#34;,&#34;_c&#34;&#93;;

_sl=_this select 0;
_ang=&#40;_this select 1&#41;/2;
_del=_this select 2;
_h = _this select 3;

_dis = 20;
_py = position _sl;
_px = _py select 0;
_py = _py select 1;

_sin = &#91;&#93;;
_cos = &#91;&#93;;

_dir = direction _sl;

for &#34;_i&#34; from _dir-_ang to _dir+_ang step 1 do
{
_sin = _sin + &#91;&#40;sin _i&#41;*_dis&#93;;
_cos = _cos + &#91;&#40;cos _i&#41;*_dis&#93;;
};

_i = -1;
_c = _ang;

while {true} do
{
while {alive gunner _sl} do
{
_sl doWatch &#91;_px + &#40;_sin select _c&#41;, _py + &#40;_cos select _c&#41;, _h&#93;;
sleep _del;
_c = _c + _i;
if &#40;_c &#60; 0&#41; then
{
_i = 1;
_c = 0;
sleep _del*5;
};
if &#40;_c &#62; 2*_ang&#41; then
{
_i = -1;
_c = 2*_ang;
sleep _del*5;
};
};
};[/QUOTE](I&#39;m sorry for the format, but my tabs are ignored by IB)

BadAss [Mapfact.net]
Dec 29 2006, 09:18
Well then i give it a try. Looks just like we&#39;re gonna get this done this year?&#33; http://forums.bistudio.com/oldsmileys/biggrin_o.gif

Thanks a lot to all&#33; http://forums.bistudio.com/oldsmileys/smile_o.gif


EDIT: I&#39;m getting an error message in line 31.


Quote[/b] ]_sl #doWatch

Type anything?(jede in german), expecting number.



EDIT 2:

Fixed it mysself.  http://forums.bistudio.com/oldsmileys/smile_o.gif

Added the height parameter to the script call and changed line 9-11 from _py = position _sl; to _pos = position _sl; and so on.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private&#91;&#34;_sl&#34;,&#34;_ang&#34;,&#34;_del&#34;,&#34;_dir&#34;,&#34;_h&#34;,&#34;_dis&#34;,&#34;_px&#34;,&#34;_py&#34;,&#34;_sin&#34;,&#34;_cos&#34;,&#34;_i&#34;,&#34;_c&#34;&#93;;

_sl=_this select 0;
_ang=&#40;_this select 1&#41;/2;
_del=_this select 2;
_h = _this select 3;

_dis = 20;
_pos = position _sl;
_px = _pos select 0;
_py = _pos select 1;

_sin = &#91;&#93;;
_cos = &#91;&#93;;

_dir = direction _sl;

for &#34;_i&#34; from _dir-_ang to _dir+_ang step 1 do
{
_sin = _sin + &#91;&#40;sin _i&#41;*_dis&#93;;
_cos = _cos + &#91;&#40;cos _i&#41;*_dis&#93;;
};

_i = -1;
_c = _ang;

while {true} do
{
while {alive gunner _sl} do
{
_sl doWatch &#91;_px + &#40;_sin select _c&#41;, _py + &#40;_cos select _c&#41;, _h&#93;;
sleep _del;
_c = _c + _i;
if &#40;_c &#60; 0&#41; then
{
_i = 1;
_c = 0;
sleep _del*5;
};
if &#40;_c &#62; 2*_ang&#41; then
{
_i = -1;
_c = 2*_ang;
sleep _del*5;
};
};
};[/QUOTE]

Call from you init.sqs (or init.sqf) with:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">searchlight = compile preprocessFile &#34;searchlight .sqf&#34;;
&#91;UnitName,AngleToCover,Delay,Height&#93; spawn searchlight;[/QUOTE]


With the height added by raedor you have excellent AA searchlights if you want to.

So once again, thanks for all your help&#33; http://forums.bistudio.com/oldsmileys/biggrin_o.gif

raedor
Dec 29 2006, 09:42
Huh? It works just fine for me, I&#39;m executing it with<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">dummy=&#91;sl2,180,.1, 5&#93; execVM &#34;MAP_Searchlight.sqf&#34;;[/QUOTE] http://forums.bistudio.com/oldsmileys/wow_o.gif

BadAss [Mapfact.net]
Dec 29 2006, 09:51
Yeah, see my Edit 2. http://forums.bistudio.com/oldsmileys/wink_o.gif


I just didn&#39;t see that you&#39;ve added the height parameter that wasn&#39;t there before... http://forums.bistudio.com/oldsmileys/tounge2.gif

raedor
Dec 29 2006, 09:53
I added a new argument for the up/down angle of the searchlight.
You remember Lester&#39;s sig? http://forums.bistudio.com/oldsmileys/whistle.gif http://forums.bistudio.com/oldsmileys/rofl.gif

Sickboy
Dec 29 2006, 10:00
Sweet&#33; Nice Ones http://forums.bistudio.com/oldsmileys/smile_o.gif

BadAss [Mapfact.net]
Dec 29 2006, 10:02
Allright, i see. just focused on the script not your text. http://forums.bistudio.com/oldsmileys/whistle.gif

Sickboy
Dec 29 2006, 10:05
Was thinking though...
How about a trigger on the map (or an array of detectable units), with somewhere a variable of which side can be detected by the searchlights?
Where it will break the loop and shines the light on their enemies, if they (or nearby enemies?) KnowsAbout anyone of the chosen side or the mentioned array, that would be sweet wouldn&#39;t it? http://forums.bistudio.com/oldsmileys/smile_o.gif

raedor
Dec 29 2006, 12:41
Was thinking though...
How about a trigger on the map (or an array of detectable units), with somewhere a variable of which side can be detected by the searchlights?
Where it will break the loop and shines the light on their enemies, if they (or nearby enemies?) KnowsAbout anyone of the chosen side or the mentioned array, that would be sweet wouldn&#39;t it? http://forums.bistudio.com/oldsmileys/smile_o.gif
It would be, definitely http://forums.bistudio.com/oldsmileys/tounge2.gif




Maybe we can include something like that. http://forums.bistudio.com/oldsmileys/smile_o.gif

Sickboy
Dec 29 2006, 13:15
It would be, definitely http://forums.bistudio.com/oldsmileys/tounge2.gif




Maybe we can include something like that. http://forums.bistudio.com/oldsmileys/smile_o.gif
Well, we can for sure, just let me know if it&#39;s wanted, and if noone else would be working on it, and which timeframe ppl are thinking of needing this for release, and i&#39;ll probably work it out for yah http://forums.bistudio.com/oldsmileys/smile_o.gif

raedor
Dec 29 2006, 16:47
It would be, definitely http://forums.bistudio.com/oldsmileys/tounge2.gif




Maybe we can include something like that. http://forums.bistudio.com/oldsmileys/smile_o.gif
Well, we can for sure, just let me know if it&#39;s wanted, and if noone else would be working on it, and which timeframe ppl are thinking of needing this for release, and i&#39;ll probably work it out for yah http://forums.bistudio.com/oldsmileys/smile_o.gif
BadAss is about to contact you. http://forums.bistudio.com/oldsmileys/wink_o.gif

Blanco
Dec 29 2006, 17:08
Was thinking though...
How about a trigger on the map (or an array of detectable units), with somewhere a variable of which side can be detected by the searchlights?
Where it will break the loop and shines the light on their enemies, if they (or nearby enemies?) KnowsAbout anyone of the chosen side or the mentioned array, that would be sweet wouldn&#39;t it? http://forums.bistudio.com/oldsmileys/smile_o.gif
Yeah, I was thinking the same when I&#39;ve wrote mine.
Even make it possible to detect friendly dead bodies and put them in some sort of known list.
Problem is.. what happens when there&#39;s an object (like a building) between the spotted enemy and the searchlight.
The spotter will follow him but he&#39;s not able to see him.


Why do you need a trigger or array with enemies when there&#39;s a command that finds the nearest enemy from a specific position?
Nearestenemy (http://community.bistudio.com/wiki/findNearestEnemy)
That should create your enemies array automatically.

Never tried that command before, but I think it&#39;s definitely worth a try.

deanosbeano
Dec 29 2006, 20:40
Quote[/b] ]what happens when there&#39;s an object (like a building) between the spotted enemy and the searchlight.
The spotter will follow him but he&#39;s not able to see him.
thats no problem in arma ,just bring the building down lol.
only joking .
i have been working on this but plane and helo spotting. crashdome was helping me earlier and i just saw this thread.
you might wanna try the nearestobjects ,its a fanatastic lil thing,
you can create arrays of helis men buildings etc within a certain range of your light and then deduce from the array ,when using man/air class of course who is enemy and who isnt.myabe create a lil pause at each unit or if its a high risk threat then increase the pause.
btw the nearestobjects is also useful for when the spotlightt is idle too, just send it an array of nearest buildings and it will look at them one by one , you can adjust the height to make it look up and down the building too.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Atw = Nearestobjects &#91;_watcher,&#91;&#34;Building&#34;&#93;,100&#93;[/QUOTE]

hope someone can write some efficient sqf stuff using these commands.i tried to learn from biki ,but alot of the code there gives me problems.

Sickboy
Dec 29 2006, 21:11
...
Gonna let it cross my mind in the weekend... Nice ideas etc&#33; Thanks http://forums.bistudio.com/oldsmileys/smile_o.gif

BadAss [Mapfact.net]
Dec 30 2006, 08:56
Nice ideas for sure. As long it&#39;s adding to the atmosphere or used to make player feel hunted it&#39;s well worth having it. http://forums.bistudio.com/oldsmileys/smile_o.gif


On the other hand this little and easy to implement function could easily turn into a mean ai addon. But before going in too deep i&#39;ld rather suggest to think about it from the in game results of it. I see a lot of script work with tons of exeptions for a rather not measurable result.

- With the OpFor using NVGs it&#39;s rather counterproductive.
- Helos will be &#39;spotted&#39; by ear rather then by sight
- in case you don&#39;t have any AA weapons it doesn&#39;t make sense to light the chopper - that just tells &#39;em where to fire his guns
- in case we&#39;re not talking &#39;bout nightstalkers the choppers might be lit up like x-mas trees - just another exception

- How does the ai react in darkness generally? Do they &#39;see&#39; less? Does light effect them?



I&#39;m not at all trying to discourage someone. Just my experience from my last OFP SP mission...

Sickboy
Dec 30 2006, 10:18
@<hidden> Dec. 30 2006,10:56)]Nice ideas for sure. As long it&#39;s adding to the atmosphere or used to make player feel hunted it&#39;s well worth having it. http://forums.bistudio.com/oldsmileys/smile_o.gif

Quote[/b] ]I&#39;m not at all trying to discourage someone. Just my experience from my last OFP SP mission...LOL, throwing up some other, good, views, aint discouraging in my books m8 http://forums.bistudio.com/oldsmileys/smile_o.gif We better be realistic and don&#39;t waste time for projects that seem little value when finished http://forums.bistudio.com/oldsmileys/biggrin_o.gif


Quote[/b] ]How does the ai react in darkness generally? Do they &#39;see&#39; less? Does light effect them?Actually I&#39;ve been so busy that I didn&#39;t watch/recognize it yet, but I thought it would be ofp like http://forums.bistudio.com/oldsmileys/smile_o.gif


Quote[/b] ]- Helos will be &#39;spotted&#39; by ear rather then by sight
- in case you don&#39;t have any AA weapons it doesn&#39;t make sense to light the chopper - that just tells &#39;em where to fire his gunsThen don&#39;t light up choppers, or even turn off search lights in case of enemy chopper nearing? http://forums.bistudio.com/oldsmileys/smile_o.gif


Quote[/b] ]- With the OpFor using NVGs it&#39;s rather counterproductive.The purpose of having this option, might be for making missions without NVG on opfor&#39;s side, while basing the spotting etc. with the search lights http://forums.bistudio.com/oldsmileys/biggrin_o.gif


Quote[/b] ]On the other hand this little and easy to implement function could easily turn into a mean ai addon. But before going in too deep i&#39;ld rather suggest to think about it from the in game results of it. I see a lot of script work with tons of exeptions for a rather not measurable result.For sure, let&#39;s check it out with some tests here and there, if the above mentioned texts got you hot for the option http://forums.bistudio.com/oldsmileys/wink_o.gif


Quote[/b] ]- in case we&#39;re not talking &#39;bout nightstalkers the choppers might be lit up like x-mas trees - just another exceptionI didn&#39;t get this part :P

deanosbeano
Dec 30 2006, 11:49
you have some very valid points there badass.
If you consider though that the command wiil take subclasses too
you can narrow down the amount of unwanted clutter from the search pattern. and also 5 or 6 logics in a circle can be randomly spotted whilst the spotlight is idle you just need to select 2 +random (??) for some variety of height .
simply replace buildings with Logic .
i have recently used this command for some addons i made ,which of course narrows down the size of the array considerably.

BadAss [Mapfact.net]
Dec 31 2006, 10:16
Quote[/b] ]- in case we&#39;re not talking &#39;bout nightstalkers the choppers might be lit up like x-mas trees - just another exceptionI didn&#39;t get this part :P

Okay, i was exaggerating a bit.  http://forums.bistudio.com/oldsmileys/tounge2.gif  OFP / ArmA helos have their position lights on, not exactly like a christmas tree. Just to stress my point that choppers are not really invisible exept maybe for the famous Nightstalkers - 160th Special Aviations Regiment. http://forums.bistudio.com/oldsmileys/wink_o.gif

@<hidden> deanosbeano: breaking something complex down to smaller and easier to swallow chunks seems to be a good idea. http://forums.bistudio.com/oldsmileys/smile_o.gif On has to remind one self from time to time. I tend to forget that, unfortunately regularily. http://forums.bistudio.com/oldsmileys/whistle.gif


Maybe it&#39;ll be a good point to start with reaserching ai skills according to light and darkness. For that the knowsAbout command will be our best friend, i guess.

deanosbeano
Dec 31 2006, 11:41
"Maybe it&#39;ll be a good point to start with reaserching ai skills according to light and darkness. For that the knowsAbout command will be our best friend, i guess. "

well i did some testing when you mentioned about lighting helos up
, so far with 2 men in the dark without nvg , both with clear line od sight about 15 -20 meters apart, knowsabout = 0,i focused searchlight on east soldier , no change same with 2 and 3 lights.
so i guess light has no effect at all.( where ai is concerned of course).
next i will try m2 static and have ai walk across its path in dark with and without light on

BadAss [Mapfact.net]
Dec 31 2006, 11:48
Hey, cool thing you&#39;ve started testing already&#33; Thanks&#33; http://forums.bistudio.com/oldsmileys/smile_o.gif

As to the results: rather disappointing that the light seems to have no effect. Can you please send me your test mission? So i can try it out with the exact same settings like you? So we can compare the results and see if that&#39;s a general rule of ai skill and behaviour?

As an addition we could test all the same in the birghtest light of day to see if there&#39;s a difference between night and day at all.

deanosbeano
Dec 31 2006, 13:14
yes of course you can have it, i will pm you my icq ,if you have it ?

one thing i have found that is strange.
scenario 1 :start up mission .touch nothing all is calm , all knownabouts are 0. abort misssion restart . all is calm.

scenario 2 start up misssion . focus 1,2,3,4 searchlights on east man . all known abouts = 0. abort misssion restart . known abouts = 4 bang east soldier dead. hmm weird.

ok after further testing ,scrap the above ,it wasnt lights it was the engine having a random guess at who kows about what http://forums.bistudio.com/oldsmileys/smile_o.gif.

@<hidden> . at roughly 4.36 am everyone knows about everyone they can see .

Landdon
Jun 3 2007, 21:47
Gentlemen,

I would like to add this to a mission I am building.  I not following the instructions in here. Do you have a demo mission I could use?

MattXR
Dec 20 2007, 21:33
Here you go. I&#39;m sorry, but the vectorDir solution was not possible (as you have to step the dir). Well, I took vb&#39;s idea to save a lot performance anyway (if you know how a computer computes sin/cos, you know why it saves a lot  http://forums.bistudio.com/oldsmileys/tounge2.gif ). I hope the 10.000 while do limit is fixed within the next patch, that&#39;s why I didn&#39;t add more while do&#39;s. I added a new argument for the up/down angle of the searchlight.<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private&#91;&#34;_sl&#34;,&#34;_ang&#34;,&#34;_del&#34;,&#34;_dir&#34;,&#34;_h&#34;,&#34;_dis&#34;,&#34;_px&#34;,&#34;_py&#34;,&#34;_sin&#34;,&#34;_cos&#34;,&#34;_i&#34;,&#34;_c&#34;&#93;;

_sl=_this select 0;
_ang=&#40;_this select 1&#41;/2;
_del=_this select 2;
_h = _this select 3;

_dis = 20;
_py = position _sl;
_px = _py select 0;
_py = _py select 1;

_sin = &#91;&#93;;
_cos = &#91;&#93;;

_dir = direction _sl;

for &#34;_i&#34; from _dir-_ang to _dir+_ang step 1 do
{
_sin = _sin + &#91;&#40;sin _i&#41;*_dis&#93;;
_cos = _cos + &#91;&#40;cos _i&#41;*_dis&#93;;
};

_i = -1;
_c = _ang;

while {true} do
{
while {alive gunner _sl} do
{
_sl doWatch &#91;_px + &#40;_sin select _c&#41;, _py + &#40;_cos select _c&#41;, _h&#93;;
sleep _del;
_c = _c + _i;
if &#40;_c &#60; 0&#41; then
{
_i = 1;
_c = 0;
sleep _del*5;
};
if &#40;_c &#62; 2*_ang&#41; then
{
_i = -1;
_c = 2*_ang;
sleep _del*5;
};
};
};(I&#39;m sorry for the format, but my tabs are ignored by IB)[/QUOTE]
When you shoot the guy on the searchlight you loose about 10 fps and then another you loose about 5?

Im not sure what happens but it seems the script cant work when the man dies.. i need help.

thegunnysgt
May 23 2008, 16:50
Hi, I&#39;m looking over this thread looking for a working searchlight script and wanted to know what is the latest working script? I want to get the latest one that works, but through all the discussion in this thread, I don&#39;t want to get one that is still being worked on.