What's wrong with my script?

Post » Wed Oct 06, 2010 5:09 pm

I have written a spell script which looks like it should work, but but when I test it in a large cell the game freezes. Heres the script. My computer is not very good (Dell laptop with 4 GB RAM and a lousy video card), so it could just be too much to process, but it's not an extremely complex script, so I don't know why it should. Here it is. Tell me if you see the problem.

scn AssassinTeleportScriptref targetfloat targetzshort initbegin scripteffectstartset target to getselfif ( target.isactor == 1 ) && ( target.getdead == 0 )set targetz to target.getangle zset init to 1endifendbegin gamemodeif ( init == 1 )player.pms effectsoultrap 3if ( targetz > 337.5 ) || ( targetz <= 22.5 )	set init to 0        player.setangle z, 0	player.moveto target 0 -50 0elseif ( targetz > 22.5 ) && ( targetz <= 67.5 )	set init to 0        player.setangle z, 45	player.moveto target -35 -35 0elseif ( targetz > 67.5 ) && ( targetz <= 112.5 )	set init to 0        player.setangle z, 90	player.moveto target -50 0 0elseif ( targetz > 112.5 ) && ( targetz <= 157.5 )	set init to 0        player.setangle z, 135	player.moveto target -35 35 0elseif ( targetz > 157.5 ) && ( targetz <= 202.5 )	set init to 0        player.setangle z, 180	player.moveto target 0 50 0elseif ( targetz > 202.5 ) && ( targetz <= 247.5 )	set init to 0        player.setangle z, 225	player.moveto target 35 35 0elseif ( targetz > 247.5 ) && ( targetz <= 292.5 )	set init to 0        player.setangle z, 270	player.moveto target 50 0 0elseif ( targetz > 292.5 ) && ( targetz <= 337.5 )        set init to 0	player.setangle z, 315	player.moveto target 35 -35 0endifendifend

User avatar
Jennifer May
 
Posts: 3376
Joined: Thu Aug 16, 2007 3:51 pm

Post » Wed Oct 06, 2010 2:38 pm

else if ? you mean elseif
why not try scripteffectFinish or update blocks ?
don't use numbers in the beginning of your editorIDs - change them all now - and in the NPCs, items etc you made
then see if it works
User avatar
Ezekiel Macallister
 
Posts: 3493
Joined: Fri Jun 22, 2007 12:08 pm

Post » Wed Oct 06, 2010 5:00 pm

as said:

they should be elseif not else if

your script name needs to start with a letter, and more importantly any ID you make must start with a letter, else the game will start thinking its a formID and get all confused.

I dont think gamemode blocks will work in a scripted effect, you'll have to use scripteffectFinish and/or scripteffectupdate blocks.


and scripts are rarely hampered by hardware power...unless they are really OBSE heavy and are doing heaps.


Can you tell use what this script is doing? (im guessing rotating something around) if you can tell us we might be able ot help stucture it to work as a spell.
User avatar
Tinkerbells
 
Posts: 3432
Joined: Sat Jun 24, 2006 10:22 pm

Post » Wed Oct 06, 2010 11:18 am

Can you tell use what this script is doing? (im guessing rotating something around) if you can tell us we might be able ot help stucture it to work as a spell.

It's a short range teleport script designed to move the Player to the target actor and face the same direction.
User avatar
Stefanny Cardona
 
Posts: 3352
Joined: Tue Dec 19, 2006 8:08 pm

Post » Wed Oct 06, 2010 9:28 am

I fixed the elseif thing and my editor ID, and my spell now works great in interior cells, but when I cast it in the city, it still freezes
User avatar
Bedford White
 
Posts: 3307
Joined: Tue Jun 12, 2007 2:09 am

Post » Wed Oct 06, 2010 3:08 pm

If this function is used to move the player, it will also act as a Return function -- no following lines of the script will be processed.


One problem may be this. Init is never getting set to zero, so the script is perpetually teleporting the player. Try setting init to zero just before the player.moveto.
User avatar
Hayley O'Gara
 
Posts: 3465
Joined: Wed Nov 22, 2006 2:53 am

Post » Wed Oct 06, 2010 7:00 am

So far I've changed everything all of you have suggested, and the spell now performs perfectly in interiors but crashes in other worldspaces. Is it possible that there is an error with collision that could be fixed if the distance from the target the player teleported to were increased? The interior cells I've tried it in were houses with perfectly flat ground, so it may also help if i make the player appear about a foot higher to allow for hills. So far I have only tested it on NPCs, not creatures. In response to da mage, I don't think gamemode blocks are a problem in spell scripts, as they are used in several enchanted weapons and spells in the Shivering Isles, and probably in the normal game as well.
Here are the only other things I can think of:
Is float the right kind of variable for an angle, or should I use something else instead?
Does setangle work on the player?

