Broken script in the mod "Erengard Mines"

Support for running, installing or compiling OpenMW

Before you submit a bug report for the first time, please read: Bug reporting guidelines
Post Reply
azmanian
Posts: 1
Joined: 30 Jun 2019, 19:39

Broken script in the mod "Erengard Mines"

Post by azmanian »

I am running version 0.46.
What's happening is Erengard uses an investment chest with an attached script to make things happen: you put gold inside the chest then spend that gold on upgrades and keeping the mine functioning (as well as being where you start getting paid). What's happening is that the instant I put money into the chest, it immediately empties and resets to 0 so I can't make anything happen. This is the script of the chest:
begin em_s_moneychest

short state
long gold_pre
long gold_diff
long gold_amount

if ( em_g_account != gold_amount )
set gold_diff to em_g_account - gold_amount

while ( gold_diff > 0 )
addItem "gold_001" 30000
set gold_diff to gold_diff - 30000
endwhile

while ( gold_diff < -29999 )
removeItem "gold_001" 30000
set gold_diff to gold_diff + 30000
endwhile

while ( gold_diff < -7499 )
removeItem "gold_001" 7500
set gold_diff to gold_diff + 7500
endwhile

while ( gold_diff < -1499 )
removeItem "gold_001" 1500
set gold_diff to gold_diff + 1500
endwhile

while ( gold_diff < -249 )
removeItem "gold_001" 250
set gold_diff to gold_diff + 250
endwhile

while ( gold_diff < -49 )
removeItem "gold_001" 50
set gold_diff to gold_diff + 50
endwhile

while ( gold_diff < -9 )
removeItem "gold_001" 10
set gold_diff to gold_diff + 10
endwhile

while ( gold_diff < -2 )
removeItem "gold_001" 3
set gold_diff to gold_diff + 3
endwhile

while ( gold_diff < 0 )
removeItem "gold_001" 1
set gold_diff to gold_diff + 1
endwhile

set gold_amount to getItemCount "gold_001"
endif

if ( state==1 )
if ( menumode==0 )
set gold_amount to getItemCount "gold_001"
set gold_diff to gold_amount - gold_pre
set em_g_account to em_g_account + gold_diff
if ( GetJournalIndex "EM_PCOwner" == 10 )
MessageBox "You now have %G goldpieces invested in your mine." em_g_account
endif
set state to 0
endif
endif

if ( OnActivate==1 )
set gold_pre to getItemCount "gold_001"
set state to 1
Activate
endif

end
User avatar
akortunov
Posts: 900
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Broken script in the mod "Erengard Mines"

Post by akortunov »

Does not seem to be a valid script IMO. Judging by code, this script updates the em_g_account variable only when the chest is closed, but calculates gold_diff variable and uses it to remove gold every frame.

For example, if you add 1000 coins to chest, the gold_diff becomes -1000 in the next frame (since the em_g_account is still 0) and the script removes 1000 money from the chest in related "while" blocks. When you close the chest then, script does not increase the em_g_account since the chest contains no money.

I see no reasons why this script should work. Maybe it would be better to contact to mod's authors - they at least should know how this script is supposed to work.
f3rno
Posts: 2
Joined: 18 Feb 2020, 17:40

Re: Broken script in the mod "Erengard Mines"

Post by f3rno »

I ran into this as well; after a bit of debugging, I realized it's due to using an animated container mod. Specifically, menumode is 0 immediately after activation, while the animation plays, and only becomes 1 after the end of the animation. Thereby triggering the relevant logic early (before the chest is closed, as was intended)

Disabling the animated containers mod fixes it.
Post Reply