Quick one: OnActivate - yes; OnGrab - no

Post » Sun Nov 18, 2012 9:09 am

Hi,

I was scripting veeery long ago for TES 4 and kinda lost the hang of it, now that it is all fancy and object orientated and all.

Im trying to get a extremely simple test script running and fail miserably.

Here is what I got:
Scriptname _WOSTest1 extends ObjectReference;defining variablesint valxint valy;some serious stuff going on hereEvent OnActivate(ObjectReference akActionRef)valx = utility.RandomInt( -8 , 5 )valy = utility.RandomInt( -30 , 20 )Debug.MessageBox(valx)Debug.MessageBox(valy)endEvent

Now my questions is:
actually I applied that script onto a dagger which I have created for test purposes.
I am pretty sure I am doing it wrong at that part already. I just duplicated the good ol' iron dagger and applied the script to it.
Now the compiler lets me use "OnActivate" but not something like "OnGrab" or "OnItemAdded" and I do not really understand why.
Since "one does not simply activate an iron dagger" ... I am not sure what to do.

In that simple first tutorial the script was applied onto an object which was already in the world somewhere, so there was a real reference.
In my case, I just want to summon that dagger into my inventory and want to see that two debug messages with two random values.
Now I am not sure how to get that reference for the dagger.
Since I am only able to call stuff like "OnItemAdded" as part of an event, I am not sure how to point to a real reference BEFORE opening an event...
Thats like having a chicken before the egg was there and I am really lost.

Any help?


[Edit] Okay, I was able to use just "OnAddedItem()" but that also does not work.
Throwing the dagger out of the inventory and using the ShowVars command reveals that no random numbers had been generated which and of course I never got any debug messages.
Where is the trick at something so simple?
User avatar
Sakura Haruno
 
Posts: 3446
Joined: Sat Aug 26, 2006 7:23 pm

Post » Sun Nov 18, 2012 4:34 am

you can try to create a fake event for the grabbed item using http://www.creationkit.com/GetPlayerGrabbedRef_-_Game in combination with some other conditions/events


most likely, you will get the most out of using an actor script from the sound of what you are doing (create a alias or a constant magic effect ability, both receive all actor events). the only objectreference event your dagger will receive that seems relevent to your test would be oncontainerchanged.
User avatar
Damned_Queen
 
Posts: 3425
Joined: Fri Apr 20, 2007 5:18 pm

Post » Sun Nov 18, 2012 7:28 am

Create a weapon property for the dagger base ID , let's call it BaseDagger and an Objectreference for the dagger you will be using, let's call it dagger. Define BaseDagger in the CK as the dagger object and leave Dagger undefined. Instead of using game.getplayer() as I do in the example, you should define a property for the player and assign the player in the CK, is not necessary, but it's way faster.

Now the summoning:
dagger=game.getplayer().placeatme(BaseDagger)
Game.Getplayer().additem(dagger, 1)


Now you can use any command or event on the dagger in player inventory as 'dagger'
User avatar
Princess Johnson
 
Posts: 3435
Joined: Wed Feb 07, 2007 5:44 pm

Post » Sun Nov 18, 2012 2:52 am

Create a weapon property for the dagger base ID , let's call it BaseDagger and an Objectreference for the dagger you will be using, let's call it dagger. Define BaseDagger in the CK as the dagger object and leave Dagger undefined. Instead of using game.getplayer() as I do in the example, you should define a property for the player and assign the player in the CK, is not necessary, but it's way faster.

Now the summoning:
dagger=game.getplayer().placeatme(BaseDagger)
Game.Getplayer().additem(dagger, 1)


Now you can use any command or event on the dagger in player inventory as 'dagger'

Hi,

