What's new

Discussion WAW Rubix Cube

  • Thread starter Sheep_Wizard2
  • Start date
  • Views 3,010
  • Tags
    pc
S

Sheep_Wizard2

Newbie
Messages
2
Reaction score
8
Rubix cube made in WAW for the map Der Riese

Code:
createCube(m_ori, s_ori, item1_ori, item1_model, item1_angle, item2_ori, item2_model, item2_angle, item3_ori, item3_model, item3_angle)
{
    a = [];
    a["model"] = spawn("script_model", m_ori);
    a["model"] SetModel("static_peleliu_crate01_short");
    a["origin"] = spawn("script_origin", s_ori);
    a["model"] LinkTo(a["origin"]);

    a["item1"] = spawn("script_model", item1_ori);
    a["item1"].angles = item1_angle;
    a["item1"] SetModel(item1_model);
    a["item1"] LinkTo(a["model"]);

    if(isDefined(item2_ori))
    {
        a["item2"] = spawn("script_model", item2_ori);
        a["item2"].angles = item2_angle;
        a["item2"] SetModel(item2_model);
        a["item2"] LinkTo(a["origin"]);
    }
    if(isDefined(item3_ori))
    {
        a["item3"] = spawn("script_model", item3_ori);
        a["item3"].angles = item3_angle;
        a["item3"] SetModel(item3_model);
        a["item3"] LinkTo(a["origin"]);
    }

    return a;
}
//spawn rubix cube
spawnCube()
{
    self IPrintLn("spawning cube");

    self.rbMoves = [];

    center = self GetOrigin() +(0,0,50);

    self.rbCubes = [];

    //middle
    self.rbCubes[0] = spawn("script_model", center);

    //centers
    //bottom

    //white beaker
    self.rbCubes[1] = createCube(center-(0,0,35), center-(0,0,20), center+(-5,0,-40), "zombie_beaker_small", (90,0,0),undefined, undefined, undefined, undefined, undefined, undefined);

    //yellow teddy bear
    self.rbCubes[2] = createCube(center+(0,0,35), center+(0,0,50), center+(0,0,70), "zombie_teddybear", (-90,90,90),undefined, undefined, undefined, undefined, undefined, undefined);

    //orange jug bottle
    self.rbCubes[3] = createCube(center-(35,0,0), center+(-35,0,15), center+(-55,0,15), "zombie_3rd_perk_bottle_doubletap", (0,-90,0),undefined, undefined, undefined, undefined, undefined, undefined);
    
    //red jug bottle
    self.rbCubes[4] = createCube(center+(35,0,0), center+(35,0,15), center+(55,0,15), "zombie_3rd_perk_bottle_jugg", (0,90,0),undefined, undefined, undefined, undefined, undefined, undefined);
    
    //blue jug bottle
    self.rbCubes[5] = createCube(center-(0,35,0), center+(0,-35,15), center+(0,-55,15), "zombie_3rd_perk_bottle_revive", (0,0,0),undefined, undefined, undefined, undefined, undefined, undefined);

    //green jug bottle
    self.rbCubes[6] = createCube(center+(0,35,0), center+(0,35,15), center+(0,55,15), "zombie_3rd_perk_bottle_sleight", (0,-180,0),undefined, undefined, undefined, undefined, undefined, undefined);



    //red jug bottle
    //green jug bottle
    self.rbCubes[7] = createCube(center+(35,35,0), center+(35,35,15), center+(55,35,15), "zombie_3rd_perk_bottle_jugg", (0,90,0), center+(35,55,15), "zombie_3rd_perk_bottle_sleight", (0,-180,0), undefined, undefined, undefined);

    //orange jug bottle
    //blue jug bottle
    self.rbCubes[8] = createCube(center+(-35,-35,0), center+(-35,-35,15), center+(-55,-35,15), "zombie_3rd_perk_bottle_doubletap", (0,-90,0), center+(-35,-55,15), "zombie_3rd_perk_bottle_revive", (0,0,0), undefined, undefined, undefined);

    //red jug bottle
    //blue jug bottle
    self.rbCubes[9] = createCube(center+(35,-35,0), center+(35,-35,15), center+(55,-35,15), "zombie_3rd_perk_bottle_jugg", (0,90,0), center+(35,-55,15), "zombie_3rd_perk_bottle_revive", (0,0,0), undefined, undefined, undefined);

    //orange jug bottle
    //green jug bottle
    self.rbCubes[10] = createCube(center+(-35,35,0), center+(-35,35,15), center+(-55,35,15), "zombie_3rd_perk_bottle_doubletap", (0,-90,0), center+(-35,55,15), "zombie_3rd_perk_bottle_sleight", (0,-180,0), undefined, undefined, undefined);

    //green jug bottle
    //yellow teddy bear
    self.rbCubes[11] = createCube(center+(0,35,35), center+(0,35,50), center+(0,55,50), "zombie_3rd_perk_bottle_sleight", (0,-180,0), center+(0,35,70), "zombie_teddybear", (-90,90,90), undefined, undefined, undefined);

    //red jug bottle
    //yellow teddy bear
    self.rbCubes[12] = createCube(center+(35,0,35), center+(35,0,50), center+(55,0,50), "zombie_3rd_perk_bottle_jugg", (0,90,0), center+(35,0,70), "zombie_teddybear", (-90,90,90), undefined, undefined, undefined);

    //orange jug bottle
    //yellow teddy bear
    self.rbCubes[13] = createCube(center+(-35,0,35), center+(-35,0,50), center+(-55,0,50), "zombie_3rd_perk_bottle_doubletap", (0,-90,0), center+(-35,0,70), "zombie_teddybear", (-90,90,90), undefined, undefined, undefined);

    //blue jug bottle
    //yellow teddy bear
    self.rbCubes[14] = createCube(center+(0,-35,35), center+(0,-35,50), center+(0,-55,50), "zombie_3rd_perk_bottle_revive", (0,0,0), center+(0,-35,70), "zombie_teddybear", (-90,90,90), undefined, undefined, undefined);

    //green jug bottle
    //white beaker
    self.rbCubes[15] = createCube(center+(0,35,-35), center+(0,35,-20), center+(0,55,-20), "zombie_3rd_perk_bottle_sleight", (0,-180,0), center+(-5,35,-40), "zombie_beaker_small", (90,0,0), undefined, undefined, undefined);

    //red jug bottle
    //white beaker
    self.rbCubes[16] = createCube(center+(35,0,-35), center+(35,0,-20), center+(55,0,-20), "zombie_3rd_perk_bottle_jugg", (0,90,0), center+(30,0,-40), "zombie_beaker_small", (90,0,0), undefined, undefined, undefined);

    //orange jug bottle
    //white beaker
    self.rbCubes[17] = createCube(center+(-35,0,-35), center+(-35,0,-20), center+(-55,0,-20), "zombie_3rd_perk_bottle_doubletap", (0,-90,0), center+(-40,0,-40), "zombie_beaker_small", (90,0,0), undefined, undefined, undefined);

    //blue jug bottle
    //white beaker
    self.rbCubes[18] = createCube(center+(0,-35,-35), center+(0,-35,-20), center+(0,-55,-20), "zombie_3rd_perk_bottle_revive", (0,0,0), center+(-5,-35,-40), "zombie_beaker_small", (90,0,0), undefined, undefined, undefined);


    //corners
    //orange jug bottle
    //blue jug bottle
    //white beaker
    self.rbCubes[19] = createCube(center+(-34,-34,-35), center+(-34,-34,-20), center+(-55,-34,-20), "zombie_3rd_perk_bottle_doubletap", (0,-90,0), center+(-34,-55,-20), "zombie_3rd_perk_bottle_revive", (0,0,0), center+(-39,-34,-40), "zombie_beaker_small", (90,0,0));

    //red jug bottle
    //blue jug bottle
    //white beaker
    self.rbCubes[20] = createCube(center+(34,-34,-35), center+(34,-34,-20), center+(55,-34,-20), "zombie_3rd_perk_bottle_jugg", (0,90,0), center+(34,-55,-20), "zombie_3rd_perk_bottle_revive", (0,0,0), center+(29,-34,-40), "zombie_beaker_small", (90,0,0));

    //orange jug bottle
    //green jug bottle
    //white beaker
    self.rbCubes[21] = createCube(center+(-34,34,-35), center+(-34,34,-20), center+(-55,34,-20), "zombie_3rd_perk_bottle_doubletap", (0,-90,0), center+(-34,55,-20), "zombie_3rd_perk_bottle_sleight", (0,-180,0), center+(-39,34,-40), "zombie_beaker_small", (90,0,0));

    //red jug bottle
    //green jug bottle
    //white beaker
    self.rbCubes[22] = createCube(center+(34,34,-35), center+(34,34,-20), center+(55,34,-20), "zombie_3rd_perk_bottle_jugg", (0,90,0), center+(34,55,-20), "zombie_3rd_perk_bottle_sleight", (0,-180,0), center+(29,34,-40), "zombie_beaker_small", (90,0,0));


    //orange jug bottle
    //blue jug bottle
    //yellow teddy bear
    self.rbCubes[23] = createCube(center+(-34,-34,35), center+(-34,-34,50), center+(-55,-34,50), "zombie_3rd_perk_bottle_doubletap", (0,-90,0), center+(-34,-55,50), "zombie_3rd_perk_bottle_revive", (0,0,0), center+(-34,-34,70), "zombie_teddybear", (-90,90,90));

    //red jug bottle
    //blue jug bottle
    //yellow teddy bear
    self.rbCubes[24] = createCube(center+(34,-34,35), center+(34,-34,50), center+(55,-34,50), "zombie_3rd_perk_bottle_jugg", (0,90,0), center+(34,-55,50), "zombie_3rd_perk_bottle_revive", (0,0,0), center+(34,-34,70), "zombie_teddybear", (-90,90,90));

    //orange jug bottle
    //green jug bottle
    //yellow teddy bear
    self.rbCubes[25] = createCube(center+(-34,34,35), center+(-34,34,50), center+(-55,34,50), "zombie_3rd_perk_bottle_doubletap", (0,-90,0), center+(-34,55,50), "zombie_3rd_perk_bottle_sleight", (0,-180,0), center+(-34,34,70), "zombie_teddybear", (-90,90,90));

    //red jug bottle
    //green jug bottle
    //yellow teddy bear
    self.rbCubes[26] = createCube(center+(34,34,35), center+(34,34,50), center+(55,34,50), "zombie_3rd_perk_bottle_jugg", (0,90,0), center+(34,55,50), "zombie_3rd_perk_bottle_sleight", (0,-180,0), center+(34,34,70), "zombie_teddybear", (-90,90,90));

    wait 2;

    //self thread rotateCube("white", "cw");
    //self waittill("rbcube_rotation_done");

    // self thread rotateCube("yellow", "cw");
    // self waittill("rbcube_rotation_done");

    // self thread rotateCube("red", "ccw");
    // self waittill("rbcube_rotation_done");

    // self rbCubeMixup();//scramble cube

    // self rbCubeDelete();//delete cube

    // self rbCubeSolve();//solve cube
    
}

