OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: RT-SuperTron on 30 Aug 2002, 08:18:45

Title: 1. Shots fired?! 2. Engine off??!
Post by: RT-SuperTron on 30 Aug 2002, 08:18:45
Ok, working an a big UN-Template. So far I got Camps working with automated Gates, and the checkpoints seem fine to. All UN personel are set to safe, and return fire only which seems to work ok.

1. How do I get them to respond on shots fired. Is it possible to make a condition that checks when shots are fired.??! I would like the units to respond to gunfire in there vicinity and go into aware.

2. how do you make check on if an engine is running or off. The UN Guard will instruct you to stop your vehicle and turn of your engine. If you dont he will take action. So far its all text on the screen at the CP, and now I would like to see it in Action.

Bonus question, how do I check if a Carhorn Or truckhorn is beeing used.

[RT]SuperTron
Title: Re:1. Shots fired?! 2. Engine off??!
Post by: toadlife on 30 Aug 2002, 09:23:43
I have an idea for you. Bare with me here as this is just a thought right now in my head.

Lets say the UN dudes are west and the side that will shoot will be from the east.

In your init.sqs script put the line: shotsfired = false

Create a gamelogic unit and name it "basegl". Place it in the center of your UN base.

Create a trigger that covers ALL of the eastern units on the map. Set it to "east present".


In the on activation field type:

"[_x] exec ""shotdetect.sqs""" foreach units thislist


Now for the "shotdetect.sqs" script.
Code: [Select]
_unit = _this select 0
_weapons = weapons _unit
_gun = _weapons select 0
_ammo = (_unit ammo _gun)

#loop
@!shotsfired
@((_unit ammo _gun) < _ammo) && ((_unit distance basegl) < 900)
shotsfired = true
location = getpos _unit
goto "loop"

Now the first time an eastern soldier fires off a round, the variable "shotfired" will be set yo true as long as he is within 900 meters of the gamelogic called basegl. The location of the shots will be placed in a variable called "location". you can set up a trigger that causes a squad to be sent to the location of the shots or to just go to aware behaviour.

You could also set up a trigger that resets the shotsfired variable after a period of time.

Set it to repeat and make it's condition "shotsfired"
set it to countdown however long you want it to wait. In the on activation field put "shotsfired=false"

None of this has been tested but I know it could work. If you want to try something like this let me know if you ahve any more questions.  

;)
Title: Re:1. Shots fired?! 2. Engine off??!
Post by: Bremmer on 30 Aug 2002, 13:13:15
Another idea for responding to shots fired:-

Try placing a couple of units on a map - both on the same side, and not grouped together. Make one the player and set the Ai units behaviour as safe. Name this guy Bob. Place a trigger with condition behaviour bob != "Safe", and On Activation hint "Under fire!".

Preview the map and try firing a few shots (not directly at bob). Bob should go aware, and the trigger should go off.

How can you put this into practice? First place a large West Present trigger over all the units you want to monitor. Make sure that all the units under the trigger have behaviour set as safe. Leave the condition as this and set the condition as westunits = thislist; safe = "safe".
Set up another trigger with condition "behaviour _x != safe" count westunits > 0, and On Activation hint "Under fire!" (+ whatever else you want to happen).

Cheers
Title: Re:1. Shots fired?! 2. Engine off??!
Post by: RT-SuperTron on 30 Aug 2002, 22:54:12
 :thumbsup:

Thanks guys, this allready gives a lot to work with. Some tweaking and testing and this will be perfect.

[RT]SuperTron
Title: Re:1. Shots fired?! 2. Engine off??!
Post by: SelectThis on 31 Aug 2002, 06:34:40
You can also try using the "knowsabout" command as a condition for a trigger.

SelectThis
Title: Re:1. Shots fired?! 2. Engine off??!
Post by: vektorboson on 31 Aug 2002, 06:58:58
I myself use something that is very similar to toadlife's solution, but if you are using any rifle that has a grenadelauncher attached, you'll get into problems with

Code: [Select]
_unit ammo ((weapons unit) select 0)
You have to search in the config.cpp for the right muzzle-class! Let's say that you have Fliper's M4-Pack and you are using the M4A1 with M203 and you want to know the ammo amount of the M4A1, then use

Code: [Select]
_ammo = _unit ammo "M4A1Muzzle"

instead of

Code: [Select]
_ammo = _unit ammo "FLPM4A1M203"

