Jump to content

[LE] Papyrus RemoveItem() and AddItem() scripting problems


gschenker

Recommended Posts

Hey, folks,

 

I've faced a very annoying problem. I'm just trying to make a script for a dialogue. In this dialogue, my character should have an opportunity for buying a cure disease potion from a priest of Arkay (Styrr) for a fair price, but in the fragment I can't remove the price from character's inventory and I can't add a bottle of a cure disease potion. Normally, payment should need a RemoveItem(Gold001, price) function calling and the taking of a cure disease potion should need an Additem() function. Theoretically, the payment could be work fine by a simply Game.GetPlayer().RemoveItem(Gold001, 50) or a simply Actor type 'akSpeaker', but it doesn't want to work at all. Strangely, I can get the values of the various character properties (for example, the GetGoldAmount() is working fine!) for debugging so I can see these values by the Debug.Notification command, but I can't remove the price of the cure disease potion from the character inventory (RemoveItem) and I can't add to his/her inventory the cure disease potion. Simply these two functions doesn't want to work and I've no idea why. Something was wrong by me and I don't know what's the problem.

 

The script what I'm using is...

;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment
;NEXT FRAGMENT INDEX 2
Scriptname TIF__031351EF Extends TopicInfo Hidden

;BEGIN FRAGMENT Fragment_1
Function Fragment_1(ObjectReference akSpeakerRef)
Actor akSpeaker = akSpeakerRef as Actor
;BEGIN CODE
akSpeaker.RemoveItem(Gold001, 50)
;END CODE
EndFunction
;END FRAGMENT

;END FRAGMENT CODE - Do not edit anything between this and the begin comment

Actor Property PlayerRef Auto
MiscObject Property Gold001  Auto

 

On the 'End' fragment section, I'm using only one command:
akSpeaker.RemoveItem(Gold001, 50)

 

Currently, neither RemoveItem nor AddItem doesn't working at all and I absolutely don't know why. I was looking for some other script fragments on this issue but on the syntax it seems everything to be okay. I was also try to use the Game.GetPlayer().RemoveItem(Gold001, 50) function calling too, but nothing was changed. Simply nothing was happened. There are no errors, no warnings or any kind of informations on the Papyrus log entries...only the meaningless nothing.

 

Could you help me, please? I just can't understand what whas I wrong... :(

Link to comment
Share on other sites

I have a script that removes firewood from the player, only differnce seems like in mine I use an int instead of the exact number, possibly give that a try? So something like this

 

 

;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment
;NEXT FRAGMENT INDEX 2
Scriptname TIF__031351EF Extends TopicInfo Hidden

;BEGIN FRAGMENT Fragment_1
Function Fragment_1(ObjectReference akSpeakerRef)
Actor akSpeaker = akSpeakerRef as Actor
;BEGIN CODE
akSpeaker
.RemoveItem(Gold001, count)
;END CODE
EndFunction
;END FRAGMENT

;END FRAGMENT CODE - Do not edit anything between this and the begin comment

Actor Property PlayerRef Auto
MiscObject Property Gold001 Auto

int Property count = 50 Auto

 

Other than that I don't see any difference really

Link to comment
Share on other sites

Maybe it's a question of "Who is the speaker?". You should use Debug.Trace() to find out, why it does not work as intended.

 

TIF__031351EF

 

;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment
;NEXT FRAGMENT INDEX 2
Scriptname TIF__031351EF Extends TopicInfo Hidden

;BEGIN FRAGMENT Fragment_1
Function Fragment_1(ObjectReference akSpeakerRef)
;Actor akSpeaker = akSpeakerRef as Actor
;BEGIN CODE
IF (akSpeakerRef as Actor == Game.GetPlayer())
    Debug.Trace(self+" Fragment_1: Player is the speaker!")                 ; info only
ELSE
    Debug.Trace(self+" Fragment_1: Speaker is " +akSpeakerRef as Actor)     ; info only
ENDIF
    myF_Action()
;END CODE
EndFunction
;END FRAGMENT
;END FRAGMENT CODE - Do not edit anything between this and the begin comment

 ;Actor Property PlayerRef Auto            ; DO NOT USE !!!
  MiscObject PROPERTY Gold001 auto

;--------------------
FUNCTION myF_Action()
;--------------------
    actor player = Game.GetPlayer()

IF (player.GetItemCount(Gold001) >= 50)
    player.RemoveItem(Gold001, 50)
ELSE
    Debug.Trace(self+" Fragment_1: speaker does not have enough gold!!")
ENDIF
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

Thank you for your quick and useful replies, friends! :)

 

I'll checking and trying all of these possibilites tomorrow. These are very interesting ideas. It is a really annoying problem and I hope it can be resolved. After so many works I don't want to stop my mod. Not yet. Modding in Skyrim SE is so exciting. Tomorrow I'll inform you about the results and, once again, thanks to you all.

Link to comment
Share on other sites

Redragon beat me to it. I was going to ask if you were sure akSpeaker was coming up as the player and not the priest. I'm pretty sure Skyrim dialogue fragments always put the npc you're talking to as the speaker (makes sense since you're always silent). So to deal with the player you either need to just ref the player directly or maybe try akSpeaker.GetDialogueTarget(). Using a debug.trace would be best to figure out if it's the npc or the player though. Player will show up as ID 00000014.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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