Author Topic: Learning to mod OpenXcom  (Read 8280 times)

Offline guille1434

  • Colonel
  • ****
  • Posts: 123
    • View Profile
Learning to mod OpenXcom
« on: July 28, 2014, 12:01:32 am »
Hello!

  I am trying to learn how to mod this wonderful game, but it seems that it is not a simple affair... After playing some OpenXcom with the Final Mod Pack installed, I decided it would be nice to introduce a small quantity of content to that already very complete mod.

My first project was to modify the sniper rifle Bigobs graphic, and then, if possible, to add a Clip of explosive bullets for that weapon. As I got tired of just getting program crashes while testing the files, I am here asking for some help.

First: Is there any documentation, tutorials, modding guides, etc, about how to mod OpenXcom? If this is so, where can I get that stuff?

Second: Maybe some more experienced modder here can have a look at my little ruleset file, and tell me where the mistake is. One thing that could point to something important: When I load the ruleset with the "handsprite: 136" line, the game crashes after loading the battlescape, past the inventory screen, then opens the battlescape proper, and when the program is auto-saving, it crashes. If I suppress that line, the game runs smoothly, till the moment the soldier who carries the Sniper Rifle is about to fire... When I give the fire order, the game immediately cashes...

Can anybody help me?

Thanks!

PS: By the way, just in case someone wants to use the "new" Sniper Rifle graphic, I am attaching it here. I decided to make this new file because, to my taste, the graphic included in the Final Mod Pack looked a little "plain-grey" to me.

Offline Falko

  • Commander
  • *****
  • Posts: 802
    • View Profile
Re: Learning to mod OpenXcom
« Reply #1 on: July 28, 2014, 12:24:37 am »
handSprite: 136 needs a corresponding
entry in extraSprites
like
  - type: HANDOB.PCK
    files:
      136: Resources/.......folderwith8images/
or
  - type: HANDOB.PCK
    subX: 32
    subY: 32
    height: 40
    width: 256
    files:
      136: Resources/......./imageofweaponin8directions.gif

Offline Dioxine

  • Commander
  • *****
  • Posts: 5412
  • punk not dead
    • View Profile
    • Nocturnal Productions

Offline yrizoud

  • Commander
  • *****
  • Posts: 1014
    • View Profile
Re: Learning to mod OpenXcom
« Reply #3 on: July 28, 2014, 02:04:56 am »
It's an extra difficulty when you "mod a mod" : Your .rul file can refer to numbered resources from the original game (those defined in Xcom1Ruleset.rul), but if you try use numbers created by a different mod, "it doesn't work" because OpenXCOM thinks you're also creating new resources.

In your case, when you copy an item to change some fields, you should systematically comment or delete the fields which point to numbered resources that you are not going to replace : bigSprite, floorSprite, handSprite, bulletSprite, and (the one which crashes currently) fireSound.



Offline guille1434

  • Colonel
  • ****
  • Posts: 123
    • View Profile
Re: Learning to mod OpenXcom
« Reply #4 on: July 28, 2014, 05:14:32 am »
Falko: Thanks for your advice. I could make it work!!  8)

Dioxine: Thanks also to you for the invaluable link. It will be very useful to me!

yrizoud: Your comment is also very valuable, and exlain a lot of thinks that were driving me almost crazy...

Thanks to all for the quick answers!!

Offline Aldorn

  • Commander
  • *****
  • Posts: 750
    • View Profile
Re: Learning to mod OpenXcom
« Reply #5 on: July 28, 2014, 01:54:23 pm »
In case it could help you, what I do when trying to add a new weapon

I got the example of Sniper Rifle :
- do not pay attention to values as they are modified in some obscure goal
- I work with many ruleset files as it is part of a global mod like the FMP ; you may use a unique file, beware never declare a section twice, also items: ... then items: ... will not work if in same file

