November 17, 2024, 00:03:52

Author Topic: Burst Fire Weapon  (Read 11811 times)

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Burst Fire Weapon
« on: January 20, 2010, 02:22:45 »
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: [Select]
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

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

Offline Arparso

  • Administrator
  • Lieutenant
  • *****
  • Posts: 558
  • Karma: 14
  • I can see you...
    • View Profile
    • http://arparso.de/nexus
Re: Burst Fire Weapon
« Reply #1 on: January 20, 2010, 03:00:27 »
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!?

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: Burst Fire Weapon
« Reply #2 on: January 20, 2010, 03:05:37 »
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.

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: Burst Fire Weapon
« Reply #3 on: February 01, 2010, 14:37:45 »
"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.
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: Burst Fire Weapon
« Reply #4 on: February 01, 2010, 16:16:57 »
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?)

Offline nasharas

  • Recruit
  • *
  • Posts: 15
  • Karma: 0
    • View Profile
    • http://
Re: Burst Fire Weapon
« Reply #5 on: February 01, 2010, 17:26:28 »
well actually it's easy done with weapons effects, simply add let's say three travel efx under one id and add to them delay function, and you got burst fire with three shots... done so far, but never managed to make them fire at the same point as first one shot...

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: Burst Fire Weapon
« Reply #6 on: February 01, 2010, 18:01:44 »
yes, but there game is going to show only one shot as damage or as the end effect.

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: Burst Fire Weapon
« Reply #7 on: February 01, 2010, 19:53:56 »
I was wondering the same myself.

@Mularac:

You don't really need to know anything about the ships involved, to be honest. It's all about the weapons.

By selecting every object in the scene and then checking them for burstfire weapons, you can place all of these weapons into a list (as I'm currently working on both light and heavy versions, I use two lists). With that done each can be given it's own variable with which the game can track what's going on. As I said earlier, the main downside is the amount of repeated code involved.

The complete machine should be able to handle twenty of each type, but if you want to put the extra effort in, then there's no reason why it can't handle more.

EDIT:

Removed the code due to a serious flaw in the initial weapon selection. Worked fine on my test ship because the rule only worked on the one ship, getting it sorted now (fingers crossed).
Better to look the fool by asking, then prove them right with ignorance.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
Re: Burst Fire Weapon
« Reply #8 on: February 01, 2010, 21:13:08 »
There's, however, a problem with your code, Old_Dragon. Since there's no way to know beforehand how many devices of the same class would be available, the reasonable thing to would be to set about 20 to be safe, right? however, the PickN command would give an error if the index is out of range, but since that error is more like a warning the editor gives, it wouldn't matter in the campaign setting, however, we do know that too much coding can make nexus buggy as hell.
Each ship may carry tops, lets say 4 weapon slots for that kind of weapon. And in the game there can be about 27 ships (lets make it a mere 12, as I doubt there would be any more ships than that at a scene at a time), so for now we have 48 different entries. And that's leaving out the code involved in including ships that may appear or drop from hyperspace later on, so the ammount of code may very well be too much for nexus to handle, and we all know how buggy it can get, specially in campaign mode.

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: Burst Fire Weapon
« Reply #9 on: February 02, 2010, 01:15:16 »
Hmmm, sometimes it can. That little 'just for fun ' mission I put together contains quite a bit of heavy coding and it ran fine here on my laptop (well, at least up untill about level five, lol).
And on top of that N:TAA is starting to get quite complicated with some missions weighing in at up to a hundred k or so without the additional 'include' files that it requires, apart from a rather annoying bit, it's not really struggling.

But, things like the index being out of range (wrestled with that one a few times) Shouldn't be a problem as the code progresses upwards with each entry and once mapped, the PickN command would only be required again if the rule were to be rerun (as in late arriving ships). In which case, the entire list would be cleaned and remapped.  

Though I do agree about the number of weapons being involved could get a bit too much. Maybe by opening up such ideas to a bit of public scrutiny then we can learn better ways doing things? Because if it wasn't for these forums, then I doubt I would of got anyway near where I am now.

So if anyone has any ideas on how to refine the code, then I'm all ears.
Better to look the fool by asking, then prove them right with ignorance.