Advertisement

Author Topic: Reworked Searchlight script!  (Read 1074 times)

0 Members and 1 Guest are viewing this topic.

Offline Blanco

  • Former Staff
  • ****
Reworked Searchlight script!
« on: 16 Feb 2004, 18:39:26 »
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,  :o gamelogic don't have AI, deletevehicle Gamelogic doesn't work!) 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: [Select]
; -- 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! 8)
« Last Edit: 25 Feb 2004, 18:15:08 by Blanco »
Search or search or search before you ask.

BoNeCoLLeCToR

  • Guest
Re:Reworked Searchlight script!
« Reply #1 on: 16 Feb 2004, 19:15:39 »
would be nice if you add a demo mission ;)

deaddog

  • Guest
Re:Reworked Searchlight script!
« Reply #2 on: 16 Feb 2004, 19:23:42 »
I think you need to use something other than "knowsabout".  I stood still about 30 meters in front of it with the light right on me and never got spotted.

I wrote a lookout script once that used the units speed to help determine if it was spotted.  Basically, if the target unit (player) was within the "cone" of detection (like your spotlight) and within a certain distance (in my case, 800 meters for a sniper) and was walking (speed > 10 or something like that) then there was a 95% chance of getting spotted.  The percent went down if he was crawling (again, based on speed).  And the closer he got to the sniper, the better the chance of being spotted.

You could use something similar.  Let's face it, if the spot light is on you and you are moving any speed at all, you should get spotted.  The human eye notices movement very well.  And if you are sitting still, you should still get spotted easily.  After all, you got a big spotlight right on you and the spotter is always looking where the light hits.

I just wonder if because it is dark (regardless of the spotlight), if that lowers the effectiveness of the knowsabout command.  I should think so.

Offline Blanco

  • Former Staff
  • ****
Re:Reworked Searchlight script!
« Reply #3 on: 16 Feb 2004, 19:28:32 »
Why for Godsake can't I attach it here? It's 5k!
I always got an error message  :-\

I got one in my briefcase ,but it need 2 addons : editorupgrade102 & mapfacts barracks, 2 popular ones, I don't think you need a link...

http://au.f2.pg.briefcase.yahoo.com/

ID : ftielemans
PW : dey8p7

In the folder demolition diver\searchlighttest.noe.zip


DL http://users.skynet.be/fa225157/be-studios/Searchlighttest.noe.zip

you need 2 addons : editorupgrade102 & mapfacts barracks, 2 popular ones, I don't think you need a link...


@deaddog Thx for trying it  ;)

I never had that prob, but eh that's why I've put it here, to betatest... :)

Great Idea about checking the player's speed but when the player stops walking/crawling... he will never be detected.
maybe knowsabout & speed... I'll give it a try...thx

Quote
I just wonder if because it is dark (regardless of the spotlight), if that lowers the effectiveness of the knowsabout command.  I should think so.

That's why I suggest the NV goggles



« Last Edit: 16 Feb 2004, 20:22:00 by Blanco »
Search or search or search before you ask.

deaddog

  • Guest
Re:Reworked Searchlight script!
« Reply #4 on: 16 Feb 2004, 20:52:17 »
Oh yeah, the NVgoggles :)  I read that the first time but forgot to put them on my spotter.  I'll give that a test.

RONIN =ASP=

  • Guest
Re:Reworked Searchlight script!
« Reply #5 on: 23 Feb 2004, 07:02:50 »
This is really good stuff,When the tower has detected you and you shoot him it bombs out to desktop...hope this can b fixed,would like to use this,you clever boys you

I have know idea how to fix it,but i'm sure you'll b able to figure it out  ;D

  ;)

Offline Blanco

  • Former Staff
  • ****
Re:Reworked Searchlight script!
« Reply #6 on: 23 Feb 2004, 18:56:05 »
It works for me.

This script needs a very fast loop (0.05), maybe that's the problem.

I agree, the mission is not very good, When I have the time I make another one with an updated version.
I've already posted the script at the official forum.

http://www.flashpoint1985.com/cgi-bin/ikonboard311/ikonboard.cgi?s=fc69731715a96f6e147cb40d66bc6e07;act=ST;f=7;t=37365

An improvement :

- Searchlight can detect dead bodies which you define in an array.

here's the script SL2.0.sqs

Code: [Select]
; -- MG Searchlight Script 2.0--
; Written by Blanco (Original by Sui)

_mg = _this select 0
_llimit = _this select 1
_rlimit = _this select 2
_lookout = _this select 3
_height = _this select 4
_bodies = _this select 5

_startposx = getpos _lookout select 0
_startposy = getpos _lookout select 1
_startposz = getpos _lookout select 2

_dis = 100

_mgg = "logic" camcreate getpos _mg
_mgg moveingunner _mg

detected = false
bodydetected = false
_newhdg = (_rlimit + _llimit)/2
_i = 0
_c = 0
_delay = 0.05

#searchloop
~_delay
_body = _bodies select _c

? (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)


_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


_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

_lookout setdir getdir _mg

_lposx = getpos _lookout select 0
_lposy = getpos _lookout select 1
_lposz = getpos _lookout select 2

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

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

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

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

?!alive _lookout : exit

?getdammage _lookout > 0.01 : goto "movein"

_i = _i + 1
_c = _c + 1
?_c > count _bodies : _c = 0
? not (detected) : goto "searchloop"



#movein
_Mgg action ["eject",_mg]
~1
_lookout assignasgunner _mg
_lookout moveingunner _mg
~0.1

#detectedloop
~_delay
_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

? (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)

? (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

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

_mgg assignasgunner _mg
_mgg moveingunner _mg
exit


#pause
_bodies = _bodies - [_body]
bodydetected = true
_delay = 0.03
~5 + random 5
goto "searchloop"

the arguments:

1 - name of the empty machinegun (object)
2 - limit of search arc (number between 0 - 360)
3 - right limit of search arc (number between 0 - 360)
4 - name of the spotter (object)
5 - start (height) position of the spotter in the tower (number)
6 - the names of the units (guards) who will be body (array with objects)

full example
Code: [Select]
[mg1,90,270,lookout,7,[unit1,unit2,unit3]] exec "SL2.0.sqs"
There are also 2 boleans. They can execute 2 different events (reinforcements, alarm...)

detected = true : when searchlight detects the player
bodydetected = true : when the searchlight detects a body

NOTE : Don't place 10 searchlights in your mission, this script is very CPU intensive! (there's no other way...)

I need time to make a demomission...

 






« Last Edit: 25 Feb 2004, 18:14:11 by Blanco »
Search or search or search before you ask.