Jump to content

Checking if player has items with keyword.


Recommended Posts

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 Waiting
Event OnActivate(ObjectReference akActionRef)
if (Game.GetPlayer().GetItemCount(MyTorch) < 1) && (Game.GetPlayer().GetItemCount(Flint) < 1)
NeedIgnite.Show(); player has no ignite source
EndIf
Int iButtonA = FlintOrTorch.Show()
EndEvent
EndState

 

Link to comment
Share on other sites

  • Replies 49
  • Created
  • Last Reply

Top Posters In This Topic

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

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

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 by maxarturo
Link to comment
Share on other sites

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 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 (Game.GetPlayer().GetItemCount(MyTorch) < 1) && (Game.GetPlayer().GetItemCount(Flint) < 1)
NeedIgnite.Show(); player has no ignite source
else
Int iButtonA = FlintOrTorch.Show()
If iButtonA == 0 && (Game.GetPlayer().GetEquippedItemType(0) != 11)
EquipTorch.Show()
If iButtonA == 1
Debug.Notification ("Flint Will Be Used To Light Fire")

EndIf
EndIf
;---------------------------------------------------------------------------------------------------
; 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 needed
if (Game.GetPlayer().GetItemCount(Rag) < 1) && (Game.GetPlayer().GetItemCount(Oil) < 1) && (Game.GetPlayer().GetItemCount(Bristle) < 1)
NeedKindAcc.Show()
EndIf
; show main menu
If (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 xxx
If iButtonB == 0
; remove 1 dry rag
Game.GetPlayer().RemoveItem(Rag, 1)
Debug.Notification ("Option 0 Dry Rag")
EndIf
If iButtonB == 1
; remove 1 oil
Game.GetPlayer().RemoveItem(Oil, 1)
debug.notification("Option 1 Oil")
EndIf
If iButtonB == 2
; remove 1 bristle
Game.GetPlayer().RemoveItem(Bristle, 1)
debug.notification("Option 2 Bristles")
EndIf
; do stuff here
MySFX.Play(Self)
FlintUseCount.Mod(1); counts how many times this piece of flint has been used
FireULock.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 finish
MyMarker.Disable()
Self.Disable()
Utility.Wait(0.5)
Self.Delete()

EndIf
EndIf
EndEvent
EndState

 

Link to comment
Share on other sites

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

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
    EndIf

this 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
    EndIf

and 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 by ReDragon2013
Link to comment
Share on other sites

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 by maxarturo
Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...