summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 1a0a1d1c1..9602f3505 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -1772,21 +1772,23 @@ int buildin_menu(struct script_state *st)
*/
int buildin_rand(struct script_state *st)
{
- int range,min,max;
-
- if(st->end>st->start+3){
- min=conv_num(st,& (st->stack->stack_data[st->start+2]));
- max=conv_num(st,& (st->stack->stack_data[st->start+3]));
- if(max<min){
- int tmp;
- tmp=min;
- min=max;
- max=tmp;
+ int range;
+
+ if (st->end > st->start+3){
+ int min, max;
+ min = conv_num(st,& (st->stack->stack_data[st->start+2]));
+ max = conv_num(st,& (st->stack->stack_data[st->start+3]));
+ if (max < min){
+ int tmp = min;
+ min = max;
+ max = tmp;
}
- range=max-min+1;
+ range = max - min + 1;
+ if (range == 0) range = 1;
push_val(st->stack,C_INT,rand()%range+min);
} else {
- range=conv_num(st,& (st->stack->stack_data[st->start+2]));
+ range = conv_num(st,& (st->stack->stack_data[st->start+2]));
+ if (range == 0) range = 1;
push_val(st->stack,C_INT,rand()%range);
}
return 0;