Jump to content

Need some help with script


Recommended Posts

I'm in the process of working on a mod and I've hit a snag. the staff I've made for the mod is supposed to give you a blessing at night depending on the current month but I've been having trouble with it, there are no errors as far as i can tell but the script wont execute ingame, could someone have a look at it and tell me what im doing wrong?

 

Begin LaW_Staff_SilyanornScript
float starmonth
short OnPCEquip
short staffOut
short addOnce
short starblessing
if ( menumode == 1)
return
endif
if ( starblessing == 1 )
set starmonth to Month
endif
if ( OnPCEquip == 0 )
if ( player->GetWeaponDrawn == 0 )
set staffOut to 0
endif
elseif ( OnPCEquip == 1 )
if ( player->GetWeaponDrawn == 0 )
set staffOut to 0
endif
endif
if ( OnPCEquip == 1 )
if ( player->GetWeaponDrawn == 1 )
set staffOut to 1
endif
endif
if ( staffOut == 0 )
if ( Player->GetItemCount "LaW_Staff_Light" > 0 )
Player->RemoveItem "LaW_Staff_Light" 1
set addOnce to 0
endif
endif
if ( staffOut == 1 )
if ( addOnce == 0 )
Player->AddItem "LaW_Staff_Light" 1
set addOnce to 1
endif
endif
if ( starblessing == 0 )
if ( GameHour > 20 )
if ( GameHour < 6 ) ;hour is 6 to 8 AM
set starblessing to 1
Messagebox "Underneath the stars, you feel the staff of silyanorn swell with their power.'"
endif
endif
endif
if ( starblessing == 1 )
if ( GameHour > 6 )
if ( GameHour < 20 ) ;hour is 6 to 8 AM
set starblessing to 0
Messagebox "As the stars fade with the dawn, so to does the power within the staff of Silyanorn.'"
endif
endif
endif
if ( starblessing == 1 )
if ( starmonth == 0 )
Player->Addspell "LaW_Staff_Ritural_Blessing" ;the Ritural
endif
if ( starmonth == 1 )
Player->Addspell "LaW_Staff_Lover_Blessing" ;the Lover
endif
if ( starmonth == 2 )
Player->Addspell "LaW_Staff_Lord_Blessing" ;the Lord
endif
elseif ( starmonth == 3 )
Player->Addspell "LaW_Staff_Mage_Blessing" ;the Mage
endif
if ( starmonth == 4 )
Player->Addspell "LaW_Staff_Shadow_Blessing" ;the Shadow
endif
if ( starmonth == 5 )
Player->Addspell "LaW_Staff_Steed_Blessing" ;the Steed
endif
if ( starmonth == 6 )
Player->Addspell "LaW_Staff_Apprentice_Blessing" ;the Apprentice
endif
if ( starmonth == 7 )
Player->Addspell "LaW_Staff_Warrior_Blessing" ;the Warrior
endif
if ( starmonth == 8 )
Player->Addspell "LaW_Staff_Lady_Blessing" ;the Lady
endif
if ( starmonth == 9 )
Player->Addspell "LaW_Staff_Tower_Blessing" ;the Tower
endif
if ( starmonth == 10 )
Player->Addspell "LaW_Staff_Attronach_Blessing" ;the Attronach
endif
if ( starmonth == 11 )
Player->Addspell "LaW_Staff_Thief_Blessing" ;the Theif
endif
if ( starblessing == 0 )
Player->removespell "LaW_Staff_Ritural_Blessing"
Player->removespell "LaW_Staff_Lover_Blessing"
Player->removespell "LaW_Staff_Lord_Blessing"
Player->removespell "LaW_Staff_Mage_Blessing"
Player->removespell "LaW_Staff_Shadow_Blessing"
Player->removespell "LaW_Staff_Steed_Blessing"
Player->removespell "LaW_Staff_Apprentice_Blessing"
Player->removespell "LaW_Staff_Warrior_Blessing"
Player->removespell "LaW_Staff_Lady_Blessing"
Player->removespell "LaW_Staff_Tower_Blessing"
Player->removespell "LaW_Staff_Attronach_Blessing"
Player->removespell "LaW_Staff_Thief_Blessing"
endif
End LaW_Staff_SilyanornScript
Link to comment
Share on other sites

There are two critical issues that I see:

if ( starblessing == 0 )
   if ( GameHour > 20 )
      if ( GameHour < 6 ) ;hour is 6 to 8 AM
         set starblessing to 1
         Messagebox "Underneath the stars, you feel the staff of silyanorn swell with their power.'"
      endif
   endif
endif

GameHour > 20 and GameHouse < 6 are mutually exclusive. It is impossible to satisfy both of these conditions at the same time. Therefore, starblessing is never set to 1 and you spells cannot be added. What you want is:

if ( starblessing == 0 )
   if ( GameHour > 20 ) ; evening/night
      set starblessing to 1
      Messagebox "Underneath the stars, you feel the staff of silyanorn swell with their power.'"
   elseif ( GameHour < 6 ) ; night/early morning
      set starblessing to 1
      Messagebox "Underneath the stars, you feel the staff of silyanorn swell with their power.'"
   endif
endif

The other issue occurs after starblessing is set to 1

elseif ( starmonth == 3 )
   Player->Addspell "LaW_Staff_Mage_Blessing" ;the Mage
endif

This creates the structure:

if ( starblessing == 1 )
   if ( starmonth == 0 )
   endif
   if ( starmonth == 1 )
   endif
   if ( starmonth == 2 )
   endif
elseif ( starmonth == 3 )
endif
if ( starmonth == 4 )
endif
if ( starmonth == 5 )
endif
if ( starmonth == 6 )
endif
if ( starmonth == 7 )
endif
if ( starmonth == 8 )
endif
if ( starmonth == 9 )
endif
if ( starmonth == 10 )
endif
if ( starmonth == 11 )
endif

This terminates the starblessing == 1 logical block before the end and sets up the remaining months to operate independently. You want if ( starmonth == 3 ), or make all of them elseif after starmonth == 0 and eliminate all of the endifs (except for the last, of course).

 

Lesser issues:

if ( staffOut == 0 )
   if ( Player->GetItemCount "LaW_Staff_Light" > 0 )
      Player->RemoveItem "LaW_Staff_Light" 1
      set addOnce to 0
   endif
endif

Add an addOnce == 1 check so the script is not doing an item count every frame.

 

Similarly, you are removing spells every frame that starblessing == 0 is true. You could introduce a doOnce condition to prevent that from happening.

 

There may be other ways of tightening up your code, but I have to run (literally).

Link to comment
Share on other sites

Thanks for the help, i'm not that good with scripting barely script kiddie tbh. that elseif was from an earlier version of the script i can't belive i missed one :confused:. im gonna make your suggested fixes to the script and try to lighten it without breaking it hopefully. thanks again for your help.

Link to comment
Share on other sites

You're welcome. Sometimes it just takes a pair of fresh eyes. The first was just a copy and paste error without making the proper adjustment for the different circumstances. The second was just your subconscious telling you that it would run more efficiently with a series of elseifs.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...