Author Topic: Easily getting vehicles to shoot on click.  (Read 4373 times)

I released this script here because it isn't directed at a player, this is rather directed at
modelers that want to implement a system that makes the vehicle shoot on click. Still, if this is the wrong forum, inform me about it.


About
This script enables you to easily make vehicles shoot projectiles on click.
It's all defined in the datablock if you choose to use this.

Screenshots of tests
Stuntplane with machine guns.


Jeep with multiple rocket launching.



Features
  • Uses a different coordinate system relative to the object, takes the direction it's facing into account.
    X: Forward vector
    Y: Left Vector
    Z: Up vector
  • Velocity uses this, too.
  • Supports holding the left mouse button to keep firing. (has a set delay between shooting)
  • Has a simple protection for clickspamming.
  • Supports scaled projectiles.
  • Supports required slots for using the system in the vehicle.
  • Very simple implementation in the vehicle. (datablocks)
  • This thing won't reexecute itself if in another add-on, so it only gets executed once.
  • Supports sounds on fire.

Usage
Include this in your zip if you are going to use it.
(don't forget to execute it in your server.cs!)

If you don't know how you would execute it, go to the server.cs, on top you write:
Code: [Select]
exec("./support_shootonclick.cs");
After doing that, go to the script file containing your datablocks.
Go to the vehicleData datablock.
In it, you can set a multitude of stuff, to activate the system simply put in this value:
Code: [Select]
ShootOnClick=1;
Now we have to set the settings, example:
Code: [Select]
ShootOnClick_Hold=1;
ShootOnClick_ShootDelay=100;
ShootOnClick_ReShootDelay=100;
ShootOnClick_ProjectileCount=2;
ShootOnClick_RequiredSlot=0;
ShootOnClick_Sound=RocketExplosionSound;

ShootOnClick_Projectile[0]=gunProjectile;
ShootOnClick_Position[0]="0 3 0";
ShootOnClick_Velocity[0]="120 0 0";
ShootOnClick_Scale[0]="1 1 1";
ShootOnClick_Projectile[1]=gunProjectile;
ShootOnClick_Position[1]="0 -3 0";
ShootOnClick_Velocity[1]="120 0 0";
ShootOnClick_Scale[1]="1 1 1";

If hold is 1, the player can hold the left mouse button to make it shoot again.
It shoots again every reshootdelay milliseconds.
Shootdelay is the minimum time between clicks, this is to prevent clickspamming.
ProjectileCount tells it how many projectiles to fire.
RequiredSlot tells it in what slot the player must be to shoot.

After that, we have the individual projectile definitions.
Projectile is the projectile's datablock.
Position is the position where it should be spawned, here it tells us:
0 forward
3 to the left
0 upwards
Velocity tells us how fast it should move, here it tells us:
120 forward
0 to the left
0 upwards
Last one is pretty easy, it's the scale the projectile should be.
Added sound: This is just an audio datablock.
(Fun fact: the example is what I tested on the stuntplane, it gave it machine guns on it's wings. ;D)

Download
You can download it here.

Changelog
V1.1
  • Added sounds, shootOnClick_Sound.

Any questions and/or suggestions? Post them here.
« Last Edit: November 23, 2008, 06:29:19 AM by NiXiLL »

Its awsome. (Bang Bang)

Love it.
Dogfights without items? o_o



Will it work for player vehicles?

Will it work for player vehicles?
Untested, but it will most likely work for anything that can be mounted to.

I'm on his Dogfight Test server, currently =D

FINALLY. This is the puzzle piece I needed for my aircraft!! Big Thanks for NiXiLL!!


After using this its great, but is it possable to make a firing sound like a gunshot?

Wut? There are no sounds?

I guess it'd be possible to make firing sounds for it, not going to do it now though, it's 05:10 here.

Cause of this Topic, I have many ideas for a good modeler and a scripter.

Say hello to V1.1!

V1.1
  • Added sounds, shootOnClick_Sound.