How can I get "Cast()" to recognize "akSource&#3

Post » Wed Jun 20, 2012 6:15 pm

Problem: akSource refuses to be recognized in my ActiveMagicEffect script when using the Cast() function

What I want to happen, on hit, the actor with the script on it will cast a stagger effect onto the player. However this never works right, because akSource confuses the function when I compile. If I use PlayerRef in both the target and the source slots, it doens't work (but it will compile!).

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)PlayerRef = Game.GetPlayer()Current2hSkill = PlayerRef.GetActorValue("TwoHanded") as intif akAggressor == PlayerRef && akSource as Weapon  ;if ((Utility.RandomInt(1, 100) as int) - (Current2hSkill / 2)) > 100    CPOStaggerSpell.Cast(akSource, PlayerRef)   PlayerGotStaggered2H.SetValue(1)  ;endifendifEndEvent

(i've commented out the random number gen, so each hit should 100% cause the spell to cast)

Error:

Starting 1 compile threads for 1 files...Compiling "TwoHandedGlobalStaggerCheckScript"...e:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\TwoHandedGlobalStaggerCheckScript.psc(15,19): type mismatch on parameter 1 (did you forget a cast?)No output generated for TwoHandedGlobalStaggerCheckScript, compilation failed.Batch compile of 1 files finished. 0 succeeded, 1 failed.Failed on TwoHandedGlobalStaggerCheckScript
User avatar
Matt Gammond
 
Posts: 3410
Joined: Mon Jul 02, 2007 2:38 pm

Post » Thu Jun 21, 2012 5:19 am

Try this:

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)PlayerRef = Game.GetPlayer()ObjectReference Source = akSourceCurrent2hSkill = PlayerRef.GetActorValue("TwoHanded") as intif akAggressor == PlayerRef && akSource as Weapon  ;if ((Utility.RandomInt(1, 100) as int) - (Current2hSkill / 2)) > 100   CPOStaggerSpell.Cast(Source, PlayerRef)   PlayerGotStaggered2H.SetValue(1)  ;endifendifEndEvent

[Edit] Wait. You can't use OnHit() in an ActiveMagicEffect script. You would need it to extend ObjectReference.
User avatar
Justin Bywater
 
Posts: 3264
Joined: Tue Sep 11, 2007 10:44 pm

Post » Wed Jun 20, 2012 10:56 pm

You can use OnHit() in an ActiveMagicEffect script. It detects all the events from Actor scripts, just like ReferenceAlias scripts.

The reason that you can't use akSource is because akSource is a form, as in the base object of the thing that hit the actor. With Cast(), you are supposed to specify an object reference.

ObjectReference Source = akSource

wouldn't work either, or at least I don't think it will.
User avatar
Makenna Nomad
 
Posts: 3391
Joined: Tue Aug 29, 2006 10:05 pm

Post » Thu Jun 21, 2012 8:17 am

Yeah, I tried prefacing it with "ObjectReference" but it got confused over object reference.

Either way, I just need it to cast a stagger on the player. I could care less honestly if it's coming from the akSource or not, but it seems like Cast() doesn't work at all unless it IS coming from a specific source.
User avatar
Louise Dennis
 
Posts: 3489
Joined: Fri Mar 02, 2007 9:23 pm

Post » Thu Jun 21, 2012 2:37 am

Would you try this:
akSource as Actor
User avatar
CArlos BArrera
 
Posts: 3470
Joined: Wed Nov 21, 2007 3:26 am

Post » Thu Jun 21, 2012 4:15 am

I could care less honestly if it's coming from the akSource or not, but it seems like Cast() doesn't work at all unless it IS coming from a specific source.

If it doesn't have to be from akSouce, why not just have the player cast it on himself?

CPOStaggerSpell.Cast(PlayerRef, PlayerRef)
User avatar
Etta Hargrave
 
Posts: 3452
Joined: Fri Sep 01, 2006 1:27 am

Post » Thu Jun 21, 2012 1:22 am

if you cast it as an objectreference, what happens?

( CPOStaggerSpell.Cast((akSource as ObjectReference), PlayerRef) )
User avatar
Calum Campbell
 
Posts: 3574
Joined: Tue Jul 10, 2007 7:55 am

Post » Wed Jun 20, 2012 9:35 pm

I'll try that, it didn't work before but my syntax was different and as such it probably threw it off.

Casting on self didnt wokr for me - likely because my spell is a fire/forget aimed one.
User avatar
Becky Palmer
 
Posts: 3387
Joined: Wed Oct 04, 2006 4:43 am

Post » Thu Jun 21, 2012 5:02 am

I've been testing a lot with Cast() and RemoteCast() and DoCombatSpellApply() I have found any "bolt" type spells or "rune" spells or even "summon" spells don't work correctly when being cast from the player because it aims toward your cross hair. On my scripts my OnHit even fires correctly and activates the spell but as its already been mentioned my script extends ActiveMagicEffect.
You could always try creating an invisible marker or actor to cast the spell and make them force face the player with SetAngle() and GetHeadingAngle()

Leon
User avatar
Kari Depp
 
Posts: 3427
Joined: Wed Aug 23, 2006 3:19 pm

Post » Thu Jun 21, 2012 3:50 am

What I want to happen, on hit, the actor with the script on it will cast a stagger effect onto the player.

Assuming the script is applied by an active magic effect, try this ...

CPOStaggerSpell.Cast( self.GetTargetActor(), PlayerRef )
User avatar
Claire Jackson
 
Posts: 3422
Joined: Thu Jul 20, 2006 11:38 pm

Post » Wed Jun 20, 2012 8:44 pm

Assuming the script is applied by an active magic effect, try this ...

CPOStaggerSpell.Cast( self.GetTargetActor(), PlayerRef )

Actors seem to only be able to cast spells at targets right in front of them with both Cast() and RemoteCast(). I suggest just changing the spell you're using to a self target spell, otherwise you'll need to cast the spell from an object (which can cast in any direction).
User avatar
Steve Fallon
 
Posts: 3503
Joined: Thu Aug 23, 2007 12:29 am

Post » Wed Jun 20, 2012 5:58 pm

The cast function expects objectreferences, not actors.
User avatar
laila hassan
 
Posts: 3476
Joined: Mon Oct 09, 2006 2:53 pm

Post » Wed Jun 20, 2012 9:41 pm

The cast function expects objectreferences, not actors.

And yet it works just fine passing in an actor. At least, it does with the player.

If the stagger effect is being done by a spell, then setting the delivery type of the spell as self should allow the following to work just fine.

CPOStaggerSpell.Cast( PlayerRef )
User avatar
Silvia Gil
 
Posts: 3433
Joined: Mon Nov 20, 2006 9:31 pm

Post » Thu Jun 21, 2012 6:21 am

And yet it works just fine passing in an actor. At least, it does with the player.

If the stagger effect is being done by a spell, then setting the delivery type of the spell as self should allow the following to work just fine.

CPOStaggerSpell.Cast( PlayerRef )

Good news! that worked perfect. The script correctly staggers the player every time I perform a hit on an actor. Now going to hook it up to my math check to only happen under certain conditions.
User avatar
Wayne W
 
Posts: 3482
Joined: Sun Jun 17, 2007 5:49 am


Return to V - Skyrim