Jump to content

Having a simple scripting issue....


markyrocks

Recommended Posts

So the main issue is I'm trying to force 2x reference aliases to an existing ref. Im basing my code for that off of a script that exists in the game, its actually the script that is supposed to actually do what im trying to do. But forget about that for a moment.

 

Im attempting to use an onadditem event to encapsulate the Alias.ForceRefTo(Ref) ect bc its not working in the custom function i made. So here is the very simple code that i can't even get to fire off and event.

this code is attached to a script that is attached to the robot workbench that i made.

Scriptname RobotTerminalScript extends ObjectReference

Quest Property DLC01MQ02 Auto Const

Event OnLoad()
 AddInventoryEventFilter(None)
   _Reg()
    debug.notification("onloadevent") ;this fires fine.... goes from here to the function _Reg()
EndEvent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
  debug.notification("itemadded event")   ;no matter what i do this notification doesn't fire....
endEvent

function _Reg()

    RegisterForRemoteEvent(Game.GetPlayer(), "OnItemAdded")
    debug.notification("_Reg()")    ;I get this notification fine so it makes it into here....
endfunction

so i can take items out of the workbench, drop items on the ground pick them up. the robotworkbench i made even adds an empty whiskey bottle into my inventory .... the notification never pops up.

 

Thats the first issue that is a result of the following problem.

 

 

So my robot workbench is a terminal that when i button is pressed it sets a quest stage and that stage calls a function in the attached script that mainly uses AttachMod(mod). That all works great.

 

Im trying to make jezebel magically appear during the DLC01 main quests. So i basically spawn and automatron. then under my quest section in the terminal jezebels head shows up. when you press the button to attach the head. I Make my custom function Automatron.AttachMod(jezebelHead) then in the following line i Alias.forceRefTo(automatron) theres 2 different aliases so i force both of them. Nothing happens except the head is attached...

 

this is the relevant code that the game is supposed to use to do this and this is what im basing what im trying to do off of...

Scriptname DLC01:MQ04QuestScript extends Quest

Quest Property DLC01MQ04 Auto Const
ReferenceAlias Property Alias_DLC01MQ04JezebelBuilt Auto Const
ReferenceAlias Property Alias_DLC01MQ04JezebelBuiltEssential Auto Const
ObjectMod Property DLC01Bot_Head_RoboBrain_Jezebel Auto Const

;This portion of the script looks for the construction of Jezebel at a Robot Workbench
Event OnInit()
	RegisterForRemoteEvent(Game.GetPlayer(), "OnPlayerModRobot")
	Debug.trace(self + "Robot Event Started")
EndEvent

Event Actor.OnPlayerModRobot(Actor akSender, Actor akRobot, ObjectMod akModBaseObject)
	Debug.trace(self + "Player modified robot")
	If akModBaseObject == DLC01Bot_Head_RoboBrain_Jezebel
		Debug.trace(self + "Jezebel Alias Filled")
		Alias_DLC01MQ04JezebelBuilt.ForceRefTo(akRobot)
		Alias_DLC01MQ04JezebelBuiltEssential.ForceRefTo(akRobot)
		Debug.trace(self + "Set done stage")
		DLC01MQ04.SetStage(200)

		;disallow companion status
		akRobot.DisallowCompanion(SuppressDismissMessage = true)		

	Endif
EndEvent

I would love to use the OnPlayerModRobotEvent but it doesn't appear that my workbench fires that event? at this point im like event impotent, i can't get any events to fire. which is really frustrating considering i already had working examples for additem events already written and commented out in my script and for whatever reason nothing is working for me now.

Link to comment
Share on other sites

if i add this to the script attached to the automatron it works , it just only fires when an item is added to the automatron despite the remote registration.

Scriptname BotScript extends Actor Const


Event Oninit()
AddInventoryEventFilter(None)
RegisterForRemoteEvent(Game.GetPlayer(), "OnItemAdded")
endevent


Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  Debug.Notification("OnItemaddedevent...")
endEvent


Edited by markyrocks
Link to comment
Share on other sites

