There is no issue with the code sample you've provided. It's a bit hard to read, but besides that, it works fine for me. To make your life easier though, may I suggest using a command like shufflearray instead? Like so:
BUILDIN_DEF(shufflearray,"r?"),
BUILDIN_FUNC(shufflearray)
{
map_session_data* sd = NULL;
int i, j;
int array_size = script_hasdata(st, 3) ? script_getnum(st, 3) : -1;
struct script_data* data = script_getdata(st, 2);
if (!data_isreference(data)) {
ShowError("buildin_shufflearray: not a variable\n");
script_reportdata(data);
script_pushnil(st);
st->state = END;
return SCRIPT_CMD_FAILURE;
}
const char* name = reference_getname(data);
int32 id = reference_getid(data);
if (not_server_variable(*name)) {
sd = map_id2sd(st->rid);
if (sd == NULL)
return SCRIPT_CMD_SUCCESS;
}
if (array_size < 0) {
array_size = script_array_highest_key(st, sd, reference_getname(data), reference_getref(data));
}
// Start shuffling the array
if (is_string_variable(name)) {
for (i = array_size - 1; i > 0; i--) {
j = rnd() % (i + 1);
const char* temp_val = get_val2_str(st, reference_uid(id, i), reference_getref(data));
set_reg_str(st, sd, reference_uid(id, i), name, get_val2_str(st, reference_uid(id, j), reference_getref(data)), reference_getref(data));
set_reg_str(st, sd, reference_uid(id, j), name, temp_val, reference_getref(data));
script_removetop(st, -1, 0);
script_removetop(st, -1, 0);
}
}
else {
for (i = array_size - 1; i > 0; i--) {
j = rnd() % (i + 1);
int64 temp_val = get_val2_num(st, reference_uid(id, i), reference_getref(data));
set_reg_num(st, sd, reference_uid(id, i), name, get_val2_num(st, reference_uid(id, j), reference_getref(data)), reference_getref(data));
set_reg_num(st, sd, reference_uid(id, j), name, temp_val, reference_getref(data));
script_removetop(st, -1, 0);
script_removetop(st, -1, 0);
}
}
return SCRIPT_CMD_SUCCESS;
}
Then you can simply code it like this:
1@thts,0,0,0 script #thanatos_main -1,{
OnInit:
setarray .@rng_floors, 3, 4, 5, 6;
shufflearray .@rng_floors;
setarray 'floors, 1, 2, .@rng_floors[0], .@rng_floors[1], .@rng_floors[2], .@rng_floors[3], 7, 8;
setarray 'maps$,
instance_mapname("1@thts"),
instance_mapname("2@thts"),
instance_mapname("3@thts"),
instance_mapname("4@thts"),
instance_mapname("5@thts"),
instance_mapname("6@thts"),
instance_mapname("7@thts"),
instance_mapname("8@thts");
setarray 'coords_coords,
0, 0,
0, 0,
27, 44, // 3rd floor
18, 97,
155, 100,
50, 18,
50, 18,
50, 18;
// other stuff here...
end;
}
1@thts,32,166,0 script #setp02 45,2,2,{
end;
OnTouch:
.@next_floor = 3;
warp 'maps$[.@next_floor], 'coords_coords[2 * .@next_floor + 0], 'coords_coords[2 * .@next_floor + 1];
end;
}
As you're clearly implementing Thanatos Tower, you might find some inspiration from when I wrote the script (though it uses quite a few custom script functions and it also has a custom hard mode, but it can probably still be of use). It's from kRO replay files, so the NPC coordinates should be very accurate.
thanatos.txt