User talk:Lisselli

From the CreationKit Wiki
Revision as of 06:55, 7 November 2016 by imported>Lisselli
Jump to navigation Jump to search

Sandbox Page for when I need to post code on the forums. Because it doesn't allow indention..

Message property SimpleMessage auto
Armor property myArmor auto
ReferenceAlias property myAliasRef auto

Event OnInit()
	; You're listening for this specific item.
	; This function needs to be called before using OnItemAdded/Removed
	AddInventoryEventFilter(myArmor)
EndEvent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
	; You want to know if your ReferenceAlias is filled. Let's do that first.
	; Note: I used parenthesises to ensure important statements run in a certain order. It's not always needed though. 
	if (myAliasRef.GetReference() != none)
		debug.notification("My alias is filled.")
		; debug.messagebox might pause/stop the script, I don't know. I prefer notification, or trace.
	else
		debug.notification("None")
	endif
	
	; if the item added was an armor and was myArmor
		if (akBaseItem as Armor == myArmor)
					
			; 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



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