Script for replacing item

Post » Wed Jun 20, 2012 4:06 am

Hi.

I am trying to replace an item that I drop with an activator. -Since the activator can't be picked up and placed in the player's inventory.
I managed to remove the activator when activating it, and placing the "dummy item" in the player's inventory. Now I just need to replace the item with the activator when the player drops the item. Obviously my script doesn't work.

Here's my script so far:

Scriptname BM_ReplaceCoalWithTrap extends ObjectReference{A script attached to the player, that replaces a certain item with an activator.}MiscObject Property BM_CoalReplaceItem  Autoevent OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)  Debug.Notification("Running!")   ;This does not show.if (akBaseItem==BM_CoalReplaceItem && !akDestContainer)	;This is supposed to mean "if the item is dropped".  Debug.Notification("Replace me, mf!")  Game.GetPlayer().PlaceAtMe(Game.GetForm(0x0100FF80))   ;I later want to replace "Game.GetForm" with a variable.  RemoveItem(akBaseItem, 1, true, none)	 ;This is me trying to remove the item that was dropped. Does not work.endifendevent

Since no Debug.Notifications are showing I am guessing the event is wrong.

I created a quest, created a player-alias and attached this script to the player.

What I need:
1. I need the trigger to run, since it seems the event is wrong and nothing runs at all.
2. I need to remove the dropped item somehow.
3. I need to create the activator where the removed item was. (In front of the player.) -I am guessing that this works, if the trigger would run.

Thanks in advance.
User avatar
Raymond J. Ramirez
 
Posts: 3390
Joined: Sun Oct 14, 2007 8:28 am

Post » Tue Jun 19, 2012 6:54 pm

Not sure but i think your script should extends ReferenceAlias instead of ObjectReference, if you use it in an Alias for the Player.
User avatar
Elisha KIng
 
Posts: 3285
Joined: Sat Aug 18, 2007 12:18 am

Post » Tue Jun 19, 2012 6:22 pm

Not sure but i think your script should extends ReferenceAlias instead of ObjectReference, if you use it in an Alias for the Player.

I tried doing this:

Scriptname BM_ReplaceCoalWithTrap extends ReferenceAlias

But it didn't compile. Am I doing something wrong?
User avatar
Kelsey Hall
 
Posts: 3355
Joined: Sat Dec 16, 2006 8:10 pm

Post » Wed Jun 20, 2012 3:17 am

*bump*
User avatar
Jason White
 
Posts: 3531
Joined: Fri Jul 27, 2007 12:54 pm

Post » Wed Jun 20, 2012 3:17 am

OnItemRemoved is the event that fires when an object is removed from this objects container, for example this would fire for the player when you drop something, not for the something that is dropped.
I think http://www.creationkit.com/OnContainerChanged_-_ObjectReference would work for you
User avatar
brandon frier
 
Posts: 3422
Joined: Wed Oct 17, 2007 8:47 pm

Post » Tue Jun 19, 2012 11:02 pm

OnItemRemoved is the event that fires when an object is removed from this objects container, for example this would fire for the player when you drop something, not for the something that is dropped.
I think http://www.creationkit.com/OnContainerChanged_-_ObjectReference would work for you

Sounds like that could work. But I want to check two things: 1. Did the player drop the item? 2. What item was dropped? Will it work both ways?

What about ReferenceAlias that Seigneur Voland mentioned?


EDIT: It works! =)
Here's my new script:

ScriptName BM_ReplaceCoalWithTrap extends ObjectReferenceMiscObject Property BM_CoalReplaceItem  AutoActivator Property BM_TrapWhichReplacesCoal  Autoevent OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)if (akOldContainer && !akNewContainer)  Game.GetPlayer().PlaceAtMe(BM_TrapWhichReplacesCoal)  Delete()endifendevent

The only problem is that it can't quite handle dropping two or more of the item at once. Is there a way to limit the player to drop only one item at a time?
I would also like to place the activator in front of the player (PlaceAtMe puts it underneath the player.)
User avatar
Angel Torres
 
Posts: 3553
Joined: Thu Oct 25, 2007 7:08 am

Post » Wed Jun 20, 2012 2:34 am

You could try using http://www.creationkit.com/MoveTo_-_ObjectReference after placeatme
User avatar
Cool Man Sam
 
Posts: 3392
Joined: Thu May 10, 2007 1:19 pm

Post » Tue Jun 19, 2012 7:32 pm

Is it possible to get the player's facing angle and from there offset X,Y,Z to move the activator to the correct location?

It would be easier if I could refer to the object itself. As you can see: my script places the activator at "Game.GetPlayer()".
The script is attached to the Object that is dropped. I want to do something like: "TriggerRef.PlaceAtMe(BM_TrapWhichReplacesCoal)"

I looked over my script and changed it around a little bit:

