OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Shadow.D. ^BOB^ on 16 Feb 2009, 13:41:50

Title: Indirect Fire Attack Simulation
Post by: Shadow.D. ^BOB^ on 16 Feb 2009, 13:41:50
Hey guys, i was hoping someone would be able to help me develop an IDF Attack simulation.  Basically i have a recording of an IDF Alarm, i would like to try and simulate an attack for my Afghan Village template.

The idea would be to have the alarm sound at random times throughout the day/night from a certain point, then have a spawned shells (possibly grenades) drop randomly in say a 500m radius around that point or another defined point (game logic or whatever). Having the attack last for say 1-5 minutes, i know there would be alot of random variables in this and I hope that it makes sense. I think it would really add something different for people making missions based on current military operations.

I'm a complete noob when it comes to making scripts, if anyone could help me with this i would be very very very  :D grateful.

Thankyou in advance for any help.
Title: Re: Indirect Fire Attack Simulation
Post by: laggy on 16 Feb 2009, 15:19:53
Hi,

Made a simple .sqs file, could make a .sqf, but since I'm slower with that... :dunno:
This script is so simple that .sqf won't make a performance difference anyway.

Solution:
An object called speaker (in my mission a roadcone).
A gameLogic called attackcenter.
A Radio alpha trigger that sets varable IDFattack to "true".

If you want to alter the "area size" being attacked, just change the "+ 50 - random 100" numbers to i.e "+ 500 - random 1000".

init.sqs
Code: [Select]
[] exec "IDF.sqs"
IDF.sqs
Code: [Select]
#start

@ IDFattack

speaker say "IDFalarm"

? ! (isServer) : IDFattack = false; goto "start"

_attacklength = 60 + random 240
_time = 0

#loop

? _time >= _attacklength : goto "end"
_delay = 5 + random 5
~ _delay
_boom = "Sh_120_HE" createVehicle [(getpos attackcenter select 0) + 50 - random 100,(getpos attackcenter select 1) + 50 - random 100, 50]
_time = _time + _delay
goto "loop"

#end

IDFattack = false
goto "start"

Use the trigger and see the effect. If you really want to have random attack times all through the day you could easily accomplish that with a looping script that sets IDFattack = true at random times. Don't forget to use publicVariable if you want it to work in MP.

Since I don't have a sound called "IDFalarm" you get an error message, but I hope you know how to define sounds in .ext and sound folder.

Example mission included.

Hope it's good enough  ;)

Laggy
Title: Re: Indirect Fire Attack Simulation
Post by: Shadow.D. ^BOB^ on 16 Feb 2009, 15:59:45
M8 the fact that you have taken the time to do this, is just a prime example of the OFP/ArmA community.  :good:

Thanks alot, i will try this out asap.

EDIT:- This is near perfect Laggy, just a couple of questions.  How exactly would i go about making this MP compatible and looping randomly throughout the day?  Also could it be activated via the init.sqf at mission start, rather that on a radio trigger?

