[TUTORIAL] Beginners guide to weapons modding

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

vedder1993
Posts: 5
Joined: Sat, 8. Dec 18, 01:02
x4

[TUTORIAL] Beginners guide to weapons modding

Post by vedder1993 » Sat, 8. Dec 18, 16:06

Hey.

With some help, I spend today making sense of the file structure used by X4. Some of you might have seen the X4 tracer world mod (thanks for that awesome mod rjtwins!) and wonder how to edit and or add weapons in X4. To get you started I have set up this basic guide to file structure. I hope this help people in understanding what files are related to gun damage, gun FX etc.
Note that this guide does not include how to make XML Patch files if there is enough demand I might make this.

First, you need to extract the needed files, for this, I refer you to this guide: viewtopic.php?f=181&t=402452

Next, we need to make sense of the file structure that is used in X4, this will help us find the right files in the right folders. Disclaimer I'm not an expert on file types.
We will be looking into files from the following folders:
Spoiler
Show
Image
We will start in libraries/wares.xml
This file contains all wares in the game including weapon systems. I like to use this file as a guide directing me to all the files I need to edit or add.
We will take a look at the medium laser turret from the Argon:
Spoiler
Show

Code: Select all

<!-- Example of a weapon ware -->
<ware id="turret_arg_m_beam_01_mk1" name="{20105,4164}" description="{20105,4161}" group="turrets" transport="equipment" volume="1" tags="equipment noplayerblueprint turret">
    <!-- The number in name and discriptoin refer to page and id number found in t/001-L044(for eng). These names are shown in the shopping list and only there-->
	<price min="45385" average="50428" max="55471" />
    <production time="10" amount="1" method="default" name="{20206,101}">
      <primary>
        <ware ware="advancedelectronics" amount="6" />
        <ware ware="energycells" amount="10" />
        <ware ware="turretcomponents" amount="10" />
      </primary>
    </production>
    <component ref="turret_arg_m_beam_01_mk1_macro" amount="1" />
	[b]<!-- this refers a macro, the linked macro in:
	Assets/props/weaponsystems/energy/macros-->[/b]
    <restriction licence="militaryequipment" />
    <use threshold="0.65" />
    <owner faction="argon" />
  </ware>
You can now already edit the price, needed components for construction etc in here, but more interested are the properties of the weapon itself.
For this, we have to go to the linked macro file: Assets/props/weaponsystems/energy/macros/turret_arg_m_beam_01_mk1_macro.xml
We will find the following file in there:
Spoiler
Show

Code: Select all

<macros>
  <macro name="turret_arg_m_beam_01_mk1_macro" class="turret" alias="turret_arg_m_beam_02_mk1_macro">
    <component ref="turret_arg_m_beam_01_mk1" />
	<!-- this refers to the component linked to this weapon listed in Assets/props/weaponsystems/energy information about the model of the weapon indicated in these 
         files -->
    <properties>
      <identification name="{20105,4164}" basename="{20105,4161}" shortname="{20105,4165}" makerrace="argon" description="{20105,4161}" mk="1" />
      <!-- The name here will show up everywhere but the shoppinglist -->
	  <bullet class="bullet_gen_turret_m_beam_01_mk1_macro" />
	  [b]<!-- This refers to the FX of the weapon,the bullet/beam etc, leaving the weapon. Found in Assets/fx/macros-->[/b]
      <rotationspeed max="90" />
      <reload rate="0.5" time="1" />
	  <!-- not sure what this does yet -->
      <hull threshold="0.2" integrated="1" />
    </properties>
  </macro>
</macros>
There are two links that are important here, first the component, listed in Assets/props/weaponsystems/energy. Altering this file results in a different look for the weapon. However, the file I'm more interested in is the bullet class located in Assets/fx/macros/bullet_gen_turret_m_beam_01_mk1_macro.xml
Spoiler
Show

Code: Select all

<macros>
  <macro name="bullet_gen_turret_m_beam_01_mk1_macro" class="bullet">
    <component ref="bullet_gen_s_beam_01_mk1" />
	<!-- this referst to a XML file in the weaponFx folder. This xml file has fx information about the projectie, however it also indicates where the weapn is fired from this 
          will become more importand later->
    <properties>
      <bullet speed="7000" lifetime="1" range="2550" amount="1" barrelamount="1" icon="weapon_beam_mk1" maxhits="1" ricochet="0" scale="1" attach="1" />
      <reload time="3" />
      <damage value="58" repair="0" />
	  <!-- properties of the projectile, this is differnt for bullet or beam weapons -->
      <effects>
        <impact ref="impact_gen_m_beam_01_mk1" />
        <launch ref="muzzle_gen_m_beam_01_mk1" />
		<!-- referst to fx for impact and muzzle blast -->
      </effects>
      <weapon system="turret_shortrange" />
	  <!--for any non turret weapons use weapon_standart here. For turrets you can use turret_shortrange/ turret_midrange/ turret_longrange or turret_mining.
	  This value needs to reflect the type of weapon you are attaching the bullet to for turrets use turret_xxxx for mining use mining and or everything else use 
          Weapon_standard-->
    </properties>
  </macro>
