Jump to content

Photo

Running a script once when a certain item is bought - possible?

fallout new vegas

  • Please log in to reply
8 replies to this topic

#1
phoneyLogic

phoneyLogic

    Nightshade Mutant

  • Supporter
  • PipPipPipPip
  • 2,258 posts
Hi folks,

I want to run a script on an object once when its bought by the player from vendors

... and ran into a very strange problem:



Begin OnAdd
... only runs when the player sells the item


Begin OnDrop
... only runs when the player sells the item


Begin OnSell
... only runs when the player sells the item


All the blocks are running as long as I sell the item, but I need them as I buy it.
But then, nothing happens.

Am I'm doing sth wrong?

#2
luthienanarion

luthienanarion

    Resident poster

  • Supporter
  • PipPipPipPipPip
  • 3,742 posts

If a vendor is the only source of obtaining the item, you can just use player.getitemcount blargobject to determine when one is obtained.



#3
phoneyLogic

phoneyLogic

    Nightshade Mutant

  • Supporter
  • PipPipPipPip
  • 2,258 posts
I want to use it for this mod:
http://newvegas.nexu....com/mods/34999


The script I'm using currently is as follows:
 
Begin MenuMode 1053

    if ( Player.GetItemCount RACEMenuToken == 0 )
            Player.AddItem RACEMenuToken 1 1
    endif
End
 
The player can buy radios to place them into the world. But therefore another item is needed, the RACEMenuToken.
 
The player may want to get rid of the Token. Anyway, the problem is, I
don't want to add the Token every time the player trades (all or none)
Items - but only in case he buys a radio.
So I attached the scripts to the radio base object in the code boxes below.
 
But as said, they only work if I sell a radio.
 
I may work around using the MenuMode above and write tons of code just to
check "are we going in barter menü? How many radios do we have? Does
this kind of change as we leave the Barter menu?" but this clearly would
not be my favourite solution.
 
I was wondering, we have this cool "Begin On..." blocks, cant I just use them?
 
I tried:
 
 
Begin OnAdd; Player
if MenuMode 1053 == 1
        if ( Player.GetItemCount RACEMenuToken == 0 )
            Player.AddItem RACEMenuToken 1 1
        endif
endif
End
 
Begin OnDrop; Player

if MenuMode 1053 == 1
        if ( Player.GetItemCount RACEMenuToken == 0 )
            Player.AddItem RACEMenuToken 1 1
        endif
endif
End
 
Begin OnSell

if ( Player.GetItemCount RACEMenuToken == 0 )
Player.AddItem RACEMenuToken 1 1
endif
End 

 
 
They work just amazing, as long as I sell the Item. But none of them works if I buy it. :-/
 
Is this a bug or something?
 
I just can't imagine why someone would intentionally disable all this blocks as soon as the player buys sth.
 
It makes no sense to me. And that's why I figure, I might do sth wrong.

Edited by tortured Tomato, 19 February 2013 - 11:00 PM.


#4
Belthan

Belthan

    Faithful poster

  • Premium Member
  • 2,045 posts

Maybe pointing out the obvious, but the semicolon after begin OnAdd starts a comment. The script will run when the object is added to any actor, not just the player, so it runs when you sell the object to a vendor. But it still seems like it should run when you buy the object from a vendor.

 

The only thing I can see that would make this fail is if you somehow already have a token in your inventory.



#5
phoneyLogic

phoneyLogic

    Nightshade Mutant

  • Supporter
  • PipPipPipPip
  • 2,258 posts

The semicolon I added was to test it without referece.

I even tried to pass the specific vendor as ref and removing all other conditions, like so
 

Begin OnSell CliffBriscoeREF

        showmessage RACEKeyRadioOnMessage

End

 

Begin OnDrop CliffBriscoeREF

Player.AddItem RACEMenuToken 1 1

End
 

 

and it didn't work.

 

In the barter menu these blocks only seems to run if the player is the reference.


Edited by tortured Tomato, 20 February 2013 - 08:38 AM.


#6
Belthan

Belthan

    Faithful poster

  • Premium Member
  • 2,045 posts

The following works as expected for me. Specifically, when I sell the object that uses this script, the script doesn't run. When I buy it back from the vendor the message is displayed and the extra item is added to my inventory.

begin OnAdd Player

	if MenuMode 1053 == 1
		showmessage Debug
		player.additem ArmorCombat 1
	endif
	
end

Which is functionally equivalent to your script, so I know it doesn't really help.

 

The only other thing I can think of is this: a few months ago I had a bizarre problem where a function wasn't working as documented, many posts and pulled out hair with no luck. Gave up on the feature I was trying to implement. For unrelated reasons I had to reinstall F3 a few weeks later, lo and behold the same mod miraculously started working.



#7
phoneyLogic

phoneyLogic

    Nightshade Mutant

  • Supporter
  • PipPipPipPip
  • 2,258 posts
This would be exactly what I'm looking for.
But somehow, OnAdd Player doesn't work for me as soon as I'm bartering.
Wait, might it be because I'm running the script on a misc item?
 
testing...


Edit
Yep, this seems to be the problem.
"OnAdd Player" works on an Apparel item but not on a Misc item.
So either Misc items are bugged or the problem still is on my end.

Edited by tortured Tomato, 20 February 2013 - 11:55 AM.


#8
Belthan

Belthan

    Faithful poster

  • Premium Member
  • 2,045 posts

Hm. Works on misc items for me. I attached the following script to BurnedBook01, and it runs when I buy it (but not when I sell it).

 

begin OnAdd player
	if MenuMode 1053 == 1
		showmessage Debug
		player.additem BurnedBook02 1
	endif
	

end


#9
phoneyLogic

phoneyLogic

    Nightshade Mutant

  • Supporter
  • PipPipPipPip
  • 2,258 posts

Weird, I changed the barter and loaded an older save and "OnAdd Player" works now.
 
Think you were right, might have been a cache or even save game related problem.
Anyways, I'm so glad it finally works now. ^^
 
Thank you for you help, I might just have given up.
 
kudos given
luthienanarion, you already have :teehee:


Edited by tortured Tomato, 20 February 2013 - 05:46 PM.






Also tagged with one or more of these keywords: fallout new vegas

Page loaded in: 1.038 seconds