ok i think i got it working. I just attached a script to the automatron itself and i'm going to have to use some kinda event to make it work as intended but forcing the ref alias over the oninit event works as long as the quest in question is in the proper stage. I wanted to avoid using all these different scripts i like to try to quarterback everything from one main script if i can but i guess the events i was trying to use just don't work unless the script extends actor. The OnPlayerModRobot event still doesn't fire but thats expected. its just very frustrating when i've been trying to get this to work for like....10 hours now...at least i got something going in the right direction.... gawd

Edited by markyrocks
Link to comment
Share on other sites

 

Scriptname RobotTerminalScript extends ObjectReference

Quest Property DLC01MQ02 Auto Const

Event OnLoad()
 AddInventoryEventFilter(None)
   _Reg()
    debug.notification("onloadevent") ;this fires fine.... goes from here to the function _Reg()
EndEvent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
  debug.notification("itemadded event")   ;no matter what i do this notification doesn't fire....
endEvent

function _Reg()

    RegisterForRemoteEvent(Game.GetPlayer(), "OnItemAdded")
    debug.notification("_Reg()")    ;I get this notification fine so it makes it into here....
endfunction
so i can take items out of the workbench, drop items on the ground pick them up. the robotworkbench i made even adds an empty whiskey bottle into my inventory .... the notification never pops up.

 

Thats the first issue that is a result of the following problem.

 

<snip>

 

The way you've got it written, the script registers for a remote event on the player. It has no local event declared to capture the call back. The event you have defined is for adding an item to the object that has the script attached to it. Not the player.

 

You have to create the callback using the type of remote trigger. In this case an ObjectReference event is being used. The first argument will also need to be added which is the calling target who's event it's from. You need to have

 

Event ObjectReference.OnItemAdded(ObjectReference akSource, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    ; put callback code here to handle when the remote target gets an item
    Debug.Trace("The item " + akBaseItem + " was added to " + akSource)
EndEvent
Edited by BigAndFlabby
Link to comment
Share on other sites

 

 

The way you've got it written, the script registers for a remote event on the player. It has no local event declared to capture the call back. The event you have defined is for adding an item to the object that has the script attached to it. Not the player.

 

You have to create the callback using the type of remote trigger. In this case an ObjectReference event is being used. The first argument will also need to be added which is the calling target who's event it's from. You need to have

 

Event ObjectReference.OnItemAdded(ObjectReference akSource, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    ; put callback code here to handle when the remote target gets an item
    Debug.Trace("The item " + akBaseItem + " was added to " + akSource)
EndEvent

that makes perfect sense. just been awhile since i had to mess with these events. Just when i think i have a good grasp on whats going on with papyrus it always finds a way to throw me a curve ball. But thankyou i definitely appreciate it. I kinda got that impression that the object that the script was attached to was what was being registered for the events and not the player when i put an even simplier version of the script on a robot and it was the object that was fireing the event i just couldn't wrap my mind around how to make the player the target even though the game.getplayer() was being used in the registration. I guess adding the objectreference. in front of the event name i guess separates the event from the object that the script is attached to?

Link to comment
Share on other sites

Event objectType.EventName, where objectType, is the calling object for the event. The player(GetPlayer()) returns the actor reference of the player(xxxxxx14), and actor references are children of the ObjectReference(casting is not necessary for any function that doesn't explicitly ask for actor calling objects). When adding GetPlayer into the Register function, the ObjectReference.OnItemAdded event will fire for the player because it is the calling object for the remove event.

 

 

I hope that helps understanding this a little more.

Edited by Rasikko
Link to comment
Share on other sites

Thanks, I was tired when I was doing that. I figured out a different work around and added additional safety checks to make sure what I wanted to happen was the only available outcome.

I got the drift that adding objectreference. Points the event at the object in the registration rather than without it the event defaults to the object the script is attached to.

 

I don't remember having to do that b4 in my previous tests it seemed to work for whatever reason but I must of just got lucky somehow.

 

I definitely appreciate all the help guys, I'm in the process of doing my final playthrough and I'll be releasing today. Idk how popular this fix will be but I know I've seen some people asking for it and I know it was something I personally wanted. Its not perfect but literally it's way better than what the previous outcome was for players of the vr version which was totally broken and even creating a new automatron was a guaranteed crash.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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