JustChill Posted June 30, 2018 Author Share Posted June 30, 2018 Hey, thanks for the input.I decided to use a different working "solution". Changed code: scn GSFarmFoodLockerScript Float GSWasOpened Ref rWhoAmI Begin OnActivate Player if GetOpenState == 3 ;=> We only want to activate / open the locker when it is closed. if Player.GetItemCount GSFarmFoodList == 0 && Player.GetItemCount GSFarmMedicalSupplies == 0 MessageEx "You have no food items in your inventory." Return endif Set rWhoAmI to GetSelf ;=> ONLY THE FOOD LOCKER WILL PROCESS THE SCRIPT, by using that variable! Set GSWasOpened to -1 ;=> To ensure the reference is not set to zero during opening animation (as that counts as game mode). Playsound DRSFootLockerOpen Activate Player endif End Begin MenuMode 1008 if rWhoAmI != 0 ;=> This is necessary as otherwise any other container would also process this block if player.getitemcount GSFarmFoodList > 0 || Player.GetItemCount GSFarmMedicalSupplies > 0 While GetMenuItemFilter 1008 > 3 || GetMenuItemFilter 1008 == 0 ClickMenuButton "ContainerMenu\NOGLOW_BRANCH\CM_ItemsRect\CM_Items_LeftFilterArrow" Loop While GetMenuItemFilter 1008 < 3 && GetMenuItemFilter 1008 != 0 ClickMenuButton "ContainerMenu\NOGLOW_BRANCH\CM_ItemsRect\CM_ItemsTitle" Loop endif Set GSWasOpened to 1 ;=> And there are plenty container in this interior, but only one will return an actual reference. endif End Begin GameMode if rWhoAmI != 0 && GSWasOpened != -1 Set rWhoAmI to 0 ;=> When things are done (menu closed), the reference is cleared again. endif If GSWasOpened >= 1 && GSWasOpened < 2 Set GSWasOpened to GSWasOpened + GetSecondsPassed elseif GSWasOpened >= 2 Set GSWasOpened to 0 Playsound DRSFootLockerClose ;=> This will make the closing sound at the right moment. endif End I am starting to work on the "exit conditions", when there is no more Aid item in the players inventory. Link to comment Share on other sites More sharing options...
JustChill Posted June 30, 2018 Author Share Posted June 30, 2018 Unfortunately, I still run into the same problem, as soon as there are no Aid items left. I simply cannot disable the left menu and the player is allowed to throw anything inside. :sad: My goal is to make this container a bit more dynamic by adding static items into the shelves, depending on what is inside the container.Yet I'll only show aid items...Maybe I simply scrap the queries and allow the player to put everything inside, even without any visual effects. Yet I would prefer if the player is unable to put anything else inside. I've tried SetOnMenuClickEventHandler, but my UDF never got into action.So I guess I simply couldn't figure the right path. :/ Link to comment Share on other sites More sharing options...
EPDGaffney Posted June 30, 2018 Share Posted June 30, 2018 I was worried about that. You could try my carryweight idea. I'd love to know what's causing the keys not to disable, though. Link to comment Share on other sites More sharing options...
JustChill Posted June 30, 2018 Author Share Posted June 30, 2018 This is a neat workaround, thanks. :DEven though, I fear that without hardcore mode, ammunition can still be added to the inventory. Yet it may be the best solution so far, so thanks again. In addition:I fully tested it and it seems that you cannot put ANYTHING into the inventory as wanted.Thanks.Guess I can continue with the other stuff now I want this Food Cabinet to do...Current script: scn GSFarmFoodLockerScript Float GSWasOpened Ref rWhoAmI Ref rWhichNPC array_var GSFPlayerAidItems Begin OnActivate Player if GetOpenState == 3 ;=> We only want to activate / open the locker when it is closed. Set rWhoAmI to GetSelf ;=> ONLY THE FOOD LOCKER WILL PROCESS THE SCRIPT, by using that variable! Set GSWasOpened to 3 ;=> To open the NPC containers at the right moment. Playsound DRSFootLockerOpen Activate Player endif End Begin MenuMode 1008 if rWhoAmI != 0 ;=> This is necessary as otherwise any other container would also process this block if rWhichNPC == 0 Set rWhichNPC to rWhoAmI.GetLinkedRef endif Let GSFPlayerAidItems := Player.GetAllItemRefs 47 if eval (Ar_Size GSFPlayerAidItems) > 0 rWhichNPC.SetAV CarryWeight 9999999 While GetMenuItemFilter 1008 > 3 || GetMenuItemFilter 1008 == 0 ClickMenuButton "ContainerMenu\NOGLOW_BRANCH\CM_ItemsRect\CM_Items_LeftFilterArrow" Loop While GetMenuItemFilter 1008 < 3 && GetMenuItemFilter 1008 != 0 ClickMenuButton "ContainerMenu\NOGLOW_BRANCH\CM_ItemsRect\CM_ItemsTitle" Loop else rWhichNPC.SetAV CarryWeight -1 endif Let GSFPlayerAidItems := Ar_Null Set GSWasOpened to 1 ;=> And there are plenty container in this interior, but only one will return an actual reference. endif End Begin GameMode if rWhoAmI != 0 && GSWasOpened < 2 Set rWhoAmI to 0 ;=> When things are done (menu closed), the reference is cleared again. endif If GSWasOpened >= 1 && GSWasOpened < 2 if GetOpenState == 1 Set rWhichNPC to 0 Activate Player endif Set GSWasOpened to GSWasOpened + GetSecondsPassed elseif GSWasOpened >= 2 && GSWasOpened < 3 Set GSWasOpened to 0 Playsound DRSFootLockerClose ;=> This will make the closing sound at the right moment. elseif GSWasOpened >= 3 && GSWasOpened < 4.6 Set GSWasOpened to GSWasOpened + GetSecondsPassed elseif GSWasOpened >= 4.6 if rWhoAmI == GSFarmFLocker1 GSFarmFLockerInv1.OpenTeammateContainer 1 elseif rWhoAmI == GSFarmFLocker2 GSFarmFLockerInv2.OpenTeammateContainer 1 endif Set GSWasOpened to 0 endif End Link to comment Share on other sites More sharing options...
EPDGaffney Posted June 30, 2018 Share Posted June 30, 2018 Excellent. It works fine without hardcore on? In your script, lines like if rWhoAmI != 0can be simply if rWhoAmIwhich evaluates it like a bool (true or false) and processes faster. Similarly, || and && are liable to crash scripts under certain conditions, where breaking them up into ElseIf lines or nested If statements will be more stable and process them faster. Mind you, the performance gains I'm referencing are very minor, but they can add up, especially in complex loops. And sometimes it's not worth the trouble to separate your || and && lines, but I do separate them most of the time. Link to comment Share on other sites More sharing options...
JustChill Posted March 28, 2019 Author Share Posted March 28, 2019 Coming back to this either since... Well just a few months until I got motivated to continue modding around on that thing. ^^ I finally came to a solution I can live with: scn GSfarmFoodCabinetDoorScript ref WhoAmI float fWasClosed short sDoorChoice short Button ref GSfarmHotkey1 ref GSfarmHotkey3 ref GSfarmHotkey4 ref GSfarmHotkey5 ref GSfarmHotkey6 ref GSfarmHotkey7 ref GSfarmHotkey8 ref GSfarmEWeapon ref GSfarmEAmmo ref GSfarmEHeadband ref GSfarmEHair ref GSfarmEeyeG ref GSfarmENeck ref GSfarmEUpper ref GSfarmEBack float GSfarmAmmoFIX ref GSfarmWepForFIX ref GSfarmAmmForFIX array_var GSfarmEquipInvRefs array_var GSfarmRemoveRefs ref GSfarmDelRef Begin OnActivate if GetActionRef == Player if (GSFarmFoodCABDoorRef1.GetOpenState == 1 || GSFarmFoodCABDoorRef1.GetOpenState == 3) && (GSFarmFoodCABDoorRef2.GetOpenState == 1 || GSFarmFoodCABDoorRef2.GetOpenState == 3) if WhoAmI == 0 Let WhoAmI := GetSelf Let fWasClosed := 1 Activate Player PlaySound DRSFootLockerOpen else if WhoAmI.GetOpenState == 1 && sDoorChoice == 0 MessageboxEx "What do you want to do?|Activate|Close" Let sDoorChoice := 1 endif endif endif endif End Begin GameMode if GSfarmAmmoFIX == 1 if player.GetAnimAction != 9 if GSfarmWepForFix == 0 Let GSfarmWepForFix := Player.GetEquippedItemRef 5 Let GSfarmAmmForFix := Player.GetCurrentAmmo if Player.GetItemCount GSfarmAmmForFix > Player.GetCurrentAmmoRounds If Player.GetCurrentAmmoRounds < GSfarmWepForFix.GetWeaponClipRounds if Player.GetItemCount GSfarmAmmForFix >= GSfarmWepForFix.GetWeaponClipRounds Let GSFarmAmmoFIX := GSfarmWepForFix.GetWeaponClipRounds Player.SetCurrentAmmoRounds GSFarmAmmoFIX else Let GSFarmAmmoFIX := Player.GetItemCount GSfarmAmmForFix Player.SetCurrentAmmoRounds GSFarmAmmoFIX endif endif endif Let GSFarmAmmoFix := 0 Let GSfarmWepForFix := 0 Let GSfarmAmmForFix := 0 endif endif endif if WhoAmI != 0 if fWasClosed >= 3.95 Let fWasClosed := 0 Playsound DRSFootLockerClose ;=> This will make the closing sound at the right moment. Let WhoAmI := 0 elseif fWasClosed >= 3 Let fWasClosed += GetSecondsPassed elseif fWasClosed == 2 if GSfarmEWeapon != 0 Let GSfarmEWeapon := Player.GetEquippedItemRef 5 GSfarmEWeapon.SetNoUnequip 0 ListReplaceNthForm GSfarmNoShovelRemove GSfarmEquippedWeapon 13 endif if GSfarmEHeadband != 0 Let GSfarmEHeadband := Player.GetEquippedItemRef 9 GSfarmEHeadband.SetNoUnequip 0 ListReplaceNthForm GSfarmNoShovelRemove GSfarmEquippedHeadband 7 endif if GSfarmEHair != 0 Let GSfarmEHair := Player.GetEquippedItemRef 1 GSfarmEHair.SetNoUnequip 0 ListReplaceNthForm GSfarmNoShovelRemove GSfarmEquippedHair 8 endif if GSfarmEeyeG != 0 Let GSfarmEeyeG := Player.GetEquippedItemRef 11 GSfarmEeyeG.SetNoUnequip 0 ListReplaceNthForm GSfarmNoShovelRemove GSfarmEquippedEyeGlasses 9 endif if GSfarmENeck != 0 Let GSfarmENeck := Player.GetEquippedItemRef 8 GSfarmENeck.SetNoUnequip 0 ListReplaceNthForm GSfarmNoShovelRemove GSfarmEquippedNecklace 10 endif if GSfarmEUpper != 0 Let GSfarmEUpper := Player.GetEquippedItemRef 2 GSfarmEUpper.SetNoUnequip 0 ListReplaceNthForm GSfarmNoShovelRemove GSfarmEquippedUpperBody 11 endif if GSfarmEBack != 0 Let GSfarmEBack := Player.GetEquippedItemRef 7 GSfarmEBack.SetNoUnequip 0 ListReplaceNthForm GSfarmNoShovelRemove GSfarmEquippedBackpack 12 endif GSFItemStorageRef.RemoveAllItems Player 0 1 if GSfarmEAmmo != 0 Player.EquipItemAlt GSfarmEAmmo 0 1 endif if GSfarmHotkey1 != 0 SetHotkeyItem 1, GSfarmHotkey1 endif if GSfarmHotkey3 != 0 SetHotkeyItem 3, GSfarmHotkey3 endif if GSfarmHotkey4 != 0 SetHotkeyItem 4, GSfarmHotkey4 endif if GSfarmHotkey5 != 0 SetHotkeyItem 5, GSfarmHotkey5 endif if GSfarmHotkey6 != 0 SetHotkeyItem 6, GSfarmHotkey6 endif if GSfarmHotkey7 != 0 SetHotkeyItem 7, GSfarmHotkey7 endif if GSfarmHotkey8 != 0 SetHotkeyItem 8, GSfarmHotkey8 endif if WhoAmI == GSFarmFoodCABDoorRef1 Call GSFarmFoodCabinet11Goodies endif if WhoAmI == GSFarmFoodCABDoorRef2 ;Call GSFarmFoodCabinet21Goodies endif Let GSfarmHotkey1 := 0 Let GSfarmHotkey3 := 0 Let GSfarmHotkey4 := 0 Let GSfarmHotkey5 := 0 Let GSfarmHotkey6 := 0 Let GSfarmHotkey7 := 0 Let GSfarmHotkey8 := 0 if GSfarmEWeapon != 0 Let GSfarmAmmoFIX := 1 endif Let GSfarmEWeapon := 0 Let GSfarmEAmmo := 0 Let GSfarmEHeadband := 0 Let GSfarmEHair := 0 Let GSfarmEeyeG := 0 Let GSfarmENeck := 0 Let GSfarmEUpper := 0 Let GSfarmEBack := 0 Let fWasClosed := 0 elseif fWasClosed == 1 if WhoAmI.GetOpenState == 1 Let fWasClosed := 0 Let sDoorChoice := 2 endif endif if sDoorChoice == 1 Let Button := GetButtonPressed if Button == 0 Let sDoorChoice := 2 elseif Button == 1 Let fWasClosed := 3 Activate Player Let sDoorChoice := 0 endif elseif sDoorChoice == 2 if Player.GetHotKeyItem 1 != 0 Let GSfarmHotkey1 := Player.GetHotkeyItem 1 endif if Player.GetHotKeyItem 3 != 0 Let GSfarmHotkey3 := Player.GetHotkeyItem 3 endif if Player.GetHotKeyItem 4 != 0 Let GSfarmHotkey4 := Player.GetHotkeyItem 4 endif if Player.GetHotKeyItem 5 != 0 Let GSfarmHotkey5 := Player.GetHotkeyItem 5 endif if Player.GetHotKeyItem 6 != 0 Let GSfarmHotkey6 := Player.GetHotkeyItem 6 endif if Player.GetHotKeyItem 7 != 0 Let GSfarmHotkey7 := Player.GetHotkeyItem 7 endif if Player.GetHotKeyItem 8 != 0 Let GSfarmHotkey8 := Player.GetHotkeyItem 8 endif if Player.GetEquippedObject 5 != 0 Let GSfarmEWeapon := Player.GetEquippedObject 5 ;=> If we use 'GetEquippedItemRef' here, the next two ListReplaceNthForm GSfarmNoShovelRemove GSfarmEWeapon 13 ;=> command lines would put the script to a halt. if Player.GetItemCount GSfarmEWeapon > 1 ;=> As using an inventory ref on ListReplaceNthForm or on GetItemCount appears to be bad. oO Let GSfarmEquipInvRefs := Player.GetInvRefsForItem GSfarmEWeapon ForEach GSfarmRemoveRefs <- GSfarmEquipInvRefs let GSfarmDelRef := GSfarmRemoveRefs["value"] if GSfarmDelRef.IsEquipped == 0 GSfarmDelRef.RemoveMeIRAlt 1 0 GSFItemStorageRef endif Loop endif Let GSfarmEWeapon := Player.GetEquippedItemRef 5 GSfarmEWeapon.SetNoUnequip 1 ;=> THIS COMMAND DEMANDS AN INVENTORY REFERENCE! 'GetEquippedItemRef' for victory! endif if Player.GetCurrentAmmo != 0 Let GSfarmEAmmo := Player.GetCurrentAmmo endif if Player.GetEquippedObject 9 != 0 Let GSfarmEHeadband := Player.GetEquippedObject 9 ListReplaceNthForm GSfarmNoShovelRemove GSfarmEHeadband 7 if Player.GetItemCount GSfarmEHeadband > 1 Let GSfarmEquipInvRefs := Player.GetInvRefsForItem GSfarmEHeadband ForEach GSfarmRemoveRefs <- GSfarmEquipInvRefs let GSfarmDelRef := GSfarmRemoveRefs["value"] if GSfarmDelRef.IsEquipped == 0 GSfarmDelRef.RemoveMeIRAlt 1 0 GSFItemStorageRef endif Loop endif Let GSfarmEHeadband := Player.GetEquippedItemRef 9 GSfarmEHeadband.SetNoUnequip 1 endif if Player.GetEquippedObject 1 != 0 Let GSfarmEHair := Player.GetEquippedObject 1 ListReplaceNthForm GSfarmNoShovelRemove GSfarmEHair 8 if Player.GetItemCount GSfarmEHair > 1 Let GSfarmEquipInvRefs := Player.GetInvRefsForItem GSfarmEHair ForEach GSfarmRemoveRefs <- GSfarmEquipInvRefs let GSfarmDelRef := GSfarmRemoveRefs["value"] if GSfarmDelRef.IsEquipped == 0 GSfarmDelRef.RemoveMeIRAlt 1 0 GSFItemStorageRef endif Loop endif Let GSfarmEHair := Player.GetEquippedItemRef 1 GSfarmEHair.SetNoUnequip 1 endif if Player.GetEquippedObject 11 != 0 Let GSfarmEeyeG := Player.GetEquippedObject 11 ListReplaceNthForm GSfarmNoShovelRemove GSfarmEeyeG 9 if Player.GetItemCount GSfarmEeyeG > 1 Let GSfarmEquipInvRefs := Player.GetInvRefsForItem GSfarmEeyeG ForEach GSfarmRemoveRefs <- GSfarmEquipInvRefs let GSfarmDelRef := GSfarmRemoveRefs["value"] if GSfarmDelRef.IsEquipped == 0 GSfarmDelRef.RemoveMeIRAlt 1 0 GSFItemStorageRef endif Loop endif Let GSfarmEeyeG := Player.GetEquippedItemRef 11 GSfarmEeyeG.SetNoUnequip 1 endif if Player.GetEquippedObject 8 != 0 Let GSfarmENeck := Player.GetEquippedObject 8 ListReplaceNthForm GSfarmNoShovelRemove GSfarmENeck 10 if Player.GetItemCount GSfarmENeck > 1 Let GSfarmEquipInvRefs := Player.GetInvRefsForItem GSfarmENeck ForEach GSfarmRemoveRefs <- GSfarmEquipInvRefs let GSfarmDelRef := GSfarmRemoveRefs["value"] if GSfarmDelRef.IsEquipped == 0 GSfarmDelRef.RemoveMeIRAlt 1 0 GSFItemStorageRef endif Loop endif Let GSfarmENeck := Player.GetEquippedItemRef 8 GSfarmENeck.SetNoUnequip 1 endif if Player.GetEquippedObject 2 != 0 Let GSfarmEUpper := Player.GetEquippedObject 2 ListReplaceNthForm GSfarmNoShovelRemove GSfarmEUpper 11 if Player.GetItemCount GSfarmEUpper > 1 Let GSfarmEquipInvRefs := Player.GetInvRefsForItem GSfarmEUpper ForEach GSfarmRemoveRefs <- GSfarmEquipInvRefs let GSfarmDelRef := GSfarmRemoveRefs["value"] if GSfarmDelRef.IsEquipped == 0 GSfarmDelRef.RemoveMeIRAlt 1 0 GSFItemStorageRef endif Loop endif Let GSfarmEUpper := Player.GetEquippedItemRef 2 GSfarmEUpper.SetNoUnequip 1 endif if Player.GetEquippedObject 7 != 0 Let GSfarmEBack := Player.GetEquippedObject 7 ListReplaceNthForm GSfarmNoShovelRemove GSfarmEBack 12 if Player.GetItemCount GSfarmEBack > 1 Let GSfarmEquipInvRefs := Player.GetInvRefsForItem GSfarmEBack ForEach GSfarmRemoveRefs <- GSfarmEquipInvRefs let GSfarmDelRef := GSfarmRemoveRefs["value"] if GSfarmDelRef.IsEquipped == 0 GSfarmDelRef.RemoveMeIRAlt 1 0 GSFItemStorageRef endif Loop endif Let GSfarmEBack := Player.GetEquippedItemRef 7 GSfarmEBack.SetNoUnequip 1 endif ListReplaceNthForm GSfarmNoShovelRemove GSfarmShovelDummy 17 Player.RemoveAllTypedItems GSFItemStorageRef 1 1 40 GSFarmNoShovelRemove ListReplaceNthForm GSfarmNoShovelRemove WeapShovel 17 Player.RemoveAllTypedItems GSFItemStorageRef 1 1 41 Player.RemoveAllTypedItems GSFItemStorageRef 1 1 24 GSFarmNoShovelRemove Player.RemoveAllTypedItems GSFItemStorageRef 1 1 25 Player.RemoveAllTypedItems GSFItemStorageRef 1 1 31 Player.RemoveAllTypedItems GSFItemStorageRef 1 1 47 GSFarmFoodCABList Player.RemoveAllTypedItems GSFItemStorageRef 1 1 103 Player.RemoveAllTypedItems GSFItemStorageRef 1 1 108 Player.RemoveAllTypedItems GSFItemStorageRef 1 1 116 Let sDoorChoice := 3 Let GSfarmRemoveRefs := Ar_Null Let GSfarmEquipInvRefs := Ar_Null Let GSfarmDelRef := 0 elseif sDoorChoice == 3 Let sDoorChoice := 0 Let fWasClosed := 2 if WhoAmI == GSFarmFoodCABDoorRef1 GSFarmFoodCABRef1.Activate Player elseif WhoAmI == GSFarmFoodCABDoorRef2 GSFarmFoodCABRef2.Activate Player endif endif endif End It simply removes ALL items from the players inventory, except the items that are allowed to go into this container.The equipped items will get the "no unequip" flag, but just as long as the player is in container view.I either save the hotkeys into a variable, but that's a bit tricky when working with other sorting containers that do the same, especially as if they don't restore the "dummy items" in the respective Form List.I've fixed that in the sorting scripts of my old mentor either so there is no bad intervention whith these dynamic containers. I just allowed canned and boxed food and created new meshes from the base game, where I simply destroyed the collision data so they are full static and the player isn't able go get them out of the shelf, without going into the container menu.But it's still a nice view.In that case, I either made an activator of door of the food cabinet, which stays open until the player closes it by using a message box (that ask for closing or going into container menu). The only downside with messing around with the "no unequip" flag of equipped gear was, that weapons always had just 1 ammo round of it's current ammo loaded.I created a minor fix that automatically takes care of that issue. Works pretty nice so far, but I am actually working on that weird washing machine that repairs clothes and gloves by washing it. XD In your script, lines likeif rWhoAmI != 0can be simplyif rWhoAmIwhich evaluates it like a bool (true or false) and processes faster. Similarly, || and && are liable to crash scripts under certain conditions, where breaking them up into ElseIf lines or nested If statements will be more stable and process them faster. Mind you, the performance gains I'm referencing are very minor, but they can add up, especially in complex loops. And sometimes it's not worth the trouble to separate your || and && lines, but I do separate them most of the time. I still use things like != 0 unfortunately. XDYet I couldn't find any issue with using, so I may stick to it. Link to comment Share on other sites More sharing options...
Recommended Posts