Home   Help Search Login Register  

Author Topic: Force a shell to land at least certain distance from something.  (Read 777 times)

0 Members and 1 Guest are viewing this topic.

Stu35

  • Guest
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:

Code: [Select]
_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?

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
You might wanna try this(edit it for better effect, this sux):

Code: [Select]
_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:

Stu35

  • Guest
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.
« Last Edit: 09 Oct 2003, 17:15:15 by Stu35 »

Offline Artak

  • The old beanbag shaker
  • Former Staff
  • ****
  • You want to talk about it, yes?
    • OFP Team Finlanders
_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]
Not all is lost.

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
This will make the shell land in different directions:
Code: [Select]
#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 ::)
« Last Edit: 09 Oct 2003, 18:43:43 by The real Armstrong »

m21man

  • Guest
Artak's snippet is much more elegant, so use it.

:beat: *Shoots Armstrong* :beat:

Offline Sui

  • Former Staff
  • ****
    • OFPEC
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:
Code: [Select]
_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]
« Last Edit: 10 Oct 2003, 02:35:31 by Sui »

PBA12511

  • Guest
Yeah, exactly what he said....  ;D

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
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).

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
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

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Force a shell to land at least certain distance from something.
« Reply #10 on: 11 Oct 2003, 19:06:25 »
Lets also not forget that Armstrong's code doesn't even work!

Code: [Select]
_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.  ::)
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!