Jump to content

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


phoneyLogic

Recommended 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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Recently Browsing   0 members

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