Jump to content
Sign in to follow this  
Blanco

Reworked searchlight script!

Recommended Posts

For those who cant reply at OFPEC etc, here is the full post - copy and paste mate.... easy peasy - lol, indeed lazy tounge_o.gif

-----------------------------------------------------------

Since OFP came out, I'm aching for a searchlight addon...

Meanwhile we have to do it with scripted searclhights and the best script I found was Sui's mgspot.sqs

The problem with mgspot is that you can still run through the lichtbeam undetected, because the unit does'nt look in the same direction the light does. That's the part I've changed, I create a gamelogic an move him in as gunner, so the lights turned on. Then I place a lookout very close to the mg and setdir him the same direction as the light. The best lookout is a sniper (with Nv goggles), without any other weapons and a this setunitpos "up" in the init.

When the lookout detects the player and the lichtbeam is directed to him ,the gamelogic disembark the mg (yeah, weird it works,   gamelogic don't have AI, deletevehicle Gamlogic doesn't!) and the lookout moves in & start firing / searching the player

When the lookout is hit, he moves in directly.

When the lookout dies before the player's detected, the script exit and the light stays on (the gamelogic is still there)

Here's the script

Code:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

; -- MG Searchlight Script --

; Written by Sui (reworked by Blanco)

_mg = _this select 0

_llimit = _this select 1

_rlimit = _this select 2

_lookout = _this select 3

; -- Create a tempgunner and move it in as gunner, so the script can start

_mgg = "logic" camcreate getpos _mg

_mgg moveingunner _mg

; -- Set the variable that calls the 2nd loop (to track the player)

detected = false

; -- sets the initial direction of the MG inbetween the two limits

_newhdg = (_rlimit + _llimit)/2

; -- First loop... random searchlight movements

#searchloop

~0.05

; -- finds the direction of the MG relative to a random heading between the arc limits

; -- If the MG's heading is within 10 degrees of the random heading, it chooses a new random heading

? (getdir _mg - _newhdg) < 10 and (getdir _mg - _newhdg) > - 10: _newhdg = ((random (_rlimit - 90)) + _llimit)

? (getdir _mg - _newhdg) > 0: _mg setdir ((getdir _mg) - 1)

? (getdir _mg - _newhdg) < 0: _mg setdir ((getdir _mg) + 1)

; -- find the direction of the player relitive to the MG

_dirplr = ((getpos player Select 0) - (getpos _mg Select 0)) ATan2 ((getpos player Select 1) - (getpos _mg Select 1))

? _dirplr < 0: _dirplr = _dirplr + 360

? _dirplr > 360: _dirplr = _dirplr - 360

;;turn the lookout to the same direction as the lightbeam, so the lookout can spot the player when he runs through the lightbeam

_lookout setdir getdir _mg

; -- If the player is within 5 degrees of the MG's heading (in the searchlight) and the MG knows the player

; -- is there, the alarm is tripped

? (getdir _mg - _dirplr) < 5 and (getdir _mg - _dirplr) > - 5 and (_lookout knowsabout player > 0): detected = true

;exit the script when the lookout's dead, the light stay on, but it doesn't move anymore

?!alive _lookout : exit

;exit the searchloop when the lookout has been hit, and move in directly, an EH "hit" should be better here

?getdammage _lookout > 0.01 : goto "movein"

; -- If the player hasn't been detected the loop repeats

? not (detected) : goto "searchloop"

; The player is detected, the tempgunner ejects (deletehicle _mgg doesn't work! ) and the lookout is the new gunner

#movein

_Mgg action ["eject",_mg]

~1

_lookout assignasgunner _mg

_lookout moveingunner _mg

~0.1

; -- Second loop... tracks the player with the searchlight

#detectedloop

~0.05

; -- finds the bearing from the MG to the player, and makes sure it is within range (0 - 360)

_newhdg = ((getpos player Select 0) - (getpos _mg Select 0)) ATan2 ((getpos player Select 1) - (getpos _mg Select 1))

? _newhdg < 0: _newhdg = _newhdg + 360

? _newhdg > 360: _newhdg = _newhdg - 360

; -- Moves the direction of the MG depending on the bearing to the player

? (getdir _mg - _newhdg) > 0 and (_lookout knowsabout player > 1): _mg setdir ((getdir _mg) - 2)

? (getdir _mg - _newhdg) < 0 and (_lookout knowsabout player > 1): _mg setdir ((getdir _mg) + 2)

; -- If there is still a live gunner manning the MG the loop goes around again

? (east countside (crew _mg) > 0): goto "detectedloop"

; when the lookout dies, the temp gunner is the new gunner, the light stays on but it won't move

_mgg assignasgunner _mg

_mgg moveingunner _mg

exit

 

1) Place an empty M2 machinegun (probably in a tower)

2) Place a lookout very close to the mg, right behind the mg works best.

the arguments: [Machinegun, left limit of search arc, right limit of search arc,name of the lookout]

