antstubell Posted July 25, 2019 Author Share Posted July 25, 2019 Ok, need help. This is part of a larger script but this is the part I am having issues with. The items required are in a Message Form and are conditioned to only show if the player has at least 1 in his inventory. If the player has neither of the required items the message "You don't have required items" appears but the menu to choose (even though there are NO choices because player doesn't have the items so conditions are not met to show the items... menu appears anyway.How can I stop the menu from appearing if the player does not have any of the required items? Auto State WaitingEvent OnActivate(ObjectReference akActionRef)if (Game.GetPlayer().GetItemCount(MyTorch) < 1) && (Game.GetPlayer().GetItemCount(Flint) < 1)NeedIgnite.Show(); player has no ignite sourceEndIfInt iButtonA = FlintOrTorch.Show()EndEventEndState Link to comment Share on other sites More sharing options...
maxarturo Posted July 25, 2019 Share Posted July 25, 2019 Have you thought of this alternative, for multiple combinations of items : - Create two or three misc items (or how many you might need) that the fire will need for it to lit. The fire's script will need to "getitemcount" just those item you will create. - Use the tanning rack to create recipes for creating the "misc items" needed. This way you can create a large amounts of combinations and recipes while dettaching completly the large amount of items from the fire + having a small script, the only downside (not for me though) is that you need to create each misc item (mesh) for the recipes. Your script : ; Now will show the menu ONLY if the player has more than ONE "MyTorch" & "Flint". ; If none of the two is in player's inventory the "NeedIgnite" message will pop up. Auto State Waiting Event OnActivate(ObjectReference akActionRef) if (Game.GetPlayer().GetItemCount(MyTorch) > 0) && (Game.GetPlayer().GetItemCount(Flint) > 0) Int iButtonA = FlintOrTorch.Show() else NeedIgnite.Show(); player has no ignite source EndIf EndEvent EndState Link to comment Share on other sites More sharing options...
antstubell Posted July 25, 2019 Author Share Posted July 25, 2019 Thanks.Line should be OR not AND if (Game.GetPlayer().GetItemCount(MyTorch) > 0) || (Game.GetPlayer().GetItemCount(Flint) > 0) All respect but I spent all day yesterday on this script, it is much larger than the part I posted and I really don't want to change the method of inventory checking that I am currently using but as said much appreciated.Now I have to tie this part of the script with the rest... I may be back…. Link to comment Share on other sites More sharing options...
maxarturo Posted July 25, 2019 Share Posted July 25, 2019 (edited) The difference between your code and the second is "Order" of things, much easier to read and write + execute script.- First is saying = If player has less than one of the items show the message.- The second is saying = If player has more than one of each item execute the functions, otherwise if none is in player's inventory show the message. You first script corrected (small mistake) : Auto State Waiting Event OnActivate(ObjectReference akActionRef) if (Game.GetPlayer().GetItemCount(MyTorch) < 1) && (Game.GetPlayer().GetItemCount(Flint) < 1) NeedIgnite.Show(); player has no ignite source else Int iButtonA = FlintOrTorch.Show() EndIf EndEvent EndState Edit : typo... Edited July 25, 2019 by maxarturo Link to comment Share on other sites More sharing options...
antstubell Posted July 25, 2019 Author Share Posted July 25, 2019 Nearly there - I am doing my best here - 1 issue remaining. I have put notes in the script but basically the player is told to equip a torch, if torch was chosen to light the fire, but regardless of if the player equips it or not the script continues. I'll attach the complete script even though it is only the first part that I think needs fixing - also to show you that I am trying here.There are a few notifications that is just for testing use and will be removed eventually. GlobalVariable Property FlintUseCount AutoGlobalVariable Property FireULock AutoLight Property MyTorch AutoSound Property MySFX AutoMiscObject Property Oil AutoMiscObject Property Rag AutoMiscObject Property Bristle AutoMiscObject Property Flint AutoMessage Property EquipTorch AutoMessage Property MyMenu AutoMessage Property NeedKindAcc AutoMessage Property NeedIgnite AutoMessage Property FlintOrTorch AutoObjectReference Property MyMarker AutoAuto State WaitingEvent OnActivate(ObjectReference akActionRef)if (Game.GetPlayer().GetItemCount(MyTorch) < 1) && (Game.GetPlayer().GetItemCount(Flint) < 1)NeedIgnite.Show(); player has no ignite sourceelseInt iButtonA = FlintOrTorch.Show()If iButtonA == 0 && (Game.GetPlayer().GetEquippedItemType(0) != 11)EquipTorch.Show()If iButtonA == 1Debug.Notification ("Flint Will Be Used To Light Fire")EndIfEndIf;---------------------------------------------------------------------------------------------------; player was informed to equip a torch to light the fire but regardless of whether the player equips a torch or not the script continues.; ----------------------------------------------------------------------------------------------------; inventory check to see if player has NONE of the required items – add to as neededif (Game.GetPlayer().GetItemCount(Rag) < 1) && (Game.GetPlayer().GetItemCount(Oil) < 1) && (Game.GetPlayer().GetItemCount(Bristle) < 1)NeedKindAcc.Show()EndIf; show main menuIf (Game.GetPlayer().GetItemCount(Rag) >= 1) || (Game.GetPlayer().GetItemCount(Oil) >= 1) || (Game.GetPlayer().GetItemCount(Bristle) >= 1)Int iButtonB = MyMenu.Show(); options presented - set by conditions in menu’s form i.e. if the player has xxx then show option xxxIf iButtonB == 0; remove 1 dry ragGame.GetPlayer().RemoveItem(Rag, 1)Debug.Notification ("Option 0 Dry Rag")EndIfIf iButtonB == 1; remove 1 oilGame.GetPlayer().RemoveItem(Oil, 1)debug.notification("Option 1 Oil")EndIfIf iButtonB == 2; remove 1 bristleGame.GetPlayer().RemoveItem(Bristle, 1)debug.notification("Option 2 Bristles")EndIf; do stuff hereMySFX.Play(Self)FlintUseCount.Mod(1); counts how many times this piece of flint has been usedFireULock.SetValue(1); sets value for next part of the puzzle i.e. “the fire is lit”Utility.Wait(1.5); allow time for sound fx to finishMyMarker.Disable()Self.Disable()Utility.Wait(0.5)Self.Delete()EndIfEndIfEndEventEndState Link to comment Share on other sites More sharing options...
maxarturo Posted July 25, 2019 Share Posted July 25, 2019 Can you write in order what you want the Script to do when activated : A)... B)... C)... ... Link to comment Share on other sites More sharing options...
antstubell Posted July 25, 2019 Author Share Posted July 25, 2019 A: Menu asks "What do you want to use to light the fire?" Based on conditions 1 or 2 options are presented. 'Torch' if player has at least 1 torch or 'Flint' if player has at least 1 piece of flint. B1: If player chooses 'Torch' script checks to see if a torch is equipped. If player has a torch but not equipped then the player is prompted to 'Equip Torch' . This is the part where I need the script to stop/wait of some kind - reset?, quit? so player is aware that to use a torch it has to be equipped. B2: Choosing 'Flint'', this is kind of a default option, if player has a piece of flint (I am aware of other issues arising as I am writing this), then the 'Equip Torch' option should not show and the script proceeds to the next menu. I am now aware that there is no means included to record what choice the player made. C: Next menu presents player with a choice of 'kindlings' and 'accelerants' to use to start the fire. Options presented are based on conditions set in the message form. So far they are, if player has collected them all, Dry Rag, Oil and Bristles. If player has none of these then the script tells player "You don't have...blah, blah". If player has at least 1 of the kindling or accelerants, player chooses that option, 1 of that item is removed and fire is lit.This 2nd menu appears to work perfectly. Link to comment Share on other sites More sharing options...
ReDragon2013 Posted July 25, 2019 Share Posted July 25, 2019 (edited) I do not want to interrupt your discussion, but next could be helpful to reach your aim. Script code like does not work properly: Int iButtonA = FlintOrTorch.Show() If iButtonA == 0 && (Game.GetPlayer().GetEquippedItemType(0) != 11) EquipTorch.Show() If iButtonA == 1 ; this condition is always False, notification cannot be shown Debug.Notification ("Flint Will Be Used To Light Fire") EndIf EndIfthis makes sense: Int iButtonA = FlintOrTorch.Show() If iButtonA == 0 && (Game.GetPlayer().GetEquippedItemType(0) != 11) iButtonA = EquipTorch.Show() ; edited !!! If iButtonA == 1 Debug.Notification ("Flint Will Be Used To Light Fire") EndIf EndIfand now I am using functions to group the script code and make them better reading/maintaining hopefully.xyzSampleScript Scriptname xyzSampleScript extends ObjectReference ; https://forums.nexusmods.com/index.php?/topic/7838193-checking-if-player-has-items-with-keyword/page-2 GlobalVariable PROPERTY FlintUseCount auto GlobalVariable PROPERTY FireUnLock auto ; FireULock MiscObject PROPERTY Oil auto MiscObject PROPERTY Rag auto MiscObject PROPERTY Bristle auto MiscObject PROPERTY Flint auto Message PROPERTY NeedIgnite auto Message PROPERTY FlintOrTorch auto Message PROPERTY EquipTorch auto Message PROPERTY NeedKindAcc auto Message PROPERTY mySelect auto ; MyMenu Light PROPERTY myLight auto ; MyTorch Sound PROPERTY mySound auto ; MySFX ObjectReference PROPERTY myMarker auto ; -- EVENTs -- ;=================================== auto State Waiting ;================= EVENT OnActivate(ObjectReference akActionRef) IF (akActionRef == Game.GetPlayer() as ObjectReference) ELSE RETURN ; - STOP - not player activated ENDIF ;--------------------- IF myF_SourceReady(akActionRef) ELSE NeedIgnite.Show() ; player does not have any source for ignite RETURN ; - STOP - ENDIF ;--------------------- IF myF_FireOK(akActionRef) gotoState("Done") mySound.Play(self) Utility.Wait(1.5) ; short delay to allow finishing of soundFX myMarker.Disable() self.Disable() Utility.Wait(0.5) ;myMarker.Delete() ;myMarker = None self.Delete() ENDIF ENDEVENT ;======= endState ;=================================== state Done ;========= ;EVENT OnActivate(ObjectReference akActionRef) ;ENDEVENT ;======= endState ; -- FUNCTIONs -- 2 ;---------------------------------------------------- Bool FUNCTION myF_SourceReady(ObjectReference player) ;---------------------------------------------------- RETURN (player.GetItemCount(myLight as Form) >= 1) || (player.GetItemCount(Flint as Form) >= 1) ENDFUNCTION ;----------------------------------------------- Bool FUNCTION myF_FireOK(ObjectReference player) ;----------------------------------------------- int i = FlintOrTorch.Show() ; i = iButtonA ;--- ; player will be informed to equip a torch to light the fire but regardless of whether ; the player equips a torch or not the script continues. ;--- IF (i == 0) && ((player as Actor).GetEquippedItemType(0) != 11) i = EquipTorch.Show() IF (i == 1) Debug.Notification ("Flint Will Be Used To Light A Fire") ENDIF ENDIF ; inventory check to see if player has NONE of the required items (dd to as needed) IF (player.GetItemCount(Rag) < 1) || (player.GetItemCount(Oil) < 1) || (player.GetItemCount(Bristle) < 1) NeedKindAcc.Show() Return False ; /1 ENDIF ;--------- ; show main menu now i = mySelect.Show() ; i = iButtonB ; options presented - set by conditions in menus form i.e. if the player has xxx then show option xxx IF (i == 0) ; remove 1 dry rag player.RemoveItem(Rag, 1) Debug.Notification ("Option 0 Dry Rag") ELSEIF (i == 1) ; remove 1 oil player.RemoveItem(Oil, 1) Debug.Notification("Option 1 Oil") ELSEIF (i == 2) ; remove 1 bristle player.RemoveItem(Bristle, 1) Debug.Notification("Option 2 Bristles") ELSE Return False ; /2 ENDIF ;--------- ; do stuff here FlintUseCount.Mod(1) ; counts how many times this piece of flint has been used FireUnLock.SetValue(1.0) ; sets value for next part of the puzzle, i.e. the fire is lit Return TRUE ; /3 ENDFUNCTION Edited July 25, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
maxarturo Posted July 25, 2019 Share Posted July 25, 2019 (edited) By all means ReDragon, do interrupt. ReDragon post a very good Script example, now you have two scripts to choose and work on. (remember what i said about ORDER). I didn't test or compile it : GlobalVariable Property FlintUseCount Auto GlobalVariable Property FireULock Auto Light Property MyTorch Auto Sound Property MySFX Auto MiscObject Property Oil Auto MiscObject Property Rag Auto MiscObject Property Bristle Auto MiscObject Property Flint Auto Message Property EquipTorch Auto Message Property MyMenu Auto Message Property NeedKindAcc Auto Message Property NeedIgnite Auto Message Property FlintOrTorch Auto ObjectReference Property MyMarker Auto Auto State Waiting Event OnActivate(ObjectReference akActionRef) if (akActionRef == Game.GetPlayer()) if (Game.GetPlayer().GetItemCount(MyTorch) > 0) && (Game.GetPlayer().GetItemCount(Flint) > 0) MyTorchIgnitesFire() ; If all items (more than one of each) are in the inventory will go to execute the FUNCTION "Function MyTorchIgnitesFire()" else NeedIgnite.Show(); player has no ignite source EndIf If (Game.GetPlayer().GetItemCount(Rag) > 0) || (Game.GetPlayer().GetItemCount(Oil) > 0) || (Game.GetPlayer().GetItemCount(Bristle) > 0) MyRagIgnitesFire() ; If all items (more than one of each) are in the inventory will go to execute the FUNCTION "Function MyRagIgnitesFire()" else NeedKindAcc.Show() EndIf EndIf EndEvent EndState State Busy Event OnActivate(ObjectReference akActionRef) ;Do nothing. EndEvent EndState Function MyTorchIgnitesFire() GoToState("Busy") Int iButtonA = FlintOrTorch.Show() If iButtonA == 0 Game.GetPlayer().GetEquippedItemType(0) != 11 else iButtonA = EquipTorch.Show() GoToState("Waiting") ; If torch is not eqipped will RETURN to be activated again EndIf If iButtonA == 1 Debug.Notification ("Flint Will Be Used To Light Fire") EndIf ; Do Stuff Here EndFunction Function MyRagIgnitesFire() GoToState("Busy") Int iButtonB = MyMenu.Show() If iButtonB == 0 Game.GetPlayer().RemoveItem(Rag, 1) Debug.Notification ("Option 0, 1 Dry Rag remove") ElseIf iButtonB == 1 Game.GetPlayer().RemoveItem(Oil, 1) debug.notification("Option 1, 1 Oil Remove") EsleIf iButtonB == 2 Game.GetPlayer().RemoveItem(Bristle, 1) debug.notification("Option 2, 1 Bristles Remove") EndIf ; Do Stuff Here EndFunction Have a happy modding !. Edited July 26, 2019 by maxarturo Link to comment Share on other sites More sharing options...
antstubell Posted July 25, 2019 Author Share Posted July 25, 2019 I was just in the process of replying so I haven't tried maxarturo newest script yet.ReDragon scripts both work. The 2nd script I have no idea on how to add to it because items will be added later to the available kindlings and accelerants - but I guess he misunderstood what I wanted. I need that if the player chooses Torch to light fire then the torch MUST be equipped. If torch is not equipped then player needs to exit the script, equip a torch and start over. This video shows what happens if Player chooses Torch, is prompted to equip torch but script doesn't care and continues.I think my comments in the script confused ReDragon. Player MUST equip torch to use torch.https://onedrive.live.com/?cid=B60C11D037429D8E&id=B60C11D037429D8E%2134442&parId=B60C11D037429D8E%21191&o=OneUp Link to comment Share on other sites More sharing options...
Recommended Posts