Home   Help Search Login Register  

Author Topic: Shoot from a vehicle  (Read 1443 times)

0 Members and 1 Guest are viewing this topic.

Loup-Garou

  • Guest
Shoot from a vehicle
« on: 20 Apr 2005, 22:57:33 »
Hi all !

I've always tough that a unit can shoot when she'es in a truck or a car would be a cool addiction to OFP. I've just found a limited, but quite good solution, with a modification of the good old script "MGCarry.sqs" (I've just changed the MG for a soldier) :

In init.sqs, type :

[Vehiclename,Unitname,0.785] exec "MGCarry.sqs"

exit

MGCarry.sqs :

_carrier = _this select 0
_cargo = _this select 1
_height = _this select 2

endCargoSession = false

goto debug

#carrier

_x = (getPos _carrier) select 0
_y = (getPos _carrier) select 1
_z = ((getPos _carrier) select 2)+_height

_cargo setPos [_x, _y, _z + 0.9 ]
_cargo setDir (getDir _carrier)

~.01

? (!endCargoSession) : goto "carrier"

@ endcargosession
_cargo setpos [_x,(_y)-1.5,0]

exit

Results of the test :

- Use the setUnitPos command to make the unit "DOWN" for cars OR "UP" for trucks. If you don't do that the unit will die after a few seconds.
- As driver, the AI doesn't drive at full speed. As "gunner", it seems that the AI shots the enemies only when they're quite close (about 50 meters), but a human (as driver) can drive at full speed without any problem. The script works perfect with two humans  :D !
- The gunner can only fire before him ; only the driver can change the direction. That limit is greater with trucks, because of the cab (the gunner can shot only enemy who are on hills or flying choppers).

If you have ideas for improve this script, don't hesitate  :) !

Loup-Garou

  • Guest
Re:Shoot from a vehicle
« Reply #1 on: 22 Apr 2005, 22:07:40 »
I'm currently searching for another solution : a kind of "killer look" :

The script :

_Gun73 CreateVehicle [getPos _Playername select 0,(getPos _Playername select 1)+3,getPos _Playername select 2]
_Gun73 setDir (getDir _Playername)
_Gun73 setVelocity [0,28,0]

exit

It actually doesn't work, but it contains the idea : create a bullet before the player, with a speed of around 28 m /s (100 km / h) <-(However I'm not sure that a bullet has this speed, but's It's actually not important). I know it's possible to get the direction the player is looking (used in artillery script of the mission "Iron Wall", for example), and I know that a grenade can be created with the command camcreate, too. BUT DOES ANYONE KNOW IF IS IT POSSIBLE TO CREATE A BULLET ??

Please help  :help: :help:  :help:  !!
« Last Edit: 22 Apr 2005, 22:09:31 by Loup-Garou »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Shoot from a vehicle
« Reply #2 on: 22 Apr 2005, 22:39:32 »
It should be possible, after all you can create a tank shell.

Both bullets and tank shells use the same p3d model.

They just differ in the class names.   ;D ;D



Planck
I know a little about a lot, and a lot about a little.

Loup-Garou

  • Guest
Re:Shoot from a vehicle
« Reply #3 on: 22 Apr 2005, 22:46:36 »
It should be possible, after all you can create a tank shell.

Really ? And how can I do this ? I'm very  interested  ;D !
« Last Edit: 22 Apr 2005, 22:46:51 by Loup-Garou »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Shoot from a vehicle
« Reply #4 on: 22 Apr 2005, 22:59:43 »
Ok try this:

shell = "Shell120" createvehicle getpos player

That should kill you.

shell = "BulletSingle" createvehicle getpos player

This probably won't kill you, in fact you may not even see the bullet as it will disappear as soon as it touches the ground, that is, as soon as it is created almost.


Planck
I know a little about a lot, and a lot about a little.

Loup-Garou

  • Guest
