PlaceAtMe and multiple objects

Post » Thu Jun 14, 2012 6:23 am

The game has a habit of putting things where it wants them... like without MCP a placeAtMe in 3rd person puts the whatever exactly under the PC, and sometimes without apparent reason an object will be placed to the right or left of the calling object instead of X number of units in front as scripted.

So, the question is, if you wanted to place two objects in front of the PC in a predetermined XYZ relationship, is there anyway to make that happen? As an example, say that you wanted to use PlaceAtMe to place a static, like the common building, and you wanted to place an activator or a door in the correct position for the door frame, is there any way to make that happen with a degree of certainty?
User avatar
steve brewin
 
Posts: 3411
Joined: Thu Jun 21, 2007 7:17 am

Post » Thu Jun 14, 2012 6:13 am

Yes, Placeitem is pretty reliable, but you usually need a little trigonometry to calculate sin/cos multipliers if your object is not aligned to 90 degrees multiples.
Here is a sample script from abotWindowsGlow.esp, placing lights in front of a window (needed rotation may depend on internal mesh alignment also, not all windows .nif are facing same direction)
Spoiler
begin ab01ExNordWin02ScriptDontSaveObjectfloat x1float y1float z1float a1short i1short i2short i3short i4float x2float x3float zsinfloat zcosif ( MenuMode )	returnendifif ( i4 == 0 )	if ( GetInterior )		if ( GetWindSpeed >= 0.01 )			set i4 to 1   ; interior as exterior		else			set i4 to 2		endif	else		set i4 to 1	endifendifif ( NightTime )	if ( i4 == 2 )		if ( GetDisabled )			enable		endif	else		if ( GetDisabled )			return		endif		set i1 to Random 1001		if ( i1 > 988 )			set i3 to 1		endif	endifelse	if ( i4 == 2 )		if ( GetDisabled )		else			if ( GetCurrentWeather < 2 )				set i3 to 2			else				set i3 to 3			endif		endif	else		if ( GetDisabled )			enable			set i3 to 0		endif	endifendifif ( i3 == 0 )	returnendifset x1 to GetPos Xset y1 to GetPos Yset z1 to GetPos Zset a1 to GetAngle Zdisableif ( i3 == 1 )	PlaceItem ab01Ex_nord_win_02ex x1 y1 z1 a1elseif ( i3 == 2 )	PlaceItem ab01Ex_nord_win_02in x1 y1 z1 a1else	PlaceItem ab01Ex_nord_win_02in2 x1 y1 z1 a1endifif ( ab01wgLightsOff == 2 )	set i3 to 0	returnendifif ( ab01wgLightsOff == 1 )	if ( i4 == 1 )		set i1 to Random 1001		if ( i1 < 750 )			set i3 to 0			return		endif	endifendifif ( a1 > 180 )	set a1 to ( a1 - 360 )   ; -180 <= a1 <= 180endifif ( a1 >= 0 )	set x3 to a1	set i2 to 1  ; i2 = clockwiseelse	set x3 to ( 0 - a1 )	set i2 to 0endifif ( x3 <= 45 )	set i1 to 1  ; i1 = quadrantelseif ( x3 <= 90 )	set x3 to ( 90 - x3 )	set i1 to 2elseif ( x3 <= 135 )	set x3 to ( x3 - 90 )	set i1 to 3elseif ( x3 <= 180 )	set x3 to ( 180 - x3 )	set i1 to 4endif; Matt Singleton/Galsiah seriesset x3 to ( x3 * 0.0174533 )set x2 to ( x3 * x3 )set zcos to ( ( ( 0.0074857 * x2 ) - 0.1655574 ) * x2 )set zcos to ( ( ( 0.9995425 + zcos ) * x3 ) + 0.0000605 )set x3 to ( 1.5707963 - x3 )set x2 to ( x3 * x3 )set zsin to ( ( ( 0.0074857 * x2 ) - 0.1655574 ) * x2 )set zsin to ( ( ( 0.9995425 + zsin ) * x3 ) + 0.0000605 )if ( i1 > 1 )	if ( i1 < 4 )		set x2 to zcos		set zcos to zsin		set zsin to x2	endifendifif ( i2 == 1 )	if ( i1 > 2 )		set zsin to ( 0 - zsin )	endifelse	if ( i1 <= 2 )		set zcos to ( 0 - zcos )	else		set zcos to ( 0 - zcos )		set zsin to ( 0 - zsin )	endifendif; fix limitsif ( zsin < -1 )	set zsin to -1elseif ( zsin > 1 )	set zsin to 1endifif ( zcos < -1 )	set zcos to -1elseif ( zcos > 1 )	set zcos to 1endif; dy rotation - traslationset x1 to ( x1 - ( 30 * zcos ) )set y1 to ( y1 - ( 30 * zsin ) )if ( ab01debug == 26 )	if ( i3 == 1 )		PlaceItem ab01WindowLightExD x1 y1 z1 a1	elseif ( i3 == 2 )		PlaceItem ab01WindowLightInD x1 y1 z1 a1	else		PlaceItem ab01WindowLightIn2D x1 y1 z1 a1	endifelse	if ( i3 == 1 )		PlaceItem ab01WindowLightEx x1 y1 z1 a1	elseif ( i3 == 2 )		PlaceItem ab01WindowLightIn x1 y1 z1 a1	else		PlaceItem ab01WindowLightIn2 x1 y1 z1 a1	endifendifset i3 to 0end
User avatar
Krystina Proietti
 
Posts: 3388
Joined: Sat Dec 23, 2006 9:02 pm

Post » Thu Jun 14, 2012 5:58 am

It looks beautiful... I take it there are weather effects taken into account, but I was a little curious about the Interior as exterior comment behind the wind speed "if".

Trig has never been my strong suit, so I'm not sure how I might adapt a script like this but I do appreciate your response and posting this. I presume that changing the object IDs would result in a second object being placed, but I don't know how I would adjust it to fine-tune the actual location.

That doesn't mean I won't try it at some point...
Thanks again,
:smile:
Neil
User avatar
Judy Lynch
 
Posts: 3504
Joined: Fri Oct 20, 2006 8:31 am

Post » Thu Jun 14, 2012 8:35 am

Yes, I think you could recycle the more complicated sin/cos factors calculation and change effective rotation/traslation formula using them, e.g. something similar to this
float dxfloat dyset dx to 30	; 30 to the rightset dy to 50	; 50 to the front; dx, dy rotation - traslation - signs should be tested but you get the ideaset x1 to ( x1 - ( dy * zcos ) - ( dx * zsin ) )set y1 to ( y1 - ( dy * zsin ) + ( dx * zcos ) )PlaceItem myObject1 x1 y1 z1 a1set dx to -30	; 30 to the leftset dy to 50	; 50 to the front; dx, dy rotation - traslation - signs should be tested but you get the ideaset x1 to ( x1 - ( dy * zcos ) - ( dx * zsin ) )set y1 to ( y1 - ( dy * zsin ) + ( dx * zcos ) )PlaceItem myObject2 x1 y1 z1 a1
Signs on the right part of the set x1/set y1 statements may be wrong, but you get the idea and possible sign combinations to test are not many
User avatar
Vicky Keeler
 
Posts: 3427
Joined: Wed Aug 23, 2006 3:03 am

Post » Wed Jun 13, 2012 9:14 pm

Yes, I think you could recycle the more complicated sin/cos factors calculation and change effective rotation/traslation formula using them, e.g. something similar to this
float dxfloat dyset dx to 30	; 30 to the rightset dy to 50	; 50 to the front; dx, dy rotation - traslation - signs should be tested but you get the ideaset x1 to ( x1 - ( dy * zcos ) - ( dx * zsin ) )set y1 to ( y1 - ( dy * zsin ) + ( dx * zcos ) )PlaceItem myObject1 x1 y1 z1 a1set dx to -30	; 30 to the leftset dy to 50	; 50 to the front; dx, dy rotation - traslation - signs should be tested but you get the ideaset x1 to ( x1 - ( dy * zcos ) - ( dx * zsin ) )set y1 to ( y1 - ( dy * zsin ) + ( dx * zcos ) )PlaceItem myObject2 x1 y1 z1 a1
Signs on the right part of the set x1/set y1 statements may be wrong, but you get the idea and possible sign combinations to test are not many

I will defrinitely give that a try, but I think I'll wait until I have a fairly large chunk of time to spend with it. :)
Thanks!
Neil
User avatar
Kayla Oatney
 
Posts: 3472
Joined: Sat Jan 20, 2007 9:02 pm


Return to III - Morrowind