Guest User

Untitled

a guest
Nov 16th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. Scriptname FyTyTweaks:AAAFyTy_ItemPhysics_HotkeyQuestScript extends Quest
  2.  
  3. ActorBase property PlayerActorBase Auto Const
  4. Actor Property PlayerRef Auto Const
  5.  
  6. FormList Property AAAFyTy_PhysicsItemsMasterFormList Auto Const
  7.  
  8. FormList Property AAAFyTy_WorkshopWorkbenchFormList Auto Const
  9.  
  10. Message Property AAAFyTy_Choice_AddToWorkBench_ItemPhysics Auto Const
  11.  
  12. Keyword Property WorkshopItemKeyword Auto Const
  13.  
  14. int iNestedFormListCount = 0
  15. int iDistance = 500
  16. int iCreatedFormIDMin = -16777216; FF000000
  17. int iCreatedFormIDMax = -1048576; FFF00000
  18.  
  19. bool bIterating = false
  20. bool bInWorkshopMenu = false
  21. string strWorkshopMenu = "WorkshopMenu"
  22.  
  23. Event OnQuestInit()
  24.  
  25. iNestedFormListCount = AAAFyTy_PhysicsItemsMasterFormList.GetSize()
  26. SetStage(10)
  27.  
  28. EndEvent
  29.  
  30. Event OnMenuOpenCloseEvent(string strMenuName, bool bOpenedMenu)
  31.  
  32. if (strMenuName == strWorkshopMenu)
  33. bInWorkshopMenu = bOpenedMenu
  34. EndIf
  35.  
  36. EndEvent
  37.  
  38. Function RegisterEventsForScript()
  39.  
  40. Debug.MessageBox("Registering")
  41. RegisterForKey(35)
  42. RegisterForKey(36)
  43. RegisterForMenuOpenCloseEvent(strWorkshopMenu)
  44.  
  45. EndFunction
  46.  
  47. Function DeRegisterEventsForScript()
  48.  
  49. Debug.MessageBox("De-Registering")
  50. UnRegisterForKey(35)
  51. unRegisterForKey(36)
  52. UnRegisterForMenuOpenCloseEvent(strWorkshopMenu)
  53.  
  54. EndFunction
  55.  
  56. Event OnStageSet(int iStageID, int iItemID)
  57.  
  58. Debug.MessageBox("Stage Changed")
  59.  
  60. if (iStageID == 10)
  61. RegisterEventsForScript()
  62. Debug.MessageBox("Stage set to 10")
  63. elseif (iStageID == 20)
  64. DeRegisterEventsForScript()
  65. Debug.MessageBox("Stage set to 20")
  66. EndIf
  67.  
  68. EndEvent
  69.  
  70. Function ChangeMotionTypeItems(bool bFreeze)
  71.  
  72. bIterating = true
  73. int iFormListIndex = 0
  74.  
  75. While iFormListIndex < iNestedFormlistCount
  76.  
  77. FormList formlistCurrent = AAAFyTy_PhysicsItemsMasterFormList.GetAt(iFormListIndex) as FormList
  78. ObjectReference[] objrefarrayFoundItems = PlayerRef.FindAllReferencesOfType(formlistCurrent, iDistance)
  79.  
  80. int iFoundItemsCount = objrefarrayFoundItems.Length
  81. int iFoundItemIndex = 0
  82.  
  83. ;Debug.MessageBox("Found items: "+ iFoundItemsCount as string)
  84.  
  85. if iFoundItemsCount > 0
  86.  
  87. While iFoundItemIndex < iFoundItemsCount
  88.  
  89. ;Debug.MessageBox("Setting Motion Type on Index: "+ iFoundItemIndex as string)
  90.  
  91. ObjectReference objrefFoundItem = objrefarrayFoundItems[iFoundItemIndex] as ObjectReference
  92.  
  93. if bFreeze
  94. objrefFoundItem.SetMotionType(objrefFoundItem.Motion_Keyframed, false)
  95. else
  96. objrefFoundItem.SetMotionType(objrefFoundItem.Motion_Dynamic, true)
  97. EndIf
  98.  
  99. iFoundItemIndex += 1
  100.  
  101. EndWhile
  102.  
  103. EndIf
  104.  
  105. iFormListIndex += 1
  106.  
  107. EndWhile
  108.  
  109. bIterating = false
  110.  
  111. EndFunction
  112.  
  113. Function LinkItemsToWorkbench()
  114.  
  115. bIterating = true
  116. int iFormListIndex = 0
  117. ObjectReference objrefWorkshop = Game.FindClosestReferenceOfAnyTypeInListFromRef(AAAFyTy_WorkshopWorkbenchFormList, PlayerRef, 20000)
  118.  
  119. While iFormListIndex < iNestedFormlistCount
  120.  
  121. FormList formlistCurrent = AAAFyTy_PhysicsItemsMasterFormList.GetAt(iFormListIndex) as FormList
  122. ObjectReference[] objrefarrayFoundItems = PlayerRef.FindAllReferencesOfType(formlistCurrent, iDistance)
  123.  
  124. int iFoundItemsCount = objrefarrayFoundItems.Length
  125. int iFoundItemIndex = 0
  126.  
  127. ;Debug.MessageBox("Found items: "+ iFoundItemsCount as string)
  128.  
  129. if iFoundItemsCount > 0
  130.  
  131. While iFoundItemIndex < iFoundItemsCount
  132.  
  133. ;Debug.MessageBox("Adding Item To Workshop At Index: "+ iFoundItemIndex as string)
  134.  
  135. ObjectReference objrefFoundItem = objrefarrayFoundItems[iFoundItemIndex] as ObjectReference
  136. ;Debug.MessageBox(objrefFoundItem.GetBaseObject().GetName() + " " + objrefFoundItem.GetFormID() as string)
  137.  
  138. int iItemFormID = objrefFoundItem.GetFormID()
  139.  
  140. if (iItemFormID > iCreatedFormIDMin) && (iItemFormID < iCreatedFormIDMax)
  141. ;Debug.MessageBox("Linking Item To Workshop")
  142. objrefFoundItem.SetLinkedRef(objrefWorkshop, WorkshopItemKeyword)
  143.  
  144. EndIf
  145.  
  146. iFoundItemIndex += 1
  147.  
  148. EndWhile
  149.  
  150. EndIf
  151.  
  152. iFormListIndex += 1
  153.  
  154. EndWhile
  155.  
  156. bIterating = false
  157.  
  158.  
  159. EndFunction
  160.  
  161.  
  162. Event OnKeyDown(int iKeyCode)
  163.  
  164. Debug.MessageBox("End Key Pressed")
  165.  
  166.  
  167. if (iKeyCode == 35) && (bIterating == false) && (bInWorkshopMenu == false)
  168.  
  169. ;Debug.MessageBox("Iterating")
  170.  
  171. if AAAFyTy_Choice_AddToWorkBench_ItemPhysics.Show() == 0
  172. ChangeMotionTypeItems(true)
  173. else
  174. LinkItemsToWorkbench()
  175. Endif
  176.  
  177. ;Debug.MessageBox("Done, reseting variables")
  178.  
  179. EndIf
  180.  
  181. if (iKeyCode == 36) && (bIterating == false) && (bInWorkshopMenu == false)
  182.  
  183. ;Debug.MessageBox("Reverting")
  184.  
  185. ChangeMotionTypeItems(false)
  186.  
  187. ;Debug.MessageBox("Done, reseting variables")
  188.  
  189. EndIf
  190.  
  191. EndEvent
Add Comment
Please, Sign In to add comment