Jump to content

Help Using ModAV on NPCs by Script


user826

Recommended Posts

Hey everyone,

 

I'm working on a mod right now where I'm trying to make a customizable companion - basically as they travel with you, they gain experience and can level up, and when they do, you get to decide where they allocate their skill points. I'm running into some trouble with the scripting though. The following snippets of code are placed inside a GameMode block in the script that is attached to my NPC.

;Companion levels up each time they earn 10 XP
	if (ExperiencePoints >= 10) && (MenuLevel == 0)
		set ExperienceLevel to (ExperienceLevel + 1)
		set TimesLeveledUp to (TimesLeveledUp + 1)
		ShowMessage aaaMESGCustomizableCompanionLevelUp ExperienceLevel
		set MenuLevel to 1
		if (MenuLevel == 1)
			set Button1 to GetButtonPressed
			if (Button1 == 0)
				ShowMessage aaaMESGCustomizableCompanionLevelUpCombat
			elseif (Button1 == 1)
				ShowMessage aaaMESGCustomizableCompanionLevelUpDiplomacy
			elseif (Button1 == 2)
				ShowMessage aaaMESGCustomizableCompanionLevelUpDexterity
			elseif (Button1 == 3)
				ShowMessage aaaMESGCustomizableCompanionLevelUpIntellect
			endif
			set MenuLevel to 2
		endif
		if (MenuLevel == 2)
			set Button2 to GetButtonPressed
			if (Button1 == 0)		;Combat
				if (Button2 == 0)
					CustomizableCompanionREF.ModAV EnergyWeapons 5
				elseif (Button2 == 1)
					CustomizableCompanionREF.ModAV Explosives 5
				elseif (Button2 == 2)
					CustomizableCompanionREF.ModAV Guns 5
				elseif (Button2 == 3)
					CustomizableCompanionREF.ModAV MeleeWeapons 5
				elseif (Button2 == 4)
					CustomizableCompanionREF.ModAV Unarmed 5
				elseif (Button2 == 5)
					ShowMessage aaaMESGCustomizableCompanionLevelUp ExperienceLevel
					set MenuLevel to 1
					Return
				endif
				set ExperiencePoints to 0
				set MenuLevel to 0
			elseif (Button1 == 1)	;Diplomacy
				if (Button2 == 0)
					CustomizableCompanionREF.ModAV Barter 5
				elseif (Button2 == 1)
					CustomizableCompanionREF.ModAV Speech 5
				elseif (Button2 == 2)
					ShowMessage aaaMESGCustomizableCompanionLevelUp ExperienceLevel
					set MenuLevel to 1
					Return
				endif
				set ExperiencePoints to 0
				set MenuLevel to 0
			elseif (Button1 == 2)	;Dexterity
				if (Button2 == 0)
					CustomizableCompanionREF.ModAV Lockpick 5
				elseif (Button2 == 1)
					CustomizableCompanionREF.ModAV Repair 5
				elseif (Button2 == 2)
					CustomizableCompanionREF.ModAV Sneak 5
				elseif (Button2 == 3)
					ShowMessage aaaMESGCustomizableCompanionLevelUp ExperienceLevel
					set MenuLevel to 1
					Return
				endif
				set ExperiencePoints to 0
				set MenuLevel to 0
			elseif (Button1 == 3)	;Intellect
				if (Button2 == 0)
					CustomizableCompanionREF.ModAV Medicine 5
				elseif (Button2 == 1)
					CustomizableCompanionREF.ModAV Science 5
				elseif (Button2 == 2)
					CustomizableCompanionREF.ModAV Survival 5
				elseif (Button2 == 3)
					ShowMessage aaaMESGCustomizableCompanionLevelUp ExperienceLevel
					set MenuLevel to 1
					Return
				endif
				set ExperiencePoints to 0
				set MenuLevel to 0
			endif
	endif
