OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Stu35 on 09 Oct 2003, 16:21:56
-
right, this is simple stuff, but i can't bloody remember it - basically i have the player under an artillery strike, but i don't want that strike to kill him, so i want it to land within a hundred metres of him, but at least 25 metres from him, if you follow me.
Now i can make the shells land within a hundred metres of him, but thats no good on its own because they kill him most of the time.
Basically what i have is:
_counter=0
~5
#shelling
_cx = _Explosion select 0
_cy = _Explosion select 1
_cz = _Explosion select 2
_cx = _cx + random _spread
_cy = _cy + random _spread2
_cz = _cz + 0
_tempObj = _AmmoType camCreate[_cx, _cy, _cz]
~0.01
_tempObj = objNull
_counter = _counter + 1
~3
?(_counter == _Shells):exit
goto "shelling"
where
_AmmoType = "Shell73"
_unit = _this select 0
_spread = 100
_spread2 =100
_Explosion = GetPos _unit
_Shells = 30
so you see, i can get the spread to 100 (using spread and spread2), but i can't remember how to set it to miss the player by 25.
i have tried putting
miss = 25
miss2 = 25
and in the script setting
_cx = _cx > random _miss
_cy = _cy > random _miss2
but it aint workin'.
Can anyone give me a bit of help here?
-
You might wanna try this(edit it for better effect, this sux):
_cx = player select 0
_cy = player select 1
_cz = player select 2
_cz = _cz + random 100
_cx = _cx + random 100 + 25
_cy = _cy + random 100 + 25
boom = "heat125" camCreate[_cx, _cy, _cz]
Syntax not guaranteed.
:beat: *Gets Shot* :beat:
-
hmmm, seems to be okay, for some reason the shells always land in exactly the same general direction (north east) rather than in a circular pattern, but its the best thing so far, cheers mate.
-
_bearing = random(360)
_distance = random(75)+25
_tempobj = _ammotype createvehicle [(getpos player select 0) + sin (getdir player + _bearing) * _distance, (getpos player select 1) + cos (getdir boat1 + _bearing) * _distance, 50]
Would that work in your loop?
[size=0.1]Ooh no I can't do anything with sin and cos and basicly anything that has anything to do with math. This is thanks to MI_Fred if I remember correctly. It's working like a charm in a mission of mine..[/size]
-
This will make the shell land in different directions:
#bombem
_cx = player select 0
_cy = player select 1
_cz = player select 2
_cz = _cz + random 100
_cx = _cx + random 100
_cy = _cy + random 100
_which = random 4
_cx = _cx - _cy
_cy = _cz - _cx
? _which <= 4: _cy = _cy - 25
? _which <= 3: _cx = _cx - 25
? _which <= 2: _cy = _cy + 25
? _which >= 1: _cx = _cx + 25
boom = "heat125" camCreate[_cx, _cy, _cz]
~0.5
goto "bombem"
Syntax not guaranteed.
:beat: *Gets Shot* :beat:
EDIT: Artak's version is probably better but at least you understand my version ::)
-
Artak's snippet is much more elegant, so use it.
:beat: *Shoots Armstrong* :beat:
-
Yikes... some clunky work arounds here ;D
If you ever want to choose a random number between two values, just double the value then take away half.
eg.
randomnumber = (random 200) - 100
randomnumber = (random 400) - 200
randomnumber = (random 500) - 250
The first of those chooses a number between -100 and 100.
The second between -200 and 200.
The third between -250 and 500. You see?
No need for cumbersome ? : operations :)
Next... checking if the explosion is within 25 of the player...
Try something like this:
_counter=0
~5
#shelling
_cx = (_Explosion select 0) + (random (_spread * 2) - _spread)
_cy = (_Explosion select 1) + (random (_spread2 * 2) - _spread2)
_cz = _Explosion select 2
? (_cx < (getpos player select 0) + 25) and (_cx > (getpos player select 0) - 25) and (_cy < (getpos player select 1) + 25) and (_cy > (getpos player select 1) - 25): goto "shelling"
_tempObj = _AmmoType camCreate[_cx, _cy, _cz]
~0.01
_tempObj = objNull
_counter = _counter + 1
~3
?(_counter == _Shells):exit
goto "shelling"
So the crux of it is this nasty looking line here:
? (_cx < (getpos player select 0) + 25) and (_cx > (getpos player select 0) - 25) and (_cy < (getpos player select 1) + 25) and (_cy > (getpos player select 1) - 25): goto "shelling"
What that does is compare the randomly chosen shell position with that of the player. If they're within a 25m circle, it rechooses the position. This means you will never get a shell landing closer than 25m to the player ;)
Anyway, try that and see if it works as advertised...
[size=0.5]Edit: typos in code are bad... mmk...[/size]
-
Yeah, exactly what he said.... ;D
-
Use ARTAK's code for more eficient use of your computer's rescources. It randomly selects distance in the range of 25 to 100 m as well as direction in a 360 arc around the player. Therefore, with his good use of trigonometry, each loop will create a viable shell without a conditional statement. Each loop produces a shell instead of sometimes going through a second or third loop before a valid shell location is found. ;)
I wrote a similar script, but it creates flak in random directions and distances around and above an aircraft. I will be submiting this code to the Editor Depot early next week (Oct 13 or 14) after I improve the user notes and comments. So if you can wait a few days you can just use that code (I will add comments explaining how to modifiy it for 2D situations as in a ground based attack).
-
Re-reading ARTEK's post, I see that MI_fred is the one who should get the credit for the good use of trigonometry!! ;D
-
Lets also not forget that Armstrong's code doesn't even work!
_cx = player select 0
_cy = player select 1
_cz = player select 2
"player select 0" will return an error, because "player" is not an array!
Armstrong, what you need is to say "getpos player select 0", because "getpos player" returns an array with the player's coordinates. "Player" just returns the player, which is an object. ::)