Jump to content

[Papyrus Question] Help with the "&&" and "if" to detect values in between 2 others


Govilku

Recommended Posts

I try not to always complain. But sheesh this one has had me stumped for days. It compiles just fine but in game only if my "DaedricPower" is over 2500 will it do anything. Anything lower and nothing seems to fire. I see that my "if" and "&&" statements aren't working. I want it to detect that if "DaedricPower" is between those to numbers (I.E. >=100 and <300), add the upgraded spell version, remove the current.

 

 


function UpgradeCheck1()
	Utility.Wait(2)
	if PlayerRef.HasSpell(DaedraPWR01)==1 && PlayerRef.HasSpell(DaedraPWR02)==1 && PlayerRef.HasSpell(DaedraPWR03)==1
		if DaedricPower.GetValueInt()>=100 && DaedricPower.GetValueInt()<300
			Debug.Notification("I feel even more powerful!")
			PlayerRef.RemoveSpell(DaedraPWR01)
			PlayerRef.RemoveSpell(DaedraPWR02)
			PlayerRef.RemoveSpell(DaedraPWR03)
			PlayerRef.AddSpell(DaedraPWR01UP)
			PlayerRef.AddSpell(DaedraPWR02UP)
			PlayerRef.AddSpell(DaedraPWR03UP)
		endif
		if DaedricPower.GetValueInt()>=300 && DaedricPower.GetValueInt()<500
			Debug.Notification("My power has risen tremoundously!")
			PlayerRef.RemoveSpell(DaedraPWR01)
			PlayerRef.RemoveSpell(DaedraPWR02)
			PlayerRef.RemoveSpell(DaedraPWR03)
			PlayerRef.AddSpell(DaedraPWR04UP)
			PlayerRef.AddSpell(DaedraPWR05UP)
			PlayerRef.AddSpell(DaedraPWR06UP)
		endif
		if DaedricPower.GetValueInt()>=500 && DaedricPower.GetValueInt()<750
			Debug.Notification("My power is overflowing!")
			PlayerRef.RemoveSpell(DaedraPWR01)
			PlayerRef.RemoveSpell(DaedraPWR02)
			PlayerRef.RemoveSpell(DaedraPWR03)
			PlayerRef.AddSpell(DaedraPWR07UP)
			PlayerRef.AddSpell(DaedraPWR08UP)
			PlayerRef.AddSpell(DaedraPWR09UP)
		endif
		if DaedricPower.GetValueInt()>=750 && DaedricPower.GetValueInt()<1500
			Debug.Notification("My power is surging!")
			PlayerRef.RemoveSpell(DaedraPWR01)
			PlayerRef.RemoveSpell(DaedraPWR02)
			PlayerRef.RemoveSpell(DaedraPWR03)
			PlayerRef.AddSpell(DaedraPWR10UP)
			PlayerRef.AddSpell(DaedraPWR11UP)
			PlayerRef.AddSpell(DaedraPWR12UP)
		endif
		if DaedricPower.GetValueInt()>=1500 && DaedricPower.GetValueInt()<2500
			Debug.Notification("I am gaining power in lines without projection!")
			PlayerRef.RemoveSpell(DaedraPWR01)
			PlayerRef.RemoveSpell(DaedraPWR02)
			PlayerRef.RemoveSpell(DaedraPWR03)
			PlayerRef.AddSpell(DaedraPWR13UP)
			PlayerRef.AddSpell(DaedraPWR14UP)
			PlayerRef.AddSpell(DaedraPWR15UP)
		endif
		if DaedricPower.GetValueInt()>=2500
			Debug.Notification("I can barely contain the power racing throughout my body!")
			PlayerRef.RemoveSpell(DaedraPWR01)
			PlayerRef.RemoveSpell(DaedraPWR02)
			PlayerRef.RemoveSpell(DaedraPWR03)
			PlayerRef.AddSpell(DaedraPWR16UP)
			PlayerRef.AddSpell(DaedraPWR17UP)
			PlayerRef.AddSpell(DaedraPWR18UP)
		endif
	endif
EndFunction

; And the code that calls it

Event OnInit()
	RegisterForUpdateGameTime(0.5)
EndEvent

