Why would PlaceAtMe spawn 2 thingies? I only want 1!

Post » Thu Jun 21, 2012 1:09 am

Hi gang, me again.

So, with some expert help from members here, I managed to make my little Dwemer Artificer mod actually usable . . . then I screwed up and tried to get all clever by making it "better" and blew everything to hell.

This script deletes a misc item and spawns a critter in its place when that item is hit by a certain projectile:

Scriptname PDAMSpiderguardianscript extends ObjectReference{Causes an inert spider guardian disappear and spawn a PDAM spider guardian in its place}ActorBase Property PDAMSpiderGuardian Auto;Declare variables for the control rod hit detectionProjectile  Property PDAMActivationBolt AutoEvent OnHit (ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)If akProjectile == PDAMActivationBolt  self.PlaceActorAtMe(PDAMSpiderGuardian)	;spawns friendly  self.Delete()		   ;deletes inert	Debug.Notification("Spider Guardian Activated!")EndIfEndEvent

THIS script is formatted identically, and should do the inverse: when the critter is hit by that same projectile, it should spawn the misc item and delete the critter (in addition to making it drop whatever it's carrying so that those things don't vanish - a feature that doesn't actually work properly . . . yet. but that's a different issue entirely!).

Scriptname PDAMSpiderGuardianDisableScript extends ObjectReference{delete active spider guardian and spawn inert one}MiscObject Property PDAMSpiderGuardianInert  Auto;Declare variables for the control rod hit detectionProjectile  Property PDAMActivationBolt AutoEvent OnHit (ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)If akProjectile== PDAMActivationBolt  Self.RemoveAllItems()		;Drop Everything  self.PlaceAtMe(PDAMSpiderGuardianInert)   ;spawns inert  self.Delete()		  ;deletes friendly	Debug.Notification("Spider Guardian Deactivated!")EndIfEndEvent

For some reason, though, it spawns TWO instances of the misc item and that makes me sad because I can't understand why it would do that.

Does anyone have any clue whatsoever why this should be happening? And, more importantly, does anyone know what I could do to fix it?

As always, thanks for the advice! This fledgling modder will be very grateful and a place in my mod's credits section is just waiting for whoever can help straighten this out.

Thanks!

-P
User avatar
Jordan Fletcher
 
Posts: 3355
Joined: Tue Oct 16, 2007 5:27 am

Post » Thu Jun 21, 2012 4:50 pm

there could be 2 copies of the script running simultaneously for some reason?
User avatar
sarah taylor
 
Posts: 3490
Joined: Thu Nov 16, 2006 3:36 pm

Post » Thu Jun 21, 2012 6:20 am

  • You're missing some white space in 'akProjectile == PDAMActivationBolt'.
  • All instances of 'Self' are unnecessary and should be omitted.
  • http://www.creationkit.com/Delete_-_ObjectReference won't work on Skyrim.ESM stuff. Instead, use http://www.creationkit.com/Disable_-_ObjectReference.
User avatar
Daniel Holgate
 
Posts: 3538
Joined: Tue May 29, 2007 1:02 am

Post » Thu Jun 21, 2012 7:39 am

mmm... I tried using If (akProjectile) as a condition in my onhit scripts and it NEVER worked.
In my notes in my scripts I have recorded that akProjectile is broken (does not work) when used in an ONHIT event.

Have you or anyone reading this actually tested this to be sure it works?


  • You're missing some white space in 'akProjectile == PDAMActivationBolt'.
  • All instances of 'Self' are unnecessary and should be omitted.
  • http://www.creationkit.com/Delete_-_ObjectReference won't work on Skyrim.ESM stuff. Instead, use http://www.creationkit.com/Disable_-_ObjectReference.
User avatar
Adam Baumgartner
 
Posts: 3344
Joined: Wed May 30, 2007 12:12 pm

Post » Thu Jun 21, 2012 11:52 am

The deletion is for clearing up the object reference that is created, it should be fine in this case as both of the objects being deleted are created. If he were to use Disable this would cause save game bloat with consecutive use of the spell.

If the OnHit occurs twice you could try changing states.

Function OnHit()	; Stuff here	GoToState("Activated")EndFunctionState "Activated"	Function OnHit()		; Do nothing, already activated	EndFunctionEndState

As for dropping all the items you'd probably need SKSE to walk over all the Forms in the inventory as there is no way to "DropObject" on all of the items in the references inventory. You could make your MiscObject a container instead, and have all the items transferred to that and back via RemoveAllItems.
User avatar
Ross Thomas
 
Posts: 3371
Joined: Sat Jul 21, 2007 12:06 am

Post » Thu Jun 21, 2012 1:02 am

Thanks, everyone! I really appreciate the ideas and advice.

there could be 2 copies of the script running simultaneously for some reason?

