Difference between revisions of "User talk:Lisselli"

Jump to navigation Jump to search
2,333 bytes removed ,  02:44, 11 May 2017
m
no edit summary
imported>Lisselli
imported>Lisselli
m
Line 1: Line 1:
Sandbox Page for when I need to post code on the forums. Because it doesn't allow indention..
<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
; Meanwhile, OnItemAdded will keep checking whatever is added to the player, but only cares about myArmor.Until you change the event filter.
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">
Scriptname SimpleTestScript extends ObjectReference 
 
Actor property PlayerRef auto
Message property SimpleMessage auto
 
Float CurrentPlayerLevel
Int iCount
Bool bLockLevel = true
 
 
Event OnRead()
Menu()
EndEvent
 
Function Menu(Int aiButton=0)
aiButton = SimpleMessage.Show()
; before doing anything we need to check the player's level for any level ups.
if (CurrentPlayerLevel != 0)
if CurrentPlayerLevel < PlayerRef.GetLevel()
; Unlock
bLocklevel = false
; reset iCount
iCount = 0
endif
endif
if aiButton == 0 ; Advance skill.
AdvanceSkillEx("Destruction", 450.0, 5)
elseif aiButton == 1 ; Cancel.
return
endif
EndFunction
 
Function AdvanceSkillEx(String asSkillName, Float afValue, Int aiClampValue=0)
if (bLockLevel == true)
; Let's say Player is level 50. This variable will store that.
CurrentPlayerLevel = PlayerRef.GetLevel()
debug.notification("CurrentPlayerLevel: " +CurrentPlayerLevel)
; Lock this level so its not updated, UNLESS the player levels up and becomes higher than this value.
elseif bLockLevel == false
CurrentPlayerLevel = PlayerRef.GetLevel()
bLockLevel = true
endif
 
;If the player is still level 50. Keep counting the times advance skill was called.
if CurrentPlayerLevel == PlayerRef.GetLevel()
if iCount != aiClampValue
Game.AdvanceSkill(asSkillName, afValue)
iCount += 1
debug.notification("iCount: " +iCount)
; Everytime advanceskill  is called, iCount goes up until it reaches the clamp value.
endif
endif
EndFunction
</source>
</source>
Anonymous user

Navigation menu