Jump to content

know who casted a spell


nery89

Recommended Posts

I was scripting when I encountered this problem. when a NPC cast a spell (scripted), if I use this magic-code

ref targetref

begin scripteffectstart
    set targetref to getself
end

obviously targetref is the target of the spell, not the caster.

How the hell I can know who casted the spell? Any idea?

Link to comment
Share on other sites

Ok, the first thing you say is good, but I really don't know how to make a trigger zone around the target...

Second. In OBSE I can see that command that seems useful:

 

GetNthActiveEffectCaster - return the caster of the Nth ActiveEffect on the target
(caster:ref) reference.GetNthActiveEffectCaster whichEffect:int
(caster:ref) reference.GetNthAECaster whichEffect:int

But I don't understand some things: what is "Nth"?

How to know that "whichEffect:int"? Is the ID of the spell? Or I have to search it by using another script (and how)? If I didn't see something already explaining that in the documentation page, I send my sorry :sweat:

******************

After some tests:

int rifermagia
ref caster

begin scripteffectstart
    set caster to getself
    set rifermagia to GetMagicEffectCode SEFF
    set caster to GetNthActiveEffectCaster rifermagia
    messagebox "caster id is %i", caster
end

but it doesn't return the caster... it returns 0000000...

******************

Other search in tes cs wiki. I found that GetNthActiveEffectCaster returns the id of the caster of the FIRST effect of the type required, and I'm testing the spell on a target that have another scripted-spell active (a birthsign, so it isn't casted from anyone). It's the right way but I don't know how to know if the effect is the searched or not...

******************

I think I'm mistaking something... not sure the GetNthActiveEffectCaster require an effect code... OBSE is powerful but not well explained. What is that damn

whichEffect:int

Because if i implement this script:

begin scripteffectupdate
set rifermagia to rifermagia +1
set caster to target.GetNthActiveEffectCaster rifermagia
if caster!=0
	printc "MAG %g Caster = %i (%n)", rifermagia, caster, caster
endif
end

from time to time the right reference appear when passed the rifermagia==1 or rifermagia==2. What is 1, or 2, or other number? What they mean? Why they change? How I can determin them?

Edited by nery89
Link to comment
Share on other sites

Ok, the first thing you say is good, but I really don't know how to make a trigger zone around the target...

 

A trigger zone, or TrigZone, is created in the object window (activator section I think). In the render window, it just looks like a box, but in the game it is invisible. TrigZones allow a special block type in it's script, Begin OnTrigger, which will run when something enters the TrigZone. You will need a parameter to filter that down though.

 

But I don't understand some things: what is "Nth"?

How to know that "whichEffect:int"? Is the ID of the spell? Or I have to search it by using another script (and how)? If I didn't see something already explaining that in the documentation page, I send my sorry :sweat:

 

"Nth" is the term for the specific value in a sequence or set. For example:

2, 4, 6, 8, 10

As you can see, each number is equal to the number before, plus two. The way this is written down is Xn+1 = X+2, because n just represents where in the sequence you are. X3 would be 6, because 6 is the 3rd number in the sequence, and N would be 3, because that is how far into the sequence we are.

 

"Int" is short for Integer, which is just a whole number. Thing is, you looked for the specific effect ID, however you are actually searching for the Nth effect that has been applied to the actor. At this point, I can't think of a way to work out how to work out the number that yours would be.

Put simply, your script was looking for something like the 1,195,657,542th effect to hit the character, when in reality you wanted to find something closer to the 3rd effect to hit the character.

 

I think I'm mistaking something... not sure the GetNthActiveEffectCaster require an effect code... OBSE is powerful but not well explained. What is that damn

whichEffect:int

Because if i implement this script:

begin scripteffectupdate
set rifermagia to rifermagia +1
set caster to target.GetNthActiveEffectCaster rifermagia
if caster!=0
	printc "MAG %g Caster = %i (%n)", rifermagia, caster, caster
endif
end

from time to time the right reference appear when passed the rifermagia==1 or rifermagia==2. What is 1, or 2, or other number? What they mean? Why they change? How I can determin them?

 

I think rifermagia == 1 because your script sets it to 1, but then doesn't do anything else with it. Every time it prints, rifermagia will be +1 higher, until the spell stops.

Link to comment
Share on other sites

Aggiorno i miei tentativi di ieri:

I update my yesterday-tests:

 

