Basic additem to player...

Post » Sun Nov 18, 2012 4:41 am

I want my NPC to give the player a bottle of ale through dialog and I have been searching for hours with no luck finding how to do this simple thing. In Oblivion we just added one line 'player.additem etc' in the dialog result box.

Can anyone please tell me how this is done for Skyrim. I am not doing complex quest stages, just a brief dialog exchange with an NPC that results in the player having a bottle of ale added to their inventory. The dialog is all done, I just need to know how to add the ale.
User avatar
Chris Duncan
 
Posts: 3471
Joined: Sun Jun 24, 2007 2:31 am

Post » Sun Nov 18, 2012 10:51 am

Method 1:
actor property player autopotion property ale autoplayer.additem(ale, 1)
This is the correct method but you need to define both player and ale properties in the CK ( select properties and use the selection lists there)


Method 2:
game.getplayer().additem((game.getform(0x00034c53) as potion), 1)

This method is slower and dirtier, but will work without further editting. getplayer is a function that gets the player id and getform gets a form from an exadecimal number.

I recommend you to use the first method, but knowing the second one will help you making tests and could be more useful in rare ocassions.
User avatar
des lynam
 
Posts: 3444
Joined: Thu Jul 19, 2007 4:07 pm

Post » Sun Nov 18, 2012 3:32 am

Thanks!
User avatar
Saul C
 
Posts: 3405
Joined: Wed Oct 17, 2007 12:41 pm

Post » Sun Nov 18, 2012 5:21 am

Method 1:
actor property player autopotion property ale autoplayer.additem(ale, 1)
This is the correct method but you need to define both player and ale properties in the CK ( select properties and use the selection lists there)


Hello there. I don't mean to hijack this thread, but can you explain the first 2 lines defining both player and ale properties? I'm trying to get into scripting, and I can't wrap my head around this part. The player and ale exist, why do they need defining? Why can't we just directly access the player's inventory? I really feel I'm missing a key concept.
User avatar
GLOW...
 
Posts: 3472
Joined: Thu Aug 03, 2006 10:40 am

Post » Sun Nov 18, 2012 4:08 pm

Hello there. I don't mean to hijack this thread, but can you explain the first 2 lines defining both player and ale properties? I'm trying to get into scripting, and I can't wrap my head around this part. The player and ale exist, why do they need defining? Why can't we just directly access the player's inventory? I really feel I'm missing a key concept.
Properties allow scripts easy access to things in the game. While the player and ale do exist, they exist in the game. A script is separated, to a degree, from the game, but the script can interact with the game. Let's say that you used this script instead:

Actor PlayerPotion AlePlayer.Additem(Ale, 1)

What do you have here? You have two variables, Player and Ale. The former accepts objects of the type actor and the latter accepts objects of the type potion. The problem is that these variables have nothing assigned to them, yet. The script doesn't know who Player refers to and what Ale is. The Player variable could be defined as the player character by adding the following line:

Player = Game.GetPlayer()

Actor PlayerPotion AlePlayer = Game.GetPlayer()Player.Additem(Ale, 1)

Now the script knows who to add the item to, but the item is still unknown. We need to find a way to define Ale as the object ale that is found in the game. As amgepo posted earlier, you could use:

game.getform(0x00034c53) as potion

Actor PlayerPotion AlePlayer = Game.GetPlayer()Ale = Game.GetForm(0x00034c53) as potionPlayer.Additem(Ale, 1)

If you use properties, then you can do a few really useful things:
- Write shorter scripts (fewer, or no, things to define in the script itself)
- Easily link variables to things in the game (no need to figure out the FormID)
- Make a single, generally applicable, script that can be used in several instances with the possibility of properties referring to different objects on a case by case basis
User avatar
Guinevere Wood
 
Posts: 3368
Joined: Mon Dec 04, 2006 3:06 pm

Post » Sun Nov 18, 2012 4:22 am

Thanks for the reply. I will have to reread that a few times. A bit tired right now, but you seem to be showing the alternative way to using properties? I want to use the proper syntax and methodology, but I'm still not quite grasping what is happening.

So in
potion property ale auto 

is "ale" the ale in the game? If the ale form info is being pulled from the game, doesn't the game already know it's a potion? I can change ale to nukacola and the script still compiles, so I'm still a bit unclear what the function is here. Why is ale a "property" and not a form? The terminology is perplexing. Properties as I understood in it other programming languages are on the form. For instance if 'potency' was a property of ale and you needed to know it, the syntax might be something like
int x = ale.potency

So maybe I can learn better by example. I added the code to a magic effect script to see if I could get it to work. The script compiles, but desired effect does not happen in game.

Scriptname WabbahackEffectScript extends ActiveMagicEffect  actor property player autopotion property ale autoEvent OnEffectStart(Actor AkTarget, Actor akCaster)	player.additem(ale, 1)	Debug.MessageBox("Was an ale added?")EndEvent

I get the messagebox, but no ale.
User avatar
Davorah Katz
 
Posts: 3468
Joined: Fri Dec 22, 2006 12:57 pm

Post » Sun Nov 18, 2012 12:51 pm