Idea is just to warn you on which sections have to be completed to add a Sniper Rifle with two types of ammo (buy-able regular one + researched/manufactured Alien Alloy ammo ; warning : the research node on Alien Alloy Ammo is not included here)

File MyMod_Items.rul
Spoiler:
items:
# Sniper Rifle
  - type: STR_SNIPER_RIFLE
    size: 0.2 #0.3
    costBuy: 16000 #12000
    costSell: 1600 #5500
    weight: 25 #9
    compatibleAmmo:
      - STR_SNIPER_RIFLE_CLIP
    minRange: 15
    accuracySnap: 0 #80
    tuSnap: 0 #33
    accuracyAimed: 150 #160
    tuAimed: 85 #50
    aimRange: 50
    battleType: 1
    twoHanded: true
    invWidth: 1
    invHeight: 3
    armor: 20
    recoveryPoints: 2 #NEW
    attraction: 1 #NEW
  - type: STR_SNIPER_RIFLE_CLIP
    size: 0.1
    costBuy: 1600 #250
    costSell: 160 #160
    weight: 5 #2
    power: 45 #35
    damageType: 1
    clipSize: 2 #10
    battleType: 2
    armor: 20
    recoveryPoints: 1 #NEW
    attraction: 1 #NEW

# Sniper Rifle
  - type: STR_SNIPER_RIFLE
    compatibleAmmo:
      - STR_SNIPER_RIFLE_CLIP
      - STR_SNIPER_RIFLE_AA_CLIP
  - type: STR_SNIPER_RIFLE_AA_CLIP
    size: 0.1
    costSell: 320
    weight: 4
    power: 54
    damageType: 1
    clipSize: 2
    battleType: 2
    armor: 20
