Talk:GetXPForLevel - Game

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search

There is no function that returns the remaining xp needed to the next level. GetXPForLevel - Game only returns the total xp needed for the next level, not remaining. I always wanted this, and thought I could never pull this off. Turns out the Actor Value "Experience", provided me with that I needed:

ActorValue Property Experience Auto

Int CurrentLvl
Event OnInit()
	CurrentLvl = Game.GetPlayer().GetLevel()
	GetXPRemainingForLevel(CurrentLvl + 1)
EndEvent

Int Function GetXPRemainingForLevel(Int aiNextLevel)
        ; Store total xp gained since level 1.
	Int TotalXP = Game.GetPlayer().GetValue(Experience) as int
	
	; Calculate total xp for the next level.
        ; Exmaple, if aiNextLevel = 35, the value would be 48,876.
	Float TotalXPForNextLvl = 37.5 * aiNextLevel * aiNextLevel + 87.5 * aiNextLevel - 124
	
	Float TotalXPRemaining = TotalXPForNextLvl - TotalXP
        ; Exmaple, if total exp earned up to your level(30) is 37,000, this will return 1,626
	return  TotalXPRemaining as int
EndFunction

How to use: The Actor Value property pointing to the AV Experience.

  • Store the player's current level to a variable outside of the function and use that var throughout the function.
  • When passing the variable into the function add 1 to it. This tells the function subtract the total xp gained up to the current level from the total exp gained for the next level. Your level + 1.
    • Though you can add as much levels as you desire, like if you want to know how much xp remaining from the current level to lvl 100 or something.

This was very simple when the missing piece became known. Lisselli (talk) 2017-04-27T14:53:44 (EDT)

OnInit isn't necessary, that's just the event I used for quick and easy calling the function.Lisselli (talk) 2017-04-27T14:54:54 (EDT)