That's an interesting idea, but I don't see how it could be. The script that spawns that live critter is setup identically to the one that spawns that item, so there shouldn't be any duplication anywhere.


  • You're missing some white space in 'akProjectile == PDAMActivationBolt'.
  • All instances of 'Self' are unnecessary and should be omitted.
  • http://www.creationkit.com/Delete_-_ObjectReference won't work on Skyrim.ESM stuff. Instead, use http://www.creationkit.com/Disable_-_ObjectReference.

Thanks for the tips - I'm still learning so it's always helpful to get suggestions for cleaning up my scripts. None of those things are going to help with my actual problem, though.

Have you or anyone reading this actually tested this to be sure it works?

Actually, yes. the first script that I posted, and several variations on it all work perfectly. It was hard to wrap my head around at first - I didn't realize that "projectile" refers to an option in the spell dialogue. This process uses a renamed duplicate of a vanilla shock spell projectile.

The deletion is for clearing up the object reference that is created, it should be fine in this case as both of the objects being deleted are created. If he were to use Disable this would cause save game bloat with consecutive use of the spell.

[snip]

As for dropping all the items you'd probably need SKSE to walk over all the Forms in the inventory as there is no way to "DropObject" on all of the items in the references inventory. You could make your MiscObject a container instead, and have all the items transferred to that and back via RemoveAllItems.

Thanks for the clarification on the delete thing. I thought that's how it worked, which is why I went with that function in the first place.

I was discovering all of that about dropping object last night after my original post. I'm not sure which way to go with it yet, but thanks for helping to point me in the right direction. :smile:

If the OnHit occurs twice you could try changing states.

This looks promising . . . I'll try it out soon and report back. What I can't figure out is why they heck is this happening in the first place? It doesn't make sense to run the script twice when hitting a critter, but only once when hitting an item.
User avatar
Chris Ellis
 
Posts: 3447
Joined: Thu Jul 26, 2007 10:00 am

Post » Thu Jun 21, 2012 3:45 pm

So you're using a spell to do the "transformation"? It could be that the critter is registering a hit from the actual projectile hitting it, and then another hit from the magic effect. And the reason the item only registers one hit is because magic only works on actors.

What if you tried leaving out the check for akProjectile so it works for anything, then try hitting the critter with a weapon?
User avatar
Jeff Tingler
 
Posts: 3609
Joined: Sat Oct 13, 2007 7:55 pm

Post » Thu Jun 21, 2012 10:15 am

So you're using a spell to do the "transformation"? It could be that the critter is registering a hit from the actual projectile hitting it, and then another hit from the magic effect. And the reason the item only registers one hit is because magic only works on actors. What if you tried leaving out the check for akProjectile so it works for anything, then try hitting the critter with a weapon?

Yes and no. The spell doesn't actually have an effect (at least, not one that has anything to do with the process in these scripts), I'm just using it as trigger, which is why I'm using the projectile to register a valid hit instead of the spell effect.

This is an interesting idea, though. I did a similar test when I was working out the item-to-critter script, and it wound up being pretty informative. Thanks for the idea!
User avatar
Lauren Dale
 
Posts: 3491
Joined: Tue Jul 04, 2006 8:57 am

Post » Thu Jun 21, 2012 11:50 am

Okay, so here's the end of this chapter in my mod's little development story:

I tried RandomNoob's idea of removing the conditional and just whacking the thing with an ax. Result: Perfection! Only one item was created, just like I wanted.

Regardless of whether I used the projectile or the enchantment (via akSource), I always get two items when I use a conditional. Weird right?

So that's when I educated myself a bit to make some sense out of PurpleLunchBox's idea to change states (hooray for the CK wiki!) and thanks to that, I've finally got my script doing what it's supposed to do! I'll add here for posterity, just in case someone else comes along with a similar problem and my experience can be of some use.

Thanks Purple! You're in my credits now. :biggrin:

Scriptname PDAMSpiderGuardianDisableScript extends ObjectReference{delete active spider guardian and spawn inert one}MiscObject Property PDAMSpiderGuardianInert  Auto;Declare variables for the control rod hit detectionProjectile Property PDAMActivationBolt Autoauto STATE ActivatingEvent OnHit (ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)  If akProjectile == PDAMActivationBolt   Self.RemoveAllItems(akTransferTo = Game.GetPlayer())  ;Transfer items to Player   self.PlaceAtMe(PDAMSpiderGuardianInert, 1)	 ;spawns inert   self.Delete()			;deletes friendly   Debug.Notification("Spider Guardian Deactivated!")   GoToState("Activated")  EndIfEndEventEndStateSTATE Activated;nothing!EndState
User avatar
Fam Mughal
 
Posts: 3468
Joined: Sat May 26, 2007 3:18 am


Return to V - Skyrim