Help -- Make a Script more efficient?

Post » Sun May 18, 2014 3:25 am

I was wondering if anyone had any thoughts on making my script more efficient?

I have ten persistent markers in a remote cell; when the Spell is cast, they are positioned relative to the player/each other, so that they form two "plus" symbols, with the first-set firing a spell at the second-set.

The firing works perfectly, but the movement part of the script can take several seconds, which makes it inefficient to actually use in combat...

;Caster's Z AnglePCZAngle = Target.GetAngleZ() ;position the first three markersMarker01.MoveTo(Caster, 120.0 * Math.Sin(Caster.GetAngleZ()), 120.0 * Math.Cos(Caster.GetAngleZ()), Caster.GetHeight() - 25.0) Marker02.MoveTo(Caster, 120.0 * Math.Sin(Caster.GetAngleZ()), 120.0 * Math.Cos(Caster.GetAngleZ()), Caster.GetHeight() - 60.0) Marker03.MoveTo(Caster, 120.0 * Math.Sin(Caster.GetAngleZ()), 120.0 * Math.Cos(Caster.GetAngleZ()), Caster.GetHeight() - 95.0) Marker01.SetAngle(0, 0, PCZAngle)Marker02.SetAngle(0, 0, PCZAngle)Marker03.SetAngle(0, 0, PCZAngle) ;turn 90 degrees for marker 04 positioningPCZAngle = ( PCZAngle + 90 )Marker03.SetAngle(0, 0, PCZAngle)Marker04.MoveTo(Marker03, 35.0 * Math.Sin(Marker03.GetAngleZ()), 35.0 * Math.Cos(Marker03.GetAngleZ()), Marker03.GetHeight() + 35.0)  ;turn 180 degress (Around) for marker 05 positioningPCZAngle = ( PCZAngle - 180 )Marker03.SetAngle(0, 0, PCZAngle)Marker05.MoveTo(Marker03, 35.0 * Math.Sin(Marker03.GetAngleZ()), 35.0 * Math.Cos(Marker03.GetAngleZ()), Marker03.GetHeight() + 35.0)  ;return to normal positioning for all five markersPCZAngle = ( PCZAngle + 90 )Marker03.SetAngle(0, 0, PCZAngle)Marker04.SetAngle(0, 0, PCZAngle)Marker05.SetAngle(0, 0, PCZAngle) ;place new markers ahead of old markersMarker06.MoveTo(Marker01, 120.0 * Math.Sin(Marker01.GetAngleZ()), 120.0 * Math.Cos(Marker01.GetAngleZ()), Marker01.GetHeight() -  15.0) Marker07.MoveTo(Marker02, 120.0 * Math.Sin(Marker02.GetAngleZ()), 120.0 * Math.Cos(Marker02.GetAngleZ()), Marker02.GetHeight() - 15.0) Marker08.MoveTo(Marker03, 120.0 * Math.Sin(Marker03.GetAngleZ()), 120.0 * Math.Cos(Marker03.GetAngleZ()), Marker03.GetHeight() - 15.0) Marker09.MoveTo(Marker04, 120.0 * Math.Sin(Marker04.GetAngleZ()), 120.0 * Math.Cos(Marker04.GetAngleZ()), Marker04.GetHeight() - 15.0) Marker10.MoveTo(Marker05, 120.0 * Math.Sin(Marker05.GetAngleZ()), 120.0 * Math.Cos(Marker05.GetAngleZ()), Marker05.GetHeight() - 15.0)  ;cast spellsZCDMVHFSpell.Cast(Marker01, Marker06)ZCDMVHFSpell.Cast(Marker02, Marker07)ZCDMVHFSpell.Cast(Marker03, Marker08)ZCDMVHFSpell.Cast(Marker04, Marker09)ZCDMVHFSpell.Cast(Marker05, Marker10)
User avatar
Nicholas C
 
Posts: 3489
Joined: Tue Aug 07, 2007 8:20 am

Post » Sun May 18, 2014 12:35 pm

You can try to rewrite your script so it does these calls only once:
Target.GetAngleZ()
Caster.GetAngleZ()
Caster.GetHeight()

Also I don't see the point of rotating Marker03. You already have the angle, no need to set -> get it though that marker.
User avatar
Stacey Mason
 
Posts: 3350
Joined: Wed Nov 08, 2006 6:18 am

Post » Sun May 18, 2014 6:51 am

Also, since you already know the z offset for your markers relative to the original Caster.GetHeight() call, you can just store Caster.GetHeight() in a variable and use it to determine all of your Z offsets through the rest of the script. And all the GetAngleZ() calls on the markers later in the script are unnecessary, since they're based off of PCZAngle. Generally using variable stored values instead as you implement these plus Schlangster's changes should dramatically improve the speed of the script.

