Help: simple Additem script within MagicEffect

Post » Sun Nov 18, 2012 9:26 pm

I want to make a basic script that adds an item to the players inventory.
I have two questions

1) Why is my current code not running (it is compiling, and I can confirm the event is firing)
Here is my broken code

Scriptname MySummonScript extends activemagiceffectEvent onEffectStart(Actor akTarget, Actor akCaster)	 Game.getPlayer().additem((Game.GetForm(0x0002f2f4) As ObjectReference).GetBaseObject(), 1)endEvent


Actual runnable code that will add an item in a similar fashion (via a magicEffect) would be greatly appreciated.

I realize there are things that need to be changed (Game.getPlayer() to aKTarget for ex) but i'm just using this as a simple test.

Other info:
For the MagicEffect magicEffectArchetype i'm using script
With debug.messageBox from within effectStart I can confirm the method is called.

I understand (and have implemented) a bound weapon duplicate would fix this for this particular item (woodcutter's axe) without the need for a script but i wanted a general solution that could work with a formlist later.


2) How do I know which item id i want to pass to Game.getForm, and how do I pass it appropriately?

I've noticed the hex codes that appear in the creation kit are the same as are used in the console to add an item/spell/etc
if I were to create a custom item and then have it be added via this script how would i reference it appropriately.

What I'm worried about is if I hardcode the item id or even create a property within the script and hardcode the hex code (as an int) within the edit properties dialog that it would run fine on my computer, but if I ever published this mod or even tried to run it on another computer later that same hexcode may have been used by some other mod and I would add an incorrect item, CTD, or just fail. How do I essentially say MyEsp.getForm( uniqueItemId ).
Should I not be using itemids at all?

Thx
User avatar
cutiecute
 
Posts: 3432
Joined: Wed Sep 27, 2006 9:51 am

Post » Sun Nov 18, 2012 8:58 pm

Is there a specific reason you are using the Hex code at all? Why not just create a property pointing to the item you want to add to the player's inventory instead? Hugely simpler.
User avatar
Jennifer May
 
Posts: 3376
Joined: Thu Aug 16, 2007 3:51 pm

Post » Sun Nov 18, 2012 3:40 pm

ScriptName MySummonScript Extends ActiveMagicEffectActor Property PlayerREF Auto ; 10^3 times faster than Game.GetPlayer()Weapon Property Axe01 Auto ; Skip the GetForm and just point to the item. Casting was unnecessary.Event OnEffectStart(Actor akTarget, Actor akCaster)	 PlayerREF.AddItem(Axe01)EndEvent
User avatar
Roberto Gaeta
 
Posts: 3451
Joined: Tue Nov 06, 2007 2:23 am

Post » Sun Nov 18, 2012 10:24 pm

Is there a specific reason you are using the Hex code at all? Why not just create a property pointing to the item you want to add to the player's inventory instead? Hugely simpler.

My understanding is that when setting the object in the properties dialog I have to actually choose an item that exists in the game as it requires a cell and reference input. I wanted to
A) not have to add an item physically in the world, and
B) not necessarily call the same object each time, but a new one.

If i'm mistaken about how that works I'd be happy to implement it given a concrete example/what specifically is incorrect about my above assumptions.
User avatar
Jah Allen
 
Posts: 3444
Joined: Wed Jan 24, 2007 2:09 am

Post » Sun Nov 18, 2012 7:46 pm

You are mistaken. Any base object can be defined as a property of your script. It is not reserved for only placed references of the object.

JustinOther provided an example of the script using properties.
User avatar
Pants
 
Posts: 3440
Joined: Tue Jun 27, 2006 4:34 am

Post » Sun Nov 18, 2012 4:54 pm

ScriptName MySummonScript Extends ActiveMagicEffectActor Property PlayerREF Auto ; 10^3 times faster than Game.GetPlayer()Weapon Property Axe01 Auto ; Skip the GetForm and just point to the item. Casting was unnecessary.Event OnEffectStart(Actor akTarget, Actor akCaster)	 PlayerREF.AddItem(Axe01)EndEvent

I didn't realize you could create an Weapon property directly I had been using ObjectReference
Just tried it, works beautifully thanks.
User avatar
Farrah Lee
 
Posts: 3488
Joined: Fri Aug 17, 2007 10:32 pm


Return to V - Skyrim

cron