Jump to content

Need help with papryus function.


Recommended Posts

The line

Game.GetPlayer().EquipItem(akBaseObject, False, True)
is going to likely introduce an infinite loop and it is certainly not needed.

 

Could you explain why it's not needed?

In my opinion the previous line is gonna unequip this item. Cause akBaseObject also has EquipSlot_A_Coat keyword. And if it doesn't the conditional is not triggered.

Edited by khazerruss
Link to comment
Share on other sites

Well, correct, but then the question might be why you unequip and reequip right away.

 

The loop Reneer means, is that the OnItemEquipped event will fire just straight away if you reequip, so you will have a loop that never ends. If you really need to do this for whatever reason, then you should put a condition variable and add it to the if function once reequipped so it doesn't loop. Maybe something like this:

Scriptname PlayerEqupingLimiter extends Actor Const

int HasBeenReequipped

Event OnInit()
   HasBeenReequipped = 0
EndEvent

Event OnItemEquipped(Form akBaseObject, ObjectReference akReference)
   if (akBaseObject.HasKeyword(EquipSlot_A_Coat) && HasBeenReequipped == 0)
      if Game.GetPlayer().HasPerk(SlotEquipped_A_Coat)
         Game.GetPlayer().RemoveItem(EquipSlot_A_Coat, -1, true)
         Game.GetPlayer().EquipItem(akBaseObject, False, True)
         Game.GetPlayer().AddPerk(SlotEquipped_A_Coat)
         HasBeenReequipped = 1
      Else
         Game.GetPlayer().AddPerk(SlotEquipped_A_Coat)
      EndIf
   EndIf
endEvent
 
 
Perk Property SlotEquipped_A_Coat Auto Const
 
Keyword Property EquipSlot_A_Coat Auto Const
Edited by Dielos
Link to comment
Share on other sites

 

The line

Game.GetPlayer().EquipItem(akBaseObject, False, True)
is going to likely introduce an infinite loop and it is certainly not needed.

Â

Could you explain why it's not needed?

In my opinion the previous line is gonna unequip this item. Cause akBaseObject also has EquipSlot_A_Coat keyword. And if it doesn't the conditional is not triggered.

That's the thing: the script as-is removes the items with the keyword attached and then tells the game to equip the base item, which has the keyword attached, which gets removed and then equipped again. And on it goes.

 

The EquipItem is needed. I was incorrect about it not being necessary, now that I've looked over the code again.

 

Dielos definitely has the right idea with the check code. That will prevent the infinite loop.

Edited by Reneer
Link to comment
Share on other sites

New code:

Scriptname PlayerEqupingLimiter extends Actor Const

Event OnItemEquipped(Form akBaseObject, ObjectReference akReference)

   if !(Game.GetPlayer().HasPerk(DisablePlayerEquipingLimiter))

      if akBaseObject.HasKeyword(EquipSlot_A_Coat)

         if Game.GetPlayer().HasPerk(SlotEquipped_A_Coat)

            Game.GetPlayer().RemoveItem(EquipSlot_A_Coat, -1, true)
            Game.GetPlayer().AddPerk(DisablePlayerEquipingLimiter)
            Game.GetPlayer().EquipItem(akBaseObject, False, True)
            Game.GetPlayer().RemovePerk(DisablePlayerEquipingLimiter)

         Else

            Game.GetPlayer().AddPerk(SlotEquipped_A_Coat)

         EndIf

      EndIf

   EndIf

endEvent

Perk Property SlotEquipped_A_Coat Auto Const

Keyword Property EquipSlot_A_Coat Auto Const

Perk Property DisablePlayerEquipingLimiter Auto Const
Link to comment
Share on other sites

Because "akObjectToRemove.HasKeyword(<KeywordNameHere>)" is not valid papyrus code. You dont put statements in double quotes and you cannot use angle brackets in variable names. Compiler errors are the most rookie of problems. If you knew enough about papyrus to say you dont need to post your source then you wouldnt be having compiler errors to begin with. LISTEN to the two pages of experienced scripters telling you what you need to do!

 

POST. YOUR. SOURCE. All of it. Post the EXACT compiler errors from the output windows and stop making yourself absolutely unhelpable.

 

Daww, you make me blush. But I'm by no means experienced :P

Link to comment
Share on other sites

 

New code:

Scriptname PlayerEqupingLimiter extends Actor Const

Event OnItemEquipped(Form akBaseObject, ObjectReference akReference)

   if !(Game.GetPlayer().HasPerk(DisablePlayerEquipingLimiter))

      if akBaseObject.HasKeyword(EquipSlot_A_Coat)

         if Game.GetPlayer().HasPerk(SlotEquipped_A_Coat)

            Game.GetPlayer().RemoveItem(EquipSlot_A_Coat, -1, true)
            Game.GetPlayer().AddPerk(DisablePlayerEquipingLimiter)
            Game.GetPlayer().EquipItem(akBaseObject, False, True)
            Game.GetPlayer().RemovePerk(DisablePlayerEquipingLimiter)

         Else

            Game.GetPlayer().AddPerk(SlotEquipped_A_Coat)

         EndIf

      EndIf

   EndIf

endEvent

Perk Property SlotEquipped_A_Coat Auto Const

Keyword Property EquipSlot_A_Coat Auto Const

Perk Property DisablePlayerEquipingLimiter Auto Const

 

Is it not compiling? Also, I think I see a problem right off the bat:

 

I suggest that if you post a script you tell us whether it failed to compile or not, or whether you are just giving us example code.

 if !(Game.GetPlayer().HasPerk(DisablePlayerEquipingLimiter))

That "!" before "(Game.GetPlayer().Blah-Blah-Blah)" might cause an error, I presume you left it in there by accident.

Edited by paulatreides0
Link to comment
Share on other sites

 if !(Game.GetPlayer().HasPerk(DisablePlayerEquipingLimiter))
That "!" before "(Game.GetPlayer().Blah-Blah-Blah)" might cause an error, I presume you left it in there by accident.

 

The "!" is actually a logical NOT operator / negation. So if Game.GetPlayer().HasPerk(DisablePlayerEquipingLimiter) returns false, the logical NOT means that it will execute the if statement's code.

Edited by Reneer
Link to comment
Share on other sites

 

 if !(Game.GetPlayer().HasPerk(DisablePlayerEquipingLimiter))
That "!" before "(Game.GetPlayer().Blah-Blah-Blah)" might cause an error, I presume you left it in there by accident.

 

The "!" is actually a logical NOT operator / negation. So if Game.GetPlayer().HasPerk(DisablePlayerEquipingLimiter) returns false, the logical NOT means that it will execute the if statement's code.

 

 

Ahh, I wasn't aware you could apply it like that.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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