Jump to content

[LE] [Script] "AND" or "OR" operator help


anb2004

Recommended Posts

I'm dumb with script, so bear with me.

Already set a trigger for auto sorting 2 different armor in player inventory and stored which is set by a script.

  if (akActivator.getItemCount(ArmorA) >= 1) && (akActivator.getItemCount(ArmorB) >= 1); Player have the items? 

That goes well if player has both items in the inventory but what if there is only one of the armor ? fiddling it around still no avail. How to expand it so it can auto sorting with only one of the armor please

 

Thank you.

 

Link to comment
Share on other sites

if (akActivator.getItemCount(ArmorA) > 0) || (akActivator.getItemCount(ArmorB) > 0); Player has just one of the items?

That should do it. :smile:

 

I've changed the evaluation to

> 0

as

>=

are actually two types of evaluations (greater and equal), which is a bit more demanding.

It shouldn't be that big of a deal, but as long as you don't really need the ">=" evaluation, I recommend to just use the ">" with asking if it is greater than 0. :wink:

 

 

You can read more about operators here:

https://www.creationkit.com/index.php?title=Operator_Reference

:)

Link to comment
Share on other sites

 

Good lord that simple !

 

When doing something like this use "else" .

if akActivator.getItemCount(ArmorA) && akActivator.getItemCount(ArmorB)

Else
; Do something here.  You do not have both items.  

EndIf

It would be best if you included your entire script.

 

That Else block would fire too, if the item count of both items is 0.

So it is not totally equivalent with the OR operator.

 

 

 

 

Thank you JustChill :thumbsup:

No worries, you are welcome.

 

However, SurfsideNaturals is right about posting more context. :wink:

 

As if you want to have a different behavior when the player has BOTH items in inventory and when there is just ONE of them in the inventory.

 

 

In that case an ElseIf with my example would be necessary too.

if akActivator.getItemCount(ArmorA) && akActivator.getItemCount(ArmorB)
; 'Do something here if the player has both items.'
ElseIf akActivator.getItemCount(ArmorA) || akActivator.getItemCount(ArmorB)
; 'Do something else here, when only one of these items is in the players inventory.'
Else
; 'Do something else here. You do not have any of the items.'
EndIf

In addition to that, you could either go

if akActivator.getItemCount(ArmorA) && akActivator.getItemCount(ArmorB)
; 'Do something here if the player has both items.'
ElseIf akActivator.getItemCount(ArmorA)
; 'Do something else here, when only ArmorA is in the inventory.'
Elseif akActivator.getItemCount(ArmorB)
; 'Do something else here, when only ArmorB is in the inventory.'
Else
; 'Do something else here. You do not have any of the items.'
EndIf

Yet as we don't exactly know what you are up to, any solution that fits your needs might do it. ^^

 

Anyways, happy modding. :smile:

Link to comment
Share on other sites

 

Good lord that simple !

 

When doing something like this use "else" .

if akActivator.getItemCount(ArmorA) && akActivator.getItemCount(ArmorB)

Else
; Do something here.  You do not have both items.  

EndIf

It would be best if you included your entire script.

 

 

Sorry about that.

 

 

Scriptname _AnbMannekinArmorActivator extends ObjectReference  
 
Armor TehArmor
Armor TehArmorB

Message Property FailMessage auto
{The message to show if the player dont have the item in their inventory}
Bool Property isPlaced = false Auto Hidden

ObjectReference Property ArmorGhostChest auto

Event OnInit()	
	TehArmor = Game.GetFormFromFile(0x000d62,"_AnbCustomMod.esp") As Armor
	TehArmorB = Game.GetFormFromFile(0x000d69,"_AnbCustomMod.esp") As Armor

EndEvent