User avatar
Lori Joe
 
Posts: 3539
Joined: Tue Jun 20, 2006 6:10 am

Post » Sat May 17, 2014 10:25 pm

This should work, but double check for errors, I typed it in a rush and haven't slept in 24 hours.

PS: consider putting all markers in a form array if you plan on making anymore markers, it helps to avoid repeating the same instruction 10 times. Also, consider using variables for literal values such a s 120. If you decide later on that 120 isn't the correct value, it's better to
change one variable than Thirty Five 120s.
 ;Caster's Z AnglePCZAngle = Target.GetAngleZ()float casterAngleZ = Caster.GetAngleZfloat casterHeight = Caster.GetHeight()float xOffset = 120.0 * Math.Sin(casterAngleZ())float yOffset = 120.0 * Math.Cos(casterAngleZ());position the first three markersMarker01.MoveTo(Caster, xOffset, yOffset, (casterHeight - 25))Marker02.MoveToMoveTo(Caster, xOffset, yOffset, (casterHeight - 60))Marker03.MoveToMoveTo(Caster, xOffset, yOffset, (casterHeight - 95))Marker01.SetAngle(0, 0, PCZAngle)Marker02.SetAngle(0, 0, PCZAngle)Marker03.SetAngle(0, 0, PCZAngle);turn 90 degrees for marker 04 positioningPCZAngle = (PCZAngle + 90)float markerAngleZ = Marker03.GetAngleZ()float markerHeight = (Marker03.GetHeight() + 35.0)xOffset = 35.0 * Math.Sin(markerAngleZ)yOffset = 35.0 * Math.Cos(markerAngleZ)Marker03.SetAngle(0, 0, PCZAngle)Marker04.MoveTo(Marker03, xOffset, yOffset, markerHeight);turn 180 degress (Around) for marker 05 positioningPCZAngle = (PCZAngle - 180)Marker03.SetAngle(0, 0, PCZAngle)Marker05.MoveTo(Marker03, xOffset, yOffset, markerHeight);return to normal positioning for all five markersPCZAngle = ( PCZAngle + 90 );##What happened to MARKER01 and MARKER02? ###Marker03.SetAngle(0, 0, PCZAngle)Marker04.SetAngle(0, 0, PCZAngle)Marker05.SetAngle(0, 0, PCZAngle);place new markers ahead of old markersmarkerAngleZ = Marker01.GetAngleZ()Marker06.MoveTo(Marker01, 120.0 * Math.Sin(markerAngleZ), 120.0 * Math.Cos(markerAngleZ), Marker01.GetHeight() - 15.0)markerAngleZ = Marker02.GetAngleZ()Marker07.MoveTo(Marker02, 120.0 * Math.Sin(markerAngleZ), 120.0 * Math.Cos(markerAngleZ), Marker02.GetHeight() - 15.0)markerAngleZ = Marker03.GetAngleZ()Marker08.MoveTo(Marker03, 120.0 * Math.Sin(markerAngleZ), 120.0 * Math.Cos(markerAngleZ), Marker03.GetHeight() - 15.0)markerAngleZ = Marker04.GetAngleZ()Marker09.MoveTo(Marker04, 120.0 * Math.Sin(markerAngleZ), 120.0 * Math.Cos(markerAngleZ), Marker04.GetHeight() - 15.0)markerAngleZ = Marker05.GetAngleZ()Marker10.MoveTo(Marker05, 120.0 * Math.Sin(markerAngleZ), 120.0 * Math.Cos(markerAngleZ), Marker05.GetHeight() - 15.0);cast spellsZCDMVHFSpell.Cast(Marker01, Marker06)ZCDMVHFSpell.Cast(Marker02, Marker07)ZCDMVHFSpell.Cast(Marker03, Marker08)ZCDMVHFSpell.Cast(Marker04, Marker09)ZCDMVHFSpell.Cast(Marker05, Marker10)
User avatar
Jessie
 
Posts: 3343
Joined: Sat Oct 14, 2006 2:54 am

Post » Sun May 18, 2014 9:46 am

I'd really like to see a video of this spell. I am curious why you need 10 markers. Is it something like a Wall of Flames spell?

~

User avatar
Nichola Haynes
 
Posts: 3457
Joined: Tue Aug 01, 2006 4:54 pm

Post » Sun May 18, 2014 8:06 am

Thanks for the help. :)

I've modified my Script a bit, and got it down to about 2-seconds between pressing the key, and the spell actually firing.

@Schlangster,

