Jump to content

Scripting Question


David Brasher

Recommended Posts

How do you say the following in Papyrus?

 

SCN AAFoundTheObject 

; Object script attached to the item you must find to advance the quest stage.

Begin OnAdd
    SetStage AAQuest 15
End

Link to comment
Share on other sites

ScriptName AAFoundTheObject extends ObjectReference

Quest Property AAQuest Auto

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
if (akNewContainer == Game.GetPlayer())
	AAQuest.SetStage(15)
endif
EndEvent

Link to comment
Share on other sites

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
 if akBaseItem == DavidsItem
      AAQuest.SetStage(15)
 endIf
endEvent

Since this is for a quest add the player as an alias and attach the script to the player alias.

Link to comment
Share on other sites

I am sorry, but I don't speak Papyrus well. This script has more unknown variables than known words in it. How would I go about substituting things from my mod in place of the unknown variables?

 

Form == Self? (Is there a way to refer to self when the script is attached to self?)

akBaseItem == Form?

akBaseItem != Form?

Form akBaseItem, == 1 item such as AABook?

Form akBaseItem, == 2 items? ( I don't think so. That does not seem right. How could there be 2 items?)

Form == akBaseItem? (Maybe that is what you are trying to say.)

Form == Lua property type?

int == Lua property type?

ObjectReference == Lua property type?

ak == AKA?

DavidsItem == ?

if akBaseItem == if akBaseItem [implied and unwritten integer 1]?

ObjectReference akItemReference, == optional and not required in every event statement?

ObjectReference akItemReference, == mandatory and not required in every event statement?

ObjectReference akOldContainer == optional and not required in every event statement?

ObjectReference akOldContainer == mandatory and not required in every event statement?

 

Is there a way to write the script with less placeholders and more real world code?

 

When reading example scripts in the wiki and elsewhere, how do you distinguish placeholder words from real words that can be used in scripts that compile and function?

Edited by David Brasher
Link to comment
Share on other sites

Well lets look at the first line. Reference Link

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

The event determines when the methods inside the event are allowed to run. In this case, when an item is added to the container this script is attached to.

The next bit is this events parameters and are defined as follows.

akBaseItem: The base object for the item that was added to this container.

aiItemCount: The number of items added to this container.

akItemReference: The specific reference added to the container, if any. Will be None if a non-persistant object is added.

akSourceContainer: The container that the object(s) came from. If None, then the object came from the world.

 

This next line is saying, if the item added is the item you were looking then do the stuff inside this if.

if akBaseItem == DavidsItem
      AAQuest.SetStage(15)

 

You will need to add two properties at least to this script one for the quest and one for the item.

Quest Property AAQuest Auto
MiscObject Property DavidsItem Auto ;object type may be different in your case. Im just guessing your quest item is a Misc Item

 

Once you have declared your properties you need to fill them will data from your plugin. Save and close your script. Look at the panel you add scripts and highlight your script > properties button. If your properties has the exact same name as the editor id your trying to attach it to you can auto fill them. If not you have to edit the value your self.

Link to comment
Share on other sites

What if the item is loose in the world and is not in a container? (It is laying on the ground in a dungeon.)

Actually, OnContainerChanged will fire whenever akNewContainer != akOldContainer. So if it was picked up by the player, or added through a scripting command, it will fire with akOldContainer = None.

Link to comment
Share on other sites

@ scrivener07

 

Having semantic difficulties. You are a genius, but I have a learning disability and couldn't pass algebra.

 

The event determines when the methods inside the event are allowed to run.

 

What is a "method" when used in this sense of the word?

 

The next bit is this events parameters and are defined as follows.

 

Events are like Begin **** blocks. Parameters? Parameters can be like a range of numbers or the design specifications of something, but what are "events parameters?" Event's parameters? Events' parameters?

 

Maybe this would imply that things with the ak- and ai- prefixes are placeholders and never appear in real scripts after all the blanks are filled in, but this theory is not born out by the next line of code:

if akBaseItem == DavidsItem

 

But maybe you are using akBaseItem as a placeholder rather than a word in a finished script that can be compiled and run.

 

I know how to set up properties and assign values to them, but often can not figure out which scripts will want to know about which properties.

 

I have great difficulty reading the wiki. The examples are terrible. If I were writing a wiki article on how to speak English, I might write an example sentence like:

The brown cow jumped over the short fence clumsily.

 

I would never write an example sentence like:

Article adjective noun verb (tense historical) preposition article modifier (adjective) noun adverb full stop

 

How could anyone ever learn English reading an example like that?

Edited by David Brasher
Link to comment
Share on other sites

Well heres a good example of a script where I used an events parameters a lot. This script is attached to a container so it will only accept certain items.

 

Scriptname ExampleContainerScript extends ObjectReference  

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
akSourceContainer = Game.GetPlayer() ;Let the event know this only applies when the player is the source. If I left this none the source could be anything.

If (akBaseItem !=  ITEM1) ;when the event fired akBaseItem stored the baseid of the triggering item
	If (akBaseItem !=  ITEM2) ;So Im going to check the akBaseItem to make sure it isnt the item I want to reject
		If (akBaseItem !=  ITEM3)
			Self.RemoveItem(akBaseItem, aiItemCount, True) ;"Self" is the object this script is attached to.
			Game.GetPlayer().Additem(akBaseItem, aiItemCount, True) ;I can use akBaseItem to give whatever item was added right back the the player and aiItemCount to return the same amount back.
			Debug.Notification("Invaild Item")
		Endif
	Endif
EndIf

EndEvent
MiscObject Property ITEM1  Auto  ;Gold
MiscObject Property ITEM2  Auto  ;BearPelt
MiscObject Property ITEM3  Auto  ;GasCan

 

Keep in mind normal function take parameters too. Look at AddItem() formally AddItem(Form akItemToAdd, int aiCount = 1, bool abSilent = false).

 

Dont think to hard about this but events and functions are almost identical.

 

Eh, Dont worry about methods. I dont think thats what its even called in papyrus.

Link to comment
Share on other sites

@scrivener07

 

I noticed you put that up on the wiki's example scripts. I tried to change it but you changed it right back. :turned:

 

Anyway, that first line should be

 

if (akSourceContainer == Game.GetPlayer())

otherwise you're just assigning the player to the akSourceContainer variable.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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