Event OnUpdateGameTime()
	while DaedricPower.GetValueInt()<300
		PlayerRef.RemoveSpell(DaedraPWR04UP)
		PlayerRef.RemoveSpell(DaedraPWR05UP)
		PlayerRef.RemoveSpell(DaedraPWR06UP)
	endwhile
	while DaedricPower.GetValueInt()<500
		PlayerRef.RemoveSpell(DaedraPWR07UP)
		PlayerRef.RemoveSpell(DaedraPWR08UP)
		PlayerRef.RemoveSpell(DaedraPWR09UP)
	endwhile
	while DaedricPower.GetValueInt()<750
		PlayerRef.RemoveSpell(DaedraPWR10UP)
		PlayerRef.RemoveSpell(DaedraPWR11UP)
		PlayerRef.RemoveSpell(DaedraPWR12UP)
	endwhile
	while DaedricPower.GetValueInt()<1500
		PlayerRef.RemoveSpell(DaedraPWR13UP)
		PlayerRef.RemoveSpell(DaedraPWR14UP)
		PlayerRef.RemoveSpell(DaedraPWR15UP)
	endwhile
	while DaedricPower.GetValueInt()<2500
		PlayerRef.RemoveSpell(DaedraPWR16UP)
		PlayerRef.RemoveSpell(DaedraPWR17UP)
		PlayerRef.RemoveSpell(DaedraPWR18UP)
	endwhile
		
	if PlayerRef.HasSpell(DaedraPWR01)==1 && PlayerRef.HasSpell(DaedraPWR02)==1 && PlayerRef.HasSpell(DaedraPWR03)==1
		UpgradeCheck1()
	elseif PlayerRef.HasSpell(DaedraPWR01UP)==1 && PlayerRef.HasSpell(DaedraPWR02UP)==1 && PlayerRef.HasSpell(DaedraPWR03UP)==1
		UpgradeCheck2()
	elseif PlayerRef.HasSpell(DaedraPWR04UP)==1 && PlayerRef.HasSpell(DaedraPWR05UP)==1 && PlayerRef.HasSpell(DaedraPWR06UP)==1
		UpgradeCheck3()
	elseif PlayerRef.HasSpell(DaedraPWR07UP)==1 && PlayerRef.HasSpell(DaedraPWR08UP)==1 && PlayerRef.HasSpell(DaedraPWR09UP)==1
		UpgradeCheck4()
	elseif PlayerRef.HasSpell(DaedraPWR10UP)==1 && PlayerRef.HasSpell(DaedraPWR11UP)==1 && PlayerRef.HasSpell(DaedraPWR12UP)==1
		UpgradeCheck5()
	elseif PlayerRef.HasSpell(DaedraPWR13UP)==1 && PlayerRef.HasSpell(DaedraPWR14UP)==1 && PlayerRef.HasSpell(DaedraPWR15UP)==1
		UpgradeCheck6()
	else
		Debug.Notification("There is much to learn of these powers..")
	endif
EndEvent



 

 

Edited by Govilku
Link to comment
Share on other sites

I think what is happening is you have some While loops in your OnUpdateGameTime event. These loops will constantly run until the value they are checking is no longer true. In essence they are preventing the script from continuing on to process the next part. It just so happens that once the value reaches 2500 none of the while loops can run and the rest of the event can process. Change the while loops into standard IF statements and it should work as intended.

Link to comment
Share on other sites

You've also got a Wait call in there. You absolutely don't want to mix Wait and any sort of OnUpdate processing.

 

Here's how I would approach your problem. I notice that you're always giving the player three spells and there are really just 7 daedric spell levels so I would use a set of three arrays to greatly simplify the spell swapping. And RegisterForSingleUpdateGameTime is much safer than RegisterForUpdateGameTime. (This version may not work if you try to replace the original in an existing game because the three spell arrays won't get initialized if OnInit doesn't run again.)

 

 

ScriptName DaedricPowerSwapperScript extends Quest

Actor Property PlayerRef Auto
GlobalVariable Property DaedricPower Auto
Spell Property DaedraPWR01 Auto 	; < 100   dpLevel 0
Spell Property DaedraPWR02 Auto 	; < 100
Spell Property DaedraPWR03 Auto 	; < 100
Spell Property DaedraPWR01UP Auto	; < 300   dpLevel 1
Spell Property DaedraPWR02UP Auto	; < 300
Spell Property DaedraPWR03UP Auto	; < 300
Spell Property DaedraPWR04UP Auto	; < 500   dpLevel 2
Spell Property DaedraPWR05UP Auto	; < 500
Spell Property DaedraPWR06UP Auto	; < 500
Spell Property DaedraPWR07UP Auto	; < 750   dpLevel 3
Spell Property DaedraPWR08UP Auto	; < 750
Spell Property DaedraPWR09UP Auto	; < 750
Spell Property DaedraPWR10UP Auto	; < 1500  dpLevel 4
Spell Property DaedraPWR11UP Auto	; < 1500
Spell Property DaedraPWR12UP Auto	; < 1500
Spell Property DaedraPWR13UP Auto	; < 2500  dpLevel 5
Spell Property DaedraPWR14UP Auto	; < 2500
Spell Property DaedraPWR15UP Auto	; < 2500
Spell Property DaedraPWR16UP Auto	; 2500+   dpLevel 6
Spell Property DaedraPWR17UP Auto	; 2500+
Spell Property DaedraPWR18UP Auto	; 2500+

