Easy: How to get the aliasreference of the NPC, that a scrip

Post » Thu Jun 21, 2012 5:33 am

Need to do this, it's probably really simple but I can't figure out how. I've got a script being dynamically added to NPC's as you encounter them. I need to be able to get the NPC this script/spell effect combo, is applied to.

I tried using "GetTargetActor()", which is for ActiveMagicEffect scripts (which my script is...) but it doesn't do anything by itself.

When I try to pair it up with the spell that applies the script (like in the wiki example) my script refuses to compile, saying that the function does not exist.

How can I get the actor ref that a script is applied to?

If it makes things easier, I'm trying to cast an effect via Papyrus on said actor who has this script, and I can't figure out how to target the actor that has the script on it, with the Cast() function.
User avatar
El Khatiri
 
Posts: 3568
Joined: Sat Sep 01, 2007 2:43 am

Post » Thu Jun 21, 2012 11:40 am

You could alway use a Global Variable Quest script.
I have made one for my mod as it saves typing the same lines of code again and again for each effect I make and passing functions etc to it is really helpfull.

On the script on your quest...
Scriptname scrQuestGlobalVar extends QuestActor Property ActTargetRef Auto		  ; Interchangeable Target from Detect spell.

I think you need to set the Property of the ActTargetRef in the "Quest - Scripts - Properties (of above script)" to None before testing.

Then on your script which is attached to said NPC...

Scriptname scrDetect extends activemagiceffect{Detection test.}scrQuestGlobalVar Property GlobalVars AutoActor Property PlayerRef AutoEVENT OnEffectStart(Actor akTarget, Actor akCaster)GlobalVars.ActTargetRef = akTargetENDEVENT

Then on the script for what you are casting or which one needs said actors reference...

Scriptname scrTestTargetSpell extends ActiveMagicEffectLFscrQuestGlobalVar Property GlobalVars Auto	   ; Reference the Quest script with global variables, saves a lot of repeated code.EVENT (what ever event you need)IF GlobalVars.ActTargetRef != NONE   TargetRef = GlobalVars.ActTargetRefENDIFENDEVENT

You could even put a while event around the IF statement to check constantly.

Hope that helps.
User avatar
Trish
 
Posts: 3332
Joined: Fri Feb 23, 2007 9:00 am

Post » Thu Jun 21, 2012 9:59 am