Re:Shoot from a vehicle
« Reply #5 on: 22 Apr 2005, 23:19:32 »
I've made this :

shell = "BulletSingle" CreateVehicle [getPos Civ1 select 0,(getPos Civ1 select 1)+3,getPos Civ1 select 2]
_shell setDir (getDir Civ1)
_shell setVelocity [0,28,0]

exit

The bullet's creation works perfect (thanks a thousand times  :thumbsup: !), but it seems that the getPos, getDir and setVelocity are a little...ignored...or perhaps they need others values. I'll search for that tomorrow (it's time to go to bed for me  ;D).

And thanks again, Planck !  :D

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Shoot from a vehicle
« Reply #6 on: 22 Apr 2005, 23:25:15 »
I think:

_shell setDir (getDir Civ1)
_shell setVelocity [0,28,0]

Should be:

shell setDir (getDir Civ1)
shell setVelocity [0,28,0]


Planck
I know a little about a lot, and a lot about a little.

Loup-Garou

  • Guest
Re:Shoot from a vehicle
« Reply #7 on: 23 Apr 2005, 17:21:22 »
THANKS AGAIN IT WORKS  :D  :D  :D !!!

In the init field of the vehicle(s) type : this addAction ["Shoot from vehicle","Nameofthescript.sqs"]

The script :

shell = "BulletSingle" CreateVehicle [getPos Nameoftheplayer select 0,(getPos Nameoftheplayer select 1)+3,(getPos Nameoftheplayer select 2)+1]
shell setDir (getDir Nameoftheplayer)
shell setVelocity [0,28,0]

exit

It's not very easy to aim at your target, but you can be certain that this attack is 100 % fatal for your enemies  :gunman: !

If you want to give limited ammo make something like this : type  : ammo=0;Shoot= Nameoftheplayer addAction ["Shoot from vehicle","Nameofthescript.sqs"] in the player's init field, and type in the script :

shell = "BulletSingle" CreateVehicle [getPos Nameoftheplayer select 0,(getPos Nameoftheplayer select 1)+3,(getPos Nameoftheplayer select 2)+1]
shell setDir (getDir Nameoftheplayer)
shell setVelocity [0,28,0]
ammo = ammo + 1
?ammo == 30: hint "No more ammo !"; Nameoftheplayer removeaction Shoot; exit

exit

I won't lock the topic immediatly...may be someone has other things to tell about the subject.  

EDIT :

If you drive toward north, you shoot before you.
If you drive toward south, you shoot behind you.
If you drive toward west, you shoot on your right.
If you drive toward east, you shoot on your left.
« Last Edit: 23 Apr 2005, 18:44:45 by Loup-Garou »

sa8gecko

  • Guest
Re:Shoot from a vehicle
« Reply #8 on: 24 Apr 2005, 17:57:58 »
Quote
EDIT :

If you drive toward north, you shoot before you.
If you drive toward south, you shoot behind you.
If you drive toward west, you shoot on your right.
If you drive toward east, you shoot on your left.
Of course. You set the velocity with [0,28,0], that is in a northern direction.
Look at what you wrote: you fires always north !
You should set the bullet velocity, for the player to fire always in
front of him, with the sine and cosine of the direction:
Code: [Select]
shell setVelocity [28*sin(getDir Nameoftheplayer),28*cos(getDir Nameoftheplayer),0]maybe sine and cosine in the above formula are misplaced or some need
a minus sign before, it all depends on the directions the values of the x,y
cohordinates grow in OFP.

Loup-Garou

  • Guest
Re:Shoot from a vehicle
« Reply #9 on: 26 Apr 2005, 14:32:48 »
Look at what you wrote: you fires always north !

Don't worry ;D ! I knew that, of course ! This was just a summary !

I've made a quick test of your code, but for the moment, I prefer my little "[0,28,0]"... :P.
« Last Edit: 26 Apr 2005, 14:33:13 by Loup-Garou »