Trying to Impelement an NPC Sell Function

Post » Tue Jun 19, 2012 1:41 pm

In my custom house, there's a resident NPC, and I want to make him able to sell a random item from all those placed in certain chest labelled Junk. Here's what I tried, and there seem to be several flaws in my approach, so I'd like any observations you all may have:

I created two quest alias, one simply referring to the JunkChest. The other, SellItem I created as Find Matching Reference with Match Condition:

Note: this isn't a script, I'm just using this box to make this info look clearerCondition Item:GetInContainer Reference:"QutChestJunk"Run on Quest Alias: JunkChest

Now I have two dialogue paths, one for selling the item, and one for saying that the chest is empty. The empty chest path has the following condition:

DoesNotExist == 1Run on Quest Alias: SellItem

PROBLEM # 1: I only ever get the empty chest dialogue, which indicates to me that either the Alias SellItem isn't being picked properly or that DoesNotExist isn't that right condition for that dialogue node (I tried finding a ContainerEmpty condition or something similar, but no luck)

PROBLEM # 2: The CK doesn't like the script fragment I have on the dialogue option that something got sold.

Game.JunkChest.RemoveItem(SellItem, 1)Game.GetPlayer().AddItem(Gold001, (SellItem.GetGoldValue()));including these properties so you see that I set them!ReferenceAlias Property SellItem  AutoReferenceAlias Property JunkChest  AutoMiscObject Property Gold001  Auto

I've tried several different iterations of the above script, but it doesn't like the functions RemoveItem and GetGoldValue, saying they don't exist.

Any thoughts?
User avatar
Alexander Horton
 
Posts: 3318
Joined: Thu Oct 11, 2007 9:19 pm

Post » Tue Jun 19, 2012 1:09 pm

oops
User avatar
neen
 
Posts: 3517
Joined: Sun Nov 26, 2006 1:19 pm

Post » Tue Jun 19, 2012 6:50 pm

LOL! Don't get my hopes up like that. It's cruel! :P
User avatar
Enie van Bied
 
Posts: 3350
Joined: Sun Apr 22, 2007 11:47 pm

Post » Tue Jun 19, 2012 4:31 pm

I have found 1 a mistake
Game.JunkChest.RemoveItem(SellItem, 1)
isn't correct
JunkChest.RemoveItem(SellItem, 1)
Correct
User avatar
Claire
 
Posts: 3329
Joined: Tue Oct 24, 2006 4:01 pm

Post » Tue Jun 19, 2012 7:02 am

OK, was able to fix some things with the script. Down to one error:

JunkChest.RemoveItem(SellItem, 1)Game.GetPlayer().AddItem(Gold001, (SellItem.GetReference().GetGoldValue()))

Error:

qut__TIF__0101D388.psc(9,10): RemoveItem is not a function or does not exist

I'm also still suspecting that the Alias SellItem isn't being filled the way I have it set up (See OP). Any ideas?
User avatar
Syaza Ramali
 
Posts: 3466
Joined: Wed Jan 24, 2007 10:46 am

Post » Tue Jun 19, 2012 10:32 pm

Try to replace
ReferenceAlias Property SellItem  Auto
at
ObjectReference Property SellItem  Auto
User avatar
James Baldwin
 
Posts: 3366
Joined: Tue Jun 05, 2007 11:11 am

Post » Tue Jun 19, 2012 1:30 pm

But it's not a specific object reference, it's an alias reference to a random object that fills the SellItem Quest Alias.

JunkChest.RemoveItem(SellItem.GetReference(), 1)

The above still gets me an error for RemoveItem.
User avatar
Devin Sluis
 
Posts: 3389
Joined: Wed Oct 24, 2007 4:22 am

Post » Tue Jun 19, 2012 11:26 pm

Strangely.....
User avatar
Lucky Boy
 
Posts: 3378
Joined: Wed Jun 06, 2007 6:26 pm

Post » Tue Jun 19, 2012 9:14 am

Try to look examples another scripts where using same function
User avatar
Dean
 
Posts: 3438
Joined: Fri Jul 27, 2007 4:58 pm

