Jump to content

[LE] Script help


Recommended Posts

I have a decent amount of scripting experience with Oblivion's construction kit, but it seems that the Skyrim Creation kit is VERY different. I have been trying to make a script that makes it so if a certain item is added to the player's inventory inventory, an NPC should be placed at them and the item should then be removed from their inventory. The item that should trigger should be the item I gave the script. This is what I tried:


Scriptname HireSoldierScript extends ReferenceAlias


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


Game.GetPlayer().PlaceAtMe(1NPCCastleGuard)


Game.GetPlayer().RemoveItem(NoteHireSoldier)


EndEvent


Nothing happens when I add the item to myself though. Does anyone know what I'm doing wrong?

Edited by CakeBandit
Link to comment
Share on other sites

Helpful hint (from personal experience!); paste the entire code of your script.

 

For example, perhaps you are missing (or have incorrectly defined) Properties at the beginning of your script. Also, you need to make sure to fill your properties (link them to the references in the CK).

Link to comment
Share on other sites

Sounds like you gonna need a script that checks if the item is present then if it returns true executes the rest this though instead of onitemadd i think it should be onit() attached to a ques. Firstly define the actorbase property 1npccastleguard at the top of the script under the name and what it extends which in this case looks to be either object reference if u activate manually or quest if its on game load registering for updates to keep check. The npte assuming is either a misc item or book needs to be defined as either book property or miscobject property umm id probley attach that to a misc object and run a event onequipped and save myself the trouble of all that extra stuff. Then after the onequipped add a unequipped event and put 1npccastleguard.delete() i believe
Link to comment
Share on other sites

Helpful hint (from personal experience!); paste the entire code of your script.

 

For example, perhaps you are missing (or have incorrectly defined) Properties at the beginning of your script. Also, you need to make sure to fill your properties (link them to the references in the CK).

I've edited my post to include everything.

 

 

Sounds like you gonna need a script that checks if the item is present then if it returns true executes the rest this though instead of onitemadd i think it should be onit() attached to a ques. Firstly define the actorbase property 1npccastleguard at the top of the script under the name and what it extends which in this case looks to be either object reference if u activate manually or quest if its on game load registering for updates to keep check. The npte assuming is either a misc item or book needs to be defined as either book property or miscobject property umm id probley attach that to a misc object and run a event onequipped and save myself the trouble of all that extra stuff. Then after the onequipped add a unequipped event and put 1npccastleguard.delete() i believe

I can't say I'm too sure what you are talking about. What do you mean by "onit() attached to a ques"?

Link to comment
Share on other sites

@CakeBandit

Oblivion scripting, as I understand it, allowed you to simply use an object's Editor ID name and the script would work. Skyrim scripting is different. The scripts have been separated from the ESP and as a result do not know what is in your plugin (or any plugin) without you expressly telling it. The way to tell it is to create properties on the script and then assign the correct data to those properties via the property button that is available on the object with the script attached.

 

Example:

You've created an alias for a note on a quest and you've added a script to this alias. You want this script to spawn an NPC at the player's location and remove the note at the same time.

 

 

Scriptname HireSoldierScript extends ReferenceAlias
{Alias script for a note, remove note when added to player}

Actor Property NPCCastleGuard1 Auto
{Assign the actor record of the NPC in question}
 
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
	If akNewContainer == Game.GetPlayer()
		ActorBase NPCGuard = NPCCastleGuard1.GetBaseObject() as ActorBase
		akNewContainer.PlaceActorAtMe(NPCCastleGuard1,4,None)
		akNewContainer.RemoveItem(Self,1)
	EndIf
EndEvent

NOTE: It may be necessary to get Self (the note) into its actual reference rather than the reference alias. If that is the case, replace Self with Self.GetReference()

 

However, the player may not get the chance to actually read the note. Thus you may wish to use the OnRead event instead. Reading by default pauses time and thus delays the script from processing until the player closes the book/note. Script would appear more like:

 

 

Scriptname HireSoldierScript extends ReferenceAlias
{Alias script for a note, remove note when read by player}

Actor Property NPCCastleGuard1 Auto
{Assign the actor record of the NPC in question}
 
Event OnRead()
	Actor PlayerRef = Game.GetPlayer()
	ActorBase NPCGuard = NPCCastleGuard1.GetBaseObject() as ActorBase
	PlayerRef.PlaceActorAtMe(NPCCastleGuard1,4,None)
	PlayerRef.RemoveItem(Self,1)
EndEvent 

NOTE: It may be necessary to get Self (the note) into its actual reference rather than the reference alias. If that is the case, replace Self with Self.GetReference()

