Quick GetEquipped Question...

Post » Fri Apr 08, 2011 12:28 am

Does anybody know at what point during equipping a scripted item/weapon that its GetEquipped status switches to true?
I find myself needing to check an items own GetEquipped status from inside it's OnEquip block, and I'm not sure if I can do that.
It's a single script for multiple different items, and I'd like to have the items check GetEquipped status so I can ID which one is in use in the OnEquip block. Just not sure if the items GetEquipped status would be updated to true at that time.
Thanks
User avatar
patricia kris
 
Posts: 3348
Joined: Tue Feb 13, 2007 5:49 am

Post » Thu Apr 07, 2011 6:30 pm

I haven't tried it, but would something like this work:

set rSelf to getself
if rSelf == AntMeat
do stuff
endif
User avatar
DeeD
 
Posts: 3439
Joined: Sat Jul 14, 2007 6:50 pm

Post » Fri Apr 08, 2011 3:59 am

Does anybody know at what point during equipping a scripted item/weapon that its GetEquipped status switches to true?
I find myself needing to check an items own GetEquipped status from inside it's OnEquip block, and I'm not sure if I can do that.
It's a single script for multiple different items, and I'd like to have the items check GetEquipped status so I can ID which one is in use in the OnEquip block. Just not sure if the items GetEquipped status would be updated to true at that time.
Thanks


Use GetContainer to get the reference of the npc that MyItem item is contained in.
set rNPCRef to GetContainer
Then let the script wait/loop to do it's main thing until rNPCRef.GetEquipped MyItem returns true.
User avatar
ashleigh bryden
 
Posts: 3446
Joined: Thu Jun 29, 2006 5:43 am

Post » Fri Apr 08, 2011 1:21 am

Use GetContainer to get the reference of the npc that MyItem item is contained in.
set rNPCRef to GetContainer
Then let the script wait/loop to do it's main thing until rNPCRef.GetEquipped MyItem returns true.

Thanks, yeah that's what I wound up doing... setting an "i'm equipped, but don't know which one I am yet" variable in the OnEquip block, and setting a conditional in GameMode to run until one of the items returns true as equipped, then move on.
I just wasn't sure if an item needed to complete the onequip block before GetEquipped would return true for that item. I still have no idea, but side-stepped the issue for now.
User avatar
saxon
 
Posts: 3376
Joined: Wed Sep 19, 2007 2:45 am

Post » Fri Apr 08, 2011 12:37 am

Maybe you can use "Begin Onequip Player" as your block type and in the end, that will solve this for you.
User avatar
sara OMAR
 
Posts: 3451
Joined: Wed Jul 05, 2006 11:18 pm

Post » Fri Apr 08, 2011 7:32 am

Maybe you can use "Begin Onequip Player" as your block type and in the end, that will solve this for you.

The thing is, I'm using one master script on 3 different rifles instead of 3 individual scripts, one for each. And there'll be many copies of this gun around so a quest or global to monitor is out.
Begin OnEquip Player would only let me know that one of the 3 is equipped, however... Begin OnActorEquip ActorID might be what I'm looking for.. thx for the heads up!

Edit: Ugh.. OnActorEquip only works if the script is on the player/NPC
User avatar
Marcia Renton
 
Posts: 3563
Joined: Fri Jan 26, 2007 5:15 am

Post » Fri Apr 08, 2011 2:51 am

The thing is, I'm using one master script on 3 different rifles instead of 3 individual scripts, one for each. And there'll be many copies of this gun around so a quest or global to monitor is out.
Begin OnEquip Player would only let me know that one of the 3 is equipped, however... Begin OnActorEquip ActorID might be what I'm looking for.. thx for the heads up!
You could...
Ref rActorInt iGunTypeBegin OnEquip    Set rActor to GetContainer    If iGunType        Return    ElseIf GetIsID Gun01WEAP        Set iGunType to 1    ElseIf GetIsID Gun02WEAP        Set iGunType to 2    ElseIf GetIsID Gun03WEAP        Set iGunType to 3    EndIfEndBegin OnUnequip    Set rActor to 0EndBegin OnDrop    Set rActor to 0EndBegin GameMode    If (rActor == 0)        Return    ElseIf (rActor == Player)        If (iGunType == 1)            ;Gun 1 Code        ElseIf (iGunType == 2)            ;Gun 2 Code        ElseIf (iGunType == 3)            ;Gun 3 Code        EndIf    Else;If (rActor != Player)        If (iGunType == 1)            ;Gun 1 Code        ElseIf (iGunType == 2)            ;Gun 2 Code        ElseIf (iGunType == 3)            ;Gun 3 Code        EndIf    EndIfEnd
...then only the appropriate code will run when any of the three guns is equipped and you could expand the rActor checks to cover any given NPC.
User avatar
Avril Louise
 