I got you about creating a property for the dagger (thats actually what I though I should do... but I dont get what a property really is and how to use it.
However, I cannot figure out what you mean by "Objectreference for the dagger"... how/where do I do this?

I think, once I have that basic script working I can figure out the rest pretty much myself but the scripting has changed so much that I am lost initially. :(

[Edit] could you mean this: http://www.creationkit.com/GetBaseObject_-_ObjectReference ?
User avatar
meghan lock
 
Posts: 3451
Joined: Thu Jan 11, 2007 10:26 pm

Post » Sun Nov 18, 2012 11:58 am

Let's start by the beggining. Properties, are variables that have some speciall features. They can be called from other scripts, they can use functions instead of having their value readed or writed and what is more important in this case (and in most cases, since it's the most used feature of properties), You can assign them an object. Usually you can't give the player three gold coins by player.additem(gold,3), but if define a property named gold and you attach the gold object to it in the CK, you can do exactly that.

To create a property, you need to define its type (int, float, weapon...). In the case of the gold object in the previous paragraph, you declare the property like: MiscObject Property gold auto.

As cold coins are miscelaneous objects the type is MiscObject. The auto word at the end, means that you won't be using the property as some kind of 'half function', but just as a variable.

Once you have done this, you need to go to the CK and in the object your script is attached to (if there is more than one, this is made separatelly by each) double click on the script, select properties and then the property you are working on. Now, you need to browse untill you find the object you want to assign (if there is just something as generic as steel dagger, just find it, if it's a steel dagger in the jarl main room in riften, you need to select the cell and then the object. The good news is that if you are using the very same name the CK uses for the object type or the object itself, you only need to puch the 'auto fill' button for the CK to fill it automatically -if it didn't do it without you even pushing the button-)




Now returning to your current mod. You need to create Two properties. The first one type will be weapon and the second one ObjectReference. You need to fill the first one, with the base object, so it will be easier if you give it the name the CK uses for it, so you can use the 'auto fill' button, instead of needing to search (not a big deal either, but if you spare 20 seconds for each property you use and you end up creating thousand of properties in the years to come, you could lost a lot of hours). The second property don't need to be defined, as it will be filled by the dagger being created on the player, in the line: dagger=game.getplayer().placeatme(BaseDagger), where you are creating a dagger and assigning the return value (the dagger reference id) to the dagger property.
User avatar
Vickey Martinez
 
Posts: 3455
Joined: Thu Apr 19, 2007 5:58 am

Post » Sun Nov 18, 2012 10:24 am

Hi amgepo,

thanks a lot, thats realling helping me to understand these new properties and stuff.
Using the placeatme-function would place a dagger under the players feet. What other possibilities do I have at that point?
For example, how do I do the same with the dagger, that I find in a chest as part of loot?
For simplicity, lets imagine there is a prepared chest and only the dagger is in it.
I guess thats not really simple as I could not identify an easy function that lists the contents of a specified container-reference (is there something for it? Maybe I just did not see it)
If I cannot get the references of objects in a specified container, I have big problem I think.

I saw, however, that there are container scripts... there isnt much wiki about them, so I dont really know if they are usefull.
Basically: how do you reference to something that is inside another container?
User avatar
Cathrine Jack
 
Posts: 3329
Joined: Sat Dec 02, 2006 1:29 am

Post » Sun Nov 18, 2012 8:46 am

Objects on containers didn't have references, as they are only a name on a list. You need to drop the items to give them a reference. An exception are persistant objects, that have a reference even when in a container (they aren't part of a list here). To make an object persistant, you need to select it with a property, yet from the begining in the CK or in a script (as an exaple, in the instructions I give you earlier, the dagger becomes persistance in the 'dagger=game.getplayer().placeatme(BaseDagger)' line, as is assigned to the 'dagger' property. Keep in mind that if you assign an item a property in the CK it will be permanently persistant and so, will be using memory constantly (this only aply to instances, you won't made all the iron daggers persistant by assigning the iron dagger form a property, but if you do the same with a given iron dagger in a given cell, it will become persistant).

To drop an object from an inventory, use the dropobject function http://www.creationkit.com/DropObject_-_ObjectReference . You also need to assign the item to store the reference (and to made it persistant, untill you clean the property assigning it a none value) like this: dagger = containername.dropobject(basedagger, 1)

Of course, you need to know that the object is stored there. For that you could use the getitemcount function like this: if containername.getitemcount(basedagger) >= 0
User avatar
jessica robson
 
Posts: 3436
Joined: Mon Oct 09, 2006 11:54 am


Return to V - Skyrim