×
Меню
Индекс

MSFD Creating new object-references with PlaceItem

 
[no fix] PlaceItem "object ID", float_var_X, float_Y, float_Z, float_Zrot
 
[no fix] PlaceItemCell "object ID", "cellID", X, Y, Z, Zrot
 
These functions are used to create new references to objects. PlaceItem will create a reference to object "Object ID" at coordinate (X, Y, Z) with Z rotation Zrot in the current cell. Z_Rot is not set in degrees (0-360°) but in minutes (1° = 60 min): So, if you want the person to face east, use 5400. South, 10800. West 16200.
The function accepts (local) float variables. PlaceItemCell does the same thing as PlaceItem except it allows you to specify a cell other than the current one in which the object should be created. With either function, if the target cell for the reference is an exterior cell and the given coordinate is outside of that cell, then the reference will be added to the cell containing the coordinate. This is a nice addition that allows you to add things to the world without previously placing them in the editor.
JOG posted the following interesting info on PlaceItemCell:
Well, When I first tried PlaceitemCell, I thought it's a great function to place items instead of having a "storage-cell" where the objects lie around until the game needs them. I soon realized that you can't refer to those objects by script. (To disable them for example.) The script won't compile until at least one of the objects is in use, and then the disable command would refer to that object, so you still need PositionCell.
 
(Note by GBG: you can circumvent this for many applications by having a script on the placed item, so that you can omit the "fix" and have functions such as disable reference to it by default.)
 
 DinkumThinkum adds:
PlaceItemCell would have been perfect for what I wanted to do, until I discovered that the placed NPC disappeared if I saved and reloaded before going to the cell they were placed in.
 
(Note by GBG: This can be avoided in most cases by making the placing of the NPC conditional on the player entering the cell. I still think PlaceItem is a very useful function.)
 
Sample Script:
Putting this script on an object causes it, on activation, to ask the user for an object type and then to create a reference to the specified object at 100 units above the activated reference with 45 degree Z rotation. If the key is selected, it is created at that same coordinate and rotation in the cell “key room” rather than the current cell.
Begin makethingsimple
 
short questionAsked
short button
float myX
float myY
float myZ
 
if ( MenuMode )
     return
endif
 
if ( OnActivate == 1 )
          if ( questionAsked == 0 )
               MessageBox, "Create new..."  "...Pot"  "...Key"
               set questionAsked to 1
               set myX to GetPos X
               set myY to GetPos Y
               set myZ to GetPos Z + 100
          endif
endif
 
if ( questionAsked != 0 )
     if ( questionAsked == 1 )
          set button to GetButtonPressed
          if ( button == -1 )
          else
               if ( button == 0 )
                    PlaceItem "Misc_pot_redware_01" myX myY myZ 45
               elseif ( button == 1 )
                    PlaceItemCell "misc key" "key room" myX myY myZ 45    
               endif
               set questionAsked to 0
               set button to -1
          endif
     endif
endif
end