Begin OnActivate Player

Post » Tue May 17, 2011 4:42 am

I must not understand the way the OnActivate Block works...

Here is my script:
scn SSSGunnySackContScript;=+= Requires FOSE v1int iActStateint iButtonfloat fIW1float fIW2float fGSWBegin OnActivate PlayerIf SSSGunnySackContStasisRef.iActState == 1	Set fGSW to SSSGunnySackContStasisRef.fGSIW	Set SSSGunnySackContStasisRef.iActState to 2EndIfShowMessage SSSGunnySackContMessageSet iActState to 1EndBegin GameModeIf iActState != 0	If iActState == 1		Set iButton to GetButtonPressed		If iButton > -1			If iButton == 0				Set fIW1 to Player.GetAV InventoryWeight				Activate Player 0				Set iActState to 2				Return			ElseIf iButton == 1				If fGSW != SSSGunnySackContStasisRef.fGSIW					Set SSSGunnySackContStasisRef.fGSIW to fGSW					Set fGSW to (fGSW + 0.1)					SetWeight fGSW SSSGunnySackMisc				EndIf				RemoveAllItems SSSGunnySackContStasisRef, 1				Player.AddItem SSSGunnySackMisc 1 1				Set SSSGunnySackContStasisRef.iActState to 0				Set iActState to 0				Disable				MarkForDelete			EndIf		EndIf	EndIf	If iActState == 2		Set fIW2 to Player.GetAV InventoryWeight		If fIW1 != fIW2			Set fIW1 to (fIW1 - fIW2)			Set fGSW to (fGSW + fIW1)		EndIf		Set iActState to 0	EndIfEndIfEnd


This script is attached to my Gunny Sack temporary container (the one the player interacts with).

If a NPC activates the container, the "ShowMessage SSSGunnySackContMessage" line fires, and the message box pops up on my screen.

The NPC is usually pretty determined to get in to the container. This results in the Message popping up, and my selecting "Cancel". Message pops up, click cancel. Message pops up, click cancel.... you get the point.

What am I doing wrong?

How do I rig this OnActivate block to only fire for the PC, and not for NPCs?
User avatar
dell
 
Posts: 3452
Joined: Sat Mar 24, 2007 2:58 am

Post » Tue May 17, 2011 7:16 am

Thats really weird. Perhaps try this instead. (I think it should work)

Begin OnActivate If IsActionRef Player == 1  If SSSGunnySackContStasisRef.iActState == 1  	Set fGSW to SSSGunnySackContStasisRef.fGSIW  	Set SSSGunnySackContStasisRef.iActState to 2  EndIf ShowMessage SSSGunnySackContMessage Set iActState to 1 EndIfEnd


Also I notice you say if the variable is 1, set it to 2 then right back to 1 again?

Also is the NPC activating it before you ever have, or after you have?
User avatar
Reanan-Marie Olsen
 
Posts: 3386
Joined: Thu Mar 01, 2007 6:12 am

Post » Tue May 17, 2011 11:45 am

You have to use:

ON ActivateIf IsActionRef Player   do stuffendifEND


in the on activate block to make sure it really is the Player. On Activate Player doesn't do it.
User avatar
noa zarfati
 
Posts: 3410
Joined: Sun Apr 15, 2007 5:54 am

Post » Tue May 17, 2011 7:13 am

Thats really weird. Perhaps try this instead. (I think it should work)

Begin OnActivate If IsActionRef Player == 1  If SSSGunnySackContStasisRef.iActState == 1  	Set fGSW to SSSGunnySackContStasisRef.fGSIW  	Set SSSGunnySackContStasisRef.iActState to 2  EndIf ShowMessage SSSGunnySackContMessage Set iActState to 1 EndIfEnd


I'll try this. It'll be hard to test, because the NPC will sometimes go in to a frenzy trying to open the container, and on other reloads the NPC won't touch it.

Also I notice you say if the variable is 1, set it to 2 then right back to 1 again?

Also is the NPC activating it before you ever have, or after you have?

There are actually three inter-connected scripts working here.

Script 1: SSSGunnySackMiscScript
I have a Misc Item that you carry in your inventory. You drop the Misc Item, then activate it. That pops up a Messagebox allowing you to either "Place the Gunny Sack", or pick it back up.
If you chose to "Place the Gunny Sack", a container is PlaceAtMe'ed by the Misc Item, and the Misc Item is MarkForDelete'ed.

Script 2: SSSGunnySackContScript
This is the script I posted in the OP. It is attached to the Container, and is what allows the PC to Open, or Pick Up the Gunny Sack.
When the Gunny Sack container is Picked Up, the contents of the temp container is moved to a persistent container in a "stasis cell" for storage, the now empty temp container is MarkForDelete'ed, and a new Misc Item Gunny Sack is added to the PC's inventory. The weight of the Misc Item Gunny Sack is modified to include the weight of the items it "contains".

Script 3: SSSGunnySackContStasisScript
This script is attached to the persistent container in the stasis cell, and basically just stores the weight of the items in the Gunny Sack, and keeps a flag telling the other two scripts what state the Gunny Sack is in at the moment.


I use the variable SSSGunnySackContStasisScript.iActState as the flag to tell what state the Gunny Sack is in.
0 = The Gunny Sack is a Misc Item.
1 = The Gunny Sack is a Container.
2 = The Player has the Gunny Sack container open, and is transferring items between their inventory and the container.

Where I confused you is, I also use a variable named iActState in the SSSGunnySackContScript to signal the script to calculate the weight of the items being transfered.

I know, the way this works is a hack job. I came up with a concept, and started trying to make it work. This is the system I came up with that does pretty much everything I had in mind.

EDIT: The NPC is activating the container after I have stored some items in it and moved away from it.
You have to use:

ON ActivateIf IsActionRef Player   do stuffendifEND


in the on activate block to make sure it really is the Player. On Activate Player doesn't do it.

Got it.

Thanks for the replies.
User avatar
Nick Jase Mason
 
Posts: 3432
Joined: Sun Jul 29, 2007 1:23 am

Post » Tue May 17, 2011 7:43 am

On the container, check the box for 'no ai aquire' and 'ignored by sandbox'. That should keep the NPC's away from it.
User avatar
Alexx Peace
 
Posts: 3432
Joined: Thu Jul 20, 2006 5:55 pm

Post » Tue May 17, 2011 2:20 am

On the container, check the box for 'no ai aquire' and 'ignored by sandbox'. That should keep the NPC's away from it.

Oh... I hadn't thought of that.
Thanks WillieSea!
User avatar
Charlotte Henderson
 
Posts: 3337
Joined: Wed Oct 11, 2006 12:37 pm


Return to Fallout 3