rotateCube(side, direction)
{
    self endon("rubixcube_end");
    self.rbMoves[self.rbMoves.size] = ""+side+":"+direction+";";
    //rotate cube clockwise
    if(direction == "cw")
    {   
        //1
        if(side == "white")
            self doRotate(1, "yaw", 90);
        //4
        if(side == "red")
            self doRotate(4, "roll", -90);
        //3
        if(side == "orange")
            self doRotate(3, "roll", 90);
        //6
        if(side == "green")
            self doRotate(6, "pitch", -90);
        //5
        if(side == "blue")
            self doRotate(5, "pitch", 90);
        //2
        if(side == "yellow")
            self doRotate(2, "yaw", -90);
    }
    //rotate cube counterclockwise
    if(direction == "ccw")
    {
        //1
        if(side == "white")
            self doRotate(1, "yaw", -90);
        //4
        if(side == "red")
            self doRotate(4, "roll", 90);
        //3
        if(side == "orange")
            self doRotate(3, "roll", -90);
        //6
        if(side == "green")
            self doRotate(6, "pitch", 90);
        //5
        if(side == "blue")
            self doRotate(5, "pitch", -90);
        //2
        if(side == "yellow")
            self doRotate(2, "yaw", 90);
    }
}
doRotate(x, rotation, dir)
{
    self endon("rubixcube_end");
    //look for cubes that are within a certain distance of cube we want to rotate then link
    for(i=1; i<self.rbCubes.size; i++)
    {
        dist = Distance(self.rbCubes[x]["origin"].origin, self.rbCubes[i]["origin"].origin);
        if(i != x && i != 0 && dist < 49)
            self.rbCubes[i]["origin"] LinkTo(self.rbCubes[x]["origin"]);
    }

    if(rotation == "roll")
        self.rbCubes[x]["origin"] RotateRoll(dir, 1);

    if(rotation == "pitch")
        self.rbCubes[x]["origin"] RotatePitch(dir, 1);

    if(rotation == "yaw")
        self.rbCubes[x]["origin"] RotateYaw(dir, 1);


    self.rbCubes[x]["origin"] waittill("rotatedone");
    self notify("rbcube_rotation_done");
}