File MyMod_ExtraStrings.rul
Spoiler:
extraStrings:
# Sniper Rifle
  - type: en-US
    strings:
      STR_SNIPER_RIFLE: Sniper Rifle
      STR_SNIPER_RIFLE_UFOPEDIA: "This 12.7-mm caliber sniper rifle is more powerful than a standard rifle and has excellent accuracy.  However, it is harder to use and has a low rate of fire."
      STR_SNIPER_RIFLE_CLIP: Sniper Rifle Clip
      STR_SNIPER_RIFLE_CLIP_UFOPEDIA: "SNIPER RIFLE CLIP PROPERTIES{NEWLINE}{NEWLINE}> Weight: 5   > Ammo: 2{NEWLINE}{NEWLINE}{NEWLINE}SNIPER RIFLE GUN PROPERTIES{NEWLINE}{NEWLINE}> Weight: 25{NEWLINE}{NEWLINE}{NEWLINE}RANGE (FULL ACCURACY){NEWLINE}{NEWLINE}> Aimed Shot: 15-50m"
      STR_SNIPER_RIFLE_AA_CLIP: Sniper Rifle Alloy Clip
      STR_SNIPER_RIFLE_AA_CLIP_UFOPEDIA: "SNIPER RIFLE ALLOY CLIP PROPERTIES{NEWLINE}{NEWLINE}> Weight: 4   > Ammo: 2{NEWLINE}{NEWLINE}{NEWLINE}SNIPER RIFLE GUN PROPERTIES{NEWLINE}{NEWLINE}> Weight: 25{NEWLINE}{NEWLINE}{NEWLINE}RANGE (FULL ACCURACY){NEWLINE}{NEWLINE}> Aimed Shot: 15-50m"
  - type: en-GB
    strings:
      STR_SNIPER_RIFLE: Sniper Rifle
      STR_SNIPER_RIFLE_UFOPEDIA: "This 12.7-mm caliber sniper rifle is more powerful than a standard rifle and has excellent accuracy.  However, it is harder to use and has a low rate of fire."
      STR_SNIPER_RIFLE_CLIP: Sniper Rifle Clip
      STR_SNIPER_RIFLE_CLIP_UFOPEDIA: "SNIPER RIFLE CLIP PROPERTIES{NEWLINE}{NEWLINE}> Weight: 5   > Ammo: 2{NEWLINE}{NEWLINE}{NEWLINE}SNIPER RIFLE GUN PROPERTIES{NEWLINE}{NEWLINE}> Weight: 25{NEWLINE}{NEWLINE}{NEWLINE}RANGE (FULL ACCURACY){NEWLINE}{NEWLINE}> Aimed Shot: 15-50m"
      STR_SNIPER_RIFLE_AA_CLIP: Sniper Rifle Alloy Clip
      STR_SNIPER_RIFLE_AA_CLIP_UFOPEDIA: "SNIPER RIFLE ALLOY CLIP PROPERTIES{NEWLINE}{NEWLINE}> Weight: 4   > Ammo: 2{NEWLINE}{NEWLINE}{NEWLINE}SNIPER RIFLE GUN PROPERTIES{NEWLINE}{NEWLINE}> Weight: 25{NEWLINE}{NEWLINE}{NEWLINE}RANGE (FULL ACCURACY){NEWLINE}{NEWLINE}> Aimed Shot: 15-50m"
  - type: fr
    strings:
      STR_SNIPER_RIFLE: Fusil de Précision
      STR_SNIPER_RIFLE_UFOPEDIA: "Ce fusil, de calibre 12.7 mm et équipé d'une lunette, est plus puissant qu'un fusil classique et dispose d'une précision exceptionnelle.  Mais sa manipulation plus complexe pénalise sa cadence de tir."
      STR_SNIPER_RIFLE_CLIP: Charg. de Fusil de Précision
      STR_SNIPER_RIFLE_CLIP_UFOPEDIA: "PROPRIÉTÉS DU CHARGEUR DE FUSIL DE PRÉCISION{NEWLINE}{NEWLINE}> Poids : 5   > Munitions : 2{NEWLINE}{NEWLINE}{NEWLINE}PROPRIÉTÉS DU FUSIL DE PRÉCISION{NEWLINE}{NEWLINE}> Poids : 25{NEWLINE}{NEWLINE}{NEWLINE}PORTÉE (SANS PÉNALITÉ À LA PRÉCISION){NEWLINE}{NEWLINE}> Tir Précis : 15-50m"
      STR_SNIPER_RIFLE_AA_CLIP: Charg. de Fusil de Précision AE
      STR_SNIPER_RIFLE_AA_CLIP_UFOPEDIA: "PROPRIÉTÉS DU CHARGEUR DE FUSIL DE PRÉCISION AE{NEWLINE}{NEWLINE}> Poids : 4   > Munitions : 2{NEWLINE}{NEWLINE}{NEWLINE}PROPRIÉTÉS DU FUSIL DE PRÉCISION{NEWLINE}{NEWLINE}> Poids : 25{NEWLINE}{NEWLINE}{NEWLINE}PORTÉE (SANS PÉNALITÉ À LA PRÉCISION){NEWLINE}{NEWLINE}> Tir Précis : 15-50m"
File MyMod_ExtraSprites.rul
Spoiler:
items:
# Sniper Rifle
  - type: STR_SNIPER_RIFLE
    bigSprite: 408
    floorSprite: 1 #408
    handSprite: 424 #IncOf8
    bulletSprite: 2 #14 #14x35=490
    fireSound: 408
  - type: STR_SNIPER_RIFLE_CLIP
    bigSprite: 409
    floorSprite: 2 #409
    hitSound: 22
    hitAnimation: 26

# Sniper Rifle
  - type: STR_SNIPER_RIFLE_AA_CLIP
    bigSprite: 459
    floorSprite: 2
    hitSound: 22
    hitAnimation: 26

