There are multiple ways to approach this. I personally find it easier to make a global variable containing all your values, and then having the NPCs access the array. For example:
prontera,151,183,0 script NPC1 77,{
dispbottom "Variable 1: " + $npc_values[0];
end;
}
prontera,153,183,0 script NPC2 77,{
dispbottom "Variable 2: " + $npc_values[1];
end;
}
prontera,155,183,0 script NPC3 77,{
dispbottom "Variable 3: " + $npc_values[2];
end;
}
prontera,157,183,0 script NPC4 77,{
dispbottom "Variable 4: " + $npc_values[3];
end;
}
- script yourscript_main -1,{
end;
OnInit:
cleararray $npc_values, 0, 50;
setarray $npc_values, 1, 2, 3, 4;
// Shuffle the array
for (.@i = getarraysize($npc_values) - 1; .@i > 0; .@i--) {
.@j = rand(.@i + 1);
.@temp = $npc_values[.@i];
$npc_values[.@i] = $npc_values[.@j];
$npc_values[.@j] = .@temp;
}
end;
}
This is handy if you plan on duplicating your NPCs, such as:
prontera,151,183,0 script NPC#0 77,{
.@id = atoi(strnpcinfo(2));
dispbottom "Variable " + (.@id + 1) + ": " + $npc_values[.@id];
end;
}
prontera,153,183,0 duplicate(NPC#0) NPC#1 77
prontera,155,183,0 duplicate(NPC#0) NPC#2 77
prontera,157,183,0 duplicate(NPC#0) NPC#3 77
- script yourscript_main -1,{
end;
OnInit:
cleararray $npc_values, 0, 50;
setarray $npc_values, 1, 2, 3, 4;
// Shuffle the array
for (.@i = getarraysize($npc_values) - 1; .@i > 0; .@i--) {
.@j = rand(.@i + 1);
.@temp = $npc_values[.@i];
$npc_values[.@i] = $npc_values[.@j];
$npc_values[.@j] = .@temp;
}
end;
}
If you plan on shuffling the arrays often, you can use the following custom script command:
// script.c
BUILDIN_FUNC(shufflearray)
{
struct script_data* data;
const char* name;
struct map_session_data* sd = NULL;
int array_size, i, j;
int32 id;
void * temp_val;
// Copy-paste from getarraysize
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;// not a variable
}
name = reference_getname(data);
id = reference_getid(data);
if (not_server_variable(*name)) {
sd = script_rid2sd(st);
if (sd == NULL)
return SCRIPT_CMD_SUCCESS;// no player attached
}
array_size = script_array_highest_key(st, sd, reference_getname(data), reference_getref(data));
// Start shuffling the array
for (i = array_size - 1; i > 0; i--) {
j = rand() % (i + 1);
temp_val = get_val2(st, reference_uid(id, i), reference_getref(data));
script_removetop(st, -1, 0);
set_reg(st, sd, reference_uid(id, i), name, get_val2(st, reference_uid(id, j), reference_getref(data)), reference_getref(data));
script_removetop(st, -1, 0);
set_reg(st, sd, reference_uid(id, j), name, temp_val, reference_getref(data));
}
return SCRIPT_CMD_SUCCESS;
}
// def
BUILDIN_DEF(shufflearray,"r"),
and use it as follow:
- script yourscript_main -1,{
end;
OnInit:
cleararray $npc_values, 0, 50;
setarray $npc_values, 1, 2, 3, 4;
shufflearray $npc_values;
end;
}
If you need something more specific, you'll have to give us more details xD