Scriptname HT_PlayerDropTrap extends ObjectReference {A script that will replace the dummy item with an actual trap when the player drops it.}MiscObject Property HT_DummyItem  AutoActivator Property HT_TrapActivator  Autoevent OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)if (akOldContainer && !akNewContainer)  Game.GetPlayer().PlaceAtMe(HT_TrapActivator)  Delete()endifendevent

I realized that I am not using "HT_DummyItem" in the script. Somehow the script only runs when I drop the item which is in the property's value anyway (the way I want it to work.) -Why does it work the way I want it to? Scripts usually do the opposite. I would feel better if I could add an "If" -check to make sure that it is the item I want to drop.

I really need to find out how to get the object that this script is attached to.
User avatar
nath
 
Posts: 3463
Joined: Mon Jan 22, 2007 5:34 am

Post » Tue Jun 19, 2012 11:40 pm

If the script is attached to your item it will only ever run for your item, the OnContainerChanged event fires when the item its attached to changes containers.

There is a variable named 'Self' that is the scripts self you can use. Also PlaceAtMe returns an objectreference of the object it just placed, so you could do something like:
ObjectReference placedObject = Game.GetPlayer().PlaceAtMe(HT_TrapActivator)placedObject.MoveTo(placedObject, 1, 0, 0, true)

Or
ObjectReference placedObject = Game.GetPlayer().PlaceAtMe(HT_TrapActivator)placedObject.MoveTo(Game.GetPlayer(), 1, 0, 0, true)


The last parameter of MoveTo makes the object match the rotation of the object you moved it to too


Is it possible to get the player's facing angle and from there offset X,Y,Z to move the activator to the correct location?
You can use http://www.creationkit.com/GetAngleZ_-_ObjectReference and the X and Y equivalents to get the players rotation and then do some trigonometry
User avatar
Queen Bitch
 
Posts: 3312
Joined: Fri Dec 15, 2006 2:43 pm

Post » Tue Jun 19, 2012 5:22 pm

If the script is attached to your item it will only ever run for your item, the OnContainerChanged event fires when the item its attached to changes containers.

Of course, I should've known that.



There is a variable named 'Self' that is the scripts self you can use. Also PlaceAtMe returns an objectreference of the object it just placed, so you could do something like:
ObjectReference placedObject = Game.GetPlayer().PlaceAtMe(HT_TrapActivator)placedObject.MoveTo(placedObject, 1, 0, 0, true)

Or
ObjectReference placedObject = Game.GetPlayer().PlaceAtMe(HT_TrapActivator)placedObject.MoveTo(Game.GetPlayer(), 1, 0, 0, true)


The last parameter of MoveTo makes the object match the rotation of the object you moved it to too

I see what you did there. I tried doing it, but sadly the trap ends up underneath the player's feet anyway. I even tried adding to the X and Y offset, but with the same result.
I believe that the trap triggers as soon as the script uses "PlaceMeAt"; which interupts "MoveTo". Is there no way to "PlaceMeAt" something else - at a safe distance from the player? (I don't mind if the trap is created mid-air, I am guessing Havok will take care of it anyway - as long as it stays away from the player.)


You can use http://www.creationkit.com/GetAngleZ_-_ObjectReference and the X and Y equivalents to get the players rotation and then do some trigonometry

Sounds advanced, I might look into that later. :P
User avatar
Red Bevinz
 
Posts: 3318
Joined: Thu Sep 20, 2007 7:25 am

Post » Tue Jun 19, 2012 10:14 pm

you could maybe try self.PlaceAtMe instead of player.placeatme (place it where the item is) but that still might be too close... you could try disabling it too
User avatar
Sarah MacLeod
 
Posts: 3422
Joined: Tue Nov 07, 2006 1:39 am

Post » Tue Jun 19, 2012 9:51 pm

EDIT #2: Sorry, my bad. I swear my brain isn't working today.

I just realized I had forgot to remove "Game.GetPlayer().PlaceAtMe(HT_TrapActivator)": so I was actually creating two traps, one that always ended up underneath me.
It works a lot better now. I will keep testing it for a while to see if I find any more bugs. (I will bump this thread if I do.)

Thanks a lot for your help. You've been priceless. =)


EDIT #3: I already found a new bug: Whenever I successfully place one trap in the game (works as intended) and want to place a second (or more) the second (or more) doesn't work at all.
I want the scripts to work independently of each other, but they seem to affect each other. I believe it has to do with the variables/properties.
Here's my current script:

Scriptname HT_PlayerDropTrap extends ObjectReference {A script that will replace the dummy item with an actual trap when the player drops it.}Activator Property HT_TrapActivator  Auto    ;Is it possible to get rid of this somehow, and replace it with a local variable instead?event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)if (akOldContainer && !akNewContainer)  Self.PlaceAtMe(HT_TrapActivator)      ;Or could I refer to an ObjectID here?  Delete()endifendevent
User avatar
Everardo Montano
 