</macros>
This is where we can edit the behaviour of the projectile itself, this also affects the fire rate and range. As stated before the code for beam weapons is different than for bullet and laser projectiles.

Beam:
Spoiler
Show

Code: Select all

    <properties>
      <bullet speed="7000" lifetime="1" range="2550" amount="1" barrelamount="1" icon="weapon_beam_mk1" maxhits="1" ricochet="0" scale="1" attach="1" />
      <!-- speed= m/s, lifetime= beam length in sec, range = max range for beam weapon -->
      <reload time="3" />
      <damage value="58" repair="0" />
NOTE: for this code, the max range for this weapon is 2550m if there was no max range indicated a 7000m long beam would travel infinitely.
Beam weapons are the only weapons on the game that have the scale=1 and attach=1 value if you create a new beam weapon make sure to set these to the right value.


Gatling:
Spoiler
Show

Code: Select all

<properties>
      <ammunition value="21" reload="1" /> <!-- rounds in clip, reload time of clip in sec. -->
      <bullet speed="1920" lifetime="2.5" amount="1" barrelamount="1" icon="weapon_gatling_mk1" timediff="0.025" angle="0.25" maxhits="2" ricochet="0.01"
       restitution="0.3" scale="0" attach="0" /> <!-- speed= ms/s, lifetime= sec alive., amount=rounds at the same time, barrel=how many barrels  -->
      <heat value="43" /> <!-- heat generated per shot -->
      <reload rate="14" /> <!-- rounds per sec. -->
      <damage value="23" repair="0" />
For example, to make a weapon fire faster you change the reload rate and lower the damage rate accordingly like done in the x4 tracer world mod.

If you are still here, thanks for reading and I hope you learned something from this. Feel free to ask questions :gruebel:

jmattspartacus2
Posts: 73
Joined: Wed, 5. Dec 18, 08:04

Re: [TUTORIAL] Beginners guide to weapons modding

Post by jmattspartacus2 » Tue, 11. Dec 18, 10:59

There's an excellent (and very relevant guide) to xml patching on the x-rebirth modding forum here
viewtopic.php?t=354310

It helped me make all the mods I've made so far (simple edits and whatnot, but a step)

Vaeo
Posts: 234
Joined: Wed, 27. May 09, 08:03
x4

Re: [TUTORIAL] Beginners guide to weapons modding

Post by Vaeo » Wed, 12. Dec 18, 13:35

Awesome topic. TY.

cirelli
Posts: 1
Joined: Fri, 30. Nov 18, 21:50
x4

Re: [TUTORIAL] Beginners guide to weapons modding

Post by cirelli » Sun, 6. Jan 19, 16:02

I'm making a Mk2 version of the Behemoth weapon, it working well but, i can not figure out how to put a image of the weapon on the buy ship UI.

I noticed there the firing animation is much slower than the firing, is there a way to speed up the animation?

alexringess
Posts: 40
Joined: Tue, 25. Sep 18, 23:57
x4

Re: [TUTORIAL] Beginners guide to weapons modding

Post by alexringess » Mon, 7. Jan 19, 12:43

Most of the peoples that want to do mods for X4 are dissuaded to start because of the data digging that must done before all (where the files are, what params must be changed, etc).
So many thanks for that usefull guide :)
+rep

pzgren
Posts: 1
Joined: Fri, 1. Feb 19, 01:04
x4

Re: [TUTORIAL] Beginners guide to weapons modding

Post by pzgren » Fri, 1. Feb 19, 02:13

How do I create a new weapon mod which do not change any original weapon but also available in shipyards

User avatar
Shuulo
Posts: 1175
Joined: Mon, 14. Apr 08, 17:03
x4

Re: [TUTORIAL] Beginners guide to weapons modding

Post by Shuulo » Mon, 11. Mar 19, 00:47

Any info on how to mod gatling sound (or any other looping sound)? It seems to NOT be assigned via sound_library and effects file.

Skatsanni
Posts: 2
Joined: Wed, 16. Oct 19, 10:07

Re: [TUTORIAL] Beginners guide to weapons modding

Post by Skatsanni » Mon, 21. Oct 19, 21:54

How can i change range for bullet projectiles?

teleportationwars
Posts: 158
Joined: Fri, 12. Jul 19, 14:03

Re: [TUTORIAL] Beginners guide to weapons modding

Post by teleportationwars » Tue, 22. Oct 19, 00:58

Skatsanni wrote:
Mon, 21. Oct 19, 21:54
How can i change range for bullet projectiles?
Lifetime * Speed

Range acts as a maximum travel distance.