//destroy cube
rbCubeDelete()
{
    self notify("rubixcube_end");
    self.rbCubes[0] Delete();
    for(i=1; i<self.rbCubes.size; i++)
        self.rbCubes[i]["origin"] MoveGravity((RandomIntRange(-600,600),RandomIntRange(-600,600),RandomIntRange(0,600)), 2);
    wait 3;
    for(i=1; i<self.rbCubes.size; i++)
    {
        self.rbCubes[i]["origin"] Delete();
        self.rbCubes[i]["model"] Delete();
        self.rbCubes[i]["item1"] Delete();
        if(isDefined(self.rbCubes[i]["item2"]))
            self.rbCubes[i]["item2"] Delete();
        if(isDefined(self.rbCubes[i]["item3"]))
            self.rbCubes[i]["item3"] Delete();
    }
}

//randomly mix up cube
rbCubeMixup()//CHANGE TO RANDOM AGAIN
{
    self endon("rubixcube_end");
    direction = 0;
    colour = "red";
    x = RandomFloatRange(15, 25);
    for(i=0; i<x;i++)
    {
        z = RandomInt(2);
        m = RandomInt(6);
        if(z == 0)
            direction = "cw";
        if(z == 1)
            direction = "ccw";


        if(m == 0)
            colour = "white";
        else if(m == 1)
            colour = "red";
        else if(m == 2)
            colour = "orange";
        else if(m == 3)
            colour = "green";
        else if(m == 4)
            colour = "blue";
        else if(m == 5)
            colour = "yellow";

        self thread rotateCube(colour, direction);
        self waittill("rbcube_rotation_done");
    }
}