extraSprites:
# Sniper Rifle
  - type: BIGOBS.PCK
    files:
      408: Resources/HellMod/Weapons/Regular/SniperRifle_BIGOBS.PNG
      409: Resources/HellMod/Weapons/Regular/SniperRifleClip_BIGOBS.PNG
  #- type: FLOOROB.PCK
    #files:
      #408: Resources/HellMod/Weapons/Regular/SniperRifle_FLOOROB.PNG
      #409: Resources/HellMod/Weapons/Regular/SniperRifleClip_FLOOROB.PNG
  - type: HANDOB.PCK
    width: 256
    height: 40
    subX: 32
    subY: 40
    files:
      #IncOf8
      424: Resources/HellMod/Weapons/Regular/SniperRifle_HANDOB.PNG
  #- type: Projectiles
    #height: 3
    #width: 57
    #subX: 3
    #subY: 3
    #files:
      #IncOf35
      #490: Resources/HellMod/Weapons/Regular/SniperRifle_BulletSprite.PNG

# Sniper Rifle
  - type: BIGOBS.PCK
    files:
      459: Resources/HellMod/Weapons/Alloy/SniperRifleClip_AA_BIGOBS.PNG

extraSounds:
# Sniper Rifle
      408: Resources/HellMod/Weapons/Regular/Sounds/SniperRifle_FireSound.WAV
File MyMod_Manufacture.rul
Spoiler:
manufacture:
# Sniper Rifle
  - name: STR_SNIPER_RIFLE_AA_CLIP
    category: STR_AMMUNITION
    requires:
      - STR_ALLOY_AMMO
    space: 2
    time: 32
    cost: 3200
    requiredItems:
      STR_ALIEN_ALLOYS: 1
File MyMod_Research.rul
Spoiler:
research:
  - name: STR_SNIPER_RIFLE_AA_CLIP
    cost: 0
    points: 0
    dependencies:
      - STR_ALLOY_AMMO
File MyMod_Ufopaedia.rul
Spoiler:
ufopaedia:
# Sniper Rifle
  - id: STR_SNIPER_RIFLE
    type_id: 4
    section: STR_WEAPONS_AND_EQUIPMENT
    text: STR_SNIPER_RIFLE_UFOPEDIA
  - id: STR_SNIPER_RIFLE_CLIP
    type_id: 4
    section: STR_WEAPONS_AND_EQUIPMENT
    text: STR_SNIPER_RIFLE_CLIP_UFOPEDIA
  - id: STR_SNIPER_RIFLE_AA_CLIP
    type_id: 4
    section: STR_WEAPONS_AND_EQUIPMENT
    text: STR_SNIPER_RIFLE_AA_CLIP_UFOPEDIA
    requires:
      - STR_SNIPER_RIFLE_AA_CLIP
File MyMod_ZListOrders_Items
Spoiler:
items:
  - type: STR_SNIPER_RIFLE
    listOrder: 2190
  - type: STR_SNIPER_RIFLE_CLIP
    listOrder: 2200
  - type: STR_SNIPER_RIFLE_AA_CLIP
    listOrder: 2210
File MyMod_ZListOrders_Manufacture
Spoiler:
manufacture:
  - name: STR_SNIPER_RIFLE_AA_CLIP
    listOrder: 1950
File MyMod_ZListOrders_Ufopaedia
Spoiler:
ufopaedia:
  - id: STR_SNIPER_RIFLE
    section: STR_WEAPONS_AND_EQUIPMENT
    listOrder: 3280
  - id: STR_SNIPER_RIFLE_CLIP
    section: STR_WEAPONS_AND_EQUIPMENT
    listOrder: 3281
  - id: STR_SNIPER_RIFLE_AA_CLIP
    section: STR_WEAPONS_AND_EQUIPMENT
    listOrder: 3282
« Last Edit: July 28, 2014, 01:57:56 pm by Aldorn »

Offline ivandogovich

  • Commander
  • *****
  • Posts: 2381
  • X-Com Afficionado
    • View Profile
    • Ivan Dogovich Youtube
Re: Learning to mod OpenXcom
« Reply #6 on: July 28, 2014, 08:57:13 pm »
This is an awesome resource.  Any chance we could sticky this?

I wanted to Chime in with a resource Falko pointed me to, the other day: 

A YAML parser  (rulesets are written in YAML, and this parser will alert you if there are any issues with your code, like tabs, missing correlations, etc.)

Copy and paste your ruleset or snippet in the window on the Left, and if there are errors, it will describe them in red on the right.  It its correct, it will show up in black on the right, parsed into json/python/etc

https://yaml-online-parser.appspot.com/

Cheers, Ivan :D

Offline Arthanor

  • Commander
  • *****
  • Posts: 2488
  • XCom Armoury Quartermaster
    • View Profile
Re: Learning to mod OpenXcom
« Reply #7 on: August 01, 2014, 12:38:39 am »
That should be stickied for sure! The learning curve is quite steep at the beginning to learn to mod, all the help is welcome! Also, with so many platforms and the 1.0 version now working, OpenXCom will likely attracj more and more players (and potential modders!).

A few questions:
1- wouldn't you have to activate all those rules files, thus making it annoying in the OpenXCom mod page?
2- don't the 2nd definitions in the items file just overwrite the first? Why not just write everything at once? (ie just define ammo types and clips once)

Offline guille1434

  • Colonel
  • ****
  • Posts: 123
    • View Profile
Re: Learning to mod OpenXcom
« Reply #8 on: August 01, 2014, 01:38:05 am »
Yes, for the complete pack I plan to make, there would be five or six .rul files (some made by me, and others which I like a lot, "borrowed" --> Always credits!) and you will have to activate all of them if you want to apply all the changes, but I think this is a good approach because...

1) It gives "modularity" to the mod: You can use only the Battlescape weapons mod, or the Craft mod, etc... You can use only what you like. On the plus side, as this new rulesets will apply changes equal o similar to various of the rulesets that come included in the game download, you will be able to delete some of those "outdated" rul files, making the mods list a little more manageable.

2) As this is a mod to be used with another mod (the Final Mod Pack) if you integrate all the new code in the FMP file, I will be forced to do the same work any time that FMP is updated (and I see that people here fortunately updates their work quite frequently).
« Last Edit: August 01, 2014, 01:43:05 am by guille1434 »

Offline Arthanor

  • Commander
  • *****
  • Posts: 2488
  • XCom Armoury Quartermaster
    • View Profile
Re: Learning to mod OpenXcom
« Reply #9 on: August 01, 2014, 06:01:27 am »
Actually, my questions were regarding Aldorn's example rule files. As they are there, each .rul would be its own ruleset, that each has to be individually turned on for the Sniper Rifle mod to work. Looking back at it though, I think he was just being organized and showing how the different sections work.

Regarding your mod, I commend you for making it modular. I think it is a good way to do it and have built mine like that as well. (inspired by the Expanded Alien Armoury, which also has both a battlescape and ufo  mod)

Offline Aldorn

  • Commander
  • *****
  • Posts: 750
    • View Profile
Re: Learning to mod OpenXcom
« Reply #10 on: August 01, 2014, 11:55:46 am »
I wondered if you weren't asking me ... ;)

A few questions:
1- wouldn't you have to activate all those rules files, thus making it annoying in the OpenXCom mod page?

1) Sure, but it still in construction, also after have experienced different methods, it seemed to me better to work with separate files
At the end, I will make a unique one
For the moment, it's right I have a lot of rulesets... but I have a dedicated options.cfg so that I have nothing to activate, just copy the options file
For the moment it presents many advantages, as for example having listorders separately (in charge of redefining all listorder including vanilla, and so in any section)
Spoiler:
  - HellMod_AlienDeployments
  - HellMod_AlienItemLevels
  - HellMod_AlienMissions
  - HellMod_AlienRaces
  - HellMod_Armors
  - HellMod_CraftWeapons
  - HellMod_Crafts
  - HellMod_ExtraStrings
  - HellMod_Facilities
  - HellMod_Invs
  - HellMod_Items
  - HellMod_ItemsExtra
  - HellMod_Language
  - HellMod_Manufacture
  - HellMod_Regions
  - HellMod_Research
  - HellMod_Soldiers
  - HellMod_Starting
  - HellMod_TerrainsAlienDeployments
  - HellMod_TerrainsCBase
  - HellMod_TerrainsCult
  - HellMod_TerrainsCulta
  - HellMod_TerrainsDawnUrbanA
  - HellMod_TerrainsDawnUrbanB
  - HellMod_TerrainsIndustrialUrban
  - HellMod_TerrainsMadUrban
  - HellMod_TerrainsMBase
  - HellMod_TerrainsNativeUrban
  - HellMod_TerrainsPortUrban
  - HellMod_TerrainsUBase
  - HellMod_TerrainsUbase2
  - HellMod_TerrainsUrban
  - HellMod_TerrainsUrban2
  - HellMod_TerrainsUrbanA
  - HellMod_TerrainsUrbania
  - HellMod_TerrainsUrbanNew
  - HellMod_TerrainsXBase
  - HellMod_UfoTrajectories
  - HellMod_UfopaediaExtra
  - HellMod_UfopaediaStep1
  - HellMod_UfopaediaStep2
  - HellMod_Ufos
  - HellMod_Units
  - HellMod_XCultist
  - HellMod_XL83Ufos
  - HellMod_XMIB
  - HellMod_ZListOrders_Items
  - HellMod_ZListOrders_Manufacture
  - HellMod_ZListOrders_Research
  - HellMod_ZListOrders_Ufopaedia

2- don't the 2nd definitions in the items file just overwrite the first? Why not just write everything at once? (ie just define ammo types and clips once)
2) Yes, and no
Right is that :
- if you have a unique file containing twice Items section, the first one will be ignored
- if you have two files containing Items section, the second one will overrule the first one
But in this case, I do not define same attributes

The second one is for extraSprites and Sounds purposes, so that I can focus just on it when dealing with sprite numbers
I also organized items by category, (Craft, CraftWeapons, Armors, Equipement, Regular Weapons, Alien Alloy W, Gauss W, Heat-Ray W, ...) and reserve a threshold to any category, to make maintenance easier
Craft : [100-150] ; CraftWeapons : [150-200] ; ...
« Last Edit: August 01, 2014, 12:00:22 pm by Aldorn »

Offline Arthanor

  • Commander
  • *****
  • Posts: 2488
  • XCom Armoury Quartermaster
    • View Profile
Re: Learning to mod OpenXcom
« Reply #11 on: August 01, 2014, 11:47:27 pm »
That's nicely organized! I need to do sonething like that with my mod too!

Regarding overwriting items, I was speaking mostly of the compatible ammo for the sniper rifle, which is defined twice in your example (but I guess the second just adds AA ammo, but if you add a 3rd this way, you have to remember all the previous ones)

Thanks for the answers.

Offline Aldorn

  • Commander
  • *****
  • Posts: 750
    • View Profile
Re: Learning to mod OpenXcom
« Reply #12 on: August 02, 2014, 12:05:10 am »
That's nicely organized! I need to do sonething like that with my mod too!

Regarding overwriting items, I was speaking mostly of the compatible ammo for the sniper rifle, which is defined twice in your example (but I guess the second just adds AA ammo, but if you add a 3rd this way, you have to remember all the previous ones)

Thanks for the answers.
Right, because redefining an attribute overwrites previous declaration, and CompatibleAmmo, even if an array (also a list of elements), is an attribute. Also redefining an attribute that is a list will overwrite previous list, not complete it

Beware that this method (so many ruleset files) is justified only because I integrated dozen of mods