Help with regenerating chest script

Post » Sun Nov 22, 2009 3:38 pm

I'm trying to make a chest that regenerates gold on the first of every month but I can't figure out what's wrong. This is my first script so it's been pretty much trial and error. The gold transfers the first time it's activated, and the message telling the player to wait appears every time after that but it doesn't reset on the next month.

begin earningsshort CurrentDayshort CounterIf ( GetJournalIndex "OCE_Armory" <5 )	Disable	set Counter to 0endifIf ( GetJournalIndex "OCE_Armory" ==5 )	Enableendif	If ( OnActivate == 1 )	If ( Counter == 0 )		MessageBox "You've collected your monthly earnings."		Player->AddItem "Gold_001" 500		PlaySound "Item Gold Up"		set Counter to 1	elseIf ( Counter == 1 )		MessageBox "You've already collected your earnings for this month."	endifendifIf ( Counter == 1 )	If ( CurrentDay == 1 )	set Counter to 0	endifendifend


What exactly am I doing wrong?
User avatar
FABIAN RUIZ
 
Posts: 3495
Joined: Mon Oct 15, 2007 11:13 am

Post » Sun Nov 22, 2009 3:40 pm

According to your script, after the initial activation the local variable counter is set to 1 thereby preventing a second payout. Counter is set back to 0 when currentDay equals 1. There is no code in your script that sets currentDay to 1, and unless it done remotely by another script or dialog results it will never happen.

I expect this is a local script attached to the chest that runs only when the player is in the same cell as the chest. This means that even if you have it set currentDay to Day and check to see if it is equal to 1 it will work only if the player is in that cell on the first day of each month. More effective is to check to see if the month has changed to reset counter. It is also not a good idea to enable/disable an object every frame. You might try something like this:

Begin oce_Earningsshort doOnceshort currentMonthshort playerPaidif ( doOnce == 0 )    set doOnce to 1    Disableendifif ( doOnce == 1 )    if ( ( GetJournalIndex "OCE_Armory" ) == 5 )        set doOnce to 2        Enable    endifendif	if ( OnActivate == 1 )    if ( playerPaid == 0 )        messagebox "You've collected your monthly earnings."        player->AddItem "Gold_001" 500        PlaySound "Item Gold Up" ; this might happen automatically        set playerPaid to 1        set currentMonth to Month    elseif ( playerPaid == 1 )        messagebox "You've already collected your earnings for this month."    endifendifif ( currentMonth != Month )    set playerPaid  to 0endifEnd oce_Earnings

This code has not been tested.

Edit: typo
User avatar
Alina loves Alexandra
 
Posts: 3456
Joined: Mon Jan 01, 2007 7:55 pm

Post » Sun Nov 22, 2009 2:16 pm

Thank you! That got it working.
User avatar
CSar L
 
Posts: 3404
Joined: Fri Nov 09, 2007 9:36 pm


Return to III - Morrowind