Jump to content

[LE] Is it possible to pass an argument to a papyrus script?


nav01

Recommended Posts

I've written the following script to make a potion restore a percentage of health and it seems to work fine, some precision withstanding, but I'd like to somehow make this script generic and support restoring a percentage of either health, magicka, or stamina, since the only real difference would be the actor value argument changing. However, I don't see anything that would allow me to distinguish what I want to restore. First, I had this.

 

 

Event OnEffectStart(Actor akTarget, Actor akCaster)
    Actor player = akTarget
    float magnitude =  GetMagnitude() / 100.0 ;turn to decimal
    int maxHealth = player.GetActorValueMax("Health") as int
    int heal = (maxHealth * magnitude) as int
    debug.notification("Max Health: " + maxHealth + ", Healing For: " + heal)
    player.RestoreActorValue("Health", heal)
EndEvent

 

 

 

One workaround that seems to work ok is to use the skill level required box in the magic effect editor and have a different value (0,1,2) for each effect since I assume that value is not used normally in alchemy. And with that I made this.

 

 

Event OnEffectStart(Actor akTarget, Actor akCaster)
    int actorValue = GetBaseObject().GetSkillLevel()
    If actorValue == 0
        RestoreValue(akTarget, "Health")
    ElseIf actorValue == 1
        RestoreValue(akTarget, "Magicka")
    ElseIf actorValue == 2
        RestoreValue(akTarget, "Stamina")
    EndIf
EndEvent

Function RestoreValue(Actor player, string value)
    float percentToRestore =  GetMagnitude() / 100 ;turn to decimal
    int maxValue = player.GetActorValueMax(value) as int
    int restore = (maxValue * percentToRestore) as int
    debug.notification("Max " + value + ":" + maxValue + ", Restored For: " + restore)
    player.RestoreActorValue(value, restore)
EndFunction

 

 

 

But that seems dirty. Is there a way to pass an argument to the script, or some other suggested method?

Link to comment
Share on other sites

Use properties.

 

 

string Property sModAV Auto
 
...
Event OnEffectStart(Actor akTarget, Actor akCaster)
    Actor player = akTarget
    float magnitude =  GetMagnitude() / 100.0 ;turn to decimal
    int maxAV = player.GetActorValueMax(sModAV) as int
    int modAmount = (maxAV * magnitude) as int
    debug.notification("Max " + sModAV + ": " + maxAV + ", Healing For: " + modAmount)
    player.RestoreActorValue(sModAV, modAmount)
EndEvent

 

You can then fill in sModAV to be whatever you like, independently on different forms.

Link to comment
Share on other sites

yes

  • String Function
  • Float Function
  • Spell Function
  • Quest Function
  • headpart Function

when your Function isn't Generic it will return an Argument.

 

Example for a String Function

String Function GetConfidenceString(int nActorValue)

	String[] sConfidence = new String[5]
	sConfidence[0] = "Cowardly"
	sConfidence[1] = "Cautious"
	sConfidence[2] = "Average"
	sConfidence[3] = "Brave"
	sConfidence[4] = "Foolhardy"
	return sConfidence[nActorValue]
EndFunction

String sNewString = GetConfidenceString(GetActorValueInt("Confidence"))

it has pass the value to the sNewString

 

Is that what you mean?

 

Edit

Not tested for Form or Function just a quickie I wrote

 

Edit 2

String sNewString = GetConfidenceString(Game.GetPlayer().GetActorValue("Confidence"))

If you can define, you can return it.

String Function GetPapyrusUtilVersion() global

	Int nResult = PapyrusUtil.GetVersion()
	Int nLength = StringUtil.GetLength(nResult As String)
	return StringUtil.Substring(nResult / 10 As Float, 0, nLength + 1)
EndFunction

String Function GetSKSEVersion() global

	return SKSE.GetVersion() + "." + SKSE.GetVersionMinor()  + "." + SKSE.GetVersionBeta()
EndFunction

To show I am more than Strings


Float[] Function SetAngleZ180(Float[] fZAngle) Global

	Int nMax = fZAngle.Length
	While nMax > 0
		nMax -= 1
		fZAngle[nMax] = GetAngleZ180(fZAngle[nMax])
	EndWhile
	return fZAngle
EndFunction

Float Function GetAngleZ180(Float fZAngle) global

	If fZAngle > 179
		return fZAngle - 180
	EndIf
	return fZAngle + 180
EndFunction

Int Function ClampInt(Int Value, Int fMin, Int fMax)  global

	If Value > fMax
		return fMax
	ElseIf(Value < fMin)
		return fMin
	EndIf
	return Value
EndFunction

Float Function ClampFloat(Float Value, Int nMin, Int nMax)  global

	If Value > nMax
		return nMax
	ElseIf Value < nMin
		return nMin
	EndIf
	return Value
EndFunction


Edit three

 

If you look at SKSE / PapryrusUtil one, it will always return the correct Version Installed.

Edited by PeterMartyr
Link to comment
Share on other sites

That's exactly what I needed foamyesque, it works perfectly. Thanks! Sorry PeterMartyr, I think I should have specified passing something to the script from outside of it.

Edited by nav01
Link to comment
Share on other sites

  • Recently Browsing   0 members

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