Event OnActivate(ObjectReference akActivator)
        if(isPlaced == FALSE)  ; is the item placed?
                if (akActivator.getItemCount(TehArmor) > 0) || (akActivator.getItemCount(TehArmorB) > 0); Does the player have the item?
                        isPlaced = TRUE
                        self.getLinkedRef().enable() ; Enable the Static Item
                        (akActivator as actor).removeItem(TehArmor, 1, False, ArmorGhostChest) ; Remove the item from the players inventory and adds it to the tempChest
			(akActivator as actor).removeItem(TehArmorB, 1, False, ArmorGhostChest) ; Remove the item from the players inventory and adds it to the tempChest
                else
                        FailMessage.show() ; If the player doesnt have the item, show the Fail message.
                endif
        else
                isPlaced = FALSE  
                self.getLinkedRef().disable() ; If the item was already placed, disable the static item
                ArmorGhostChest.removeItem(TehArmor, 1, False, akActivator) ; add the item back.
		ArmorGhostChest.removeItem(TehArmorB, 1, False, akActivator) ; add the item back.
                utility.wait(0.2)
;               Game.GetPlayer().EquipItem(TehArmor)
;               Game.GetPlayer().EquipItem(TehArmorB)
        endif
endEvent

 

 

 

 

 

It's not my script but a modified script originally made by Sjogga Dragon Claw holder that i enquire years ago (ebony_ivory is my old nickname) which i try to apply it with static mannequin because real mannequin is just buggy for me and i like it fast and simple (though, make it requires lots of work but i enjoyed it) no more opening mannequin inventory, simple activate, armor get unequipped/equipped. Not into armors also helped, still using same old custom hide (TehArmor) and custom iron armor (TehArmorB), i just haven't made the static for gauntlets, boots and helmets tho.

 

Just found "equipitem" just won't add the enchantment effect. Another disappoinment :wallbash:

 

Thanks

 

 

 

 

When doing something like this use "else" .

if akActivator.getItemCount(ArmorA) && akActivator.getItemCount(ArmorB)

Else
; Do something here.  You do not have both items.  

EndIf

It would be best if you included your entire script.

 

That Else block would fire too, if the item count of both items is 0.

So it is not totally equivalent with the OR operator.

 

 

 

 

Thank you JustChill :thumbsup:

No worries, you are welcome.

 

However, SurfsideNaturals is right about posting more context. :wink:

 

As if you want to have a different behavior when the player has BOTH items in inventory and when there is just ONE of them in the inventory.

 

 

In that case an ElseIf with my example would be necessary too.

if akActivator.getItemCount(ArmorA) && akActivator.getItemCount(ArmorB)
; 'Do something here if the player has both items.'
ElseIf akActivator.getItemCount(ArmorA) || akActivator.getItemCount(ArmorB)
; 'Do something else here, when only one of these items is in the players inventory.'
Else
; 'Do something else here. You do not have any of the items.'
EndIf

In addition to that, you could either go

if akActivator.getItemCount(ArmorA) && akActivator.getItemCount(ArmorB)
; 'Do something here if the player has both items.'
ElseIf akActivator.getItemCount(ArmorA)
; 'Do something else here, when only ArmorA is in the inventory.'
Elseif akActivator.getItemCount(ArmorB)
; 'Do something else here, when only ArmorB is in the inventory.'
Else
; 'Do something else here. You do not have any of the items.'
EndIf

Yet as we don't exactly know what you are up to, any solution that fits your needs might do it. ^^

 

Anyways, happy modding. :smile:

 

 

To be honest those makes me even more confused :unsure: but let see if i can fiddle with it.

 

Thanks

Link to comment
Share on other sites

Hm,

I cannot agree with his script being a mess.
Especially as there is no unified way of how to write scripts. If they work, they work.
That's actually the main goal of writing a script, I guess. ^^


@ anb2004
I've read your code and I assume you try to put the armor onto the mannequin and remove it again, when activating.

The only issue I have is, are these two different types of armor or are these just two pieces of armor that can be combined with each other?
As in your screen, I see two different tops, but the same bottoms.

Do you only focus on the tops here?
Where "TheArmor" is one top and "TheArmorB" is the other one and the mannequin has these bottoms per default?