Spell[] DaedraPower1
Spell[] DaedraPower2
Spell[] DaedraPower3


Event OnUpdateGameTime()
	int dpLevel  ; the new daedric power level
	if DaedricPower.GetValue() < 0
		dpLevel = -1
	elseif DaedricPower.GetValue() < 100
		dpLevel = 0
	elseif DaedricPower.GetValue() < 300
		dpLevel = 1
	elseif DaedricPower.GetValue() < 500
		dpLevel = 2
	elseif DaedricPower.GetValue() < 750
		dpLevel = 3
	elseif DaedricPower.GetValue() < 1500
		dpLevel = 4
	elseif DaedricPower.GetValue() < 2500
		dpLevel = 5
	else
		dpLevel = 6
	endif

	int oldLevel = 6  ; the previous daedric power level
	while !PlayerRef.HasSpell(DaedraPower1[oldLevel])
		oldLevel -= 1
	endwhile

	if dpLevel != oldLevel  ; daedric power level has changed
		; some notifications when gaining power based on the new level
		if dpLevel > oldLevel
			if dpLevel == 1
				Debug.Notification("I feel even more powerful!")
			elseif dpLevel == 2
				Debug.Notification("My power has risen tremoundously!")
			elseif dpLevel == 3
				Debug.Notification("My power is overflowing!")
			elseif dpLevel == 4
				Debug.Notification("My power is surging!")
			elseif dpLevel == 5
				Debug.Notification("I am gaining power in lines without projection!")
			elseif dpLevel == 6
				Debug.Notification("I can barely contain the power racing throughout my body!")
			else ; dpLevel == 0
				Debug.Notification("There is much to learn of these powers..")
			endif
		endif

		; swap out the spells
		if oldLevel > -1
			PlayerRef.RemoveSpell(DaedraPower1[oldLevel])
			PlayerRef.RemoveSpell(DaedraPower2[oldLevel])
			PlayerRef.RemoveSpell(DaedraPower3[oldLevel])
		endif
		if dpLevel > -1
			PlayerRef.AddSpell(DaedraPower1[dpLevel])
			PlayerRef.AddSpell(DaedraPower2[dpLevel])
			PlayerRef.AddSpell(DaedraPower3[dpLevel])
		endif
	endif

	; check again in after a half-hour of game time
	RegisterForSingleUpdateGameTime(0.5)
EndEvent


Event OnInit()
	; set up power level arrays
	DaedraPower1 = new Spell[7]
	DaedraPower1[0] = DaedraPWR01
	DaedraPower1[1] = DaedraPWR01UP
	DaedraPower1[2] = DaedraPWR04UP
	DaedraPower1[3] = DaedraPWR07UP
	DaedraPower1[4] = DaedraPWR10UP
	DaedraPower1[5] = DaedraPWR13UP
	DaedraPower1[6] = DaedraPWR16UP
	DaedraPower2 = new Spell[7]
	DaedraPower2[0] = DaedraPWR02
	DaedraPower2[1] = DaedraPWR02UP
	DaedraPower2[2] = DaedraPWR05UP
	DaedraPower2[3] = DaedraPWR08UP
	DaedraPower2[4] = DaedraPWR11UP
	DaedraPower2[5] = DaedraPWR14UP
	DaedraPower2[6] = DaedraPWR17UP
	DaedraPower3 = new Spell[7]
	DaedraPower3[0] = DaedraPWR03
	DaedraPower3[1] = DaedraPWR03UP
	DaedraPower3[2] = DaedraPWR06UP
	DaedraPower3[3] = DaedraPWR09UP
	DaedraPower3[4] = DaedraPWR12UP
	DaedraPower3[5] = DaedraPWR15UP
	DaedraPower3[6] = DaedraPWR18UP
	; start the update cycle
	OnUpdateGameTime()
EndEvent

 

 

Link to comment
Share on other sites

You've also got a Wait call in there. You absolutely don't want to mix Wait and any sort of OnUpdate processing.

 

Here's how I would approach your problem. I notice that you're always giving the player three spells and there are really just 7 daedric spell levels so I would use a set of three arrays to greatly simplify the spell swapping. And RegisterForSingleUpdateGameTime is much safer than RegisterForUpdateGameTime. (This version may not work if you try to replace the original in an existing game because the three spell arrays won't get initialized if OnInit doesn't run again.)

'

 

Super awesome help on arrays, I'm screenshotting and saving this for later reference, you guys are great. I'm surprised you figured out all the conventions so quickly. Some real intelligence in these forums.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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