Difference between revisions of "User talk:Lisselli"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Lisselli
imported>Lisselli
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
Sandbox Page for when I need to post code on the forums. Because it doesn't allow indention..
<br>
 
<source lang="papyrus">
<source lang="papyrus">
Message property SimpleMessage auto
Function SetActorValueCap(Actor akActor, String asValueName, Float afValueCap = 100.0)
Armor property myArmor auto
    ; Store the base and current value.
ReferenceAlias property myAliasRef auto
    Float BaseValue = akActor.GetBaseActorValue(asValueName)
 
    Float CurrentValue = akActor.GetActorValue(asValueName)
Event OnInit()
   
; You're listening for this specific item.
    ; Cap default is 100. If checking for attributes, adjust the desired cap accordingly.
; This function needs to be called before using OnItemAdded/Removed
     
AddInventoryEventFilter(myArmor)
        ; Check if the current value is over the cap.
EndEvent
        if (BaseValue <= afValueCap && CurrentValue > afValueCap)
 
         
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
            ;Unless the base is also over the cap, we\ll assume it\s not.
; You want to know if your ReferenceAlias is filled. Let's do that first.
            akActor.ForceActorValue(asValueName, afValueCap)
; Note: I used parenthesises to ensure important statements run in a certain order. It's not always needed though.
       
if (myAliasRef.GetReference() != none)
        elseif BaseValue > afValueCap && CurrentValue > BaseValue
debug.notification("My alias is filled.")
            ; bring the base and current back down to the cap.
; debug.messagebox might pause/stop the script, I don't know. I prefer notification, or trace.
            BaseValue = BaseValue - (BaseValue - afValueCap)
else
            akActor.SetActorValue(asValueName, BaseValue)
debug.notification("None")
            akActor.ForceActorValue(asValueName, afValueCap)
endif
        else
            return
; if the item added was an armor and was myArmor
        endif
if (akBaseItem as Armor == myArmor)
   
EndFunction
; Here you add your armor to a variable and can do stuff with it later
</source>
; Meanwhile, OnItemAdded will keep checking whatever is added to the player, but only cares about myArmor.Until you change the event filter.
<br>
Armor kArmor = akBaseItem as Armor
; Getting around GetItemCount's issue with properties, hopefully, and calling it on the variable.
Int iMyArmorCount = Game.GetPlayer().GetItemCount(kArmor)
 
; Print how many of myArmor was added,OR print how many instances of the object that is identicial to myArmor's base object.
debug.messagebox("Total Armor Count " +iMyArmorCount)
endif
; If you're done with this event, remove the filter.
; This is called after everything is done above.
RemoveAllInventoryEventFilters()
EndEvent</source><br><br>
<source lang="papyrus">
<source lang="papyrus">
Scriptname SimpleTestScript extends ObjectReference 
Float Function GetDaysInMonth(Float afMonth=0.0) Global
 
; Returns number of days of a month
Actor property PlayerRef auto
Message property SimpleMessage auto
 
Float CurrentPlayerLevel
Int iCount
Bool bLockLevel = true
 


Event OnRead()
; Morning Star ; 0.0 ; days 31.0 :: Sun's Height ; 6.0 ; days 31.0 
Menu()
; Sun's Dawn  ; 1.0 ; days 28.0 :: Last Seed    ; 7.0 ; days 31.0
EndEvent
; First Seed  ; 2.0 ; days 31.0 :: Hearthfire  ; 8.0 ; days 30.0
; Rain's Hand  ; 3.0 ; days 30.0 :: Frostfall    ; 9.0 ; days 31.0
; Second Seed  ; 4.0 ; days 31.0 :: Sun's dusk  ; 10.0 ; days 30.0
; Midyear      ; 5.0 ; days 30.0 :: Evening Star ; 11.0 ; days 31.0


Function Menu(Int aiButton=0)
if afMonth == 0.0
aiButton = SimpleMessage.Show()
  return 31.0
; before doing anything we need to check the player's level for any level ups.
elseif afMonth == 1.0
if (CurrentPlayerLevel != 0)
  return 28.0
