Jump to content

G.E.C.K. Scripting - AddItem From Variable


ZephyrWarrior

Recommended Posts

Hey, so, I'm not sure where to post this, but this seemed like the most applicable subreddit.

I'm trying to make a G.E.C.K. script accept a variable to add items to that player (or anyone)'s inventory. My goal is to accomplish this without having lengthy if statements checking against a numerical variable, for example "If var == 1, add item x. If var == 2, add item y." etc. Ideally it would just be "player.additem var #".

Examples of things I've tried:

ref ActiveTech
set ActiveTech to 6b465
player.additem ActiveTech 1

This did not error out, but did not work either.

ref ActiveTech
set ActiveTech to ArmorTeslaHelmet
player.additem ActiveTech 1

This did not error out, but did not work either.

(Other script)

ref ActiveTech

(This Script)

set FFOutcasts.ActiveTech to 6b465
player.additem FFOutcasts.ActiveTech 1

"Reference not allowed in this context."

(Other script)

ref ActiveTech

(This Script)

set FFOutcasts.ActiveTech to ArmorTeslaHelmet
player.additem FFOutcasts.ActiveTech 1

"Reference not allowed in this context."

It's entirely possible I'm just being stupid. I'm not a scripting novice, but I am relatively new to the G.E.C.K.

Any help would be greatly appreciated.

Link to comment
Share on other sites

ref ActiveTech
set ActiveTech to ArmorTeslaHelmet
player.additem ActiveTech 1

​That one should work. If it doesn't, I'd say the problem comes from somewhere else. Maybe the script is crashing at some point before that line runs or something else like bad logic is making it skip that line altogether.

​EDIT: I'm assuming you're using the EditorID of the item, if you're not you have to make sure you do. Those Reference not allowed in this context errors typically mean that you're using a reference as a parameter where you should be using an ObjectID/EditorID/Base Object (whatever you wanna call it).

Edited by claustromaniac
Link to comment
Share on other sites

I'm using a reference variable, but it is pointing to the base item. The reason I need to use a variable as a parameter is because I only want one topic for a "How many would you like to give?" topic, and use it for multiple items, with the item defined in the previous topic.

ref ActiveTech
set ActiveTech to ArmorTeslaHelmet
player.additem ActiveTech 1

Is literally the whole script in that case. It was a simple test script I hooked onto a basic conversation, to test the logic. It doesn't give any errors in the G.E.C.K. or in game, it simply doesn't trigger. If I hook "player.additem ArmorTeslaHelmet 1" into the same line, it triggers fine and gives me a Tesla Helmet.

 

In the latter ones where I used a variable embedded in the "FFOutcastsSCRIPT" script, which is tied to the quest (FFOutcasts.ActiveTech), that does give errors in the G.E.C.K.

Edited by ZephyrWarrior
Link to comment
Share on other sites

Assigning a base object to a reference variable only works with FOSE/NVSE. The vanilla script engine won't give you a compiler warning if you do this, but it won't work either.

 

Of course! It must be that. I'm so used to FOSE/NVSE that that thought never dared to cross my mind :laugh:

 

In case you have NVSE installed but don't know how to run the GECK with it, these are the instructions included in the readme:

 

Scripts written with these new commands must be created via the G.E.C.K. after it is launched via nvse_loader. Open a command prompt window, navigate to your NV install direcory, and type "nvse_loader -editor". Alternately you can create a shortcut to nvse_loader.exe, open the properties window and add "-editor" to the Target field. The normal editor can open plugins with these extended scripts, but it cannot recompile them and will give errors if you try.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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