If nobody knows, I'm probably going to have to just going to give this up for now and maybe come in the future once I've really gotten the hang of scripting.
User avatar
Miragel Ginza
 
Posts: 3502
Joined: Thu Dec 21, 2006 6:19 am

Post » Wed Oct 06, 2010 5:20 am

Setangle works on the player, as far as I know.

You could do a "getpos z" on the target and pass that to the player to compensate for hills, perhaps.

I don't see why this would make a difference, but in Worldspaces the coordinate system is 90 degrees off from in interiors, if I recall correctly. But since you are using offsets from the target, I don't see why that would cause a freeze.

If you were using OBSE I could offer a small bit of code that would place the player in the same position relative to the target every time, without the elseifs and the approximations. Takes into account worldspaces vs. cell as well. Assuming that moving the player within the same worldspace isn't the problem.
User avatar
Emma Pennington
 
Posts: 3346
Joined: Tue Oct 17, 2006 8:41 am

Post » Wed Oct 06, 2010 5:29 am

Just learned that the function moveto is almost the same as positioncell, for moving things in a cell, while positionworld is for worldspaces, but they are for coordinates, not relative to objects. does that mean moveto is cells only, or at least less stable in worldspaces? If so, could I run a check to see if its a cell or worldspace to decide which function to use then use setpos to teleport?
User avatar
Sweets Sweets
 
Posts: 3339
Joined: Tue Jun 13, 2006 3:26 am

Post » Wed Oct 06, 2010 11:09 am

If you were using OBSE I could offer a small bit of code that would place the player in the same position relative to the target every time, without the elseifs and the approximations. Takes into account worldspaces vs. cell as well. Assuming that moving the player within the same worldspace isn't the problem.
Please, please, please I'd like to see this bit of code :icecream:

Just learned that the function moveto is almost the same as positioncell, for moving things in a cell, while positionworld is for worldspaces, but they are for coordinates, not relative to objects. does that mean moveto is cells only, or at least less stable in worldspaces? If so, could I run a check to see if its a cell or worldspace to decide which function to use then use setpos to teleport?

Do you read the wiki ? http://cs.elderscrolls.com/constwiki/index.php/PositionWorld : In almost every case, you would rather use MoveTo instead of this command it says - maybe it will work though :shrug:
http://cs.elderscrolls.com/constwiki/index.php/MoveTo
http://cs.elderscrolls.com/constwiki/index.php/Talk:MoveTo
http://cs.elderscrolls.com/constwiki/index.php/Common_Bugs#MoveTo_Oddities

I would be interested to see if setpos causes the same problems - try it
Also do try the scriptEffectUpdate and/or scriptEffecFinish block instead of gamemode
and comment out the setangle part to see how that goes

Finally teleport a marker to where you want the player to go and move the player to that marker - then move the marker back to your test cell
this freeze is strange I admit
User avatar
Averielle Garcia
 
Posts: 3491
Joined: Fri Aug 24, 2007 3:41 pm

Post » Wed Oct 06, 2010 5:32 pm

This is the original bit of code. It places the object directly in front of the player, facing him and 100 units away. The references would need to be reversed so the player is moving instead of the item, and if you want the player next to the object/npc, you'd need to tweak the offsets. Should be doable.

set xpos to player.getpos x	set ypos to player.getpos y	set zpos to player.getpos z + 26		;The plus 26 probably says more about my modelling skill then the Oblivion engine.	set rot to player.getangle z	if rot <= 90		set trigrot to  (90 - rot)	else		set trigrot to (450 - rot)		;this section fixes the fact that the player angle and angle used in positioncell/positionworld are off by 90 degrees	endif	if rot >= 180		set rotmirror to (rot - 180)	else		set rotmirror to (rot + 180)		;Just makes the item face the player	endif	set xposmirror to (xpos + (100 * (cos trigrot)))	set yposmirror to (ypos + (100 * (sin trigrot)))		;calculates the correct offset from the player depending on the angle he's facing	if player.IsInInterior		showlerUniversalArmorStandRef0000.positioncell, xposmirror, yposmirror, zpos, rotmirror, yourcurrentcell	else		showlerUniversalArmorStandRef0000.positionworld, xposmirror, yposmirror, zpos, rotmirror, yourcurrentcell	endif	showlerUniversalArmorStandRef0000.setangle z rotmirror	showlerUniversalArmorStandRef0000.enable	showlerUniversalArmorStandRef0000.disable

User avatar
Chica Cheve
 
Posts: 3411
Joined: Sun Aug 27, 2006 10:42 pm

Post » Wed Oct 06, 2010 11:38 am

snip

Thank you very much indeed - I need to see scripts like this for an idea I had - in my free time :rolleyes:

This could be much use to zorg also :)
User avatar
sas
 
Posts: 3435
Joined: Thu Aug 03, 2006 8:40 am


Return to IV - Oblivion