Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ScriptName CUPID_OnPlayerEquip Extends ReferenceAlias
- ;=================================================================================
- ;PROXiCide aka Taewon
- ;Steam: http://steamcommunity.com/id/PROXiCiDE
- ;Nexus: http://skyrim.nexusmods.com/users/3018315
- ;Bethesda: http://forums.bethsoft.com/user/425376-taewon/
- ;=================================================================================
- ; Cupid 0.4a
- ; Revised script, no longer attached to Player
- ;
- ; Version
- ; 0.4a
- ; - Added the ability to enable / disable cupid via Global Variable
- ; - Fixed Bound Bow problems when the player had more arrows than the bound arrow scripted Event
- FormList Property AmmoList Auto
- FormList Property AmmoDefList Auto
- Int Property MaxAmmoInList Auto
- Keyword Property WeapTypeBow Auto
- Keyword Property VendorItemArrow Auto
- Keyword Property WeapTypeBoundArrow Auto
- Float Property CupidUpdateIntervalve = 1.0 Auto
- GlobalVariable Property CupidInstalled Auto
- Bool bUpdating = False
- Form formAmmo
- Bool bKeepAlive = True
- Bool Function IsCupidInstalled()
- If CupidInstalled.GetValueInt() == 0
- Return False
- EndIf
- Return True
- EndFunction
- Function DebugMessage(String msg)
- ;Debug.Notification(msg)
- EndFunction
- Function RunScript()
- CallUpdate()
- EndFunction
- ;Detects if Cupid is installed if not we will no longer call our items
- ;Why are we updating? well incase we happen to equip arrows and when
- ;the bow is no longer present
- Function CallUpdate()
- If !IsCupidInstalled()
- bKeepAlive = False
- Return
- EndIf
- If !bUpdating
- bUpdating = True
- RegisterForSingleUpdate(CupidUpdateIntervalve)
- EndIf
- EndFunction
- Event OnUpdate()
- DebugMessage("OnUpdate")
- Actor player = GetActorRef()
- Bool IsArrowVendorEquipped = (player.WornHasKeyword(VendorItemArrow))
- Bool IsBoundBow = (player.WornHasKeyword(WeapTypeBoundArrow))
- Bool IsBowEquipped = (player.GetEquippedItemType(1) == 7 || player.GetEquippedItemType(0) == 7)
- If !IsBowEquipped && IsArrowVendorEquipped
- UnequipArrows(player)
- EndIf
- If bKeepAlive
- RegisterForSingleUpdate(CupidUpdateIntervalve)
- EndIf
- EndEvent
- Form Function GrabAmmoFromList()
- Int i = 0
- Int save_count = 0
- Int item_count = 0
- Int equal_count = 0
- Form save_form = None
- Actor player = GetActorRef()
- While i < AmmoList.GetSize()
- item_count = player.GetItemCount(AmmoList.GetAt(i))
- If item_count > save_count
- save_count = item_count
- save_form = AmmoList.GetAt(i)
- EndIf
- i += 1
- EndWhile
- ;Incase we lagged while doing the loop, lets recheck
- Bool IsBoundBow = (player.WornHasKeyword(WeapTypeBoundArrow))
- Bool IsBowEquipped = (player.GetEquippedItemType(1) == 7 || player.GetEquippedItemType(0) == 7)
- If !IsBowEquipped
- save_form = None
- EndIf
- Return save_form
- EndFunction
- Function EquipArrows(Actor akPlayer)
- Bool IsArrowVendorEquipped = (akPlayer.WornHasKeyword(VendorItemArrow))
- Bool IsBoundBow = (akPlayer.WornHasKeyword(WeapTypeBoundArrow))
- Bool IsBowEquipped = (akPlayer.GetEquippedItemType(1) == 7 || akPlayer.GetEquippedItemType(0) == 7)
- If IsBoundBow
- Return
- EndIf
- If IsBowEquipped && !IsBoundBow
- If AmmoList != None
- Form new_form = GrabAmmoFromList()
- If new_form != None
- If !akPlayer.IsEquipped(new_form)
- akPlayer.EquipItem(new_form,False,True)
- EndIf
- Else
- EndIf
- EndIf
- ElseIf !IsBowEquipped && !IsBoundBow && IsArrowVendorEquipped
- UnequipArrows(akPlayer)
- EndIf
- EndFunction
- Function UnequipArrows(Actor akPlayer)
- Int i = 0
- Int count = AmmoList.GetSize()
- While i < count
- If akPlayer.IsEquipped(AmmoList.GetAt(i))
- akPlayer.UnequipItem(AmmoList.GetAt(i))
- i = count
- EndIf
- i += 1
- EndWhile
- EndFunction
- Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
- DebugMessage("OnItemAdded")
- If IsCupidInstalled()
- If akBaseItem As Ammo
- If !AmmoList.HasForm(akBaseItem)
- ;Debug.Notification(akBaseItem + " Added in List")
- AmmoList.AddForm(akBaseItem)
- EndIf
- EndIf
- EndIf
- EndEvent
- Event OnItemRemoved(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
- DebugMessage("OnItemRemoved")
- If IsCupidInstalled()
- If akBaseItem As Ammo
- ;Exit out so we dont accidently remove the default ammo
- If AmmoDefList.HasForm(akBaseItem)
- ;Debug.Notification("We are returning")
- Else
- ;Check to see if we are adding a new Ammo to the list
- If AmmoList.HasForm(akBaseItem)
- ;Debug.Notification("Removed Item from List " + akBaseItem)
- AmmoList.RemoveAddedForm(akBaseItem)
- EndIf
- EndIf
- EndIf
- EndIf
- EndEvent
- Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
- DebugMessage("OnObjectEquipped")
- If IsCupidInstalled()
- Actor player = GetActorRef()
- CallUpdate()
- If akBaseObject As Weapon
- EquipArrows(player)
- EndIf
- If akBaseObject As Ammo
- formAmmo = akBaseObject As Form
- If !AmmoList.HasForm(formAmmo)
- AmmoList.AddForm(formAmmo)
- EndIf
- EndIf
- EndIf
- EndEvent
- Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
- DebugMessage("OnObjectUnequipped")
- If IsCupidInstalled()
- Actor player = GetActorRef()
- Bool IsArrowVendorEquipped = (player.WornHasKeyword(VendorItemArrow))
- Bool IsBoundBow = (player.WornHasKeyword(WeapTypeBoundArrow))
- If IsBoundBow
- Return
- EndIf
- CallUpdate()
- If akBaseObject As Weapon
- If player.GetEquippedItemType(0) != 7 && !IsBoundBow
- player.UnequipItem(formAmmo,False,True)
- EndIf
- EndIf
- If akBaseObject As Ammo
- formAmmo = akBaseObject As Form
- If !AmmoList.HasForm(formAmmo)
- AmmoList.AddForm(formAmmo)
- EndIf
- If player.GetEquippedItemType(0) == 7 && !IsBoundBow && !IsArrowVendorEquipped
- EquipArrows(player)
- EndIf
- EndIf
- EndIf
- EndEvent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement