SetPos

Post » Fri Jan 01, 2010 5:00 pm

From MWSFD RE: SetPos:

Note: With Tribunal, this function accepts local float variables, but only within the currently active cells. This is relevant for exteriors, you can not move objects an arbitrary distance, the target location must be within the active cells (current cell of player plus surrounding cells).


I'm trying to use SetPos to move an object INTO the player's cell, but I've found it only actually works if the player is within the surrounding cells of the object's original cell.

It works fine whenever I move the object around the cells next to its starting position but as soon as I try and move it one cell too far, the object disappears until the next time I load my saved game, when it appears back at its original location.

Does anyone know a workaround for this without deleting and re-placing the object? I need to keep the reference consistent.

Thanks,

- Danjb
User avatar
Keeley Stevens
 
Posts: 3398
Joined: Wed Sep 06, 2006 6:04 pm

Post » Sat Jan 02, 2010 4:33 am

first thing I'd try is using positioncell/position before setpos and see if it works better
if ( getInterior )  Position x1 y1 z1 zangleelse  PositionCell x1 y1 z1 zangle "Balmora"endifSetPos X x1SetPos Y y1SetPos Z z1

User avatar
Sabrina garzotto
 
Posts: 3384
Joined: Fri Dec 29, 2006 4:58 pm

Post » Fri Jan 01, 2010 4:06 pm

Thanks for the suggestion, but no luck.

Here's the code that places the item:

set xPos to GetPos, xset yPos to GetPos, yset zPos to GetPos, z"private_stash_container"->Position, xPos, yPos, zPos, 0"private_stash_container"->SetPos, x, xPos"private_stash_container"->SetPos, y, yPos"private_stash_container"->SetPos, z, zPos"private_stash_container"->Enable


It's set to only work in exterior cells.

Essentially:
  • With the "Position" before "SetPos", the object doesn't appear at all.
  • Without the "Position", the object only appears if it's within its starting cell (or surrounding cells), and otherwise gets reset.

User avatar
Heather M
 
Posts: 3487
Joined: Mon Aug 27, 2007 5:40 am

Post » Fri Jan 01, 2010 8:48 pm

What happens if you call FixMe after moving the object into the player's cell?
User avatar
Misty lt
 
Posts: 3400
Joined: Mon Dec 25, 2006 10:06 am

Post » Sat Jan 02, 2010 1:28 am

It's PositionCell if you want to place an item in the interior.
set xPos to GetPos, x ; From *what* do you take coordinates? The object in its original place? Would do rubbish.set yPos to GetPos, yset zPos to GetPos, z"private_stash_container"->PositionCell, 0, 0, 0, 0, "My House" ; PositionCell does *not* accept variables"private_stash_container"->SetPos, x, xPos"private_stash_container"->SetPos, y, yPos"private_stash_container"->SetPos, z, zPos"private_stash_container"->Enable

User avatar
Franko AlVarado
 
Posts: 3473
Joined: Sun Nov 18, 2007 7:49 pm

Post » Fri Jan 01, 2010 9:14 pm

Moving a container is one of the most difficult tasks to accomplish with Morrowind scripting. To accomplish this several things have to happen.

First the character must have been in the cell with the container since the most recent game load. This can be detected in one of two ways: by setting a journal entry to an invalid value which will be reset to the next lowest valid value for that journal entry or by setting and object to a scale greater than 2. Your script will need to move the player to the container's holding cell and then back to the player's original position the first time the move container script is called after a cell load.

if ( NI_mycontainer->getScale != 3 )   fadeOut 0, .01   set myX to player->getPos X   set myY to player->getPos Y   set myZ to player->getPos Z   set myA to player->getAngle   player->positionCell "My Holding Cell" 0 0 0 0   player->position myX, myY, myZ, myA   fadeIn 1, .01endIf


The next thing that has to happen is you most move the container to a cell within 1 cell of the player's position. To do this you would look at the player's X and Y coordinates and using a long list of nested if() statements find a cell close to the player. The numbers below are not right for the first myX test it would be the value of the right hand edge of the maps right most X column of cells. For the first myY test in each of the myX tests it would be the bottom most row of Y cell values. These values are decremented by 3 times the height/width of each cell (I don't have the number on hand) and position statement would use the middle of the cell that is centered between the current and next test values. That probably doesn't make sense. So assuming that the map goes from -14 to 14 on the x axis and -14 to 14 on the Y axis you would first check if the value of X > 13 * width of a cell. The Y value would start testing for Y > 13 * height of a cell. If these two test pass the container would move to the center of cell 14, 14.

if ( myX > 80000 )    if ( myY > 80000 )       NI_myContainer->position 84000 84000 0 0   elseIf (myY 56000       NI_myContainer->position 84000 60000 0 0   elseIf     ; ect. ect. ect.   endIfelseIf ( myX > 56000 )   elseIf ( myY > 80000 )       NI_myContainer->position 60000 84000 0 0   elseIf ( myY > 56000 )       NI_myContainer->position 60000 60000 0 0   elseIf        ; ect. ect. ect.elseIf   ; ect ect ectendIf


Once the the container is close to the player it can then be positioned at the player's final destination using setPos. However the container will not display correctly so it will have disable, enable, fixme performed on the container twice each and then positioned again to fix the display.

NI_myContainer->setScale 1 NI_myContainer->setPos X myXNI_myContainer->setPos Y myYNI_myContainer->setPos Z myZNI_myContainer->disableNI_myContainer->enableNI_myContainer->fixMeNI_myContainer->disableNI_myContainer->enableNI_myContainer->setPos X myXNI_myContainer->setPos Y myYNI_myContainer->setPos Z myZ


When done with the container the script needs to store the container in the holding cell

NI_myContainer->setScale 3NI_myContainer->positionCell "My Holding Cell" 0 0 0 0

User avatar
Jessica Lloyd
 
Posts: 3481
Joined: Fri Aug 25, 2006 2:11 pm

Post » Sat Jan 02, 2010 12:17 am

What happens if you call FixMe after moving the object into the player's cell?

I might give this a go but I tried it in the console and it didn't seem to do anything. Looking at Nicholiathan's post something tells me it won't work :P

It's PositionCell if you want to place an item in the interior.

I'm only trying to place the item in exterior cells for now.

Moving a container is one of the most difficult tasks to accomplish with Morrowind scripting. To accomplish this several things have to happen...

Thanks a lot for all your advice, it's very much appreciated! I'll see what I can do. Most likely I'll be back looking for some more help ;)
A few questions, though...

First the character must have been in the cell with the container since the most recent game load...

No problem, thanks to your help in my other thread!

Your script will need to move the player to the container's holding cell and then back to the player's original position the first time the move container script is called after a cell load.

Ugh, that's a pain, since the only reason I'm trying to move an object in the first place is to avoid the player having to visit the container's original cell every time the game loads.
What if the player is in an interior cell before you move him? You can't move him back to his original position using "Position"...

The next thing that has to happen is you most move the container to a cell within 1 cell of the player's position. To do this you would look at the player's X and Y coordinates and using a long list of nested if() statements find a cell close to the player.

That sounds insane! The map must stretch at least a hundred cells in each direction! Could you not just place the container at the player's co-ordinates (either disable it first, or modify the co-ordinates slightly so it doesn't get in the way)?

Once the the container is close to the player it can then be positioned at the player's final destination using setPos. However the container will not display correctly so it will have disable, enable, fixme performed on the container twice each and then positioned again to fix the display.

Twice each? Interesting... do you think there's any chance using these commands twice each with my existing code would work?

When done with the container the script needs to store the container in the holding cell

This holding cell idea is interesting... If all this is an difficult as you say it is, I might just give the player an item that teleports him to the holding cell so the container doesn't have to move at all.
User avatar
Crystal Birch
 
Posts: 3416
Joined: Sat Mar 03, 2007 3:34 pm

Post » Sat Jan 02, 2010 1:44 am

The next thing that has to happen is you most move the container to a cell within 1 cell of the player's position.

That's one of those things that I wouldn't even do if I couldn't use MWSE. xPosition is in the version included with MGE, so it's not that bad.
User avatar
Marine x
 
Posts: 3327
Joined: Thu Mar 29, 2007 4:54 am

Post » Sat Jan 02, 2010 1:03 am

Ugh, that's a pain, since the only reason I'm trying to move an object in the first place is to avoid the player having to visit the container's original cell every time the game loads.
What if the player is in an interior cell before you move him? You can't move him back to his original position using "Position"...


I forgot to mention using toggle menus off, fadeout before moving and fade in and toggle menus on all that will display will be a very brief black screen while the player is moved and reposisitioned.


That sounds insane! The map must stretch at least a hundred cells in each direction! Could you not just place the container at the player's co-ordinates (either disable it first, or modify the co-ordinates slightly so it doesn't get in the way)?


Without using MWSE the process makes only a few checks of in the If/elseIf blocks. The space covered by the original map ranges from about -14 to 19 on the X and about the same on the Y (I'm not finding the exact numbers at this time. But with these you'd have 11 checks for the X axis each of these would have 11 checks for the Y axis. As OnmyojiOmn suggests MWSE makes this much easier


Twice each? Interesting... do you think there's any chance using these commands twice each with my existing code would work?


I got that from working with better portable containers when I got permition to addapt those scripts for Carrie Iriette's protable container.


This holding cell idea is interesting... If all this is an difficult as you say it is, I might just give the player an item that teleports him to the holding cell so the container doesn't have to move at all.


That's the easiest way to handle it.
User avatar
Jani Eayon
 
Posts: 3435
Joined: Sun Mar 25, 2007 12:19 pm

Post » Sat Jan 02, 2010 6:04 am

Thanks again Nicholiathan, I'll be sure to drop you a line in the credits.

EDIT:
I've made it so that player's co-ordinates are stored as variables and then he is restored to his original position. It all works, except that I can't seem to get SetAngle to work, so the player always ends up facing north.

	set private_stash_xPos to ( Player->GetPos, x )	set private_stash_yPos to ( Player->GetPos, y )	set private_stash_zPos to ( Player->GetPos, z )	set private_stash_zAngle to ( Player->GetAngle, z )


float xPosfloat yPosfloat zPosfloat zAngle	set xPos to private_stash_xPos	set yPos to private_stash_yPos	set zPos to private_stash_zPos	set zAngle to private_stash_zAngle	Player->Position, xPos, yPos, zPos, zAngle	Player->SetPos, x, xPos	Player->SetPos, y, yPos	Player->SetPos, z, zPos	Player->SetAngle, z, zAngle	FixMe	Player->SetPos, x, xPos	Player->SetPos, y, yPos	Player->SetPos, z, zPos	Player->SetAngle, z, zAngle

User avatar
Laura Richards
 
Posts: 3468
Joined: Mon Aug 28, 2006 4:42 am

Post » Fri Jan 01, 2010 11:36 pm

Edit: never mind, misread.
User avatar
Logan Greenwood
 
Posts: 3416
Joined: Mon Jul 30, 2007 5:41 pm


Return to III - Morrowind