The reason why I am asking this is, that you try to equip both armors at the same time. XDDDD
So, I guess if these are really just the tops you've overthought it here.
No worries, I overthink things either pretty often, SurfsideNaturals knows about. :D

I simply continue my assumptions from the start, that these mannequins are used to display just these two types of tops.

;=> RATHER CHECK OUT THE SCRIPT WHICH I ATTACHED AT THE LAST SPOILER IN THIS POST.

Scriptname _AnbMannekinArmorActivator extends ObjectReference

Armor TehArmor
Armor TehArmorB

Message Property FailMessage auto
{The message to show if the player dont have the item in their inventory}
Bool Property isPlaced = false Auto Hidden

ObjectReference Property ArmorGhostChest auto
Form Property TehArmorMannequin auto    ;=> You need to add the respective base items
Form Property TehArmorBMannequin auto    ;=> of your static mannequin items here. Link them in the property window.

Event OnInit()    
    TehArmor = Game.GetFormFromFile(0x000d62,"_AnbCustomMod.esp") As Armor    ;=> Sorry for putting comments in your script. I just like how you use that functions to get stuff from other plugins.
    TehArmorB = Game.GetFormFromFile(0x000d69,"_AnbCustomMod.esp") As Armor ;=> I used something similar in my very first mod for Fallout New Vegas, so thumbs up for that to avoid unnecessary masters. :)

EndEvent

Event OnActivate(ObjectReference akActivator)
    if(isPlaced == FALSE) ; is the item placed?
        if akActivator.getItemCount(TehArmor) ; Does the player have the item?
            isPlaced = TRUE
            self.getLinkedRef().enable() ; Enable the Static Item
            (akActivator as actor).removeItem(TehArmor, 1, False, ArmorGhostChest) ; Remove the item from the players inventory and adds it to the tempChest
        elseif akActivator.getItemCount(TehArmorB) ;=>Credit SurfsideNaturals on that one, as the condition will be true for every value other than 0. It's surely the quickest way to get it done. :)'
            isPlaced = TRUE
            self.getLinkedRef().enable() ; Enable the Static Item
            (akActivator as actor).removeItem(TehArmorB, 1, False, ArmorGhostChest) ; Remove the item from the players inventory and adds it to the tempChest
        else
            FailMessage.show() ; If the player doesnt have the item, show the Fail message.
        endif
    else
        isPlaced = FALSE
        if self.GetLinkedRef().GetBaseObject() == TehArmorMannequin
            ArmorGhostChest.removeItem(TehArmor, 1, False, akActivator) ; add the item back.
            utility.wait(0.2)
            Game.GetPlayer().EquipItemEx(TehArmor)        ;=> You need SKSE for EquipItemEx, but the bug with custom enchanted items might be fixed?
        elseif  self.GetLinkedRef().GetBaseObject() == TehArmorBMannequin
            ArmorGhostChest.removeItem(TehArmorB, 1, False, akActivator) ; add the item back.
            Game.GetPlayer().EquipItemEx(TehArmorB)        ;=> SKSE
        endif
        self.getLinkedRef().disable() ; If the item was already placed, disable the static item
    endif
endEvent






In addition:

still using same old custom hide (TehArmor) and custom iron armor (TehArmorB), i just haven't made the static for gauntlets, boots and helmets tho.

Ah sorry, I just read that now.

That makes it a bit more complicated, when you add the other parts either as a linked reference.

Let me think over again. ^^



Another addition:

 

Scriptname _AnbMannekinArmorActivator extends ObjectReference

Armor TehArmor
Armor TehArmorB
Armor TehGauntlets
Armor TehBoots
Armor TehHelmet

Keyword Property TehArmorKey auto    ;=> GetLinkedRefs doesn't work nice with more than one linked ref.'
Keyword Property TehArmorBKey auto    ;=> And there is currently no array function that returns all linked refs.
Keyword Property TehGauntletsKey auto    ;=> So we need to work with keywords.
Keyword Property TehBootsKey auto        ;=> Create new keywords and link them here in the properties.
Keyword Property TehHelmetKey auto        ;=> Also be sure that ALL your linked static armor pieces have
                                        ;=> their desired keyword assigned to, when you add them as linked reference to the mannequin activator.
                                        ;=> Which means when you add the linked reference to the mannequin,
                                        ;=> you can also choose a keyword for the specificly added reference.