Skatsanni
Posts: 2
Joined: Wed, 16. Oct 19, 10:07

Re: [TUTORIAL] Beginners guide to weapons modding

Post by Skatsanni » Tue, 22. Oct 19, 10:34

teleportationwars wrote:
Tue, 22. Oct 19, 00:58
Skatsanni wrote:
Mon, 21. Oct 19, 21:54
How can i change range for bullet projectiles?
Lifetime * Speed

Range acts as a maximum travel distance.
Thanks!

Where can i change types of weapons which can i install?

Can i add more "fire sounds" for one weapon type?

teleportationwars
Posts: 158
Joined: Fri, 12. Jul 19, 14:03

Re: [TUTORIAL] Beginners guide to weapons modding

Post by teleportationwars » Tue, 22. Oct 19, 13:43

Skatsanni wrote:
Tue, 22. Oct 19, 10:34
teleportationwars wrote:
Tue, 22. Oct 19, 00:58
Skatsanni wrote:
Mon, 21. Oct 19, 21:54
How can i change range for bullet projectiles?
Lifetime * Speed

Range acts as a maximum travel distance.
Thanks!

Where can i change types of weapons which can i install?

Can i add more "fire sounds" for one weapon type?
The connection on the weapon and the connection on the ship are connected by customizable inclusive tags.

Max Bain
Posts: 889
Joined: Wed, 27. Jun 18, 19:05
x3ap

Re: [TUTORIAL] Beginners guide to weapons modding

Post by Max Bain » Wed, 30. Oct 19, 09:52

I have got a question.

We have turrets and we have projectiles. And both have reloadrate and reloadtime values.

I think that reloadrate defines the time between shooting two times until the magazin is empty. Then the reload timetime defines the time to reload the magazin, right?
But why do we have the same values for turrets and projectiles?

What is the difference?

WHat is the complete forumla for calculating DPS?
X4 Editor (view stats of objects and make your own mod within a few clicks) viewtopic.php?f=181&t=421306
XR Ship Pack (adds several ships from XR) viewtopic.php?f=181&t=419641
Weapon Pack (adds several new weapons) viewtopic.php?f=181&t=421266

User avatar
Shuulo
Posts: 1175
Joined: Mon, 14. Apr 08, 17:03
x4

Re: [TUTORIAL] Beginners guide to weapons modding

Post by Shuulo » Wed, 30. Oct 19, 10:47

Max Bain wrote:
Wed, 30. Oct 19, 09:52
I have got a question.

We have turrets and we have projectiles. And both have reloadrate and reloadtime values.

I think that reloadrate defines the time between shooting two times until the magazin is empty. Then the reload timetime defines the time to reload the magazin, right?
But why do we have the same values for turrets and projectiles?

What is the difference?

WHat is the complete forumla for calculating DPS?
You are correct on reload rate (for rate of fire) and reload time (reload of magazine).
Turret values for reload are not used at all, it seems to be a redundancy after XR.
Last edited by Shuulo on Wed, 30. Oct 19, 10:59, edited 1 time in total.

User avatar
Shuulo
Posts: 1175
Joined: Mon, 14. Apr 08, 17:03
x4

Re: [TUTORIAL] Beginners guide to weapons modding

Post by Shuulo » Wed, 30. Oct 19, 10:51

Skatsanni wrote:
Tue, 22. Oct 19, 10:34
teleportationwars wrote:
Tue, 22. Oct 19, 00:58
Skatsanni wrote:
Mon, 21. Oct 19, 21:54
How can i change range for bullet projectiles?
Lifetime * Speed

Range acts as a maximum travel distance.
Thanks!

Where can i change types of weapons which can i install?

Can i add more "fire sounds" for one weapon type?
As for fire sounds - yes, you can make an entry in sound library to randomly choose one of few samples. Check vro mod how it is implemented

Max Bain
Posts: 889
Joined: Wed, 27. Jun 18, 19:05
x3ap

Re: [TUTORIAL] Beginners guide to weapons modding

Post by Max Bain » Wed, 30. Oct 19, 15:35

What about beam weapons and their damage?

An L Beamweapon has 112 Damage and 0 reloadrate and 5 reload time. I doubt that the DPS of the L turret is 112 until it overheats when an M railgun has 800 damage per shot and shoots once every second. I think it does 112 damage way more often than once a second.

Whats the tick rate per second in X4? Does anyone know that? Maybe 10 per second or 5? And am I right that beam weapons do the damage per tick instead of reload rate (reloadrate is 0)?
X4 Editor (view stats of objects and make your own mod within a few clicks) viewtopic.php?f=181&t=421306
XR Ship Pack (adds several ships from XR) viewtopic.php?f=181&t=419641
Weapon Pack (adds several new weapons) viewtopic.php?f=181&t=421266

Post Reply

Return to “X4: Foundations - Scripts and Modding”