I was actually just thinking about this, and I have an idea. (I'm making a zombie apocalypse spell, and I needed to do this.)

Actor OtherGuywhile OtherGuy==NONEwhile OtherGuy==NONE  OtherGuy = Game.GetRandomActorNearRef(Game.GetPlayer(), radiusofyourcloak as int)Utility.Wait(0.30)endWhileOtherGuy.DoWhateverYouWantToHim()OtherGuy=NONEendWhile
User avatar
Nauty
 
Posts: 3410
Joined: Wed Jan 24, 2007 6:58 pm

Post » Thu Jun 21, 2012 7:55 am

HUH? You guys are confusing me, how is this so difficult? Why would this not work for you (it works for me):

Scriptname MyScript extends activemagiceffectEVENT OnEffectStart(Actor akTarget, Actor akCaster)Actor TargetRef = akTarget;do stuff with the Actor REF TargetREF like:	if TargetRef == game.getplayer()ENDEVENT

Maybe I do not really understand what you are asking.

(Wow only eight people in this CT forum!? This sure is not like Oblivion CK forum was, or maybe it was in the first year. That was so long ago I may not remember it clearly.)


Need to do this, it's probably really simple but I can't figure out how. I've got a script being dynamically added to NPC's as you encounter them. I need to be able to get the NPC this script/spell effect combo, is applied to.

I tried using "GetTargetActor()", which is for ActiveMagicEffect scripts (which my script is...) but it doesn't do anything by itself.

When I try to pair it up with the spell that applies the script (like in the wiki example) my script refuses to compile, saying that the function does not exist.

How can I get the actor ref that a script is applied to?

If it makes things easier, I'm trying to cast an effect via Papyrus on said actor who has this script, and I can't figure out how to target the actor that has the script on it, with the Cast() function.
User avatar
Cesar Gomez
 
Posts: 3344
Joined: Thu Aug 02, 2007 11:06 am

Post » Thu Jun 21, 2012 3:37 am

The problem is I'm needing to fire off functions not based with the OnEffectStart event.

Such as, I'm having trouble in a script that is dynamically attached to NPC's, finding the actual ref of the NPC I have the script attached to. For use with events like OnHit (so, when the enemy gets hit it will trigger X functions... except onhit has no native variables to detect who is getting hit unlike OnEffectStart, so I can't pass the "akTarget" of the hit to functions like casting, which require a specific reference to be provided in order to work last I checked).

I guess I can work this out an using a seperate script that doesn't run off of NPC's for what I want to do. I.E. maybe attaching a script to the player, that somehow detects when he/she hits an NPC, then casting my effect through that. I've done this before I think, I just need to remember how..

This would be a LOT easier if you could do something like... "SpellEffect.Cast(self)" and it would always target whoever the script/magiceffect/etc belongs to. But you can only, as far as know, target very specific references with Cast.
User avatar
Alexis Acevedo
 
Posts: 3330
Joined: Sat Oct 27, 2007 8:58 pm

Post » Thu Jun 21, 2012 9:20 am

You could alway use a Global Variable Quest script.
I have made one for my mod as it saves typing the same lines of code again and again for each effect I make and passing functions etc to it is really helpfull.

On the script on your quest...
Scriptname scrQuestGlobalVar extends QuestActor Property ActTargetRef Auto		  ; Interchangeable Target from Detect spell.

I think you need to set the Property of the ActTargetRef in the "Quest - Scripts - Properties (of above script)" to None before testing.

Then on your script which is attached to said NPC...

Scriptname scrDetect extends activemagiceffect{Detection test.}scrQuestGlobalVar Property GlobalVars AutoActor Property PlayerRef AutoEVENT OnEffectStart(Actor akTarget, Actor akCaster)GlobalVars.ActTargetRef = akTargetENDEVENT

Then on the script for what you are casting or which one needs said actors reference...

Scriptname scrTestTargetSpell extends ActiveMagicEffectLFscrQuestGlobalVar Property GlobalVars Auto	   ; Reference the Quest script with global variables, saves a lot of repeated code.EVENT (what ever event you need)IF GlobalVars.ActTargetRef != NONE   TargetRef = GlobalVars.ActTargetRefENDIFENDEVENT

You could even put a while event around the IF statement to check constantly.

Hope that helps.

I don't really follow...

GlobalVars isn't a function and neither is ActorTargetRef

I'm unsure how you are magically calling these, even though they are simply properties you defined in different scripts..?

And "scrQuestGlobalVar" doesn't really appear to be a valid type to declare properties with. Unless, because its a script you made, any script can basically be used as a container to declare properties with?
User avatar
Robert Jr
 
Posts: 3447
Joined: Fri Nov 23, 2007 7:49 pm

Post » Thu Jun 21, 2012 11:11 am

I agree with Duke Patrick... I'm confused as to what the problem is. The OnHit event in this script works perfectly fine for me:

Scriptname DamageMonitorScript extends ActiveMagicEffect  Actor MySelfFloat HealthEvent OnEffectStart(Actor akTarget, Actor akCaster)	MySelf = akTarget	Health = MySelf.GetActorValue("Health")	RegisterForSingleUpdate(0.25)EndEventEvent OnUpdate()	Health = MySelf.GetActorValue("Health")	RegisterForSingleUpdate(0.25)EndEventEvent OnEffectFinish(Actor akTarget, Actor akCaster)	UnregisterForUpdate()EndEventEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, \  bool abSneakAttack, bool abBashAttack, bool abHitBlocked)	Float Damage = Health - MySelf.GetActorValue("Health")	Health = MySelf.GetActorValue("Health")	if (akAggressor == Game.GetPlayer())		Debug.Notification("You did " + Damage as Int + " points of damage.")	endifEndEvent
[/left]
User avatar
dav
 
Posts: 3338
Joined: Mon Jul 30, 2007 3:46 pm

Post » Thu Jun 21, 2012 11:21 am

The problem is I'm needing to fire off functions not based with the OnEffectStart event.

Such as, I'm having trouble in a script that is dynamically attached to NPC's, finding the actual ref of the NPC I have the script attached to. For use with events like OnHit (so, when the enemy gets hit it will trigger X functions... except onhit has no native variables to detect who is getting hit unlike OnEffectStart, so I can't pass the "akTarget" of the hit to functions like casting, which require a specific reference to be provided in order to work last I checked).

If I understand you correctly, you can use "self". This will return the actor that the script is attached to.
User avatar
lucile
 
Posts: 3371
Joined: Thu Mar 22, 2007 4:37 pm

Post » Thu Jun 21, 2012 1:46 pm

Odd, when I tried declaring my own equivalent of "MySelf" variable on the OnEffectStart event, it wouldn't actually call the akTarget and nothing would happen. Maybe I just need to tinker some more.
User avatar
AnDres MeZa
 
Posts: 3349
Joined: Thu Aug 16, 2007 1:39 pm

Post » Thu Jun 21, 2012 8:29 am

If I understand you correctly, you can use "self". This will return the actor that the script is attached to.

Oh? Is there anywhere on the Wiki I can read up on stuff like that? I was under the impression Cast() required a specific target reference in order to work.
User avatar
Kayleigh Williams
 
Posts: 3397
Joined: Wed Aug 23, 2006 10:41 am

Post » Thu Jun 21, 2012 8:45 am

You cannot use "self" on an ActiveMagicEffect script. Well, you could but in that case "self" would refer to the current instance of the magic effect, not the actor that the magic effect is attached to.
User avatar
Beast Attire
 
Posts: 3456
Joined: Tue Oct 09, 2007 5:33 am

Post » Thu Jun 21, 2012 5:15 pm

Wow I feel like such a nub

Turns out, duke's solution is the working one - the reason it wasn't working for me was because I forgot I was casting the effect under conditions where the effect would never appear, so it wasn't working. Thanks for dealing with the newbness :P
User avatar
sophie
 
Posts: 3482
Joined: Fri Apr 20, 2007 7:31 pm

Post » Thu Jun 21, 2012 8:18 am

You cannot use "self" on an ActiveMagicEffect script. Well, you could but in that case "self" would refer to the current instance of the magic effect, not the actor that the magic effect is attached to.

Yeah. I thought he was saying it was a script placed on the actor, in which case it would call the actor. But you're right; I don't think I understood what he was saying.

Glad you got it worked out.

Oh? Is there anywhere on the Wiki I can read up on stuff like that? I was under the impression Cast() required a specific target reference in order to work.

"Self" always refers to the object that the script is placed in. So if you place the script on an actor it will refer to that actor every time. In this case you could use "Self.Cast ()" to make the actor that the script is attached to cast a spell. It's very convenient sometimes.
User avatar
Kat Stewart
 
Posts: 3355
Joined: Sun Feb 04, 2007 12:30 am


Return to V - Skyrim