Home   Help Search Login Register  

Author Topic: Search Light script: help needed  (Read 2860 times)

0 Members and 1 Guest are viewing this topic.

Offline NightJay0044

  • Former Staff
  • ****
  • Let's make OFPEC great again
    • My Steam Workshop
Search Light script: help needed
« on: 23 Mar 2009, 20:27:16 »
Hi , I'm trying to create a searchlight script that will make the searchlight in ArmA rotate back and forth slowly.

But this script I have is not full proof, I'm not much of a scripter but I get the idea...So here is my try.

Quote
_guard1 = _this select 0

#target1
_Guard1 dowatch look1

~2

goto "target2"

#Target2
_Guard1 dowatch look2

~2

goto "target1"

Exit

What I did is placed to invisible targets on the map and had the soldier target those two targets to simulate the searchlight to go back and forth. But this doesn't work. The results are, the light targets the 1st target but then it goes crazy and just moves back and forth fast in the middle of both targets doesn't even target the targets really any more.

So how can I make a script to rotate the light slowly? I know there is one out there or it is possible. I just don't rememember where it was...thanks..
Who's hyped for Arma4, long live Arma!

Offline Deadfast

  • Members
  • *
Re: Search Light script: help needed
« Reply #1 on: 23 Mar 2009, 20:43:49 »
I think the best you could do would be to use just one target which you'd simply move around to the left and right to have the searchlight turn after it ;)


Let me know if you need me to write an example, but it won't be in SQS :(

Offline NightJay0044

  • Former Staff
  • ****
  • Let's make OFPEC great again
    • My Steam Workshop
Re: Search Light script: help needed
« Reply #2 on: 23 Mar 2009, 22:08:28 »
yeah could you write a little script like that sqf is ok. I don't know how to make it move.
Who's hyped for Arma4, long live Arma!

Offline Deadfast

  • Members
  • *
Re: Search Light script: help needed
« Reply #3 on: 23 Mar 2009, 23:58:03 »
OK, done:

Code: [Select]
_light = this select 0;

_target = _light modelToWorld [0,10,0];
_dir = getDir _light;

_light doWatch _target;

while {(alive _light) && (alive (gunner _light))} do
{
_i = 0;
while {_i < 300} do
{
_target = [(_target select 0) + ((cos _dir) * 0.1), (_target select 1) + ((sin _dir) * 0.1), _target select 2];
sleep 0.05;
_i = _i + 1;
_light doWatch _target;
hint format ["%1", _target];
};
_i = 0;
while {_i < 300} do
{
_target = [(_target select 0) - ((cos _dir) * 0.1), (_target select 1) - ((sin _dir) * 0.1), _target select 2];
sleep 0.05;
_i = _i + 1;
_light doWatch _target;
hint format ["%1", _target];
};
};


Made it a little better by using doWatch *position* so you don't need the dummy target anymore.


It's thrown together really fast so if you don't understand it I'll comment it out tomorrow ;)

Offline Dajan

  • Members
  • *
Re: Search Light script: help needed
« Reply #4 on: 30 Mar 2009, 16:00:54 »
@deadfast
I know this was for Nightjay, but could Ibeg you to make a comment it anyway? I have a real hard time learning scripting and commented scripts are a major source of inspiriation for me. I just wish more people would do it.
TIA

Offline Deadfast

  • Members
  • *
Re: Search Light script: help needed
« Reply #5 on: 30 Mar 2009, 16:23:49 »
Sure, I usually do comment my scripts, but this was written right before the midnight and to tell you the truth not even I was sure what I was doing :D

Actually looking back at it I even made some mistakes  :whistle:

Code: [Select]
_light = this select 0; //The light to work with

_target = _light modelToWorld [0,10,0]; //Create a position 10 meters in front (Y axis) and to the left (-X) of the light
_dir = getDir _light; //Get directions the light is facing (for trigonometry later)


while {(alive _light) && (alive (gunner _light))} do //Loop while both the light and its "gunner" is alive
{
_i = 0;
while {_i < 300} do //Moving target pos to the right
{
_target = [(_target select 0) + ((cos _dir) * 0.1), (_target select 1) + ((sin _dir) * 0.1), 0]; //Move target to the right (relative to the light)
sleep 0.05;
_i = _i + 1;
_light doWatch _target; //Make the light face the position
};
_i = 0;
while {_i < 300} do //Moving back to the left
{
_target = [(_target select 0) - ((cos _dir) * 0.1), (_target select 1) - ((sin _dir) * 0.1), 0];
sleep 0.05;
_i = _i + 1;
_light doWatch _target;
};
};

Offline F2kSel

  • Members
  • *
Re: Search Light script: help needed
« Reply #6 on: 24 Jun 2009, 00:16:13 »
Could someone explain how to use this script as I carn't seem to get anything to happen.


I'm trying to get it to work in Arma2 so that could be the problem, when I use the following command I get an error [unit] execVM "searchlight.sqf"  when placed in the init string of the unit.


Can Anyone help please.