×
Меню
Индекс

MSFD Enabling and disabling objects

 
Enable
Disable
 
"ObjectID"->enable
 
GetDisabled     (returns Boolean/short)
     If ( GetDisabled == 1 )
          Return
     Endif
 
The Disable function makes an object completely vanish from the game world, meaning it's neither rendered nor processed (attached scripts are still active, however). The Enable function makes a disabled object visible and processed again. GetDisabled (returns 1 if object is disabled) can be used to obtain the current status of an Object. These functions are very powerful and could e.g. be used to swap different models of statics (normal house replaced by house burnt to the ground, etc). It is e.g. used for the stronghold building process.
Note that disable should not be called every frame, as this will cause a drop in framerate. Instead, use GetDisabled or some other condition to ensure the object is disabled only when necessary.
 
Example script:
An example from the game is the SlaveScript that makes freed slaves vanish once the player leaves the cell:
 
begin slaveScript
 
short slaveStatus
short doOnce
short NoLore
 
[other slaves status checks – check original script!]
 
if ( slaveStatus == 3 )
     if ( GetCurrentAIPackage == 3 )
          AIWander 512 0 0 0 0 0 0 0 0 0 0 0
     endif
     if ( GetItemCount Slave_Bracer_Left > 0 )
          Drop Slave_Bracer_Left 1
     endif
     if ( GetItemCount Slave_Bracer_Right > 0 )
          Drop Slave_Bracer_Right 1
     endif
     if ( CellChanged == 1 )
          Disable ;****** Make slaves vanish once freed and player leaves
     endif
endif
 
end slaveScript
 
Caution: disabling lights
There seems to be a game engine issue with disabled lights – Actors and some other types of objects still seem to be illuminated, while the world around is not. I have not thoroughly tested if this can be avoided, but a suitable workaround is to physically remove the light to a remote location (e.g. a few meters below the floor) instead of disabling it. Another trick comes from Indigo: If you enable a light that is set to "negative" (which means its generating darkness instead of light) after you disable the normal light, the illumination problem goes away.
 
Note:
When you are in an exterior cell (haven't checked with interiors, but presumably it applies in interiors as well) any object you disable in the loaded cells while you are in that cell will retain its collision properties in the game world until the next time that exterior cell is loaded - i.e. you disable a fence piece through a script where that fence piece is in the same exterior cell as your PC. You still can't walk through the area where the fence piece is disabled until you exit and reenter that exterior cell. Similarly, you subsequently reenable that fence piece that was disabled when your PC entered that exterior cell. You can walk right through that fence piece until the next time that exterior cell is reloaded by the game.
 
To fix this use the "FixMe" command in your script after you disable or enable a game object that exhibits collision. You should check that you are in the same exterior cell as the game object before you execute the FixMe command - if you aren't you don't need FixMe. This is useful in global scripts that enable or disable objects with references persist so you could be in any cell when the object is enabled or disabled. Using FixMe will cause your PC to also move 128 game units (hardly noticeable in most cases other than as a "stutter") when it executes but since there is no other script command that reloads a cell that is something you will have to live with. Using FixMe will cause the collision to be reset for the cell FixMe reloads so is a way to immediately fix collision on script enabled/disabled objects. (Forum info / Rougetet)