Code update...
Part 1 : the scenario script parts
--------
Code:
// SCENARIO SCRIPTbeginscenarioscript;variables; short count, result, done, pos_x, pos_y; short i, j, k;body;// *************************************************************************************************// START_SCEN_STATE// *************************************************************************************************beginstate START_SCEN_STATE;// init unique stats for switching, to avoid switching effects on scenario start// uses flags (pos_x to pos_x+4, pos_y) = (30 to 30+4, 29)// uses flags (pos_x to pos_x+7(+4 for joined-NPCs), pos_y) = (10 to 10+7(+4 for joined-NPCs), 29) // take switch flags pos_x = 30; pos_y = 29; i = 0; while (i <= 3) { if (char_status(i) != 0) { done = 0; j = 0; // try stat from Strength (0) to Pathfinder (24), use bought levels while (j <= 24 && done == 0) { result = get_stat_levels_bought(i, j) % 10; done = 0; k = 0; while (k <= 3 && done < 3) { // don't check against himself if (k != i) { if (char_status(k) == 0) done = done + 1; else if (result != (get_stat_levels_bought(k, j) % 10)) done = done + 1; } k = k + 1; } if (done == 3) done = 1; else done = 0; j = j + 1; } j = j - 1; // can't get a unique stat for char (i), drop it if (done == 0) set_flag(pos_x + i, pos_y, 250); // got a unique stat for char (i) else set_flag(pos_x + i, pos_y, (j * 10) + result); } // set to default value for non-existing char (i) else set_flag(pos_x + i, pos_y, 250); i = i + 1; }// set switching difficulty level to 'reordering + lost a turn' (3), this can be changed at any time// uses flags (pos_x to pos_x+4, pos_y) = (30 to 30+4, 29)// uses flags (pos_x to pos_x+7(+4 for joined-NPCs), pos_y) = (10 to 10+7(+4 for joined-NPCs), 29) // take switch flags pos_x = 30; pos_y = 29; set_flag(pos_x + 4, pos_y, 3);break;// *************************************************************************************************// LOAD_SCEN_STATE// *************************************************************************************************beginstate LOAD_SCEN_STATE;break;// *************************************************************************************************// START_STATE// *************************************************************************************************beginstate START_STATE;// relocation **************************************************************************************// check current game mode for relocation on combat end (0 : outdoor) (1 : town) (2 : combat)// uses flags (pos_x to pos_x+7(+4 for joined-NPCs), pos_y) = (10 to 10+7(+4 for joined-NPCs), 29)// and flag (pos_x+12, pos_y) = (10+12, 29) (last turn mode flag) // take position and last turn mode flags pos_x = 10; pos_y = 29; // outdoor mode : just record if (is_outdoor() == 1) { set_flag(pos_x + 12, pos_y, 0); } // town mode : check for last turn mode, if it was combat relocate all chars else if (is_town() == 1) { // on combat end, in town mode only, relocate all chars to their last positions during the last combat turn // and center screen on the first living, present, non joined-NPC character (the leader) if (get_flag(pos_x + 12, pos_y) == 2) { done = 0; i = 0; // while (i <= 3) { // if joined-NPCs relocation is not needed while (i <= 5) { if (char_status(i) == 1 && get_flag(pos_x + (2 * i), pos_y) != 250) { relocate_character(i, get_flag(pos_x + (2 * i), pos_y), get_flag(pos_x + (2 * i) + 1, pos_y)); if (done == 0) { force_view_center(get_flag(pos_x + (2 * i), pos_y), get_flag(pos_x + (2 * i) + 1, pos_y)); done = 1; } } i = i + 1; } force_instant_terrain_redraw(); print_str_color("End combat.", 4); } set_flag(pos_x + 12, pos_y, 1); } // combat mode : just record else if (is_combat() == 1) { set_flag(pos_x + 12, pos_y, 2); }// update chars positions **************************************************************************// update all chars positions between turns// uses flags (pos_x to pos_x+7(+4 for joined-NPCs), pos_y) = (10 to 10+7(+4 for joined-NPCs), 29) // take position flags pos_x = 10; pos_y = 29; i = 0; // while (i <= 3) { // if joined-NPCs relocation is not needed while (i <= 5) { if (char_status(i) == 1) { set_flag(pos_x + (2 * i), pos_y, char_loc_x(i)); set_flag(pos_x + (2 * i) + 1, pos_y, char_loc_y(i)); } else { set_flag(pos_x + (2 * i), pos_y, 250); set_flag(pos_x + (2 * i) + 1, pos_y, 250); } i = i + 1; }// switching ***************************************************************************************// switching party order is prevented and/or paralyses whole party for one turn, not outdoor// switching difficulty level : 0 = normal, 1 = reordering, 2 = lost a turn, 3 = reordering + lost a turn// uses flags (pos_x to pos_x+4, pos_y) = (30 to 30+4, 29)// uses flags (pos_x to pos_x+7(+4 for joined-NPCs), pos_y) = (10 to 10+7(+4 for joined-NPCs), 29) // take switch flags (beware pos_x, pos_y will be swapped to position flags) pos_x = 30; pos_y = 29; // check stats for switching if (is_outdoor != 1) { j = 0; i = 0; while (i <= 3 && j <= 2) { count = get_flag(pos_x + i, pos_y); // check all existing chars with their unique stat, if stats modulus 10 are !=, stats are != if (char_status(i) != 0 && count != 250) { result = count % 10; done = (count - result) / 10; // if stat mismatch increase j by 1 if (get_stat_levels_bought(i, done) != result) j = j + 1; } i = i + 1; } // switching means at least two characters having their identification stat changed if (j >= 2) { // if flag(pos_x + 4, pos_y) = 1 or 3 // physical reordering is prevented (reversed to last chars positions) if (get_flag(pos_x + 4, pos_y) == 1 || get_flag(pos_x + 4, pos_y) == 3) { print_str_color("Reordering party...", 2); i = 0; while (i <= 3) { if (char_status(i) == 1) { count = get_flag(pos_x + i, pos_y); result = count % 10; done = (count - result) / 10; // find the position the char had and relocate it there j = 0; while (j <= 3 && get_flag(pos_x + (2 * j), pos_y) != 250) { if (get_stat_levels_bought(j, done) == result) { // take positions flags (this heavy but used only when switching occurs) pos_x = 10; pos_y = 29; relocate_character(i, get_flag(pos_x + (2 * j), pos_y), get_flag(pos_x + (2 * j) + 1, pos_y)); // take switch flags (this heavy but used only when switching occurs) pos_x = 30; pos_y = 29; } j = j + 1; } } i = i + 1; } // center screen on the first living, present, non joined-NPC character (the leader) done = 0; i = 0; while (i <= 3 && done == 0) { if (char_status(i) == 1) { // take positions flags (this heavy but used only when switching occurs) pos_x = 10; pos_y = 29; force_view_center(get_flag(pos_x + (2 * i), pos_y), get_flag(pos_x + (2 * i) + 1, pos_y)); // take switch flags (this heavy but used only when switching occurs) pos_x = 30; pos_y = 29; done = 1; } i = i + 1; } force_instant_terrain_redraw(); } // if flag(pos_x + 4, pos_y) = 2 or 3, paralyse all chars, and joined-NPCs, one turn, unblockable if (get_flag(pos_x + 4, pos_y) == 2 || get_flag(pos_x + 4, pos_y) == 3) { if ((get_flag(pos_x + 4, pos_y) == 2) || is_town() == 1) { print_str_color("You spend a turn reordering your party...", 3); } else { print_str_color("You lost a turn trying to reorder your party...", 1); } i = 0; while (i <= 5) { if (char_status(i) != 0) set_char_status(i, 11, 1, 1, 0); i = i + 1; } } } } // refresh unique stats for switching i = 0; while (i <= 3) { if (char_status(i) != 0) { done = 0; j = 0; // try stat from Strength (0) to Pathfinder (24), use bought levels while (j <= 24 && done == 0) { result = get_stat_levels_bought(i, j) % 10; done = 0; k = 0; while (k <= 3 && done < 3) { // don't check against himself if (k != i) { if (char_status(k) == 0) done = done + 1; else if (result != (get_stat_levels_bought(k, j) % 10)) done = done + 1; } k = k + 1; } if (done == 3) done = 1; else done = 0; j = j + 1; } j = j - 1; // can't get a unique stat for char (i), drop it if (done == 0) set_flag(pos_x + i, pos_y, 250); // got a unique stat for char (i) else set_flag(pos_x + i, pos_y, (j * 10) + result); } // set to default value for non-existing char (i) else set_flag(pos_x + i, pos_y, 250); i = i + 1; }break;
Part 2 : the terrain script to place once in each town--------
Code:
// TERRAIN SCRIPT// Script for updating characters positions in combat mode (to place on one terrain in each town)// uses flags (pos_x to pos_x+7(+4 for joined-NPCs), pos_y) = (10 to 10+7(+4 for joined-NPCs), 29)beginterrainscript;variables; short pos_x, pos_y, i;body;beginstate INIT_STATE; // run script every move even if party is far set_script_mode(3);break;beginstate START_STATE;// update all chars positions on each individual step during combat// uses flags (pos_x to pos_x+7(+4 for joined-NPCs), pos_y) = (10 to 10+7(+4 for joined-NPCs), 29) // take position flags pos_x = 10; pos_y = 29; if (is_combat() == 1) { i = 0; // while (i <= 3) { // if joined-NPCs relocation is not needed while (i <= 5) { if (char_status(i) == 1) { set_flag(pos_x + (2 * i), pos_y, char_loc_x(i)); set_flag(pos_x + (2 * i) + 1, pos_y, char_loc_y(i)); } else { set_flag(pos_x + (2 * i), pos_y, 250); set_flag(pos_x + (2 * i) + 1, pos_y, 250); } i = i + 1; } }break;