Nexus Modding > Mod Development / Released Mods

Beam Weapons

<< < (2/3) > >>

The Old Dragon:
Ok, technically not beam weapons, but they are weapons none-the-less.

My first foray into weapons creation has yielded the light PPC and its bigger brother, the heavy PPC.
The lighter, tactical version fires three to five shots per burst while the meatier, hull wrecking heavy PPC is restricted to two to three shots a go. Both have a recharge period of five to ten seconds.





If anyone has any ideas on how to improve the code, then please let me know because it's a lot of work involved to increase the machines capacity.

Edit - 05/02/2010:

Updated to V1.1.
Now uses Arparso's refined machine script.
Weapons limit removed.
Much smaller size.

Arparso:
A quick suggestion - in your first rule ("In") you can remove most of your selection logic. For example:

SelectShips(WeaponsCheck,S.race=#race_Player|Not(S.race=#race_Player));

... is a needlessly complicated way to select all ships in the scene. Better just use:

Select(WeaponsCheck, s.ship);

That achieves the same result while being much cleaner and requiring less processing time (although that's purely theoretical - your original SeletShips()-command shouldn't have any impact on performance). Actually, you won't need that line either, since all your care about are the devices and not the ships. You don't need to select all ships in the scene in order to collect all the PPC weapons on them - just select the weapons straightaway:

Select(M.PPCL, s.device & s.devType = #weap_Light_PPC);

Another optimization hint: don't use prefixes, where you don't need them. If you store your selection in M.PPCL, this selection will be available to the whole mission script and all its machines and rules, comparable to a global variable in programming languages. Generally, you don't want that. What if a completely separate part of your mission script uses the same name for a completely different selection? You may get unexpected conflicts all over the place and will have a hard time debugging them. In short: use prefixes only where you need them:
- use no prefix for variables, that all the rules in your machine need to access
- use E. for variables, that only matter for the current rule and can be thrown away after the rule's execution
- use M. for variables you want to share with the whole mission script

So a proper select-statement could be:

Select(PPCL, s.device & s.devType = #weap_Light_PPC);

---------------------------------------------------

Enough about coding style, now the interesting bits: the biggest drawback of your script is the lack of flexibility. Adding new burst weapon types or expanding the current limit of 40 weapons per weapon type will require a lot of copy&paste, which is a pain in the ass, basically. If you change a small part of your script (e.g. to fix a bug) you'll need to copy&paste that fix to several dozen locations. That procedure itself takes a lot of time and may even introduce new bugs along the way, if you forget something or make any error while copying.

You're using a huge amount of explicit variables keeping track of the current burst length, targetted ships, etc. ... that works, but is also the reason for the problem mentioned above. I've rewritten your script to fix that issue with the use of arrays, which allow for an unlimited number of burst fire weapons in the scene and make adding new weapon types much easier. Basically I'm using three lists:

BurstWeapons contains all burst fire weapons, light or heavy PPCs or whatever you want
RemainingBurstShots contains the remaining shots in the current burst - if it's 0, a new burst is about to begin
BurstTargets contains the last target of each weapon before being disabled

All three lists are linked by the weapon's index in the BurstWeapons-list, which you can get using IndexOf(). A weapon at index 3 in BurstWeapons will have its remaining burst shots stored at index 3 in RemainingBurstShots while its target is also saved at index 3 in BurstTargets.

Just take a look at the provided script to see how it works in detail.

The Old Dragon:
Thanks Arparso, that's certainly a lot easier then my behemoth, lol.

First off, just a quick note for those who d/l the new version. There's just a little typo in the 'DisableBurstWeapon' rule. The Timer command ends in a comma, not a semi:colon. So you'll just need to make a liitle edit before you run it.

And the first time I ran it, I did get an error where the mission editor got upset about an 'e.dev:device' not being valid, though I've not been able to reproduce it again. So hopefully it was just an odd quirk.

My first efforts did involve using temporary variables (such as the E.******), but after about ten or so weapons things started to go wrong. My thought here was that sometimes a variable was being overwritten by a new firing event before the old one could be fully processed.  Hence the use of permanant variables to keep track of things.

Time to get my studying head on, quite a few bits in there that I've hardly even seen, let alone used  :D

Once again, thank you. :thumbsup:

nasharas:
ok, I'm a noob here, but what a hell I have to do to make it work? I already included this file in my mission script, and called that machine, replaced weapons with my own, but still no work, my weapons shoot as they originally supposed... btw, mission was created by nexus skirmisher...please help, cos I really love the idea of burst firing...

Arparso:
What I actually don't like about this burst weapon approach is the disabling of the weapon. This prevents the user from cancelling the weapon fire or changing the target while the weapon is "recharging". I don't have any idea on how to do it better, though, given Nexus' scripting limitations...


--- Quote ---First off, just a quick note for those who d/l the new version. There's just a little typo in the 'DisableBurstWeapon' rule. The Timer command ends in a comma, not a semi:colon. So you'll just need to make a liitle edit before you run it.
--- End quote ---
Thanks, fixed that and another error in the LongRangeArrived rule and re-uploaded the script. I also changed some of the conditions to just check, if the device is part of the BurstWeapons-list instead of checking for each burst fire devicetype individually... makes expanding the script to apply to more weapon types easier, since you have to change fewer lines now.


--- Quote ---And the first time I ran it, I did get an error where the mission editor got upset about an 'e.dev:device' not being valid, though I've not been able to reproduce it again. So hopefully it was just an odd quirk.
--- End quote ---
That sounds strange. I obviously haven't had time to extensively test the script, so I can't guarantee, there'll be absolutely no error.


--- Quote ---My first efforts did involve using temporary variables (such as the E.******), but after about ten or so weapons things started to go wrong. My thought here was that sometimes a variable was being overwritten by a new firing event before the old one could be fully processed.  Hence the use of permanant variables to keep track of things.
--- End quote ---
Event variables shouldn't be accidently overwritten - they only exist during that specific rule's execution. Even if you call that rule multiple times (like for several weapons), each call should use their own set of event variables. Of course, that's only my assumption based on past experiences and observation - I don't know about the inner workings of Nexus' script support, so there could be some sort of bug causing variables to leak into spaces they don't belong to.


--- Quote ---ok, I'm a noob here, but what a hell I have to do to make it work? I already included this file in my mission script, and called that machine, replaced weapons with my own, but still no work, my weapons shoot as they originally supposed... btw, mission was created by nexus skirmisher...please help, cos I really love the idea of burst firing...
--- End quote ---
It's more of a modder's ressource and thus isn't as easily installed as an actual mod. I'll try to give a short guide:

(you'll need both Old Dragon's ppc.zip and my updated PPC.rar for this)
1. copy dev_weapons_new.ini to the mod's universetextstexts-folder
2. copy the contents of efx.ini to the mod's universeenginemod_efx.ini file
3. copy the contents of tacticstypes.ini to the mod's universetacticstacticstypes.ini (don't overwrite anything, just insert somewhere)
4. your mod may already have a DEVICETYPE 41 or DEVICETYPE 42, so change these two numbers of both inserted devicetypes to something, that's not being used already (e.g. for the Nexus Skirmisher mod, 360 and 361 work)
5. copy my ppc.mach to the mod's universemod_missions-folder
6. create a mission using the Skirmisher including a ship, that has the #weap_Light_PPC or #weap_Heavy_PPC onboard
7. open your mission file and include GetMachine("PPC"):ChangeState(Default, 0); in the SceneInit-RULE
8. include #include "PPC.mach" below the SceneInit-RULE

Repeat steps 6 to 8 for additional missions.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version