Home   Help Search Login Register  

Author Topic: Mortar  (Read 1470 times)

0 Members and 1 Guest are viewing this topic.

Offline Jimboob

  • Former Staff
  • ****
Mortar
« on: 05 Jun 2006, 16:35:32 »
Trying to create a random mortar to a certain location for a certain ammount of time. All my scripting knowledge has disppeared since ofpecs disappearce.

So i need a revamp. :)

Offline Northgarden

  • Members
  • *
Re: Mortar
« Reply #1 on: 05 Jun 2006, 17:40:29 »
I just use this Barrage script:

_Actor = _this select 0
_Centre = _this select 1
_area = _this select 2
_freq = _this select 3
_rounds = _this select 4

_ActorPos = GetPos _Actor
_oldx = _ActorPos select 0
_oldy = _ActorPos select 1
_oldz = _ActorPos select 2

_CentrePos = GetMarkerPos _Centre
_cx = _CentrePos select 0
_cy = _CentrePos select 1

_areaX2 = _area * 2

#Update
_rounds = _rounds - 1
_Actor SetPos [_cx + Random(_areaX2) - _area,_cy + Random(_areaX2) - _area, 0]
_Actor SetDammage 1
~0.01
_Actor SetPos [_oldx,_oldy,_oldz]
_Actor SetDammage 0
~_freq
? (_rounds > 0) : goto "Update"
exit


This script uses the variable named _freq to control the delay between each round. It uses _rounds to keep track of how many shells to fire and how many that is left. If you study the line which jumps to Update you will see that I check if rounds is greater then 0, if it is continue to bombard else exit the script. You will also notice that I added a variable named _area in order to specify the maximum divergence from the centre each round could get. You might also notice that I choose not to multiply _area with 2 each time I fire a round, instead I created another local variable named _areaX2 which is only calculated once. This will speed up things a little. In these kinds of scripts speed is almost everything. That's it!
Start off by creating an empty  mortarshell or something which we will use as an detonator. Name it explo. (You just create your player first) Continue by creating a marker somewhere and name it Here. In the players init field type something like this.

[explo, "here", 50, 0.5, 100] exec "barrage.sqs"

This will set up an artillery barrage with 100 rounds which will fire 2 rounds each second. The bombardment will stay within a good 50 metres from the marker. You should place the detonator vehicle somewhere where the player won't see it.