[This page is outdated! See instead the wiki page: https://wiki.project-tamriel.com/wiki/Scripting#Examples]
Triggering Journal Updates
Triggering on death conditions
Trigger journal when a NPC dies
;Local script on the NPC or creature Begin TR_m3_OnDeathExample short TR_Map if ( OnDeath ) ;update journal here ;add conditions if necessary, ;like checking that the quest to kill the NPC was started endif if ( TR_Map == 3 ) return endif set TR_Map to 3 End
Trigger journal once several NPCs are dead
;Local script on each NPC, the same script, only one is needed Begin TR_m3_MultiOnDeathExample short TR_Map if ( OnDeath ) If ( GetDeadCount "TR_m3_NPCExample1" > 0 ) If ( GetDeadCount "TR_m3_NPCExample2" > 0 ) If ( GetDeadCount "TR_m3_NPCExampleX" > 0 ) ;update journal here ;add conditions if necessary, ;like checking that the quest to kill the NPCs was started Endif Endif Endif endif if ( TR_Map == 3 ) return endif set TR_Map to 3 End
Trigger journal once several creatures are dead
;Local script on the creature ID Begin TR_m3_CreaturesOnDeathExample short TR_Map if ( OnDeath ) If ( GetDeadCount "TR_m3_CreatureExample" >= 3 ) ;3 of the creature to kill ;update journal here ;add conditions if necessary, ;like checking that the quest to kill the creatures has started Endif endif if ( TR_Map == 3 ) return endif set TR_Map to 3 End
Triggering on timed conditions
Wait 24 hours before triggering something
;Global script, start in dialogue results or another script with Startscript, terminates itself Begin TR_m3_24HoursExample short DayTarget float HourTarget if ( DayTarget > DaysPassed ) return elseif ( DayTarget == DaysPassed ) if ( GameHour <= HourTarget ) return endif endif if ( DayTarget == 0 ) set DayTarget to ( DaysPassed + 1 ) set HourTarget to ( GameHour ) return endif ;24 hours have passed, update journal here StopScript "TR_m3_24HoursExample" End
Wait a week before triggering something
;Global script, start in dialogue results or another script with Startscript, terminates itself Begin TR_m3_7DaysExample short DayTarget if ( DayTarget > DaysPassed ) return endif if ( DayTarget == 0 ) set DayTarget to ( DaysPassed + 7 ) return endif ;7 days have passed, update journal here StopScript "TR_m3_7DaysExample" End
Triggering events per Quest Stage
Disable a NPC or object until a quest starts
;Local script on the object ;If it's a NPC, add the generic NPC variables and script like in T_ScNpc_Mw_Map3 ;If it's lootable, don't forget Morrowind is an open world that doesn't make things magically pop up only when the player needs them, instead your quest logic often needs to account for the object being found first ;If it's a static object with collision, don't forget you also need to change its position Begin TR_m3_QuestEnableExample if ( GetJournalIndex "TR_m3_JournalExample" < 10 ) if ( GetDisabled ) return else Disable endif elseif ( GetDisabled ) Enable endif End
Make a NPC in exteriors leave after a quest is finished
;Local script on the NPC ;Unless they're using magic, you may not disable NPCs in front of the player Begin TR_m3_QuestDisableExample short TR_Map short control short controlQ float GameHourCheck if ( TR_Map != 3 ) set TR_Map to 3 endif if ( GetJournalIndex "TR_m3_JournalExample" < 100 ) return elseif ( GetDisabled ) ;don't use "SetDelete 1" here unless the NPC instance never needs to be referred to again return elseif ( CellChanged ) if ( GetInterior ) Disable return else ;do not disable when crossing exterior cell borders set GameHourCheck to ( ( GameHour - GameHourCheck ) * 30 / TimeScale ) if ( GameHourCheck < 0 ) set GameHourCheck to ( -1 * GameHourCheck ) endif if ( GameHourCheck < 0.01 ) if ( GetDistance, player < 6500 ) return endif endif Disable endif endif set GameHourCheck to GameHour End
Book Scripts
Perform an action when the player opens a book or a scroll
Begin your_script_name short OnPCEquip short PCSkipEquip set PCSkipEquip to 0 ; any actions that might end the script must be placed lower than this line ; Activating from the inventory if ( MenuMode ) ; the vanilla engine fails to set PCSkipEquip under certain ; conditions, so we must do it ourselves for ; OnPCEquip to work properly set PCSkipEquip to 1 if ( OnPCEquip ) ; place actions for when the player opened the book from the inventory here set OnPCEquip to 0 set PCSkipEquip to 0 ; OpenMW fails to open the book without this line Activate endif ; this return is important ; we must make sure OnActivate secton is only accessed outside of MenuMode ; or the vanilla engine fails to take the book if opened from the world return endif ; Activating in the world if ( OnActivate ) ; place actions for when the player opened the book from the world here Activate endif end