Side note: Do not start variable names with a digit. Papyrus has trouble with those. It tries to use them as a number instead of a variable name. Instead if you need a numbered variable put the number at the end.

Link to comment
Share on other sites

  • 1 month later...

@CakeBandit

Oblivion scripting, as I understand it, allowed you to simply use an object's Editor ID name and the script would work. Skyrim scripting is different. The scripts have been separated from the ESP and as a result do not know what is in your plugin (or any plugin) without you expressly telling it. The way to tell it is to create properties on the script and then assign the correct data to those properties via the property button that is available on the object with the script attached.

 

Example:

You've created an alias for a note on a quest and you've added a script to this alias. You want this script to spawn an NPC at the player's location and remove the note at the same time.

 

 

Scriptname HireSoldierScript extends ReferenceAlias
{Alias script for a note, remove note when added to player}

Actor Property NPCCastleGuard1 Auto
{Assign the actor record of the NPC in question}
 
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
	If akNewContainer == Game.GetPlayer()
		ActorBase NPCGuard = NPCCastleGuard1.GetBaseObject() as ActorBase
		akNewContainer.PlaceActorAtMe(NPCCastleGuard1,4,None)
		akNewContainer.RemoveItem(Self,1)
	EndIf
EndEvent

NOTE: It may be necessary to get Self (the note) into its actual reference rather than the reference alias. If that is the case, replace Self with Self.GetReference()

 

However, the player may not get the chance to actually read the note. Thus you may wish to use the OnRead event instead. Reading by default pauses time and thus delays the script from processing until the player closes the book/note. Script would appear more like:

 

 

Scriptname HireSoldierScript extends ReferenceAlias
{Alias script for a note, remove note when read by player}

Actor Property NPCCastleGuard1 Auto
{Assign the actor record of the NPC in question}
 
Event OnRead()
	Actor PlayerRef = Game.GetPlayer()
	ActorBase NPCGuard = NPCCastleGuard1.GetBaseObject() as ActorBase
	PlayerRef.PlaceActorAtMe(NPCCastleGuard1,4,None)
	PlayerRef.RemoveItem(Self,1)
EndEvent 

NOTE: It may be necessary to get Self (the note) into its actual reference rather than the reference alias. If that is the case, replace Self with Self.GetReference()

Side note: Do not start variable names with a digit. Papyrus has trouble with those. It tries to use them as a number instead of a variable name. Instead if you need a numbered variable put the number at the end.

Sorry for taking so long to respond, thank you.

 

I tried the second one but I got an error: type mismatch on parameter 1. I got this error twice. I thought it was because the PlaceActorAtMe should be NPCGuard since NPCCastleGuard1 is not an actor base. Changing that got rid of one error but not the other one.

 

I assume the other error is because the Self parameter on the line "PlayerRef.RemoveItem(Self,1)" but I have no clue why that doesn't work. Any ideas?

 

I tried it without the remove line and it didn't work. Not sure how to debug this.

Edited by CakeBandit
Link to comment
Share on other sites

 

@CakeBandit

Oblivion scripting, as I understand it, allowed you to simply use an object's Editor ID name and the script would work. Skyrim scripting is different. The scripts have been separated from the ESP and as a result do not know what is in your plugin (or any plugin) without you expressly telling it. The way to tell it is to create properties on the script and then assign the correct data to those properties via the property button that is available on the object with the script attached.

 

Example:

You've created an alias for a note on a quest and you've added a script to this alias. You want this script to spawn an NPC at the player's location and remove the note at the same time.

 

 

 

Scriptname HireSoldierScript extends ReferenceAlias
{Alias script for a note, remove note when added to player}

Actor Property NPCCastleGuard1 Auto
{Assign the actor record of the NPC in question}
 
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
	If akNewContainer == Game.GetPlayer()
		ActorBase NPCGuard = NPCCastleGuard1.GetBaseObject() as ActorBase
		akNewContainer.PlaceActorAtMe(NPCCastleGuard1,4,None)
		akNewContainer.RemoveItem(Self,1)
	EndIf
EndEvent
NOTE: It may be necessary to get Self (the note) into its actual reference rather than the reference alias. If that is the case, replace Self with Self.GetReference()

 

However, the player may not get the chance to actually read the note. Thus you may wish to use the OnRead event instead. Reading by default pauses time and thus delays the script from processing until the player closes the book/note. Script would appear more like:

 

 

Scriptname HireSoldierScript extends ReferenceAlias
{Alias script for a note, remove note when read by player}