Posts: 3408
Joined: Thu Jun 15, 2006 10:37 pm

Post » Fri Apr 08, 2011 8:55 am

You could...

:facepalm: GetIsID... why, oh why didn't that ocurr to me.. :shakehead:

Thanks Justin. Yeah that would've been the real easy solution as the script used to look when I first wondered about all this.
Might have to revert the code and use that as it's real clean to look at too. Thanks!
User avatar
Rhysa Hughes
 
Posts: 3438
Joined: Thu Nov 23, 2006 3:00 pm

Post » Fri Apr 08, 2011 6:30 am

:facepalm: GetIsID... why, oh why didn't that ocurr to me.. :shakehead:

Thanks Justin. Yeah that would've been the real easy solution as the script used to look when I first wondered about all this.
Might have to revert the code and use that as it's real clean to look at too. Thanks!
Right on! :) The iGunType var set in the OnEquip block should make the GameMode block 'cheaper', I'd imagine, as it can check that var rather than calling GetIsID every frame.
User avatar
Cagla Cali
 
Posts: 3431
Joined: Tue Apr 10, 2007 8:36 am

Post » Fri Apr 08, 2011 1:19 am

Right on! :) The iGunType var set in the OnEquip block should make the GameMode block 'cheaper', I'd imagine, as it can check that var rather than calling GetIsID every frame.

Yep, GetIsID was the magic word I was missing. Whichever gun is in use IDs itself reguardless of whether its GetEquipped status has updated yet or not.. Thanks again!
Yeah, I have everything in the GameMode block behind a conditional based on a local variable, except the GetItemCount for monitoring ammo counts, which is setup differently depending on which version of the gun is in use. Whenever possible though I do have it excluded from running because I like 'cheaper' gamemodes :)
User avatar
kirsty williams
 
Posts: 3509
Joined: Sun Oct 08, 2006 5:56 am

Post » Fri Apr 08, 2011 7:25 am

Now here's something odd...
ScriptName KIRAInfiltrator1FireXSCRRef myselfShort GunTypeShort TrickShort FlipTypeBegin OnEquip  set myself to GetContainer  ;<-------- 1 ------ <<<  if (GetIsID KIRAInfiltrator1FireX == 1)    set GunType to 1  endif  if (GetIsID KIRAInfiltrator1FireXMelee == 1)    set GunType to 2  endifEndBegin OnUnequip  ;set myself to 0  ;<-------- 2 ------<< 0)      set Trick to 1      set FlipType to 2    endif  endif  if (Trick == 1)    myself.AddItem KIRABlankArmor 1    myself.EquipItem KIRABlankArmor    myself.RemoveItem KIRABlankArmor 2    set Trick to 0  endif  if (FlipType == 1)    if (myself.GetItemCount KIRAInfiltrator1FireXMelee > 0)      set GunType to 2      set FlipType to 0      myself.EquipItem KIRAInfiltrator1FireXMelee    else      set GunType to 2      set FlipType to 0      myself.AddItem KIRAInfiltrator1FireXMelee 1      myself.EquipItem KIRAInfiltrator1FireXMelee    endif  endif  if (FlipType == 2)    if (myself.GetItemCount KIRAInfiltrator1FireX > 0)      set GunType to 1      set FlipType to 0      myself.EquipItem KIRAInfiltrator1FireX    else      set GunType to 1      set FlipType to 0      myself.AddItem KIRAInfiltrator1FireX 1      myself.EquipItem KIRAInfiltrator1FireX    endif  endifEnd

While trying to track down a problem of the guns not switching automatically when ammo counts trigger switching, I simplified it (a lot) down to 2 gun variants instead of 3 (left out the mangled model for when damage gets high), and I axed the elseif's that were in there and left the equip messages on. Anyways...
The problem was that the guns would only ever switch the first time after being equipped from inventory, but not any after that no matter what ammo counts were.
The solution was to comment out the OnUnequip statement (#2 arrow).
The reason: Hehe this is great... The game was running TWO copies of this script at the same time during switching. One script was starting on the rifle being equipped, and the previous script still running on the rifle being UNequipped by the other one.
One does not finish before it's replacement begins, and the OnUnequip statement was overriding (as in.. running after) the new guns OnEquip call to GetContainer reference (#1 arrow), which nullified it and put GameMode into a loop.
The code above works perfectly as it is, but uncomment that OnUnequip line and you'll get one weapon change and then nothing.
I never would've guessed that 2 items in the same equip spot, one removing the other to make room for itself, could have a script collision like that :rolleyes:
User avatar
Marie Maillos
 
Posts: 3403
Joined: Wed Mar 21, 2007 4:39 pm


Return to Fallout 3