as in the latter case _ammo will be always 0!
Title: Re:1. Shots fired?! 2. Engine off??!
Post by: RT-SuperTron on 31 Aug 2002, 17:03:27
 :)
Another interesting example. Maaann, the power of combined knowledge..

Thanks

 [RT]SuperTron
Title: Re:1. Shots fired?! 2. Engine off??!
Post by: Chris Death on 02 Sep 2002, 09:31:39
Quote
"[_x] exec ""shotdetect.sqs""" foreach units thislist

Toadlife;

Wouldn't that way totally screw up the performance, if
there would be let's say: 60 units running a loop script
in the background?
:not sure about that, just a thinking

My idea would be, to put all that ammo counts into variables,
and check for whole_ammo < ammo_at_start

hope this makes some sense  :D

~S~ CD
Title: Re:1. Shots fired?! 2. Engine off??!
Post by: toadlife on 04 Sep 2002, 22:38:49
I dont think it would hurt performance. One thing you could do is to start each script at a slighly diff time by putting:

~(random 3)

before the start of the script.

You could also do a timed loop insted of an @ command that checks for ammo depletion like this:

Code: [Select]
#loop
@!shotsfired
?((_unit ammo _gun) < _ammo) && ((_unit distance basegl) < 900):goto "shotsfired"
~(random 3)
goto "loop"

#shotsfired
shotsfired=true
goto "loop"
Title: Re:1. Shots fired?! 2. Engine off??!
Post by: RT-SuperTron on 05 Sep 2002, 02:09:13
 :afro:

Keep em' coming...

[RT]SuperTron
Title: Re:1. Shots fired?! 2. Engine off??!
Post by: MaZ on 06 Sep 2002, 10:04:01
toadlifes method of making the scripts execute @ different times makes a helluva lot of difference...

I made a random traffic script a few months ago, which had about 60 civ. vehicles and planes and choppers, each with a single looping script in their init.

All running together, the game got so choppy i couldnt even shoot (and im used to running with a bad fps). I decided to make em execute in order, and now it runs perfectly fine :)

So use toadys method for doing it :D
Title: Re:1. Shots fired?! 2. Engine off??!
Post by: bn880 on 10 Oct 2002, 02:15:40
I saw people still looking at shoot detect scripts, so here is a simplified script I used for my TWMN mission a while ago:

Code: [Select]
; bn880 August 2002
_Player = _this select 0;

; STORES THE WEAPONS THE PLAYER CURRENTLY HAS
_weapons = []

; STORES THE NUMBER OF WEAPONS PLAYER HAS
_numWeapons =0;

; STORES THE ROUND INFORMATION FOR EACH WEAPON
_magAmmo =[];

; STORES THE NUMBER OF MAGS PLAYER CURRENLY HAS
_magNumber =0;

@(count (weapons vehicle _Player) > 0)

#loop1
_Player removeMagazines "HandGrenade"
_Player removeMagazines "SmokeShell"
_weapons= +(weapons vehicle _Player)
_numWeapons = count _weapons;
_magAmmo resize _numWeapons;

_x=0;
#loopMagAmmo
_magAmmo set [_x, (vehicle _Player ammo (format ["%1",_weapons select _x]))]
_x = _x + 1;
?_x < _numWeapons:goto "loopMagAmmo";

;hint format ["weapons\n%2\nmagAmmo\n%1\nmags\n%3",_magAmmo,_weapons,magazines vehicle _Player];
_magNumber = count magazines vehicle _Player;
~0.3

_x=0;
#loopMagAmmoNew
_curMagAmmo = vehicle _Player ammo (format ["%1",_weapons select _x]);
?(_curMagAmmo < _magAmmo select _x && _magNumber == count magazines vehicle _Player):goto "shot";
_x = _x + 1;
?_x < _numWeapons:goto "loopMagAmmoNew";
goto "loop1";

; HE PROBABLY SHOT
#shot

; CHECK WEAPON CHANGE
_weaponsNow = +(weapons vehicle _Player);
_x = 0;
#loopWeaponChange
?(_x >= _numWeapons):goto "doneWeaponChange"
?(_weaponsNow select _x != _weapons select _x):goto "loop1";
_x = _x +1;
goto "loopWeaponChange"

; WEAPON NOT CHANGED
#doneWeaponChange
_Player globalchat format ["%1> fired",DayTime];
goto "loop1";

To call it send the script the unit to be monitored.
Note, shot detection does not work with grenade launchers or grenades.  I think this was overlooked in all shoot detect scripts. (maybe not)