Message Property FailMessage auto
Message Property MessageForAddOrRemove auto    ;=> This must be a message box with 2 options / 3 if you make "Cancel" out of option 3.
{The message to show if the player dont have the item in their inventory}

Event OnInit()    
    TehArmor = Game.GetFormFromFile(0x000d62,"_AnbCustomMod.esp") As Armor    ;=> Sorry for putting comments in your script. I just like how you use that functions to get stuff from other plugins.
    TehArmorB = Game.GetFormFromFile(0x000d69,"_AnbCustomMod.esp") As Armor ;=> I used something similar in my very first mod for Fallout New Vegas, so thumbs up for that to avoid unnecessary masters. :)
    TehGauntlets = Game.GetFormFromFile(0x000???,"_AnbCustomMod.esp") As Armor    ;=> BE SURE TO ADD THE CORRECT ID HERE, instead of "???"!!!
    TehBoots = Game.GetFormFromFile(0x000???,"_AnbCustomMod.esp") As Armor    ;=> BE SURE TO ADD THE CORRECT ID HERE, instead of "???"!!!
    TehHelmet = Game.GetFormFromFile(0x000???,"_AnbCustomMod.esp") As Armor    ;=> BE SURE TO ADD THE CORRECT ID HERE, instead of "???"!!!
EndEvent

Event OnActivate(ObjectReference akActivator)
    if akActivator == Game.GetPlayer()
        int isEmpty = 0
        if Game.GetPlayer().GetItemCount(TehArmor) + Game.GetPlayer().GetItemCount(TehArmorB) + Game.GetPlayer().GetItemCount(TehGauntlets) + Game.GetPlayer().GetItemCount(TehBoots) + Game.GetPlayer().GetItemCount(TehHelmet)
            if Self.GetLinkedRef(TehArmorKey).IsDisabled()
                isEmpty += 1
            endif
            if Self.GetLinkedRef(TehArmorBKey).IsDisabled()
                isEmpty += 1            
            endif
            if Self.GetLinkedRef(TehGauntletsKey).IsDisabled()
                isEmpty += 1            
            endif
            if Self.GetLinkedRef(TehBootsKey).IsDisabled()
                isEmpty += 1            
            endif
            if Self.GetLinkedRef(TehHelmetKey).IsDisabled()
                isEmpty += 1            
            endif
            if isEmpty == 0    ;=> The mannequin is fully loaded. No message box necessary, just remove the items.
                RemoveItemsFromMannequin()
            elseif isEmpty < 4        ;=> This will fire on values of and between 1 and 3.
                int button = MessageForAddOrRemove.Show()    ;=> Items in inventory and items on mannequin
                if button == 0
                    PlaceItemsOnMannequin()
                elseif button == 1
                    RemoveItemsFromMannequin()
                endif
            else  ;=> Will only run on 4, as it is not possible to have 5 (you cannot put two armors on one mannequin).
                PlaceItemsOnMannequin()
            endif
        else
            if Self.GetLinkedRef(TehArmorKey).IsDisabled()
                isEmpty += 1
            endif
            if Self.GetLinkedRef(TehArmorBKey).IsDisabled()
                isEmpty += 1            
            endif
            if Self.GetLinkedRef(TehGauntletsKey).IsDisabled()
                isEmpty += 1            
            endif
            if Self.GetLinkedRef(TehBootsKey).IsDisabled()
                isEmpty += 1            
            endif
            if Self.GetLinkedRef(TehHelmetKey).IsDisabled()
                isEmpty += 1            
            endif
            if isEmpty > 3 ;=> Max value is 4, as 5 cannot be reached, since there are two different body armors available.
                FailMessage.Show()
            else
                RemoveItemsFromMannequin()
            endif
        endif
    endif