The reason you aren't getting any ale is probably because you haven't defined what Player and Ale refer to in the script's Properties window. You should be able to see a button called Properties in the window where you attach a script to an object. Click that button to open the Properties window and you will get a list of all the properties that you have in the script. You should be able to see that the Default Value of each property is not set to anything. You will have to define values to the properties in order to get the script to work.

As long as the properties haven't been defined properly the script you attached to the magic effect is going to be processed by Papyrus as if the properties were abstract concepts. The properties have nothing to do with anything that exists in game until they have been linked to something in the game.

What I was trying to explain in my previous post was the difference between properties and variables in a script. I apologize if I wasn't being clear about that.


potion property ale auto 

is "ale" the ale in the game?

No. You have a property called Ale, but it could reference any potion in the game.

If the ale form info is being pulled from the game, doesn't the game already know it's a potion?

Depending on the type of property, you might be referring to slightly different things.

Potion Property Ale Auto
would refer to the base object. This will "magically" give you an ale (it won't be taken from somewhere in the game world). This ale exists as a concept until it is materialized as it is added into the game world.

ObjectReference Property Ale Auto
would refer to an instance of a base object. This will give you a specific ale (it will be taken from somewhere in the game world). This ale could be placed in a specific cell and it is this particular bottle of ale that the property refers to.

I can change ale to nukacola and the script still compiles, so I'm still a bit unclear what the function is here.

You are changing what the property is called, not what it references.

Why is ale a "property" and not a form? The terminology is perplexing. Properties as I understood in it other programming languages are on the form. For instance if 'potency' was a property of ale and you needed to know it, the syntax might be something like
int x = ale.potency

I'm not really sure. I also found it befuddling when I started.
User avatar
scorpion972
 
Posts: 3515
Joined: Fri Mar 16, 2007 11:20 am

Post » Sun Nov 18, 2012 8:15 am

Your script does work so I suspect you haven't filled the properties correctly. The only thing i changed in your script was to change player to PlayerRef. This means i can auto-fill the property. I added the script to the magic effect RestoreHealthConcSelf, this was purely for easy of use, as this is the effect which is used in healing, a spell the player starts with.

Apologies if you already know this but i'll do step by step instructions
  • Open up the magic effect that your script is attached to
  • Highlight your script, the properties box (to the right) should become active. Left click on Properties.
  • This opens a box listing your 2 properties, if any of the properties have a value of <>, this means that your property is not filled.
  • Your property Ale should be able to be auto-filled, click on the Auto-Fill box.
  • If you changed Player to PlayerRef, this can also be auto-filled

As such your properties should have their values displaying Ale(00034C5E) and PlayerRef(00000014)
  • If you keep Player, you can't auto-fill this property and it will have to be manually filled.
  • Highlight the Player, click the edit value button.
  • This brings up two drop down boxes, a cell box and a reference box.
  • In the cell box, select (any)
  • In the Reference Box, select PlayerRef('player')
Click OK, and Ok the magic effect, save your mod, and test in game. This should work as long as your magic effect is applied.
User avatar
OnlyDumazzapplyhere
 
Posts: 3445
Joined: Wed Jan 24, 2007 12:43 am

Post » Sun Nov 18, 2012 11:59 am

Brilliant!!! There's a step outside the script to load properties into the script. The script gives the desired effect now, thank you both.

So in the script I posted above, could 'akCaster' be used instead of PlayerRef, eliminating the need to setup the player property externally?

And suppose instead of an ale, I wanted to pick something from a formlist, could I do

property formlist mylist auto
User avatar
Avril Churchill
 
Posts: 3455
Joined: Wed Aug 09, 2006 10:00 am

Post » Sun Nov 18, 2012 3:33 am

So in the script I posted above, could 'akCaster' be used instead of PlayerRef, eliminating the need to setup the player property externally?

Yes. You wouldn't need to declare any properties or variables and link them to the player.

In the case of a formlist the property would be declared thusly:

FormList Property MyList Auto

and of course then point that property at a formlist of your choice. You then need to figure out a way to decide which form you want to use from that list and give it to yourself. For example:

FormList Property MyList Auto ;Your FormListMessage Property Menu Auto ;The menu that will allow you to choose which form you wantEvent OnActivate(ObjectReference akActionRef) ;akActionRef is the player, if he/she has activated the object which sent the OnActivate eventint Choice = Menu.Show() ;An integer variable (Choice) that is assigned a value based on which button you press in the message (Menu)if(Choice == 0) ;You pressed the first button  ;Add the first entry in the list  akActionRef.AddItem(MyList.GetAt(0) as ObjectReference, 1) elseif(Choice == 1) ;You pressed the second button  ;Add the second entry in the list  akActionRef.AddItem(MyList.GetAt(1) as ObjectReference, 1) else ;You pressed the third button  ;Close the menu and do nothing endifEndEvent

This script would require making a new message with the appropriate description and/or labeled buttons.
User avatar
Silvia Gil
 
Posts: 3433
Joined: Mon Nov 20, 2006 9:31 pm

Post » Sun Nov 18, 2012 12:44 pm

So helpful! Thank you.
User avatar
DAVId Bryant
 
Posts: 3366
Joined: Wed Nov 14, 2007 11:41 pm


Return to V - Skyrim