;Companion also gains a SPECIAL point every 10 levels
	if (TimesLeveledUp == 10)
		ShowMessage aaaMESGCustomizableCompanionLevelUpSPECIAL ExperienceLevel
		set Button3 to GetButtonPressed
		if (Button3 == 0)
			CustomizableCompanionREF.ModAV Strength 1
		elseif (Button3 == 1)
			CustomizableCompanionREF.ModAV Perception 1
		elseif (Button3 == 2)
			CustomizableCompanionREF.ModAV Endurance 1
		elseif (Button3 == 3)
			CustomizableCompanionREF.ModAV Charisma 1
		elseif (Button3 == 4)
			CustomizableCompanionREF.ModAV Intelligence 1
		elseif (Button3 == 5)
			CustomizableCompanionREF.ModAV Agility 1
		elseif (Button3 == 6)
			CustomizableCompanionREF.ModAV Luck 1
		endif
		set TimesLeveledUp to 0
	endif

The issue that I'm having is that when the correct conditions are met, the message appears, but after clicking the appropriate button, nothing happens. It would appear that the GetButtonPressed line (and everything after it) isn't running. I've tried pasting these snippets into the result script of a Quest stage, and then using a SetStage command to trigger it, but no luck. I also tried pasting these snippets into a persistent activator and using a "ActivatorREF.Activate player" command to trigger it, but it also doesn't work! No matter what I try, the script always fails after the message box appears. Can anyone offer any suggestions?

Link to comment
Share on other sites

Well, the code to await a response from the user must be separate from the part that shows the message.

 

Here is a basic idea:

if MenuLevel == 0     ; see if the NPC leveled up
    if (ExperiencePoints >= 10) 
        set ExperienceLevel to (ExperienceLevel + 1)
        set TimesLeveledUp to (TimesLeveledUp + 1)
        ShowMessage aaaMESGCustomizableCompanionLevelUp ExperienceLevel
        set MenuLevel to 1
        return     
   endif
else    ; We are waiting for a button press
   set Button1 to GetButtonPressed
   if Button1 < 0
       return
   endif
   if MenuLevel == 1
       if (Button1 == 0)
           set MenuLevel to 2
           ShowMessage aaaMESGCustomizableCompanionLevelUpCombat
       elseif (Button1 == 1)
           set MenuLevel to 3
           ShowMessage aaaMESGCustomizableCompanionLevelUpDiplomacy
       elseif (Button1 == 2)
           set MenuLevel to 4
           ShowMessage aaaMESGCustomizableCompanionLevelUpDexterity
       elseif (Button1 == 3)
            set MenuLevel to 5
           ShowMessage aaaMESGCustomizableCompanionLevelUpIntellect
       endif
       return
   elseif MenuLevel == 2   ; Combat
      if (Button1 == 0)
         CustomizableCompanionREF.ModAV EnergyWeapons 5
      elseif (Button1 == 1)
         CustomizableCompanionREF.ModAV Explosives 5
      elseif (Button1 == 2)
         CustomizableCompanionREF.ModAV Guns 5
      elseif (Button1 == 3)
         CustomizableCompanionREF.ModAV MeleeWeapons 5
      elseif (Button1 == 4)
         CustomizableCompanionREF.ModAV Unarmed 5
      elseif (Button2 == 5)
         ShowMessage aaaMESGCustomizableCompanionLevelUp ExperienceLevel
         set MenuLevel to 1
         Return
      endif
      set ExperiencePoints to 0
      set MenuLevel to 0
   elseif MenuLevel == 3  ;Diplomacy

*** ETC****
Edited by GamerRick
Link to comment
Share on other sites

@GamerRick: It works! Thank you so much! I had no idea I needed so many 'Return' statements, haha

 

As a bonus, I also managed to figure out how to make it so that every 10 levels, he earns a SPECIAL point instead of skill points. I can finally move forward now, thank you!

Link to comment
Share on other sites

I added the return statements to highlight how it works, by showing that you are now waiting for the block to get called again by the game instead of doing everything top-down,

 

However, I have read that adding a return statement, when you know the rest won't be processed below there, makes the script process more efficiently, because without it the scripting code still has to parse the rest of the code to find the end. No idea if this is true or not.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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