if CurrentPlayerLevel < PlayerRef.GetLevel()
elseif afMonth == 2.0
; Unlock
    return 31.0
bLocklevel = false
elseif afMonth == 3.0
; reset iCount
    return 30.0
iCount = 0
elseif afMonth == 4.0
endif
    return 31.0
endif
elseif afMonth == 5.0
if aiButton == 0 ; Advance skill.
    return 30.0
AdvanceSkillEx("Destruction", 450.0, 5)
elseif afMonth == 6.0
elseif aiButton == 1 ; Cancel.
    return 31.0
return
elseif afMonth == 7.0
endif
    return 31.0
elseif afMonth == 8.0
    return 30.0
elseif afMonth == 9.0
    return 31.0
elseif afMonth == 10.0
    return 30.0
elseif afMonth == 11.0
    return 31.0
endif
EndFunction
EndFunction
</source>


Function AdvanceSkillEx(String asSkillName, Float afValue, Int aiClampValue=0)
<source lang="papyrus">
if (bLockLevel == true)
Int Function GetNumMaxSkills(bool abGetNonMaxed=false)
; Let's say Player is level 50. This variable will store that.
; returns the number of skills that are capped.
CurrentPlayerLevel = PlayerRef.GetLevel()
Actor Player = Game.GetPlayer()
debug.notification("CurrentPlayerLevel: " +CurrentPlayerLevel)
Float[] fSkills = new Float[18]
; Lock this level so its not updated, UNLESS the player levels up and becomes higher than this value.
fSkills[0] = Player.GetActorValue("Alteration")
elseif bLockLevel == false
fSkills[1] = Player.GetActorValue("Alchemy")
CurrentPlayerLevel = PlayerRef.GetLevel()
fSkills[2] = Player.GetActorValue("Block")
bLockLevel = true
fSkills[3] = Player.GetActorValue("Conjuration")
endif
fSkills[4] = Player.GetActorValue("Destruction")
 
fSkills[5] = Player.GetActorValue("Enchanting")
;If the player is still level 50. Keep counting the times advance skill was called.
fSkills[6] = Player.GetActorValue("HeavyArmor")
if CurrentPlayerLevel == PlayerRef.GetLevel()
fSkills[7] = Player.GetActorValue("Illusion")
if iCount != aiClampValue
fSkills[8] = Player.GetActorValue("Lockpicking")
Game.AdvanceSkill(asSkillName, afValue)
fSkills[9] = Player.GetActorValue("LightArmor")
iCount += 1
fSkills[10] = Player.GetActorValue("Marksman")
debug.notification("iCount: " +iCount)
fSkills[11] = Player.GetActorValue("OneHanded")
; Everytime advanceskill is called, iCount goes up until it reaches the clamp value.
fSkills[12] = Player.GetActorValue("Pickpocket")
endif
fSkills[13] = Player.GetActorValue("TwoHanded")
fSkills[14] = Player.GetActorValue("Restoration")
fSkills[15] = Player.GetActorValue("Sneak")
fSkills[16] = Player.GetActorValue("Smithing")
fSkills[17] = Player.GetActorValue("Speechcraft")
Int index = fSkills.Length
Int iCount
if abGetNonMaxed
While index
index -= 1                 ; Start from the last index
if fSkills[index] == 100.0  ; Find any skill that is lvl 100.
iCount += 1            ; record how many were found.
endif
EndWhile
else
While index
index -= 1                  ; Start from the last index
if fSkills[index] < 100.0 ; Find any skill that is lvl 100.
iCount += 1            ; record how many were found.
endif
EndWhile
endif
endif
return iCount
EndFunction
EndFunction
</source>
</source>

Latest revision as of 06:44, 15 August 2017


