Jump to content

Removing An Equipped Item. How?


Recommended Posts

I have made a triggerbox base that I can place anywhere that if the player enters it (water will be falling or player will be submerged) and has a torch EQUIPPED, not important if player has x amount in inventory, that I want to dowse the torch i.e. remove the torch the player has equipped. I don't know how to add this to the script. There is no RemoveEquippedItem or similar that I know of.

Help please.

 

 

import sound

Actor Property PlayerREF Auto
Message Property MyMSG Auto
Sound Property FireOut Auto
GlobalVariable Property MyGV Auto

int instanceID ;used to store sound ref

auto state waiting
Event OnTriggerEnter(ObjectReference akActionRef)
if akActionRef == PlayerRef
if (PlayerRef.GetEquippedItemType(0) == 11)
FireOut.Play(self)
if MyGV.GetValue() == 0.0
MyMSG.show()
MyGV.SetValue(1.0)

GoToState("Done")

else
; Do nothing

EndIf
EndIf
EndIf

ENDEVENT
ENDSTATE

 

Link to comment
Share on other sites

I found this to be very difficult to for different purposes. You can unequip items obviously through UnequipItem, but removing them is a different story. You can check if there is more than one of the equipped item in the inventory, through GetItemCount and then use RemoveItem(as it has a frustrating preference for removing the first instance of an item, which happens to be the equipped one.)

Edited by Rasikko
Link to comment
Share on other sites

If player has torch equipped, it is usually lit. You want the torch to be removed as if it were to have been put out by the water. But you do not want to screw up how many additional torches the player may be carrying.

 

Hmm... You might need to use a "pass back method" (not an official term, I just made it up LOL ).

 

Something like this:

 

 

Light Property myTorch Auto
ObjectReference Property myHiddenContainer Auto

Event OnTriggerEnter(ObjectReference akActivator)
  If akActivator == Game.GetPlayer()  ; --- make sure it is the player
    Int Num = akActivator.GetItemCount(myTorch)  ; --- get number of torches
    akActivator.RemoveItem(myTorch,Num,true,myHiddenContainer)  ; --- remove all torches to the container
    myHiddenContainer.RemoveItem(myTorch,(Num - 1),true, akActivator)  ; --- return all torches but one to the player
  EndIf
EndEvent

This uses a container that you have hidden somewhere out of the player's reach. I prefer an unlinked empty interior cell for this sort of thing.

Eventually the container may get loaded with a lot of torches if this is intended to happen a lot. Should that be the case, adding an additional RemoveItem call to send the remaining torch from the container into the void (and effectively removing it from the game) may be desired. To send an item to the void, do not designate a target container in the RemoveItem function call.

 

 

The only downside to this method is that there is no visible torch dropped at the player's feet. DropObject can be used but there is no way to determine definitively if the dropped object will be the equipped one or one that is not. Furthermore, if the torch is lit when dropped it tends to remain lit. Probably best not to worry about having a visual reference to the torch that was put out.

 

Or just take the torches away and return them without reducing by one. After all the player could be considered "smart enough" to hold on to the torch while it goes out and saves it for later use.

Link to comment
Share on other sites

@IsharaMeradin

That works perfect. Made a small interior cell with a chest for dumping purposes.

What I discovered if I don't designate a target container in the RemoveItem function call, the script still works and the torch goes to 'the void' but so do all torches in player's inventory.

Thanks.

 

EDIT: Duh! I've just understood why.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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