CellChanged returns 1 for one frame when player changes cells. It doesn’t return 1 for scripted teleporting or magic teleporting. CellChanged returns true almost immediately after the player changes cells. This means a local script running in an interior cell won't fire when the user leaves a cell, but rather when the player enters the cell.
Scripted teleporting may trigger CellChanged if the script is global or targeted (local scripts will not trigger it). (Forum info / Zennorious, Tamandra)
Note:
CellChanged doesn't always trigger, even if the player enters the cell via a normal teleport door. Possibly scripts running in the cell can have some effect on this, somehow. ForceGreeting seems to muck it up in particular (and no there wasn't a menumode return in that script).
Sample Script: In the SlaveScript, which governs freeing slaves in the game, CellChanged is the trigger to disable the slave – the slave has left for a better future:
Begin SlaveScript
[…]
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
endif
endif
end slaveScript
another nice example is the Gateway Haunt's script. This spectre always comes back just when you are not watching:
Begin ResurrectHaunt
;town_Sadrith quest
;gateway_haunt resurrects until journal town_Sadrith >= 35