Newbie scripting question: How to pick up the Player Add Ite

Post » Sun Nov 18, 2012 5:31 pm

I apologize if this has been brought up before... I found similar topics, but not close enough to actually answer my question.

I'm having the fundamental issue of not understanding how to subscribe to events that have to do with the player character. I want to make a mod that causes a player to instantly eat certain food upon that food being put in the inventory. I've got what I think is a viable idea for a script to do that, and noticed in the wiki that there is a "Player Add Item" event you can catch. However, I fundamentally don't understand where I am supposed to put my script so that it receives that event notification. The tutorials I went through for scripting involved attaching a script to a specific object in the world, but I couldn't figure out how to attach a script to the user's player like that.

Frustrated that I couldn't figure out how to do that, I saw the alternative "on container changed" event from ObjectReference that I thought might be a way to catch and handle it on the food side instead of the player side, but I guess from the tutorials I've done, I also don't understand how I could get a large volume of objects to inherit that behavior. It seems like there's plenty of nice identifiers and such I can use to assign traits to the specific items I ultimately want affected by this script, but would I also have to add the script itself to every one of the food objects I want to be insta-eaten?

These are probably basic questions, I know... but the tutorials I've seen focus on attaching new behavior to specific objects in e.g. a new quest or dungeon, and I was looking to get some insight into more overall game changes that I'm more interested in modding for my own gaming experience personally. Thanks for any help offered :).
User avatar
Silvia Gil
 
Posts: 3433
Joined: Mon Nov 20, 2006 9:31 pm

Post » Mon Nov 19, 2012 2:29 am

I'm not sure about the event, but I've been using scripts to count pelts an hides in the players inventory for quests. How they work is a script on quest sets the stages, a script in the stage calls it, and a script attached to the Player as a quest alias checks when items are added to the inventory. You could look at that.

Check out FreeformRiften04 and FreeformIvarstead03. Both of these a fetch quests that count the items as they are added to the player. Once added though you can basically do anything in the script.
User avatar
Robert DeLarosa
 
Posts: 3415
Joined: Tue Sep 04, 2007 3:43 pm

Post » Sun Nov 18, 2012 9:33 pm

There are a number of ways to do what you want, but all of them are a little involved if you're not an experienced scriptor.

1. Story Manager. Will make your hair bleed when you first attempt to use it, but is probably the easiest way to do what you want.

2. Dynamically Attaching Scripts: There's probably a way to get this to work in your situation, but it is going to be quite involved (if it is actually possible) ... usually this is used to attach scripts to other actors and in-world-objects ... Food Items are a little odd (but it should be possible). I would only use this if the No1 above was no good

3. The method you already identified ... but that means adding scripts to all of the Food Items in game ... And that's quite a bit of editing (and editing vanilla items, which should be avoided if at all possible)


So: Have a butchers at this little lot ... then post for some help ;)

http://www.creationkit.com/Bethesda_Tutorial_Story_Manager - Basic overview ... It's a bit scary ...
http://www.creationkit.com/Category:Story_Manager - More detail and links to all applicable events
http://www.creationkit.com/Player_Add_Item - This is the "Event" you want
User avatar
Claudz
 
Posts: 3484
Joined: Thu Sep 07, 2006 5:33 am

Post » Sun Nov 18, 2012 4:28 pm

I want to make a mod that causes a player to instantly eat certain food upon that food being put in the inventory.

You can create a Quest and an Alias for PlayerRef. Then create a script for this Alias that extends ReferenceAlias, with this code :

Scriptname PlayerAliasScript extends ReferenceAliasActor Property PlayerRef AutoPotion Property Food AutoEVENT OnItemAdded(Form Object, int ObjectCount, ObjectReference ObjectRef, ObjectReference ContainerRef)if ( Object == Food )	 PlayerRef.EquipItem(Food, false, true)endifEndEVENT
User avatar
TIhIsmc L Griot
 
Posts: 3405
Joined: Fri Aug 03, 2007 6:59 pm

Post » Mon Nov 19, 2012 1:50 am

Thanks for the pointers on where to look. I started by trying to implement it through the story manager, considering it was the Player Add Item event that I originally found in the documentation that gave me the first clue on how to do it. I created a quest with an empty first stage, added a script to the quest that extended Quest and caught the Player Add Item event from the story manager, and tried to use the info from that data to get the player to eat any food that came in. However, I could never get my code to be triggered. Maybe I'm getting hung up on what happens when a quest "starts"... the story manager information says that the quests added to an event's tree get "started" when the event happens. I'm not sure if I put the script in an inappropriate place or something: there is a scripts tab in the quest editor that allows you to add scripts, which I added my Quest-extending script to, but I guess I can't tell if that is just some useful repository of scripts used in the various quest stages or what. However I set it up, my quest script was not getting called. Does anyone have any insight into this? Is there a place to put a script to say "you are now active when the quest starts?" that isn't the scripts tab on the far right of the quest editor popup?

Anyways, discouraged that I couldn't get even a message box popping up in response to the story manager events, I went at it the way Voland suggested, creating a script on an alias refing the player. I had a lot of trouble being sure I was refing the player, since looking at the Player actor, it looked like just the dummy debug character, but it seemed to work when I chose a forced alias reference and (this is where I was majorly hung up before) said to look in Cell (all), and the PlayerRef was right up at the top of the filtered list. Sorry if this is obvious to you guys that were helping me, but I thought I would type out my personal experience actually hooking up the suggested solution, in case it might help someone else. I'm not sure if I just haven't found the tutorial examples talking about this class of problem, but I haven't found any examples of referencing the player outside of scripts placed in particular objects in e.g. a new dungeon, where they get some reference from event parameters, not even setting a property to reference the player.

I saw a checkbox to mark the quest as a "startup quest" or something like that... I hope that's the correct way to get the script I wrote listening in on events. I didn't see any evidence of my quest starting, despite adding a log entry for the first stage, but my script was receiving the OnItemAdded events and I got my player eating food right after picking it up now :).
User avatar
Nikki Hype
 
Posts: 3429
Joined: Mon Jan 01, 2007 12:38 pm

Post » Sun Nov 18, 2012 4:24 pm

The way you're doing it is fine - Top job :)
User avatar
Siobhan Wallis-McRobert
 
Posts: 3449
Joined: Fri Dec 08, 2006 4:09 pm


Return to V - Skyrim