tc2r Posted February 15, 2008 Share Posted February 15, 2008 I would like to ask you for advice and tips and help on some code I've been trying to script. It was taken from a mod that a guy gave up on and I think it could work... if I can figure out the right changes. See in his mod, the user gets an spell which when cast at a actor, quickly moves the user towards that actor ultimately ending with the PC behind the actor... a "shadowstep". I would like to change the code so that when NPCs use the spell on each other/the player, it will work for them too. I think it should be as simple as changing the script so whever it says "player" I replace it with "the onewho cast this spell" but I can't figure out how to make that a reference ID. Someone told me to use "long indexref NPC set index to GetScriptActiveEffectIndexset NPC to GetNthActiveEffectCaster "But unless i'm using it wrong, this doesn't return the refid of the one who cast the spell. I've tried the following code and replaced every instance of "player" with "npc" and it didn't work. technically speaking when this script is finished it should work for all actors, not just npcs or player. Could you look at it and see if you can figure out what i'm doing wrong please? btw I have aim, yahooIM, and xfire, do you use an instant messaging sytem? scn PJAssassinsRush ref self ref act float xp float xc float yp float yc float zp float zc float angle float angleoriginal float anglecorrect float sine float cosine float fact2 float fact3 float fact4 float fact5 float fact6 float fact7 float fact8 float fact9 float x2 float x3 float x4 float x5 float x6 float x7 float x8 float x9 float newx float newy float newz float dummy int done int stagger float d float prevd float a float angletarget float stopposx float stopposy Begin ScriptEffectStart set self to GetSelf set act to self.placeatme PJActivatorSource 1,0,0 if (self != player && self.IsActor == 1 && self.getdistance player > 200 && self.getdistance player < 1800) set angleoriginal to player.GetAngle z set angletarget to self.GetAngle z if (angleoriginal >= 360) set angleoriginal to angleoriginal - 360.0 endif if (angletarget >= 360) set angletarget to angletarget - 360.0 endif set anglecorrect to angleoriginal set angleoriginal to angleoriginal % 90 set angle to (angleoriginal / 57.29) set fact2 to 2.0 set fact3 to 6.0 set fact4 to 24.0 set fact5 to 120.0 set fact6 to 720.0 set fact7 to 5040.0 set fact8 to 40320.0 set fact9 to 362880.0 set x2 to (angle * angle) set x3 to (angle * angle * angle) set x4 to (x2 * x2) set x5 to (x2 * x3) set x6 to (x3 * x3) set x7 to (x3 * x4) set x8 to (x4 * x4) set x9 to (x5 * x4) set sine to (angle - (x3 / fact3) + (x5 / fact5) - (x7 / fact7) + (x9 / fact9)) set cosine to (1.0 - (x2 / fact2) + (x4 / fact4) - (x6 / fact6) + (x8 / fact8)) set newx to sine * 1625 * GetSecondsPassed set newy to cosine * 1625 * GetSecondsPassed if (anglecorrect >= 270) set dummy to newx set newx to 0 - newy set newy to dummy elseif (anglecorrect >= 180) set newx to 0 - newx set newy to 0 - newy elseif (anglecorrect >= 90) set dummy to newy set newy to 0 - newx set newx to dummy endif set xc to player.getpos x set xp to act.getpos x set yc to player.getpos y set yp to act.getpos y set zc to player.getpos z set zp to act.getpos z set newz to (zc - zp) / 20 set done to 0 set stagger to 0 set anglecorrect to angletarget set angleoriginal to angleoriginal % 90 set angle to (angleoriginal / 57.29) set fact2 to 2.0 set fact3 to 6.0 set fact4 to 24.0 set fact5 to 120.0 set fact6 to 720.0 set fact7 to 5040.0 set fact8 to 40320.0 set fact9 to 362880.0 set x2 to (angle * angle) set x3 to (angle * angle * angle) set x4 to (x2 * x2) set x5 to (x2 * x3) set x6 to (x3 * x3) set x7 to (x3 * x4) set x8 to (x4 * x4) set x9 to (x5 * x4) set sine to (angle - (x3 / fact3) + (x5 / fact5) - (x7 / fact7) + (x9 / fact9)) set cosine to (1.0 - (x2 / fact2) + (x4 / fact4) - (x6 / fact6) + (x8 / fact8)) set stopposx to sine * -50 set stopposy to cosine * -50 if (anglecorrect >= 270) set dummy to stopposx set stopposx to 0 - stopposy set stopposy to dummy elseif (anglecorrect >= 180) set stopposx to 0 - stopposx set stopposy to 0 - stopposy elseif (anglecorrect >= 90) set dummy to stopposy set stopposy to 0 - stopposx set stopposx to dummy endif else set done to 1 endif set d to player.GetDistance act set prevd to d End Begin ScriptEffectUpdate set d to player.GetDistance act if (stagger > 0 && stagger < 30) self.setangle z a set stagger to stagger + 1 endif if (player.GetDistance act < 300 && done == 0 && stagger == 0) set a to self.getangle z self.setangle z a player.setangle z a set stopposx to stopposx + self.getpos x set stopposy to stopposy + self.getpos y player.setpos x stopposx player.setpos y stopposy set stagger to 1 set done to 1 self.removespell PJOverEncumber endif if (self != player && self.IsActor == 1 && done != 1) self.addspell PJOverEncumber set xc to xc + newx set yc to yc + newy if ((newz < 0 && zc < zp) || (newz > 0 && zc > zp)) set zc to zc - newz endif player.setpos x xc player.setpos y yc player.setpos z zc self.TriggerHitShader 1 endif set prevd to d End Begin ScriptEffectFinish self.removespell PJOverEncumber act.disable End Link to comment Share on other sites More sharing options...
Vagrant0 Posted February 15, 2008 Share Posted February 15, 2008 The issue is that the reference of the caster cannot be obtained unless the spell is either cast on self or obrained through GetNthActiveEffectCaster. However since GetNthActiveEffectCaster is a OBSE function, and doesn't have clear usage documentaton, you may need to do quite a bit of work trying to figure out how to make it return the ID of the caster. As for the scripting, that's a bit too much math for something that you want to run quickly. Regardless, it seems you have some inconsistancies between what you're trying to do with references. Unless I'm reading it wrong, you want to be moving self, not player. If you reverse those two within the updte block, where appropiate, then attach this script to a self cast spell, it should function. You could even replace instances of "player" with a reference gained from "getcombattarget" to make the NPC appear behind whoever they're fighting. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.