Nexus Modding > Scripting

Burst Fire Weapon

(1/2) > >>

Mularac:
Got an other one. I was fooling arround, trying to create a "burst fire" effect for a weapon, and I finally did it, and it works, also. The downside is that the effect would only work properly if you use the F5, F6 or  F7 keys, manually, not so much. Also, the AI can't seem to be able to fully use it (it would only fire one burst at you).
So, here it is:

--- Code: ---MACHINE "Burst_Fire"

State Main

Rule event in
:action
SelectEx(s.this:Devtype=#*weapon*,
RequestFiredEvent(s.this,1);
);
:end
END

Rule event Fired
condition IsValid(E.location)&e.location:devtype=#*weapon*
:action
if(e.location:count=1,
EnableDevice(e.location,0);
                                                weap:=e.location;
Timer(Reload,3,e.dev:=weap);
);
:end
END

Rule event Reload
:action
enabledevice(e.dev,1);
LoadWeapon(e.dev,10);
:end
END
END
END

--- End code ---

The problem with this code is the fact that I had to use ammunition as a way to control the bursts, if only I could safely use a regular counter...

EDIT: Seriously, there's got to be something magical about this place, the solution came to me no more than 5 seconds after I finished posting this... perhaps it's the fact to express something out loud (in a figure of speech, that is), dunno.
Anyhow, all I had to do was to tell the weapon to open fire to the ship it was firing to before, if it existed, that is. It now works like a charm.
The revised code, if somebody wants it:


--- Code: ---MACHINE "Burst_Fire"

State Main

Rule event in
:action
SelectEx(s.this:Devtype=#*weapon*,
RequestFiredEvent(s.this,1);
);
:end
END

Rule event Fired
condition IsValid(E.location)&e.location:devtype=#*weapon*
:action
if(e.location:count=1,
weap:=e.location;
targ:=e.location:target;
ownr:=e.location:owner;
Debug("The weapon's owner is", ownr, "and the target would be",targ);
EnableDevice(e.location,0);
Timer(Reload,3,e.dev:=weap;e.targ:=targ;e.ownr:=ownr);
);
:end
END

Rule event Reload
:action
enabledevice(e.dev,1);
LoadWeapon(e.dev,10);
Debug("The weapon's owner is", e.ownr, "and the target would be",e.targ);
if(IsValid(e.targ)&IsValid(e.ownr),
TargetWeapon(e.dev,e.targ);
);
:end
END
END
END

--- End code ---

Arparso:
I like self-solving problems :D

I always thought groupfire in the TacticsTypes.ini was supposed to allow burst fire, but I'm terribly wrong with that, I guess!?

Mularac:
yep. Groupfire is the ammount of projectiles (or lasers, or missiles) fired at the same time. It's mostly used in fighters, as the groupfire command specifies how many fighters make every wing.
On the other hand, burst fire is a sucession of shots fired at quick sucession with a following period of inactivity as the weapon prepares for the next burst.

The Old Dragon:
"if only I could safely use a regular counter..." said Mularac wistfully.

Such things are possible, with Mularacs work as inspiration,I've been experimenting  with burst fire coding and now have Pulsed Plasma Cannons that seem to work fairly well.
By using the 'RequestFiredEvent' command, we can keep track of when a weapon fires and how many times it's fired (therefore cutting out the need for ammunition to regulate the burst size).

With the first shot, I set the current burst size and when the counter reaches this value, the weapon gets disabled to represent its 'recharging' period before being reactivated and fired again.

The downside is that I don't think Nexus would differentiate between weapons if you used temporary variables (E.ship, E.location, E.target, etc) while several burstweapons are firing simultaneously without having permanant variables to back up the data. Meaning that  the machine required to run burst firing (another downside, Nexus doesn't appear to have been written with this sort of thing in mind, resulting in the need for an 'include' file) would have to have enough names and rules already predefined to accomadate all the possible burstfire weapons in the scene, kinda making it a bit 'clunky'.

Once I've finished the machine, I'll look at adding it here with the weapons.

Mularac:
yeah, I've thought of that too, but it didn't work out for me... I found no way to difference between the shots of the different ships (withouth knowing beforehand how many ships were going to be in the battle with that weapon, and even so, how would the game know which counter belongs to which weapon if a ship had two or more of those burst-firing weapons?)

Navigation

[0] Message Index

[#] Next page

Go to full version