Fantastic job tho m8, wish i could get me head around scripting.  :-[

Title: Re: Indirect Fire Attack Simulation
Post by: laggy on 16 Feb 2009, 16:32:11
init.sqs

Code: [Select]
[] exec "IDF.sqs"

? ! (isServer) : exit

#loop
_timetowait = 3600 + random 3600
~ _timetowait
IDFattack = true
publicVariable "IDFattack"
goto "loop"


Unless I'm stupid (quite busy right now) this should make it start every 1-2 hours, (3600 sec = 1 hour) and work in MP.

EDIT:  :-[ :-[ :-[ 6000 sec != 1 hour  :whistle: :whistle: :whistle:

Also about scripting, It's not much more complicated than triggers as long as you study what all the commands can do, vacuum clean the COMREF! I am not a really good scripter (suck at math and logic), have to bother this forum a lot with my questions, but you learn a lot from copying and pasting as well as starting of with smaller self made scripts, where you work on them until they work as you want them to. Look at scripts that you like and try to figure out how they work. I am just starting off with .SQF and find myself as a newbee, compared to working in .SQS, so just get started mate.

Laggy
Title: Re: Indirect Fire Attack Simulation
Post by: Shadow.D. ^BOB^ on 16 Feb 2009, 17:40:29
First of all let me reiterate what i said about this community being the best.  :D

Laggy this script works perfectly, just what i was looking for.  I have tested it with a lower time randomness and it all seems great.  Will do some more testing in MP once its implemented into my template, but i cannot thank you enough for this.

I will definatly look into scripting a bit more, like u say its spending the time and starting small. (All my free time is going into making missions atm.)

Once again thankyou for this, i will make sure you are credited once the template is complete.
Title: Re: Indirect Fire Attack Simulation
Post by: laggy on 16 Feb 2009, 17:47:30
 :) Mission making is really what it's all about Eh?  :good:
Script making is just one way of trying to make better missions.

In OFPres the original missions didn't include many complicated scripts, but were still some of the best missions to play in my opinion.

Laggy
Title: Re: Indirect Fire Attack Simulation
Post by: Shadow.D. ^BOB^ on 16 Feb 2009, 18:31:45
I agree Laggy simplicity generally works best.

Just another question, could it be possible to replay the sound file say repeated every 10 seconds for the duration of the IDF attack?

At the moment it works as intended, in RL though the IDF alarm keeps playing while there are still rockets/shells are in the air.  If this could be implemented it would finish the script off nicely.

Cheers.
Title: Re: Indirect Fire Attack Simulation
Post by: laggy on 16 Feb 2009, 19:12:58
Not a very slimmed solution, but quick to implement, is to have a third script:

init.sqs
Code: [Select]
[] exec "IDF.sqs"
[] exec "alarmsound.sqs"

? ! (isServer) : exit

#loop
_timetowait = 3600 + random 3600
~ _timetowait
IDFattack = true
publicVariable "IDFattack"
goto "loop"


IDF.sqs
Code: [Select]
#start
? ! (isServer) : exit

@ IDFattack

_attacklength = 60 + random 240
_time = 0

#loop

? _time >= _attacklength : goto "end"
_delay = 5 + random 5
~ _delay
_boom = "Sh_120_HE" createVehicle [(getpos attackcenter select 0) + 50 - random 100,(getpos attackcenter select 1) + 50 - random 100, 50]
_time = _time + _delay
goto "loop"

#end

IDFattack = false
publicvariable "IDFattack"
goto "start"

alarmsound.sqs
Code: [Select]
#loop
? IDFattack : speaker say "IDFalarm"
~12
goto "loop"

Just make sure the ~ delay in alarmsound.sqs is not shorter than your soundfile, as that might "pile up" your sounds, so that it continues to play long after the attack is over. At least I believe so.
Like I said, not beautiful, but should work well :P
Some .SQF master could make a much more elegant solution  :confused:
Title: Re: Indirect Fire Attack Simulation
Post by: Ext3rmin4tor on 16 Feb 2009, 19:14:01
Laggy is a good scripter, but he should learn SQF syntax  :D
Title: Re: Indirect Fire Attack Simulation
Post by: laggy on 16 Feb 2009, 19:15:35
 :weeping: I'm trying for heavens sake...
Title: Re: Indirect Fire Attack Simulation
Post by: Shadow.D. ^BOB^ on 16 Feb 2009, 19:39:01
Laggy i could kiss you  :-* (Maybe not, lol).   How about a night with my missus instead?  :whistle:

Working like a charm, gives a fantastic atmosphere.  Still need to do a bit of tweaking with the sound file, but here's an example mission, i've shortened the time to 1/2 minutes for testing.

Once again m8, thankyou so much.

Title: Re: Indirect Fire Attack Simulation
Post by: laggy on 16 Feb 2009, 19:53:01
Cool, keep up the good work mate  :good:

Maybe add some sound of the shells whizzing through the air before impact too  :scratch:
I'm too busy packing right now though, travelling for a week without PC  :weeping:
Title: Re: Indirect Fire Attack Simulation
Post by: Shadow.D. ^BOB^ on 16 Feb 2009, 20:15:17
Hey laggy slight problem, do i need to add a publicvariable to the looping sound script? (If so could you give me an example of what it would look like).  I have just tested this on my dedicated server and the sound only plays once.
Title: Re: Indirect Fire Attack Simulation
Post by: Rommel92 on 16 Feb 2009, 20:33:41
Thanks to laggy for the original scripts, I just optimized them into one with simpler execution and hopefully better use. If theres errors please tell me, and sorry for the inconvience.  :P

<see newer post>
Title: Re: Indirect Fire Attack Simulation
Post by: Shadow.D. ^BOB^ on 16 Feb 2009, 20:47:04
Hi Rommel, thanks for taking a look at this.  Any other input on Laggy's fantastic work, is greatly appreciated.

I have tried the script but currently get an error regarding a missing ";" on line 13.
Title: Re: Indirect Fire Attack Simulation
Post by: Rommel92 on 16 Feb 2009, 20:57:47
Code: (init.sqf) [Select]
execVM "IDFattack.sqf";
Code: (IDFattack.sqf) [Select]
see below...
Problem line:
Code: [Select]
speaker setvehicleinit format["this say %1", IDFalarm];
This was the only line I could see as being a problem as I've forgotten the notation with talking marks, if that doesn't work try these solutions (sorry for the screw around, I really need to get ArmA re-installed.)
Code: [Select]
solved...
Title: Re: Indirect Fire Attack Simulation
Post by: laggy on 16 Feb 2009, 21:02:53
The only script that needs publicvariable is the IDF.sqs.

The other scripts are simply waiting for the publicvariable command  :cool2:

Might be:

alarmsound.sqs
Code: [Select]
#loop
if (IDFattack) then {speaker say "IDFalarm"}
~12
goto "loop"

I would go with Rommels script though, when it doesn't report errors  ;)
Title: Re: Indirect Fire Attack Simulation
Post by: Rommel92 on 16 Feb 2009, 21:18:56
(Just installed ArmA - Installing Patches  :P)

In future Laggy, try a addPublicEventHandler (http://community.bistudio.com/wiki/addPublicVariableEventHandler)

Its better then having a constant loop.
Title: Re: Indirect Fire Attack Simulation
Post by: Shadow.D. ^BOB^ on 16 Feb 2009, 21:22:37
Rommel, i have used the original script again:-

Code: [Select]
if (not isserver) exitwith {};

waituntil {IDF_attack};

while {true} do {
private"_w";
_w = time + 1;
while {_w < time} do {sleep 1};
_w = time + 6 + random 2;
[_w] spawn {
while {_this select 0 < time} do {
sleep 12;
speaker setvehicleinit format["this say %1", IDFAlarm];
processinitcommands;
};
};
while {_w < time} do {
sleep (5 + random 5);
private"_b";
_b = "Sh_120_HE" createVehicle [(getpos IDFCenter select 0) + 50 - random 100,(getpos IDFCenter select 1) + 50 - random 100, 50];
};
};


I've just changed the sound file name to IDFAlarm (to match the sound file) and gamelogic to IDFCenter to tie in with my mission.  I have also changed the time so that i can test if it works.  Although i dont get any errors, the script doesnt seem to start. No sound and no spawning shells.

I hope i've not changed anything i should'nt have with the time stuff, if so what should i enter so i can test it works.  I figured the values i have entered would get the script to start soon after mission start.


Thanks again to everyone for takin an interest in this.

Title: Re: Indirect Fire Attack Simulation
Post by: laggy on 16 Feb 2009, 21:31:16
(Just installed ArmA - Installing Patches  :P)

In future Laggy, try a addPublicEventHandler (http://community.bistudio.com/wiki/addPublicVariableEventHandler)

Its better then having a constant loop.

I never got my head around how the addPublicVariableEventHandler is used.
Could you give a quick example Rommel?
Title: Re: Indirect Fire Attack Simulation
Post by: Rommel92 on 16 Feb 2009, 21:35:16
Code: (IDFAttack.sqf) [Select]
if (not isserver) exitwith {};

waituntil {IDF_attack};

while {true} do {
private"_w";
_w = time + 1;
waituntil {time > _w};
_w = time + 6 + random 2;
[_w] spawn {
while {time < _this select 0} do {
sleep 12;
speaker setvehicleinit format["this say %1", IDFAlarm];
processinitcommands;
};
};
while {time < _w} do {
sleep (5 + random 5);
private"_b";
_b = "Sh_120_HE" createVehicle [(getpos IDFCenter select 0) + 50 - random 100,(getpos IDFCenter select 1) + 50 - random 100, 50];
};
};

Positive Results! - Works a beauty.

Logic failure, I had _w < time instead of time < _w ... atleast I think.

Quote from: Laggy
I never got my head around how the addPublicVariableEventHandler is used.
Could you give a quick example Rommel?

Code: (example) [Select]
"IDFAttack" addPublicVariableEventHandler {
hint ((_this select 0) + " has been updated to: " + str (_this select 1));
if (_this select 1) then { //boolean true
while {IDFAttack} do {
sleep 12;
speaker say "IDFalarm";
};
};
};

EXAMPLE FOR LAGGY.
Title: Re: Indirect Fire Attack Simulation
Post by: laggy on 16 Feb 2009, 21:57:10
Ughhh  :blink:

What does it do?

What is the "//boolean true" thingy?

EDIT:

Awesome, must try it out  :good:
Thanks for taking the time to explain it  :)

Laggy
Title: Re: Indirect Fire Attack Simulation
Post by: Rommel92 on 16 Feb 2009, 22:02:19
Code: (init) [Select]
"Laggyexample" addPublicVariableEventHandler {
player sidechat "I'm a little bit laggy today. Damn latency.";
};

Alpha Radio Trigger:
Code: (onAct) [Select]
laggyexample = "test"; publicVariable "laggyexample";
This however will not show on your computer:
Quote from: BIS
Note that the EH is only fired on clients where the publicVariable command has not been executed, as publicVariable does not change the variable where it has been executed.

So if tested on a dedicated server, it will come up on your computer saying "I'm a little bit laggy today. Damn Latency".

_this select 0 being the variable itself as a string "Laggyexample" and _this select 1 being the variables new value as a value: "test".
Title: Re: Indirect Fire Attack Simulation
Post by: Shadow.D. ^BOB^ on 16 Feb 2009, 22:10:46
Hmmm tried that script again Rommel, but i cant hear the alarm and no shells.  I have waited a couple of minutes for it to start (just incase).  Any chance you could repost the last template i uploaded with it working?  Just incase i'm missing something.  How long does it take generally to sound when you try the script using the above time numbers?

Cheers.

Edit:- This can be tested from the editor right? Or does it need to be on a dedicated server?
Title: Re: Indirect Fire Attack Simulation
Post by: Rommel92 on 16 Feb 2009, 22:31:51
Make sure you have the Radio trigger working correctly.

Code: (OnAct) [Select]
IDF_attack = true
I tested it with a wolf sound and the shells, and my first (and only) error was that I had:

Code: (onAct) [Select]
IDFattack = true
So maybe double check that.

Note: it should be IDFattack, but I made a mistake in the script, so whichever one you chose, make sure they are consistent.
Title: Re: Indirect Fire Attack Simulation
Post by: Shadow.D. ^BOB^ on 16 Feb 2009, 23:55:52
ah i see, i wasnt setting the IDFattack to true via the radio.

EDIT:- Ok tested this, i get an error once its started. 

Code: [Select]
'this say scalar |#|bool array string 0xe0ffffef'
Error Missing ;

The shells come in fine, so im guessing the error is sound related.

Sorry if it sounds like im nagging you.  :D

I've attached the example mission again as it stands now.
Title: Re: Indirect Fire Attack Simulation
Post by: Rommel92 on 17 Feb 2009, 01:23:05
Code: [Select]
speaker setvehicleinit format["this say %1", "IDFAlarm"];
Hopefully that works. I'd test it, but I'm now at a different computer 30km away from ArmA.  :whistle:
Your not nagging me at all; I just needed to test these before posting solutions :P.
Title: Re: Indirect Fire Attack Simulation
Post by: Shadow.D. ^BOB^ on 17 Feb 2009, 01:37:32
Getting there  :D

The error has gone, the shells come in, but no sound plays.  ???

You gotta love this game, definatly keeps you busy.
Title: Re: Indirect Fire Attack Simulation
Post by: Rommel92 on 17 Feb 2009, 06:29:57
All fixed and working, you forgot to set up the sound in the description.ext. You were missing \sound\ for the file path and it was also really quiet, but you can modify that.

There also appears to be a loop in the sound that powers down, and it the sound lasts about 26 seconds, so I made a 2s crossover period instead of about four sounds at once.  :whistle:
Title: Re: Indirect Fire Attack Simulation
Post by: Shadow.D. ^BOB^ on 17 Feb 2009, 14:06:42
Well what can i say, you guys are top notch.  Thankyou to Laggy for the original scipt and Rommel for his super "pimped" version.  :cool2: This is the reason, OFP/ArmA has the best community out there.

Before I call this one as complete, can i just verify the values to change:-

1. The length of the random time in which the attack begins.

2. The length of time the attack continues.

3. The length of time before the sound file replays, during the attack.

I will get testing this in my template asap, it really is gonna add something special.

Once again, you boys have far exceeded my expectations.  THANKYOU!!  :clap: