switching an items imodbit when equipped ?

Users who are viewing this thread

HokieBT

Grandmaster Knight
In my Star Wars mod we have a few alien races where the body is either bigger (wookiee, gamorrean) or smaller (jawa).  We've done this by creating different sized body/head/armor models and then creatively rigging or moving the position of the item.  This concept works well provided the troop is using equipment that was specifically designed for them, but if you tried to equip 'stormtrooper armor' on a jawa then the jawa head would appear in the middle of their chest..... So there are a few ways we could potentially solve this:

a) only give the correct sized equipment to these troops.  This is fine for mercs and faction troops but it most likely means no playable races or companions which don't use a human sized body since you could equip items that didn't fit correctly.
b) code something where you cannot equip certain type of armor if you are a certain smaller/bigger race, etc.
c) my latest concept with using imodbits to switch the models when equipped....

1) we could potentially create multiple models for normal, bigger, smaller sized troops.
2) then, its possible to define different models depending on an items imodbit, so we could do something like this...

Code:
["imperial_stormtrooper_armor", "Imperial Stormtrooper Armor", 
            [
               ("imperial_stormtrooper_armor",0),
               ("imperial_stormtrooper_armor_jawa_size",imodbits_jawa),
               ("imperial_stormtrooper_armor_wookiee_size",imodbits_wookiee)
            ]
           .........

3) there would have to be some type of code that if the player or companion was a bigger/smaller race and equipped an item model, it would switch the imodbit to be one for that race....  So is it possible to switch an item imodbits in code or when equipped?  MartinF suggested I could probably remove and re-add an item to the player/companion or their inventory, so that might be an option as well.

FYI - I'm not sure if I want to actually try and code/model this concept, but I am curious to see if it is possible.  Also, it would probably mess up the existing imodbits on items so you might have to limit those or do additional coding, etc.
 
3) there would have to be some type of code that if the player or companion was a bigger/smaller race and equipped an item model, it would switch the imodbit to be one for that race....  So is it possible to switch an item imodbits in code or when equipped?  MartinF suggested I could probably remove and re-add an item to the player/companion or their inventory, so that might be an option as well.

Well I think that would be pretty easy, just scan inventory for the item and then replace it. You can assign any imodbits when you make the new item.

The thing that has me stumped tho is how to make it so that a jawa can't wear the wookie armor. If the code for checking for item requirements is hardcoded, I don't see how to do it.
 
You could use a troop slot called body_type.  it can have 3 values (or how ever many you need) small = 1, med =2, large =3.  You would have to run a script to change the actual item when they recieve it.  What you might want to do is have a dummy object for each type (such as armor), that is like a commonity item.  When ever this item is found, they should get the dummy item.  Then make a camp option called fit gear.  Test the body type, and if they can use it, switch the item to the real item.

Just a thought.  I had to deal with this some time ago with some other project, and I found this a workable way.  The issue is to make sure that when the item is bought or found, that you only get the dummy item.
 
Ah so you'd use a placeholder item? And use a game menu to turn the item into a usable item for the player.. alright.

But what happens when the player gives that item to his wookie companion?

I thought of the slots as well, as you could set those up in the script on game creation, but I think hokie's imodbits option might be better because apparently you can use different meshes for different imodbits (learn something new every day :smile:)

How would you check the slot and see if it matches when equipping items? Autoloot was another thing that popped up in this area, although I reckon you could rewrite that so companions only put on items they're actually supposed to.. so I guess that would be easier than for the player.
 
Keep in mind an item can only have one mod type, so if you have wookie and jawa as types you can't have battered armor or rusty armor, or anything like that with them.  Unless you create a whole set of imodbits for wookies and jawas.  The problem becomes each modbit is hard coded as to what it actually does to the armor itself, so be careful in picking which one to use to represent wookies and jawas.

However, it's very very very easy to change an items imodbit on the fly in the game.  troop_set_inventory_slot_modifier is what you want.  If it affects an item in a hero's inventory, then the change is permanent, otherwise I don't think it actually does anything.  One way you could do it is create a mission_template trigger that triggers on ti_agent_spawn, then checks if the agent is a jawa or wookie, then flies through their inventory stacks looking for particular items or item types and then setting the modbit appropriately to their size.

*pause in writing this reply as Jinnai gets an idea and tests some code*

Oh, you're going to LOVE this.  I found a way to do it.  The file module_tableau_materials has the entry game_inventory_window.  That entry is called every single time a troop's inventory changes on the inventory screen.  This means you can put code there that checks the type of the troop and all gear in their first 8 inventory slots.  If the gear in those first 8 slots (0-3 are weapons, and 4-7 iirc are armor, and 8 is horse (i think, horse might be 4)) doesn't match the right size you can either push it out of their wearing slot to the first free inventory slot and complain about not being able to use it, or you could adjust the modbit right there.  One thing to note, the troop_id in game_inventory_window is not the troop_id you want to work on.  It's got a flag in it that determines the camera angle to view the troop from in the inventory window.  So you'll want to do something like:

(store_div, ":troop", ":troop_no", 4),

and then use ":troop" for all your stuff, since :troop_no needs to survive unscathed as it's passed on to further functions later on.

EDIT: If you're using the autoloot script, then it won't work with the tableau method I mention above, as that code will never be called since the companions will grab gear without actually going to the inventory screen.

Further edit: I recommend putting the code that does this check right at the start of the game_inventory_window code, so any changes you make will be seen by the time tableau_troop_inventory_alpha_mask is called.  If you add your code to the end of that block then what the player sees will not be what is actually there.
 
haha you're scary, mate! :smile:

well done.. can't believe none of the fantasy modders wanting dwarves and gnomes have ever come up with this..
 
ok, thanks guys, this is some very good info.  Now, as Jinnai mention, there are some problems since you can't stack imodbits so you may lose some of that functionality.  This would require us to re-size and make multiple versions of all our helmets, armor, etc.  So while it would be cool to have a jawa a wookiee companion, and be able to equip a shirt on either one and have it fit correctly, its probably not an immediate priority for me. But I will keep this in mind for a future project.

However, I think this concept does have other uses.  For example, you could potentially create a single armor and weapon that would use different models for each faction.  This might be helpful in balancing mods (since they would all have the same stats) or making it easier to equip troops (since they could all get the same equipment).

Code:
["faction_armor", "Faction Armor",
            [
               ("faction_armor",0),
               ("faction1_armor",imodbits_faction1),
               ("faction2_armor",imodbits_faction2),
               ("faction3_armor",imodbits_faction3),
               ("faction4_armor",imodbits_faction4),
               ("faction5_armor",imodbits_faction5),
            ]
           .........

["faction_weapon", "Faction Sword",
            [
               ("faction_sword",0),
               ("faction1_sword",imodbits_faction1),
               ("faction2_sword",imodbits_faction2),
               ("faction3_sword",imodbits_faction3),
               ("faction4_sword",imodbits_faction4),
               ("faction5_sword",imodbits_faction5),
            ]
           .........

I had thought about trying to create an OSP Module System or version of Native that would be easily modifiable.  For example, go through all the troops and rename them to just "f1_tier1_troop", "f2_guard", "f3_messenger", etc.  So people wouldn't have to search through the code and remove all instances of "nord_" or "vaegir", etc....  So this imod concept like this would be very cool, since you could give every troop faction_boots, faction_armor, etc, and just switch the model it was using to customize them.  You'd probably have to expand the concept to have "faction_sword_tier1, faction_sword_tier2, etc, but the possibilities are very cool.  With only modifying a few lines you could release a completely different mod in a day or two (which might actually be a bad thing).  :wink:
 
Back
Top Bottom