• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Fix in Progress Jar of Leeches fails to apply the intended HP removal when used.

MrMister

Sailor Apprentice
As part of the testing of another bug involving leeches, I also discovered that the game fails to applu the -10HP they are supposed to give (image is screenshot from initItems.c).

Not sure if this applies to just leeches in particular or to any ispotion item that is set to heal a negative amount of HP, but my bucks are on the later.
 

Attachments

  • Screenshot 2022-07-22 133814.png
    Screenshot 2022-07-22 133814.png
    28.5 KB · Views: 62
There don't seem to be any other medical items which give negative HP, but it does seem that negative HP effects are not applied.

For one thing, potions with negative HP, even if they do exist now or are created in future, won't give negative HP. They're set up by function 'InitPotion', also included in "initItems.c", which checks for non-positive HP:
Code:
if ( health > 0 )     potionitm.potion.health = health;

Leeches are different, they're set up by 'InitApothItem', which only checks for non-zero HP:
Code:
if ( health != 0 )  itm.potion.health = health;

Use of a medical item is controlled by "PROGRAM\ITEMS\items_utilite.c", function 'DoCharacterUsedItem', which checks if the item has the "potion.health" attribute and then calls 'LAi_UseHealthBottle(chref,stf(arItm.potion.health))'. That is defined in "PROGRAM\Loc_ai\LAi_character.c":
Code:
void LAi_UseHealthBottle(aref chr, float healthInBottle)
{
    if(healthInBottle <= 0) return;   
    if(CheckPerkForGroup(chr, "ImprovePotions")) healthInBottle = healthInBottle * 1.1;//partywide boost
    if(!CheckAttribute(chr, "chr_ai.hp_bottle"))
    {
        chr.chr_ai.hp_bottle = "0";
    }
    chr.chr_ai.hp_bottle = stf(chr.chr_ai.hp_bottle) + healthInBottle;
}
And there's the final check on whether the item has negative or zero health - if it does, 'LAi_UseHealthBottle' quits without doing anything.

Copy your existing "PROGRAM\Loc_ai\LAi_character.c" to somewhere safe just in case this doesn't work or has unexpected side-effects. Then put this version in its place. Test the effects of various medical items, especially leeches, and see if they all behave properly.

Edit: re-uploaded "LAi_character.c" on 25th July to fix another check on the item's health in function 'LAi_AllCharactersUpdate'. Checked by using console to give myself some bottles, not adding in @MrMister's fix to prevent leeches from being used for quick-heal, then going out into the jungle to get injured in a fight. Quick-heal chose the leeches and I lost HP.
 

Attachments

  • LAi_character.c
    34.2 KB · Views: 55
Last edited:
It does seem to work now, draining 10 HP (actually 9 since natural healing counters it a bit) over a few seconds, thanks! You can probably add it to the next hotfix batch.

One last thing re: jar of leeches though - the game still treats it as both a potion and an antidote, in that it will appear in the Use Item menu if you are poisoned AND/OR are not at full HP. Ideally the game should only present it as an option if you are poisoned, like it does Antidotes. At least it does present it as an option alongside only antidotes if you are poisoned and yet somehow at full HP, so in a way it is recognising that it is an antidote too.

I tried changing its ispotion value to 0 in initItems.c , but it is still presented as an option when you're missing HP but not poisoned.

Now that HP-draining consumables are a thing, I imagine it's possible to try wilder ideas.
 
Try this version of "items_utilite.c". In function 'EnablePotionUsing', this...
Code:
if( CheckAttribute(arItm,"potion.health") ) {
... becomes this...
Code:
if( CheckAttribute(arItm,"potion.health") && stf(arItm.potion.health) > 0) {

I tested it by using console to give myself some leech bottles, then going out into the jungle to look for trouble and get wounded. Leeches no longer appear as one of the items to use. Then I used console to both give myself leech bottles and to poison myself, and both antidote and leeches then do appear among the items to be used.
 

Attachments

  • items_utilite.c
    88.6 KB · Views: 45
Back
Top