Post » Tue Jun 19, 2012 2:52 pm

OK, the following will compile:

JunkChest.GetReference().RemoveItem(SellItem.GetReference().GetBaseObject())Game.GetPlayer().AddItem(Gold001, (SellItem.GetReference().GetGoldValue()))

Sheesh. What's weird is that the example on the CKWiki is using a reference alias for the chest as well without the GetReference() added.

Now I need to get the alias definition to work right, so I can test to see if the script doesn't just compile, but actually work!

Thanks for your help, STEEP
User avatar
Avril Louise
 
Posts: 3408
Joined: Thu Jun 15, 2006 10:37 pm

Post » Tue Jun 19, 2012 3:35 pm

OK, I got my scripts working, but I still need help with my Alias. I want it to grab an item (randomly, but in order wouldn't be so bad) from a certain chest. On the Alias WIndow, I've discovered, you can't just check Find Matching Reference and then create a conditional. You have to check at least one of the options (In Loaded Area, From Event, or Near Alias. So what I've been testing is check in Loaded Area and adding the conditional "GetInContainer: QutJunkChest" (the object reference).

Now I've tried running the conditional on different things. If you run on the Subject, doesn't that mean it checks to see if the NPC you're talking to is in the chest? If you run on the Chest, then doesn't it mean that it checks whether the chest is inside itself. And you can't really check the alias on itself.

So I'm thinking I might be able to do something with finding a matching reference from Event. But I'm not sure how to define it, or how to link it with a script that would define the event. Any one have some experience with this?

And a related question: Where do things in an inventory go? Are the things in the chest not technically in the cell?

Another route I'm looking at is perhaps putting some kind of flag on items that get put into that chest that the alas can look for, as long as the flag could be removed if you took the item out.
User avatar
Richard Thompson
 
Posts: 3302
Joined: Mon Jun 04, 2007 3:49 am

Post » Tue Jun 19, 2012 9:42 pm

OK, just to move closer to what I want, I've put a script on the chest, so that it forces the item put into it into the Alias Sell Item. I can get the following script to compile, but it doesn't seem to actually assign the alias.

Scriptname QutJunkAssignScript extends ObjectReferenceEvent OnItemAdded(Form akBaseItem, int aiCount, ObjectReference akItem, ObjectReference akContainer)	  SellItem.ForceRefTo(akItem)	  debug.trace("Assigned Alias to " + akItem)EndEventEvent OnItemRemoved( Form akBaseItem, int aiCount, ObjectReference akItem, ObjectReference akContainer)	 SellItem.Clear()EndEventReferenceAlias Property SellItem  Auto
User avatar
Stu Clarke
 
Posts: 3326
Joined: Fri Jun 22, 2007 1:45 pm

Post » Tue Jun 19, 2012 3:04 pm

So dumb question.

This 'chest', is it meant for storage, or is it meant for 'selling' items for gold?
I ask cause... You could make an Chest an NPC, and make it a 'companion' type chest, that sits in the house, and you could 'trade' it goods, or you could 'sell' it goods. :P Not the same thing I know but...
User avatar
T. tacks Rims
 
Posts: 3447
Joined: Wed Oct 10, 2007 10:35 am

Post » Tue Jun 19, 2012 8:17 pm

It's a normal storage chest called "Junk." I want the player to actually be able to remove stuff to sell to vendors in town. But I want to have the house's resident NPC have a dialogue option with the player that says, "Hey, I took item X from the chest and sold it today." So I'm trying to get the selling quest to assign the SellItem alias to a random item stored in the chest. The script immediately above is kind of an intermediate test that should simply mark the first thing you put in the chest as that alias. But it's not working! But I know I'm close.
User avatar
Scotties Hottie
 
Posts: 3406
Joined: Thu Jun 08, 2006 1:40 am

Post » Tue Jun 19, 2012 11:18 am

I think that the sellitem being inside another container is what the problem is. AFAIK you can only have alias's point to items inworld.
In your script check, do an 'if (akItem)'. Unless it's a persistent object then it will probably be None.
User avatar
Alberto Aguilera
 
Posts: 3472
Joined: Wed Aug 29, 2007 12:42 am

Post » Tue Jun 19, 2012 10:28 pm

I was afraid the fact that it's inside the chest might be an issue. But on the other hand, you can create quest aliases inside containers (the radiant quests add items to chests all the time, are able to attach objective markers to them, and even move them between inventories), but I guess creating and then placing in an inventory is different than finding something already in an inventory to flag - but it just seems like an arbitrary limitation if that's the case.

I have a dialogue node that is supposed to fire if the alias isn't assigned properly, and it always fires, so I know nothing I've tried so far is working :P
User avatar
Allison Sizemore
 
Posts: 3492
Joined: Wed Jul 19, 2006 6:09 am

Post » Tue Jun 19, 2012 8:32 pm

Yeah once you have an alias handle on the item, then it will be persistent.
Making it temporarily persistent only needs you to have an active script variable on the ref. So as long as you can get a ref for the item then forceRefTo should work.

Ermm... wonder if it would be possible to place a stuff_to_sell box or bucket, and have a trigger box to grab the first thing entered.
Do trigger boxes work on items?

w.r.t. the ingame radiant quests, I think they make the items to retrieve persistent from game start.

TG spoiler...
Spoiler

I dunno how many times I had to retrieve the same items from the thieves guild when they went missing from the display shelves time after time.
User avatar
Lyndsey Bird
 
Posts: 3539
Joined: Sun Oct 22, 2006 2:57 am

Post » Tue Jun 19, 2012 8:32 pm

Yeah, the TG items do exist from the start, and are activated and deactivated with the quest. But other quests, like the caravan amulet retrieval quest actually creates the amulet in the container (the tutorial quest on the wiki does this, too). So an object with an alias tag can still be tracked inside a container, There is a "Get Near Alias" option to find a matching reference in the alias definition interface. I might play around with that, but since things retain alias tags inside containers, I don't see why you can't assign one to an object already inside a container.
User avatar
Jessica Colville
 
Posts: 3349
Joined: Wed Oct 18, 2006 6:53 pm

Post » Tue Jun 19, 2012 4:36 pm

Yeah you're probably right. Just need to make it persistent somehow beforehand so it retains the ref.
(I think I was mixing it up with the Story Manager starting the quest and auto filling the Aliases.)
User avatar
Yonah
 
Posts: 3462
Joined: Thu Aug 02, 2007 4:42 am

Post » Tue Jun 19, 2012 4:56 pm

OK, trying to go about this another way.

How do you pull up the inventory of a container as a list? My understanding of FormLists in a container context is that the form list is the list of things that are supposed to go in a container (like leveled lists) rather than the list of what may be in a given container during the game. If you could summon the inventory list as a form list, perhaps I could use a script like this:

FormList Property JunkChestInventoryReferenceAlias Property SellItemint JunkMax = JunkChestInventory.GetSize()int ChooseItem = RnadomInt(0, JunkMax)ObjectReference Chosen = JunkChestInventory.GetAt(ChooseItem) as ObjectReferenceSellItem.ForceRefTo(Chosen)

But I'm not sure if you can summon a current inventory as a form list. Is there some other way to do something like this?
User avatar
Dragonz Dancer
 
Posts: 3441
Joined: Sat Jun 24, 2006 11:01 am

Post » Tue Jun 19, 2012 11:24 am

But I'm not sure if you can summon a current inventory as a form list. Is there some other way to do something like this?

No, unfortunately you can't loop over an inventory directly.

Once a script is attached to a container though, you can keep a tabs of it with the OnItemAdded/OnItemRemoved events.
If you needed to get the current inventory then spawn a new temp container, and use removeAllItems to and fro.
The pain is knowing when the queue of OnItemAdded events has completed, so it can return the full list and delete itself.

BTW, have you played with GetGoldValue() yet?
I'm not sure if you can get the value of improved items.
User avatar
KRistina Karlsson
 
Posts: 3383
Joined: Tue Jun 20, 2006 9:22 pm


Return to V - Skyrim