without know that you (WarRatsG) answer me so fast, I implemented this code (is so complicated, but I'll explain).

Now, think that NPC1 casts a spell. this spell attaches to the target a script (for 2 sec) and a feather (for 2 seconds). How many NPC can cast a similar spell??? Anyone but the wanted NPC1 at 90%. So if I find a caster that, at the same time, had casted script+feather spell... that's it!

[can I say in english "the game is done" istead of "that's it!", like in italian "il gioco è fatto"? or is no-sense?]

 

Now, in base of my tests, I presumed that GetNthActiveEffectCaster requires the index of the active effect on the target. But the index is only an integer from 1 to the number of active effects (even: I presumed) so i made a cycle that find the presumed caster.

 

ref target ; target of the spell

ref caster ; will be the presumed caster of script
ref castertemp ; will be the presumed caster of feather

short effnum ; number of active effects
int rifermagia ; number from 1 to effnum
int rifermagia2 ; number from 1 to effnum

int riferscript ; the code of the [i]script effect[/i]
int riferscript2 ; the code of the [i]feather effect[/i]

short i ; controls if the cycle found the right (presumed) caster

begin scripteffectstart
set target to GetSelf

let riferscript := MECodeFromChars "SEFF" ; script
let riferscript2 := MECodeFromChars "FTHR" ; feather
set rifermagia to -1
set rifermagia to -1

set effnum to target.GetActiveEffectCount
printc "%g active effects", effnum

; first loop: search a caster of a scripted spell (hoping to be those who casted this script)
while rifermagia < effnum
	set rifermagia to rifermagia + 1
	set caster to GetNthActiveEffectCaster rifermagia
	if caster != target && (GetNthAECode rifermagia == riferscript2)
			;printc "TEST2 | I %g | Caster = %i (%n)", rifermagia, caster, caster
			set i to i+1

			; second loop: search same caster of a feather spell (if exist)
			while rifermagia2 < effnum
				set rifermagia2 to rifermagia2 + 1
				set castertemp to GetNthActiveEffectCaster rifermagia2
				if caster == castertemp && (GetNthAECode rifermagia2 == riferscript)
					;printc "TEST2 | II %g | Caster = %i (%n)", rifermagia2, caster, caster
					set i to i+1
					set rifermagia2 to effnum
				endif
			loop
		
			; control if, at the end of 2nd loop, the search is failed or not
			if i==2
				set rifermagia to effnum
			else
				set rifermagia2 to -1
				set i to 0 ; restart cycle from last rifermagia index
			endif
	endif
loop
end

begin scripteffectupdate
if i == 2 ; only if cycle found the caster
	; ** do stuff **
endif
end

It works fine. But the limits is: if other NPC casted a spell with the same effects, the caster can (will) be wrong.

Another thing: I tryed to use less than 2 seconds for the spell duration (over a target with 9 effects active). That settings cause the failure of the script. I don't know why I have to set at least 2 sec, even if the effects to the target are immediate in-game, but so it work...

Ehi! E' il più complesso script che abbia mai creato per Oblivion!

Edited by nery89
Link to comment
Share on other sites

Another script I made is less elegant, but work fine. Please, note that I need that the caster is npc or creature.

This is how it work (I don't post the code):

  • take a creature with a reference (we call it CREAT) initially disabled with a script containing some variables A, B, C... V==0
  • take the caster (NPC)
  • take the target (TARG)

 

NPC casts a a target-spell on TARG: this spell wait that CREAT.V is equal to 1

at the same time NPC had casted a on-self spell that summon CREAT with the same position, and he pass to her some values, overwriting A, B, C... and set control value V==1

Now the CREAT is serving as invoice of NPC and the spell that was waiting can do some stuff (and disable CREAT)

 

Pro: low cost of time, simple script, caster and target ever known.

Contro: CREAT is visible and reachable, even if for a few frames. If other npcs cast nearby in time the same spell, this can cause oddity or malfunctions

Link to comment
Share on other sites

Sei italiano? Parlo un po d'italiano - ma mi dispiace, non molto bene. Sto cercando di imparare 8)

"il gioco è fatto" è "slang" italiano, è figura retorica. Abbiamo capito però. ;) Ma ciò che è "Rifer"?

 

Miei Italiano è non brillante. In inglese, per favore, ma si può parlare italiano se è necessario. Grazie a Dio per Google Translate 8)

 

 

The index starts at 0, like GetButtonPressed.

 

If you have worked out a script that works, I will not try to fix it. But instead of a creature, you can create a "token", which is just a piece of armor or clothing marked "unplayable" in the CS. Each token's variables are unique, so for example: A token is added to NPC1, V=1 on this token. A token is added to NPC2, this time V=2 on the token. But the Token on NPC1 will still be V=1. All you need to do then is remove the token when the script effect ends.

 

Or alternatively, you can set the scale of the creature to something very small, like 0.00000000001, so that you can't even see it when it is enabled.

Link to comment
Share on other sites

Or alternatively, you can set the scale of the creature to something very small, like 0.00000000001, so that you can't even see it when it is enabled.

It's what I did, but there is a chance to hit the creature. it happened and the Imp (i've used it) said YAAARGHH! :biggrin:

however, I'll think about your purpose (also make trigger zones).

 

Thanks!

grazie mille!

(si, sono italiano. scusa il mio pessimo inglese)

Link to comment
Share on other sites

I think if you are using creatures just to store the variables, then you would be better off using Tokens to do the same thing, only with much less hassle.

 

 

Nessun problema, il tuo inglese è bene. Sono scozzese, così scusa il mio pessimo italiano. Piacere di conoscerti e di praticare italiano. È una bella lingua :)

Ma, ciò che è "rifermagia", in inglese? Magia è "magic", ma ciò che è "rifer"? È l'abbreviazione di riferimento?

Inoltre, se non ti dispiace mi chiede, come sta il mio italiano?

Edited by WarRatsG
Link to comment
Share on other sites

I think if you are using creatures just to store the variables, then you would be better off using Tokens to do the same thing, only with much less hassle.

 

 

Nessun problema, il tuo inglese è bene. Sono scozzese, così scusa il mio pessimo italiano. Piacere di conoscerti e di praticare italiano. È una bella lingua :)

Ma, ciò che è "rifermagia", in inglese? Magia è "magic", ma ciò che è "rifer"? È l'abbreviazione di riferimento?

Inoltre, se non ti dispiace mi chiede, come sta il mio italiano?

 

Ahahah, yes, i had cut RIFERIMENTO to have less letters (it's not a slang -> MagicReference if you like to translate it). and yes, your italiano isn't so bad... you aren't Montale, but I understand what you seem to say :P

I had found another way to do the same thing. i'll post as soon as possible my code (is more simple, it require only the target script!)

but, for the retless:

 

short i
begin scripteffectstart
    set i to getscriptactiveeffectindex
    set TheCasterRef to (getnthactiveeffectcaster i)
    set TheTargetRef to getself

it's less ambitious than the firsts, but it's so simple and free to use! I don't know if there are some "Contro", only "Pro"... ;D

Edited by nery89
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...