function dicecontrol(ENTITY* dicepointer)
{
VECTOR* my_pos = {x=0; y=0; z=0;}
var vertexarray[6] = {1695, 311, 1692, 81, 1698, 312};
var resulting = 1;
var i;
for(i=0; i!=6; i++)
{
vec_for_vertex(my_pos, dicepointer, vertexarray[i]);
if(my_pos.z >= 600)
{resulting = i+1;break;}
}
return(resulting);
}
function dicing()
{
var seedget = random(333.3);
var dice_1_result = 1;
var dice_2_result = 1;
random_seed(seedget);
seedget = random(333.3);
random_seed(seedget);
ENTITY* dicebox = ent_create ("dicebox.mdl", vector(-750, 0, 550), NULL);
c_setminmax(dicebox);
set(dicebox, INVISIBLE | POLYGON);
reset(dicebox, PASSABLE);
vec_set(dicebox.scale_x, vector(10.0, 10.0, 5.0));
wait(1);
ENTITY* dice1 = ent_create ("würfel.mdl", vector(200, 200, 2000), NULL);
ENTITY* dice2 = ent_create ("würfel.mdl", vector(-200, -200, 2000), NULL);
c_setminmax(dice1); c_setminmax(dice2);
set(dice1, POLYGON); set(dice2, POLYGON);
vec_set(dice1.scale_x, vector(40.0, 40.0, 40.0)); vec_set(dice2.scale_x, dice1.scale_x);
vec_set(dice1.pan, vector(random(360)-180, random(360)-180, random(360)-180)); vec_set(dice2.pan, vector(random(360)-180, random(360)-180, random(360)-180));
ph_setgravity (vector(random(300)-150, random(300)-150, -1000));
phent_settype (dice1, PH_RIGID, PH_BOX); phent_settype (dice2, PH_RIGID, PH_BOX);
phent_setmass (dice1, 2000, PH_BOX); phent_setmass (dice2, 2000, PH_BOX);
phent_setfriction (dice1, 50); phent_setfriction (dice2, 50);
phent_setdamping (dice1, 50, 50); phent_setdamping (dice2, 50, 50);
phent_setelasticity (dice1, 100, 100); phent_setelasticity (dice2, 100, 100);
ph_setgravity (vector(0, 0, -386));
VECTOR* old_pos1 = {x=0; y=0; z=0;}
VECTOR* old_pos2 = {x=0; y=0; z=0;}
VECTOR* new_pos1 = {x=0; y=0; z=0;}
VECTOR* new_pos2 = {x=0; y=0; z=0;}
while(1)
{
vec_set(old_pos1.x, dice1.x); vec_set(old_pos2.x, dice2.x);
wait(10);
vec_set(new_pos1.x, dice1.x); vec_set(new_pos2.x, dice2.x);
if(vec_dist(new_pos1.x, old_pos1.x) <= 0)
{
break;
}
wait(1);
}
dice_1_result = dicecontrol(dice1);
wait_for(dicecontrol);
dice_2_result = dicecontrol(dice2);
wait_for(dicecontrol);
diceresult = dice_1_result + dice_2_result;
waitcount = 200;
while(key_space == 0)
{
if(waitcount < 1){break;}
waitcount -= 1;
wait(1);
}
ent_remove(dice1);
ent_remove(dice2);
ent_remove(dicebox);
dicetrigger = 0;
}