I don't quite understand what you mean about not needing to rotate Marker 3? Maybe I'm just not getting it, but in case we're misunderstanding each other I'll re-explain what I'm trying to do, hopefully you'll see why I think it is needed?

1) I place three markers in front of the player at head, chest and waist height (Roughly)

2) One marker appears to the right of Marker 02, so about level with the Player's Shoulder

3) One marker appears to the left of Marker 02, so about level with the Player's Shoulder

(Although I'm using Marker03 to actually set them)

The code as I understand it places the item AHEAD of the Marker, based on the "forward" reading of it's zero-coordinate on the Z-axis; which when Marker03 is moved to the player, is the same heading the Player is on. So making the next two markers appear would put them in a line ahead of the Player, rather than to the Player's left or right? That's why I turn it, 90 right, and then 180, so that it moves Markers 04 and 05 to where they should be (And then turns all three around). Is there a better way I can get the position for Markers 04 and 05, without needing to turn Marker 03?

@FiveAlpha,

Thanks, I edited my script and compared it to yours; I made a few changes, but you gave me a good basis of what I was needed to do :)

@Shadey,

Yes-- it's mean to be like a five-fireball "Plus" sign, sort of thing, with all five shots firing at once to create a kind of three-by-three wall, if that makes sense?

User avatar
MARLON JOHNSON
 
Posts: 3377
Joined: Sun May 20, 2007 7:12 pm

Post » Sun May 18, 2014 6:20 am

I'd love to see that! Maybe, if you cannot trim the time down any more, and it's a Master level spell, you could have a 1 second casting time instead of the 3 second animation and it ends up as 3 seconds total? it might not look as cool as you want, though. Unless you can fill in the 2 second delay with some other visual effect, like the caster appearing to burst into flames for 2 seconds?

~

User avatar
Riky Carrasco
 
Posts: 3429
Joined: Tue Nov 06, 2007 12:17 am

Post » Sun May 18, 2014 3:40 am

Well I meant something like this:
float targetAngle = Target.GetAngleZ()float casterAngle = Caster.GetAngleZ()float casterHeight = Caster.GetHeight()float casterAngleSin = Math.Sin(casterAngle)float casterAngleCos = Math.Cos(casterAngle)float markerXOffset = 120.0 * casterAngleSinfloat markerYOffset = 120.0 * casterAngleCosfloat sideAngle = targetAngle + 90float sideXOffset = 35.0 * Math.Sin(sideAngle)float sideYOffset = 35.0 * Math.Cos(sideAngle); fromMarker01.MoveTo(Caster, markerXOffset, markerYOffset, casterHeight - 25.0) Marker01.SetAngle(0, 0, targetAngle)Marker02.MoveTo(Caster, markerXOffset, markerYOffset, casterHeight - 60.0) Marker02.SetAngle(0, 0, targetAngle)Marker03.MoveTo(Caster, markerXOffset, markerYOffset, casterHeight - 95.0) Marker03.SetAngle(0, 0, targetAngle)Marker04.MoveTo(Marker03,  sideXOffset,  sideYOffset, casterHeight - 60.0) Marker04.SetAngle(0, 0, targetAngle)Marker05.MoveTo(Marker03, -sideXOffset, -sideYOffset, casterHeight - 60.0) Marker05.SetAngle(0, 0, targetAngle)  ; toMarker06.MoveTo(Marker01, markerXOffset, markerYOffset), casterHeight - 40.0) Marker07.MoveTo(Marker02, markerXOffset, markerYOffset), casterHeight - 75.0) Marker08.MoveTo(Marker03, markerXOffset, markerYOffset), casterHeight - 110.0) Marker09.MoveTo(Marker04, markerXOffset, markerYOffset), casterHeight - 75.0) Marker10.MoveTo(Marker05, markerXOffset, markerYOffset), casterHeight - 75.0)  ; castZCDMVHFSpell.Cast(Marker01, Marker06)ZCDMVHFSpell.Cast(Marker02, Marker07)ZCDMVHFSpell.Cast(Marker03, Marker08)ZCDMVHFSpell.Cast(Marker04, Marker09)ZCDMVHFSpell.Cast(Marker05, Marker10)
User avatar
[Bounty][Ben]
 
Posts: 3352
Joined: Mon Jul 30, 2007 2:11 pm

Post » Sun May 18, 2014 12:27 pm

Ah, I see!

I am afraid I do not really understand the math side of it, so I think I misunderstood how the script worked, then :) (I based the moveto part on the method on the MoveTo Wiki Page)

Thank-you for your help! I will try that when I am next at the CK :)

User avatar
Matthew Aaron Evans
 
Posts: 3361
Joined: Wed Jul 25, 2007 2:59 am


Return to V - Skyrim