Posts: 3373
Joined: Mon Dec 03, 2007 4:23 am

Post » Wed Jun 20, 2012 4:32 am

Np :]
User avatar
Cool Man Sam
 
Posts: 3392
Joined: Thu May 10, 2007 1:19 pm

Post » Wed Jun 20, 2012 12:35 am

Sounds advanced, I might look into that later. :tongue:

It is. My advice: Don't Go there unless you have a doctorate in mathematics. I can't even get an object to rotate on it's local axes in this game.
User avatar
Rebecca Dosch
 
Posts: 3453
Joined: Thu Jan 18, 2007 6:39 pm

Post » Tue Jun 19, 2012 10:32 pm

I can't even get an object to rotate on it's local axes in this game.

Challange accepted!

No, but seriously, please check my third edit in this post:

http://www.gamesas.com/topic/1356843-script-for-replacing-item/page__p__20459104#entry20459104
User avatar
Jonathan Windmon
 
Posts: 3410
Joined: Wed Oct 10, 2007 12:23 pm

Post » Tue Jun 19, 2012 8:38 pm

It shouldn't be the property causing problems, what exactly doesn't work? The dummy item just falls on the ground and doesn't spawn the activator?
User avatar
Trista Jim
 
Posts: 3308
Joined: Sat Aug 25, 2007 10:39 pm

Post » Wed Jun 20, 2012 7:00 am

It shouldn't be the property causing problems, what exactly doesn't work? The dummy item just falls on the ground and doesn't spawn the activator?

Yep, that is exactly what happens. As if the script doesn't have time to fire.
User avatar
D LOpez
 
Posts: 3434
Joined: Sat Aug 25, 2007 12:30 pm

Post » Tue Jun 19, 2012 9:56 pm

The game should make different instances of the script for each item, try putting in debug.Notification s or .messagebox s to see if the event goes or not
User avatar
cheryl wright
 
Posts: 3382
Joined: Sat Nov 25, 2006 4:43 am

Post » Wed Jun 20, 2012 4:36 am

I added two Debug.Notifications. One inside the event, and one inside the If.
The event runs when picking up (activating the activator) - since it's being added to the player's inventory.
The if runs only when the item is being dropped from the player's inventory.

When I dropped two at once from the inventory, without closing the inventory, the script only ran once.

I also created a second trap (1=iron, 2=steel). The iron and the steel scripts works independently, but if I drop two of the same kind the second one won't work.
User avatar
Jason White
 
Posts: 3531
Joined: Fri Jul 27, 2007 12:54 pm

Post » Wed Jun 20, 2012 1:59 am

Are you dropping them in a stack of 2? If so that is probably your problem
User avatar
Vicki Gunn
 
Posts: 3397
Joined: Thu Nov 23, 2006 9:59 am

Post » Wed Jun 20, 2012 7:34 am

Are you dropping them in a stack of 2? If so that is probably your problem

I drop them one-by-one. I also tried dropping 5+ at the same time. It only works on the first item dropped, the others shows up as the dummy item.
User avatar
Jessica Raven
 
Posts: 3409
Joined: Thu Dec 21, 2006 4:33 am

Post » Wed Jun 20, 2012 6:29 am

I'm not really sure what the problem is, sorry
User avatar
louise tagg
 
Posts: 3394
Joined: Sun Aug 06, 2006 8:32 am

Post » Wed Jun 20, 2012 12:12 am

That's because PlaceAtme only returns a reference to the first one placed. You have to place one at a time, or you lose any reference to the others.
User avatar
roxxii lenaghan
 
Posts: 3388
Joined: Wed Jul 05, 2006 11:53 am

Post » Wed Jun 20, 2012 7:40 am

That's because PlaceAtme only returns a reference to the first one placed. You have to place one at a time, or you lose any reference to the others.

Is there a way to work around this? Perhaps use another function than "PlaceAtMe"?
User avatar
Enny Labinjo
 
Posts: 3480
Joined: Tue Aug 01, 2006 3:04 pm

Post » Wed Jun 20, 2012 5:28 am

Is there a way to work around this? Perhaps use another function than "PlaceAtMe"?

Nope. PlaceAtMe is the only function that lets you spawn an item. If you want a refrence to multiple items, you'll have to use a loop, placing one at a time, doing what you want to it, placing the next one, etc...you could use an array...

ObjectReference[] MakeItems = new ObjectReference[5]int count = 0while count < 5  MakeItems[count] = PlaceAtme(MyItemType,1)  Count += 1endwhile
User avatar
Angel Torres
 
Posts: 3553
Joined: Thu Oct 25, 2007 7:08 am

Next

Return to V - Skyrim