EndEvent

Function PlaceItemsOnMannequin()
    if Game.GetPlayer().GetItemCount(TehArmor)
        if Self.GetLinkedRef(TehArmorKey).IsDisabled()
            if Self.GetLinkedRef(TehArmorBKey).IsDisabled()  ;=> Check if the other body armor is disabled too.
                Game.GetPlayer().RemoveItem(TehArmor, 1, false)    ;=> I don't' think we need to save them in a chest. ;)
                Self.GetLinkedRef(TehArmorKey).Enable()
            endif
        endif
    endif
    if Game.GetPlayer().GetItemCount(TehArmorB)
        if Self.GetLinkedRef(TehArmorBKey).IsDisabled()
            if Self.GetLinkedRef(TehArmorKey).IsDisabled()  ;=> Check if the other body armor is disabled too.
                Game.GetPlayer().RemoveItem(TehArmorB, 1, false)
                Self.GetLinkedRef(TehArmorBKey).Enable()            
            endif
        endif    
    endif
    if Game.GetPlayer().GetItemCount(TehGauntlets)
        if Self.GetLinkedRef(TehGauntletsKey).IsDisabled()
            Game.GetPlayer().RemoveItem(TehGauntlets, 1, false)
            Self.GetLinkedRef(TehGauntletsKey).Enable()                
        endif    
    endif
    if Game.GetPlayer().GetItemCount(TehBoots)
        if Self.GetLinkedRef(TehBootsKey).IsDisabled()
            Game.GetPlayer().RemoveItem(TehBoots, 1, false)
            Self.GetLinkedRef(TehBootsKey).Enable()            
        endif        
    endif
    if Game.GetPlayer().GetItemCount(TehHelmet)
        if Self.GetLinkedRef(TehHelmetKey).IsDisabled()
            Game.GetPlayer().RemoveItem(TehHelmet, 1, false)
            Self.GetLinkedRef(TehHelmetKey).Enable()            
        endif        
    endif
EndFunction
        
Function RemoveItemsFromMannequin()
    if Self.GetLinkedRef(TehArmorKey).IsDisabled() == False
        Game.GetPlayer().AddItem(TehArmor, 1, false)
        Self.GetLinkedRef(TehArmorKey).Disable()
        Game.GetPlayer().EquipItemEx(TehArmor)
    endif
    if Self.GetLinkedRef(TehArmorBKey).IsDisabled() == False
        Game.GetPlayer().AddItem(TehArmorB, 1, false)
        Self.GetLinkedRef(TehArmorBKey).Disable()
        Game.GetPlayer().EquipItemEx(TehArmorB)        
    endif    
    if Self.GetLinkedRef(TehGauntletsKey).IsDisabled() == False
        Game.GetPlayer().AddItem(TehGauntlets, 1, false)
        Self.GetLinkedRef(TehGauntletsKey).Disable()
        Game.GetPlayer().EquipItemEx(TehGauntlets)        
    endif    
    if Self.GetLinkedRef(TehBootsKey).IsDisabled() == False
        Game.GetPlayer().AddItem(TehBoots, 1, false)
        Self.GetLinkedRef(TehBootsKey).Disable()
        Game.GetPlayer().EquipItemEx(TehBoots)        
    endif        
    if Self.GetLinkedRef(TehHelmetKey).IsDisabled() == False
        Game.GetPlayer().AddItem(TehHelmet, 1, false)
        Self.GetLinkedRef(TehHelmetKey).Disable()
        Game.GetPlayer().EquipItemEx(TehHelmet)        
    endif        
EndFunction      

 




I hope it works. oO

I haven't worked on my own with linked references with keywords before, but I guess this is the only way to check for specific linked references when there are multiple ones.

Anyways, here you add a keyword to a linked reference (LINK).

 

Oh and don't forget to add the message box with 2 buttons (first one = "Add armor pieces to mannequin", second = "Remove armors pieces from mannequin").

