Author Topic: How do we add effects to items?  (Read 980 times)

How do we add effects to items?
« on: January 03, 2025, 11:22:38 pm »
Hi there!

I don't think we have a guide on how to add special effects to items. I use the FOClassic engine.

My particular case is something I saw on fo3: I want bags and backpacks to add a percentage to player's max carry weight when equipped in hands.

I looked at how other things are implemented like the mirrored shades, but I'm not sure about all the steps I need to take to properly add some logic to an item. It would be great if someone could share the steps. Thanks!

Offline Slowhand

  • Go for the eyes, Boo! Go for the eyes!
Re: How do we add effects to items?
« Reply #1 on: February 04, 2025, 10:32:21 am »
https://fodev.net/forum/index.php/topic,30344.msg263772.html#msg263772

Check that on how to change carry weight from extensions.

Once it works, all you need to do is change the formula based on your idea, an example would be if character has backpack in Slot 1 or Slot 2, they would receive extra carry weight and also this solution would be moderately simple to implement. Keep in mind to write simple changes or you will leave server hanging, crashing etc.

This is your current extension function for it:
Code: [Select]
EXPORT int getParam_MaxWeight(CritterMutual& cr, uint)
{
int val = max(cr.Params[ST_CARRY_WEIGHT] + cr.Params[ST_CARRY_WEIGHT_EXT], 0);
val += CONVERT_GRAMM(25 + getParam_Strength(cr, 0) * 25);
if(cr.Params[PE_PACK_RAT])
{
val*=4;
val/=3;
}
val+=20000;

const Item* armor=cr.ItemSlotArmor;
val+=checkBonus(armor, BONUS_ARMOR_CARRY_WEIGHT)*1000;

return CLAMP(val, 0, 2000000000);
}

You might want to add your change before where the conversion to gramms is called, for example to make the bag add 50 extra, you could do something like:

Code: [Select]
#define PID_BAG                             (46)
#define PID_BACKPACK                        (90)
#define PID_BROWN_BAG                       (93)

EXPORT int getParam_MaxWeight(CritterMutual& cr, uint)
{

int val = max(cr.Params[ST_CARRY_WEIGHT] + cr.Params[ST_CARRY_WEIGHT_EXT], 0);
int extra = 0;
if (cr.ItemSlotExt->Proto->ProtoId == PID_BACKPACK || cr.ItemSlotMain->Proto->ProtoId == PID_BACKPACK) {
extra += 50;
}
val += CONVERT_GRAMM(25 + getParam_Strength(cr, 0) * 25 + extra);
if(cr.Params[PE_PACK_RAT])
{
val*=4;
val/=3;
}
val+=20000;

const Item* armor=cr.ItemSlotArmor;
val+=checkBonus(armor, BONUS_ARMOR_CARRY_WEIGHT)*1000;

return CLAMP(val, 0, 2000000000);
}

So here I only change for backpack, but you would need to add the all the defines that your server uses for backpacks and change to code accordingly.

NOTE: I did not test it, as I want to make a more complex version, but should be able to get started from here.

Re: How do we add effects to items?
« Reply #2 on: Yesterday at 01:45:43 am »
oh damn it's in the dlls? What a pain.
« Last Edit: Yesterday at 01:58:29 am by cthulchu »