Function SetActorValueCap(Actor akActor, String asValueName, Float afValueCap = 100.0)
    ; Store the base and current value.
    Float BaseValue = akActor.GetBaseActorValue(asValueName)
    Float CurrentValue = akActor.GetActorValue(asValueName)
    
    ; Cap default is 100. If checking for attributes, adjust the desired cap accordingly.
       
        ; Check if the current value is over the cap.
        if (BaseValue <= afValueCap && CurrentValue > afValueCap)
           
            ;Unless the base is also over the cap, we\ll assume it\s not.
            akActor.ForceActorValue(asValueName, afValueCap)
        
        elseif BaseValue > afValueCap && CurrentValue > BaseValue
            ; bring the base and current back down to the cap.
            BaseValue = BaseValue - (BaseValue - afValueCap)
            akActor.SetActorValue(asValueName, BaseValue)
            akActor.ForceActorValue(asValueName, afValueCap)
        else
            return
        endif
     
EndFunction


Float Function GetDaysInMonth(Float afMonth=0.0) Global
; Returns number of days of a month

; Morning Star ; 0.0 ; days 31.0 :: Sun's Height ; 6.0 ; days 31.0  
; Sun's Dawn   ; 1.0 ; days 28.0 :: Last Seed    ; 7.0 ; days 31.0
; First Seed   ; 2.0 ; days 31.0 :: Hearthfire   ; 8.0 ; days 30.0
; Rain's Hand  ; 3.0 ; days 30.0 :: Frostfall    ; 9.0 ; days 31.0
; Second Seed  ; 4.0 ; days 31.0 :: Sun's dusk   ; 10.0 ; days 30.0
; Midyear      ; 5.0 ; days 30.0 :: Evening Star ; 11.0 ; days 31.0

if afMonth == 0.0
   return 31.0
elseif afMonth == 1.0
   return 28.0
elseif afMonth == 2.0
    return 31.0
elseif afMonth == 3.0
    return 30.0
elseif afMonth == 4.0
    return 31.0
elseif afMonth == 5.0
    return 30.0
elseif afMonth == 6.0
    return 31.0
elseif afMonth == 7.0
    return 31.0
elseif afMonth == 8.0
    return 30.0
elseif afMonth == 9.0
    return 31.0
elseif afMonth == 10.0
    return 30.0
elseif afMonth == 11.0
    return 31.0
endif
EndFunction
Int Function GetNumMaxSkills(bool abGetNonMaxed=false)
	; returns the number of skills that are capped.
	Actor Player = Game.GetPlayer()
	Float[] fSkills = new Float[18]
	fSkills[0] = Player.GetActorValue("Alteration")
	fSkills[1] = Player.GetActorValue("Alchemy")
	fSkills[2] = Player.GetActorValue("Block")
	fSkills[3] = Player.GetActorValue("Conjuration")
	fSkills[4] = Player.GetActorValue("Destruction")
	fSkills[5] = Player.GetActorValue("Enchanting")
	fSkills[6] = Player.GetActorValue("HeavyArmor")
	fSkills[7] = Player.GetActorValue("Illusion")
	fSkills[8] = Player.GetActorValue("Lockpicking")
	fSkills[9] = Player.GetActorValue("LightArmor")
	fSkills[10] = Player.GetActorValue("Marksman")
	fSkills[11] = Player.GetActorValue("OneHanded")
	fSkills[12] = Player.GetActorValue("Pickpocket")
	fSkills[13] = Player.GetActorValue("TwoHanded")
	fSkills[14] = Player.GetActorValue("Restoration")
	fSkills[15] = Player.GetActorValue("Sneak")
	fSkills[16] = Player.GetActorValue("Smithing")
	fSkills[17] = Player.GetActorValue("Speechcraft")
	
	Int index = fSkills.Length
	Int iCount
	
	if abGetNonMaxed 
		While index
			index -= 1                  ; Start from the last index
			if fSkills[index] == 100.0  ; Find any skill that is lvl 100.
				iCount += 1             ; record how many were found.
			endif
		EndWhile
	else
		While index
			index -= 1                  ; Start from the last index
			if fSkills[index] < 100.0  ; Find any skill that is lvl 100.
				iCount += 1             ; record how many were found.
			endif
		EndWhile
	endif
	
	return iCount
EndFunction