Advertisement
PROXiCiDE

Cupid Source

Mar 13th, 2013
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.86 KB | None | 0 0
  1. ScriptName CUPID_OnPlayerEquip Extends ReferenceAlias  
  2.  
  3. ;=================================================================================
  4. ;PROXiCide aka Taewon
  5. ;Steam:      http://steamcommunity.com/id/PROXiCiDE
  6. ;Nexus:      http://skyrim.nexusmods.com/users/3018315
  7. ;Bethesda:   http://forums.bethsoft.com/user/425376-taewon/
  8. ;=================================================================================  
  9. ; Cupid 0.4a
  10. ; Revised script, no longer attached to Player
  11. ;
  12. ; Version
  13. ; 0.4a
  14. ; - Added the ability to enable / disable cupid via Global Variable
  15. ; - Fixed Bound Bow problems when the player had more arrows than the bound arrow scripted Event
  16.  
  17. FormList Property AmmoList Auto
  18. FormList Property AmmoDefList Auto
  19. Int Property MaxAmmoInList Auto
  20. Keyword Property WeapTypeBow Auto
  21. Keyword Property VendorItemArrow Auto
  22. Keyword Property WeapTypeBoundArrow Auto
  23. Float Property CupidUpdateIntervalve = 1.0 Auto
  24. GlobalVariable Property CupidInstalled Auto
  25.  
  26. Bool bUpdating = False
  27. Form formAmmo
  28. Bool bKeepAlive = True
  29.  
  30. Bool Function IsCupidInstalled()
  31.     If CupidInstalled.GetValueInt() == 0
  32.         Return False
  33.     EndIf
  34.     Return True
  35. EndFunction
  36.  
  37. Function DebugMessage(String msg)
  38.     ;Debug.Notification(msg)
  39. EndFunction
  40.  
  41. Function RunScript()
  42.     CallUpdate()
  43. EndFunction
  44.  
  45. ;Detects if Cupid is installed if not we will no longer call our items
  46. ;Why are we updating? well incase we happen to equip arrows and when
  47. ;the bow is no longer present
  48. Function CallUpdate()
  49.     If !IsCupidInstalled()
  50.         bKeepAlive = False
  51.         Return
  52.     EndIf
  53.    
  54.     If !bUpdating
  55.         bUpdating = True
  56.         RegisterForSingleUpdate(CupidUpdateIntervalve)
  57.     EndIf
  58. EndFunction
  59.  
  60. Event OnUpdate()
  61.     DebugMessage("OnUpdate")
  62.     Actor player = GetActorRef()
  63.     Bool IsArrowVendorEquipped = (player.WornHasKeyword(VendorItemArrow))
  64.     Bool IsBoundBow = (player.WornHasKeyword(WeapTypeBoundArrow))
  65.     Bool IsBowEquipped = (player.GetEquippedItemType(1) == 7 || player.GetEquippedItemType(0) == 7)
  66.    
  67.     If !IsBowEquipped && IsArrowVendorEquipped
  68.         UnequipArrows(player)
  69.     EndIf
  70.    
  71.     If bKeepAlive
  72.         RegisterForSingleUpdate(CupidUpdateIntervalve)
  73.     EndIf
  74.    
  75. EndEvent
  76.  
  77. Form Function GrabAmmoFromList()
  78.     Int i = 0
  79.     Int save_count = 0
  80.     Int item_count = 0
  81.     Int equal_count = 0
  82.     Form save_form = None
  83.     Actor player = GetActorRef()
  84.    
  85.     While i < AmmoList.GetSize()
  86.         item_count = player.GetItemCount(AmmoList.GetAt(i))
  87.         If item_count > save_count
  88.             save_count = item_count
  89.             save_form = AmmoList.GetAt(i)
  90.         EndIf
  91.         i += 1
  92.     EndWhile
  93.    
  94.     ;Incase we lagged while doing the loop, lets recheck
  95.     Bool IsBoundBow = (player.WornHasKeyword(WeapTypeBoundArrow))
  96.     Bool IsBowEquipped = (player.GetEquippedItemType(1) == 7 || player.GetEquippedItemType(0) == 7)
  97.     If !IsBowEquipped
  98.         save_form = None
  99.     EndIf
  100.    
  101.     Return save_form
  102. EndFunction
  103.  
  104. Function EquipArrows(Actor akPlayer)
  105.    
  106.     Bool IsArrowVendorEquipped = (akPlayer.WornHasKeyword(VendorItemArrow))
  107.     Bool IsBoundBow = (akPlayer.WornHasKeyword(WeapTypeBoundArrow))
  108.     Bool IsBowEquipped = (akPlayer.GetEquippedItemType(1) == 7 || akPlayer.GetEquippedItemType(0) == 7)
  109.    
  110.     If IsBoundBow
  111.         Return
  112.     EndIf
  113.    
  114.     If IsBowEquipped && !IsBoundBow
  115.         If AmmoList != None
  116.             Form new_form = GrabAmmoFromList()
  117.             If new_form != None
  118.                 If !akPlayer.IsEquipped(new_form)
  119.                     akPlayer.EquipItem(new_form,False,True)
  120.                 EndIf
  121.             Else
  122.             EndIf
  123.         EndIf
  124.     ElseIf !IsBowEquipped && !IsBoundBow && IsArrowVendorEquipped
  125.         UnequipArrows(akPlayer)
  126.     EndIf
  127. EndFunction
  128.  
  129. Function UnequipArrows(Actor akPlayer)
  130.     Int i = 0
  131.     Int count = AmmoList.GetSize()
  132.     While i < count
  133.         If akPlayer.IsEquipped(AmmoList.GetAt(i))
  134.             akPlayer.UnequipItem(AmmoList.GetAt(i))
  135.             i = count
  136.         EndIf
  137.         i += 1
  138.     EndWhile
  139. EndFunction
  140.  
  141. Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  142.     DebugMessage("OnItemAdded")
  143.     If IsCupidInstalled()
  144.         If akBaseItem As Ammo
  145.             If !AmmoList.HasForm(akBaseItem)
  146.                 ;Debug.Notification(akBaseItem + " Added in List")
  147.                 AmmoList.AddForm(akBaseItem)
  148.             EndIf
  149.         EndIf
  150.     EndIf
  151. EndEvent
  152.  
  153. Event OnItemRemoved(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
  154.     DebugMessage("OnItemRemoved")
  155.     If IsCupidInstalled()
  156.         If akBaseItem As Ammo
  157.             ;Exit out so we dont accidently remove the default ammo
  158.             If AmmoDefList.HasForm(akBaseItem)
  159.                 ;Debug.Notification("We are returning")
  160.             Else
  161.                 ;Check to see if we are adding a new Ammo to the list
  162.                 If AmmoList.HasForm(akBaseItem)
  163.                     ;Debug.Notification("Removed Item from List " + akBaseItem)
  164.                     AmmoList.RemoveAddedForm(akBaseItem)
  165.                 EndIf
  166.             EndIf
  167.         EndIf
  168.     EndIf
  169. EndEvent
  170.  
  171. Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
  172.     DebugMessage("OnObjectEquipped")
  173.     If IsCupidInstalled()
  174.         Actor player = GetActorRef()
  175.        
  176.         CallUpdate()
  177.         If akBaseObject As Weapon                      
  178.             EquipArrows(player)
  179.         EndIf
  180.        
  181.         If akBaseObject As Ammo
  182.             formAmmo = akBaseObject As Form
  183.             If !AmmoList.HasForm(formAmmo)
  184.                 AmmoList.AddForm(formAmmo)
  185.             EndIf
  186.         EndIf
  187.     EndIf
  188. EndEvent
  189.  
  190. Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
  191.     DebugMessage("OnObjectUnequipped")
  192.     If IsCupidInstalled()
  193.         Actor player = GetActorRef()
  194.         Bool IsArrowVendorEquipped = (player.WornHasKeyword(VendorItemArrow))
  195.         Bool IsBoundBow = (player.WornHasKeyword(WeapTypeBoundArrow))
  196.        
  197.         If IsBoundBow
  198.             Return
  199.         EndIf
  200.        
  201.         CallUpdate()
  202.         If akBaseObject As Weapon
  203.             If player.GetEquippedItemType(0) != 7 && !IsBoundBow
  204.                 player.UnequipItem(formAmmo,False,True)
  205.             EndIf
  206.         EndIf
  207.        
  208.         If akBaseObject As Ammo
  209.             formAmmo = akBaseObject As Form
  210.             If !AmmoList.HasForm(formAmmo)
  211.                 AmmoList.AddForm(formAmmo)
  212.             EndIf
  213.            
  214.             If player.GetEquippedItemType(0) == 7 && !IsBoundBow && !IsArrowVendorEquipped
  215.                 EquipArrows(player)
  216.             EndIf
  217.         EndIf
  218.     EndIf
  219. EndEvent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement