# setNextScriptIndex

<p class="callout info">An eventCall to set the index of the next script in an idEncounterManager.</p>

## Usage

```
item[0] = {
	eventCall = {
		eventDef = "setNextScriptIndex";
		args = {
			num = 1;
			item[0] = { // nextScriptIndex
				int = 1;
			}
		}
	}
}

```

- `nextScriptIndex` is the index of next script

## Example Usage

```
entity { // Custom Encounter #1
	entityDef mod_encounter_manager_custom_1 {
	inherit = "encounter/manager";
	class = "idEncounterManager";
	expandInheritance = false;
	poolCount = 0;
	poolGranularity = 2;
	networkReplicated = true;
	disableAIPooling = false;
	edit = {
		enableAIHighlightOnFinish = true;
		disabledAITypeForHighlight = "AI_MONSTER_SPECTRE AI_MONSTER_BUFF_POD AI_MONSTER_TENTACLE";
		playerMetricDef = "encounter/player_metrics";
		chargeCombatGrouping = "encounter/combat_role/charge_command";
		aiTypeDefAssignments = "actorpopulation/default/default_no_bosses";
		spawnPosition = {
			x = 0;
			y = 0;
			z = 0;
		}
		soundOcclusionBypass = true;
		combatRatingScale = "COMBAT_RATING_SCALE_IGNORE";
		encounterComponent = {
			entityEvents = {
				num = 2;
				item[0] = { // Part 0
					entity = "mod_encounter_manager_custom_1";
					events = {
						num = 5;
						item[0] = {
							eventCall = {
								eventDef = "setMusicState";
								args = {
									num = 3;
									item[0] = {
										entity = "sound_sound_musicentity_1";
									}
									item[1] = {
										decl = {
											soundstate = "music_ghost_states/main_heavy";
										}
									}
									item[2] = {
										string = "";
									}
								}
							}
						}
						item[1] = {
							eventCall = {
								eventDef = "spawnSingleAI";
								args = {
									num = 3;
									item[0] = {
										eEncounterSpawnType_t = "ENCOUNTER_SPAWN_BARON";
									}
									item[1] = {
										entity = "ai_target_spawn_87";
									}
									item[2] = {
										string = "";
									}
								}
							}
						}
						item[2] = {
							eventCall = {
								eventDef = "waitAIRemaining";
								args = {
									num = 3;
									item[0] = {
										eEncounterSpawnType_t = "ENCOUNTER_SPAWN_ANY";
									}
									item[1] = {
										int = 0; // desired_remaing_ai_count
									}
									item[2] = {
										string = ""; // group_label
									}
								}
							}
						}
						item[3] = {
							eventCall = {
								eventDef = "setNextScriptIndex";
								args = {
									num = 1;
									item[0] = { // index of next script
										int = 1;
									}
								}
							}
						}
						item[4] = {
							eventCall = {
								eventDef = "proceedToNextScript";
								args = {
									num = 2;
									item[0] = {
										bool = true; // bypassNextWaitForCommit
									}
									item[1] = {
										bool = true; // carryOverExistingUserFlags
									}
								}
							}
						}
					}
				}
				item[1] = { // Part 1
					entity = "mod_encounter_manager_custom_1";
					events = {
						num = 2;
						item[0] = {
							eventCall = {
								eventDef = "setMusicState";
								args = {
									num = 3;
									item[0] = {
										entity = "sound_sound_musicentity_1";
									}
									item[1] = {
										decl = {
											soundstate = "music_ghost_states/main_ambient";
										}
									}
									item[2] = {
										string = "";
									}
								}
							}
						}
						item[1] = {
							eventCall = {
								eventDef = "activateTarget";
								args = {
									num = 2;
									item[0] = {
										entity = "game_target_count_cp11"; // target
									}
									item[1] = {
										string = ""; // designComment
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
}
```

In this example we use `setNextScriptIndex` after all there are no ai remaning, followed by [`proceedToNextScript`](https://wiki.eternalmods.com/books/entities-custom-encounters/page/proceedtonextscript "proceedToNextScript") to advance to the next script. Note that the encounter manager has to be split into multiple scripts (line 26 and 110) in order for `setNextScriptIndex` to work properly. The next script index does not have to be in sequential order either, as in an encounter manager with 4 scripts, it is possible to advance from script 0 to script 3, skipping over scripts 1 and 2.

## See Also

- [proceedToNextScript](https://wiki.eternalmods.com/books/entities-custom-encounters/page/proceedtonextscript)