//solve rubix cube but reversing all previous moves
rbCubeSolve()
{
    self endon("rubixcube_end");
    if(self.rbMoves.size == 0)
        return;
    string = "";
    for(i=0;i<self.rbMoves.size; i++)
        string += self.rbMoves[i];
    t = StrTok(string, ";");
    tkn = flipArray(t);
    for(i=0; i<tkn.size; i++)
    {
        x = StrTok(tkn[i], ":");
        wait 0.05;
        if(x[1] == "cw")
            self rotateCube(x[0], "ccw");
        if(x[1] == "ccw")
            self rotateCube(x[0], "cw");
    }
}
//flip array
flipArray(a)
{
    new = [];
    x = 0;
    for(i=a.size-1; i> -1; i--)
    {
        new[x] = a[i];
        x++;
    }
    return new;
}

The function you can call to spawn and rotate the cube are:
Code:
self spawnCube(); // spawns the rubix cube
self rotateCube(side, direction); //rotate 1 side of the cube, the sides being "white", "red", "orange", "green", "blue", "yellow" and the directions being "cw", "ccw"
self rbCubeMixup(); //scrambles the cube
self rbCubeDelete(); //delete the cube
self rbCubeSolve(); //solves the rubix cube
self waittill("rbcube_rotation_done"); //waits for the cube to finish rotating
 
I

ISOCheated

Illuminati
Messages
148
Reaction score
83
Cool man. Nicely done .
 
N

NighttimeHawk

Matrix Trident, Icedcube XenochipGC, Slim XDK
Messages
323
Reaction score
45
Anybody know how I could add this to elasticity? Trying to port it into the Xbox 360 version of the menu
 
M

mso

Enthusiast
Messages
41
Reaction score
3
nice release, kepp releasing nice stuff on waw please :biggrin:
 
I

IELIITEMODZX

Enthusiast
Messages
506
Reaction score
222
I actually like this alot, good work
 
F

FRlNZ

Newbie
Messages
1
Reaction score
0
any other dope releases mate?i would like to seeem more gsc stuff from you
 
Top Bottom