eg. [mg1,90,270,lookout] exec "SL.sqs"

If you like stealth missions Project IGI style, give it a try.

I also have another version where the lookout reacts when he spots  dead bodies, but it's not very user friendly. I need help

I wouild like to know how I can add and 5th argument : an array of the names of potential bodies, something like :

[mg1,90,270,lookout,[unit1,unit2,unit3] exec "SL.sqs"

When he spots a corps he'll bring his light in position and sound the alarm and continue searching the player...

Searchlights are scary! tounge_o.gif

Share this post


Link to post
Share on other sites

AFAIK there aren"t searchlights addons (yet)

I hope I can stimulate somebody to make one, searchlights are cool!

 ghostface.gif

HERE's a testmission : you need editorupgrade102 & mapfact barracks

Share this post


Link to post
Share on other sites

those lights are not only scary indeed ghostface.gif, but also very atmospheric

grab this movie to see what this script adds to ofp gameplay.

Share this post


Link to post
Share on other sites

Very nice work Blanco, I've been wanting a search light since day 1  smile_o.gif

One question, have you tried it in MP?

BTW: Walker from CoC was working on a search light thing/object a while ago but haven't heard anything from him since but maybe someday we can get rid of the MG? Maybe he will chime in?

/Christer (a.k.a KeyCat)

Share this post


Link to post
Share on other sites

Dunno..., I can't test in MP and my skills in MP-scripting are very limited. Could be very cool in coop missions.

Be free to make it happen, Keycat tounge_o.gif You're the master, love your grouplink II script, very usefull script

Is there a conflict with the command player if you use it in a MP script?

I mean : Can the spot find every playable unit in a MP mission when I just use player?

Is there a problem with random in Mp?

Share this post


Link to post
Share on other sites

I will test it in MP as soon as I get some free time... Don't really remember if there are any special issues with the "player" command?

Glad you like the GroupLink II script but the "master title" dosen't belong to me.... I think guys like toadlife, Snypir, LCD and a bunch of others over at www.ofpec.com deserves it better since it was there I found most of the info to be able to improve taodlifes original GL script tounge_o.gif

Will take a look at your script and see if I can add something usefull. When testing it in SP yesterday wondered if it was able to have the search light sweep vertical as well as horisontal.

Also lets hope Mr. Walker chime in about the searchlight object/thing he and the other guys at CoC was/is working on.

/Christer (a.k.a KeyCat)

Share this post


Link to post
Share on other sites

I don't think you can sweep it vertical because you can't tilt objects. rock.gif

I've got a new version, but no demomission (not yet)

This version can spot bodies you define in an array (6th parameter)

Here we go, it's big...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

; -- MG Searchlight Script 2.0--

; Written by Blanco (Original by Sui)

; -- the arguments: [Machinegun, left limit of search arc,right

; --limit of search arc,name of the lookout,start (height)

; -position of the lookout,array of the names of the units who

; --will be body]

; eg. [mg1,90,270,lookout,7,[unit1,unit2,unit3]] exec "SL.sqs"

_mg = _this select 0

_llimit = _this select 1

_rlimit = _this select 2

_lookout = _this select 3

_height = _this select 4

_bodies = _this select 5

; get the start position of the lookout

_startposx = getpos _lookout select 0

_startposy = getpos _lookout select 1

_startposz = getpos _lookout select 2

; -- this variable sets the watchdistance

_dis = 100

; -- Create a tempgunner and move it in as gunner, so the script can start

_mgg = "logic" camcreate getpos _mg

_mgg moveingunner _mg

; -- Set the variable that calls the 2nd loop (to track the player)

detected = false

bodydetected = false

; -- sets the initial direction of the MG inbetween the two limits

_newhdg = (_rlimit + _llimit)/2

; -- some variables...

_i = 0

_c = 0

_delay = 0.05

; -- First loop... random searchlight movements

#searchloop

~_delay

; -- select a unit in bodies array

_body = _bodies select _c

; -- finds the direction of the MG relative to a random heading between the arc limits

; -- If the MG's heading is within 10 degrees of the random heading, it chooses a new random heading

? (getdir _mg - _newhdg) < 10 and (getdir _mg - _newhdg) > - 10: _newhdg = ((random (_rlimit - 90)) + _llimit)

? (getdir _mg - _newhdg) > 0: _mg setdir ((getdir _mg) - 1)

? (getdir _mg - _newhdg) < 0: _mg setdir ((getdir _mg) + 1)

; -- find the direction of the player relitive to the MG

_dirplr = ((getpos player Select 0) - (getpos _mg Select 0)) ATan2 ((getpos player Select 1) - (getpos _mg Select 1))

? _dirplr < 0: _dirplr = _dirplr + 360

? _dirplr > 360: _dirplr = _dirplr - 360

; -- find the direction of a potential body relative to the MG

_dirbody = ((getpos _body Select 0) - (getpos _mg Select 0)) ATan2 ((getpos _body Select 1) - (getpos _mg Select 1))

? _dirbody < 0: _dirbody = _dirbody + 360

? _dirbody > 360: _dirbody = _dirbody - 360

;; -- turn the lookout to the same direction as the light, so there's a bigger change the lookout spots the player

_lookout setdir getdir _mg

; -- get the position array of the lookout

_lposx = getpos _lookout select 0

_lposy = getpos _lookout select 1

_lposz = getpos _lookout select 2

; -- this should prevent the lookout falls from tower; this put the lookout back in startposition every 25 sec

; -- and reset the timer (_i = 0)

?_i > 500 && alive _lookout :_lookout setpos [_startposx,_startposy,_height];_i=0

; -- Let him watch in the same direction. The lookout is already turned in the right direction with setdir,

; -- but that does'nt mean he's watching that direction too!

_lookout dowatch [_cposx + ((sin getdir _mg) * _dis), _cposy + ((cos getdir _mg) * _dis), 2]

; -- If the player is within 10 degrees of the MG's heading (in the searchlight) and the MG knows the player

; -- is there, detected = true

? not(detected) && (getdir _mg - _dirplr) < 10 and (getdir _mg - _dirplr) > - 10 and (_lookout knowsabout player > 0.105): detected = true

; -- If a body is within 10 degrees of the MG's heading (in the searchlight) and the MG knows the body

; -- is there, bodydetected = true

? not(detected) && (getdir _mg - _dirbody) < 10 and (getdir _mg - _dirbody) > - 10 and (_lookout knowsabout _body > 0.105) && !alive _body : goto "pause"

; -- exit the script when the lookout's dead, the light stay on, but it doesn't move anymore

?!alive _lookout : exit

; -- exit the searchloop when the lookout has been hit, and move in directly, an EH "hit" should be better here

?getdammage _lookout > 0.01 : goto "movein"

; -- update the counter for the startposition of the lookout

_i = _i + 1

; -- Select next unit in the _bodiesarray

_c = _c + 1

; -- When all units in the _bodiesarray are checked, reset so it can start all over again

?_c > count _bodies : _c = 0

; -- If the player hasn't been detected the loop repeats

? not (detected) : goto "searchloop"

#movein

; -- The player is detected, the temp gunner ejects (deletehicle _mgg doesn't work! ) and the lookout is the new gunner

_Mgg action ["eject",_mg]

~1

_lookout assignasgunner _mg

_lookout moveingunner _mg

~0.1

; -- Second loop... tracks the player with the searchlight

#detectedloop

~_delay

; -- finds the bearing from the MG to the player, and makes sure it is within range (0 - 360)

_newhdg = ((getpos player Select 0) - (getpos _mg Select 0)) ATan2 ((getpos player Select 1) - (getpos _mg Select 1))

? _newhdg < 0: _newhdg = _newhdg + 360

? _newhdg > 360: _newhdg = _newhdg - 360

; -- Moves the direction of the MG depending on the bearing to the player

? (getdir _mg - _newhdg) > 0 and (_lookout knowsabout player > 0.105): _mg setdir ((getdir _mg) - 2)

? (getdir _mg - _newhdg) < 0 and (_lookout knowsabout player > 0.105): _mg setdir ((getdir _mg) + 2)

; -- If the player is within 10 degrees of the MG's heading (in the searchlight) and the MG knows the player,

; -- The player will be revealed and will be attacked

? (getdir _mg - _dirplr) < 10 and (getdir _mg - _dirplr) > - 10 and (_lookout knowsabout player > 0.105): gunner _mg dowatch player; gunner _mg reveal player;gunner _mg dofire player

; -- If there is still a live gunner manning the MG the loop goes around again

? (count (crew _mg) > 0): goto "detectedloop"

; -- when the lookout dies, the temp gunner is the new gunner, the light stays on but it won't move

_mgg assignasgunner _mg

_mgg moveingunner _mg

exit

#pause

; -- remove the body from the array

_bodies = _bodies - [_body]

; -- Set the variable true

bodydetected = true

; _-- the lookout is alerted, from now on he's searching a bit faster

_delay = 0.03

; -- pause. The light's turned to the body for a few seconds

~5 + random 5

; -- go on and continue the search

goto "searchloop"

There are two bolean who can activate 2 different events

Detected : when the player's detected by the searchlight

bodydetected : when the lookout finds a body from the _bodies array.

Spice it up with an alarmsirene or reinforcements or whatever...

Don't use groupnames in the _bodies array or units Grp1 doesn't work either, You have to name every unit (who could be a potential body) individual!

Also, I got better results when I use the wiretower from editorupgrade102 instead of the mapfact barracks.

1 Thing you can add :

Give the lookout "ears" but only for non-silenced weapons smile_o.gif

Make him turn the spot to the action...would be cool & realistic...

ohmy god, my English... crazy_o.gif

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×