You can also add a third button as "Cancel". It will work right away. ^^

This message box only comes, when you have armor pieces in your inventory and there are still some free slots (but also armor pieces in some slots) on the mannequin.

 

If the mannequin is empty you will add all your armor pieces without being asked for.

 

If the mannequin is fully geared, you get all armor pieces back without a question.

 

I try to avoid message boxes, sometimes they are handy. :smile:

Decisions, decision... :wink:

 

 

Also add only one of each armor piece to one mannequin (5 in total)

You can add both body armors overlapping each other in the Creation Engine.

The script will only activate one (favoring "TehArmor").

If you want to add "TehArmorB" on a mannequin be sure that "TehArmor" is not in the players inventory.

 

But if the armor is unique and you have two mannequins, that issue should solve itself. ^^

Link to comment
Share on other sites

Hmm..

 

_AnbMannekinArmorActivator

 

Scriptname _AnbMannekinArmorActivator extends ObjectReference  
; https://forums.nexusmods.com/index.php?/topic/8445053-script-and-or-or-operator-help/

  Message         PROPERTY FailMessage     auto        ; {The message to show if the player dont have the item in their inventory}
  ObjectReference PROPERTY ArmorGhostChest auto        ; a hidden chest to store armor

  Armor TehArmor
  Armor TehArmorB
 
  Bool bBusy        ; False by default


; -- EVENTs -- 2

EVENT OnCellLoad()    
    TehArmor  = Game.GetFormFromFile(0x000d62,"_AnbCustomMod.esp") as Armor
    TehArmorB = Game.GetFormFromFile(0x000d69,"_AnbCustomMod.esp") as Armor
ENDEVENT


EVENT OnActivate(ObjectReference akActionRef)
IF ( bBusy )
    RETURN    ; - STOP -    threadlock active
ENDIF
;---------------------
    bBusy = TRUE
    IF (akActionRef == Game.GetPlayer() as ObjectReference)
        myF_Action(akActionRef)
    ENDIF
    bBusy = False
ENDEVENT


; -- FUNCTIONs -- 2

;-------------------------------------------------------------------------------
FUNCTION myF_REM(ObjectReference akSender, ObjectReference akReceiver, Armor AR)  ; internal helper
;-------------------------------------------------------------------------------
    IF (akSender.GetItemCount(AR) > 0)
        akSender.RemoveItem(AR, 1, False, akReceiver)
    ENDIF
ENDFUNCTION


;-----------------------------------------------
FUNCTION myF_Action(ObjectReference akActionRef)  ; player activation only
;-----------------------------------------------
    objectReference oRef = self.GetLinkedRef()

IF ( oRef )
ELSE
    RETURN    ; - STOP -    linkedRef is missing
ENDIF
;---------------------
IF oRef.IsEnable()
; at least one item was already placed to hidden chest, send armor(s) from hidden chest back to player
    myF_REM(ArmorGhostChest, akActionRef, TehArmor)
    myF_REM(ArmorGhostChest, akActionRef, TehArmorB)

    oRef.Disable()        ; switch off the static item
    RETURN    ; - STOP -
ENDIF
;---------------------
; try to remove items from players inventory to hidden chest
    myF_REM(akActionRef, ArmorGhostChest, TehArmor)
    myF_REM(akActionRef, ArmorGhostChest, TehArmorB)
    
IF (ArmorGhostChest.GetItemCount(TehArmor) == 0) && (ArmorGhostChest.GetItemCount(TehArmorB) == 0)
    FailMessage.Show()
    RETURN    ; - STOP -    no item transfer from player to chest
ENDIF
;---------------------
    oRef.Enable()         ; switch on the static item
ENDFUNCTION

 

 

Link to comment
Share on other sites

Wow, you both sure give me more headache with those scripts. But i get it and thank you, sincerely to both of you for pushing me to learn scripting better.

 

Wish i can change the thread title to make it more precise about what i'm trying to do, to help those that wanted to do the same thing like i did but sucks with scripting.

 

Thank you guys.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...