Actor Property NPCCastleGuard1 Auto
{Assign the actor record of the NPC in question}
 
Event OnRead()
	Actor PlayerRef = Game.GetPlayer()
	ActorBase NPCGuard = NPCCastleGuard1.GetBaseObject() as ActorBase
	PlayerRef.PlaceActorAtMe(NPCCastleGuard1,4,None)
	PlayerRef.RemoveItem(Self,1)
EndEvent 
NOTE: It may be necessary to get Self (the note) into its actual reference rather than the reference alias. If that is the case, replace Self with Self.GetReference()

 

 

Side note: Do not start variable names with a digit. Papyrus has trouble with those. It tries to use them as a number instead of a variable name. Instead if you need a numbered variable put the number at the end.

Sorry for taking so long to respond, thank you.

 

I tried the second one but I got an error: type mismatch on parameter 1. I got this error twice. I thought it was because the PlaceActorAtMe should be NPCGuard since NPCCastleGuard1 is not an actor base. Changing that got rid of one error but not the other one.

 

I assume the other error is because the Self parameter on the line "PlayerRef.RemoveItem(Self,1)" but I have no clue why that doesn't work. Any ideas?

 

I tried it without the remove line and it didn't work. Not sure how to debug this.

playerref.removeitem(saiditem, 1) may have something to do with it. I always use a space between the comma and #. Unless said item dont have a property yet.
Link to comment
Share on other sites

 

@CakeBandit

Oblivion scripting, as I understand it, allowed you to simply use an object's Editor ID name and the script would work. Skyrim scripting is different. The scripts have been separated from the ESP and as a result do not know what is in your plugin (or any plugin) without you expressly telling it. The way to tell it is to create properties on the script and then assign the correct data to those properties via the property button that is available on the object with the script attached.

 

Example:

You've created an alias for a note on a quest and you've added a script to this alias. You want this script to spawn an NPC at the player's location and remove the note at the same time.

 

 

Scriptname HireSoldierScript extends ReferenceAlias
{Alias script for a note, remove note when added to player}

Actor Property NPCCastleGuard1 Auto
{Assign the actor record of the NPC in question}
 
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
	If akNewContainer == Game.GetPlayer()
		ActorBase NPCGuard = NPCCastleGuard1.GetBaseObject() as ActorBase
		akNewContainer.PlaceActorAtMe(NPCCastleGuard1,4,None)
		akNewContainer.RemoveItem(Self,1)
	EndIf
EndEvent

NOTE: It may be necessary to get Self (the note) into its actual reference rather than the reference alias. If that is the case, replace Self with Self.GetReference()

 

However, the player may not get the chance to actually read the note. Thus you may wish to use the OnRead event instead. Reading by default pauses time and thus delays the script from processing until the player closes the book/note. Script would appear more like:

 

 

Scriptname HireSoldierScript extends ReferenceAlias
{Alias script for a note, remove note when read by player}

Actor Property NPCCastleGuard1 Auto
{Assign the actor record of the NPC in question}
 
Event OnRead()
	Actor PlayerRef = Game.GetPlayer()
	ActorBase NPCGuard = NPCCastleGuard1.GetBaseObject() as ActorBase
	PlayerRef.PlaceActorAtMe(NPCCastleGuard1,4,None)
	PlayerRef.RemoveItem(Self,1)
EndEvent 

NOTE: It may be necessary to get Self (the note) into its actual reference rather than the reference alias. If that is the case, replace Self with Self.GetReference()

Side note: Do not start variable names with a digit. Papyrus has trouble with those. It tries to use them as a number instead of a variable name. Instead if you need a numbered variable put the number at the end.

Sorry for taking so long to respond, thank you.

 

I tried the second one but I got an error: type mismatch on parameter 1. I got this error twice. I thought it was because the PlaceActorAtMe should be NPCGuard since NPCCastleGuard1 is not an actor base. Changing that got rid of one error but not the other one.

 

I assume the other error is because the Self parameter on the line "PlayerRef.RemoveItem(Self,1)" but I have no clue why that doesn't work. Any ideas?

 

I tried it without the remove line and it didn't work. Not sure how to debug this.

 

 

That's because your self, in that script, is the ReferenceAlias. RemoveItem is expecting a Form, which nearly everything has as a base type; ReferenceAliases are one of the few exceptions. The Form you plug into the first parameter is the item that should be removed, the second parameter is how many of that to take out. If this script is attached to an alias pointing at the note, you want to use "PlayerRef.RemoveItem(Self.GetReference().GetBaseObject(), 1)" instead, or, alternatively and probably a better option, store the base form in a property and use that.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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