Page 1 of 1

generic chest script for those who want it

Posted: Tue Oct 31, 2006 3:22 pm
by Jay
I have made a generic chest script that gets the things that are inside from its EntityName.

I want to share it with you all, as for me it has proven very usefull.

A_OPEN is the 'open'-animation of the chest.
D_INT is the distance in which you can right-click on it to open it.
D_RENDER is the rendering distance.
D_DIST_P, CHEST, INCHEST and AMOUNT are used for inner calculations in the script.

Code: Select all

{
    //EntityName of a chest must be: CHESTxxx0000
    //where 0000 is a four letter number defining the amount of xxx thats in the chest
    //xxx does not need having a special amount of letters
    CONSOLE      [false]
    D_DIST_P     [0]
    D_INT           [30]
    D_RENDER    [4000]
    A_OPEN      [chest_open]
    CHEST        [CHESTxxx0000]
    INCHEST     [torches]
    AMOUNT      [5]
    
    Setup[ ()
    {
        Console(CONSOLE);
        Gravity(false);
        SetGroup("STATIC");
        LowLevel("Init");
    } ]
    Init[ ()
    {
        CHEST = RightCopy(self.EntityName,GetStringLength(self.EntityName)-5);
        INCHEST = LeftCopy(CHEST,GetStringLength(CHEST)-4);
        AMOUNT = RightCopy(CHEST,4);
        self.think="Idle";
    } ]
    Idle[ ()
    {
        self.ThinkTime=0.5;
        D_DIST_P=DistanceBetweenEntities("Player",self.EntityName,true);
        if(D_DIST_P<D_INT)
        {
            self.think="inters";
            return;
        }
        if(D_DIST_P>D_RENDER)
        {
            PawnRender(false);
            self.think="wI";
            return;
        }
    } ]
    inters[ ()
    {
        self.ThinkTime=0.01;
        if(DistanceBetweenEntities("Player",self.EntityName,true)>D_INT)
        {
            self.think="Idle";
            return;
        }
        if(self.key_pressed=73)
        {
            if(MouseSelect(false,false)=self.EntityName)
            {
                AnimateHold(A_OPEN);
                self.think="Open";
            }
        }
    } ]
    wI[ ()
    {
        self.ThinkTime=1.0;
        if(DistanceBetweenEntities("Player",self.EntityName,true)<D_RENDER)
        {
            PawnRender(true);
            self.think="Idle";
            return;
        }
    } ]
    Open[ ()
    {
        SetAttribute(INCHEST,GetAttribute(INCHEST,"Player")+AMOUNT,"Player");
        self.think="Opened";
    } ]
    Opened[ ()
    {
        self.ThinkTime=0.5;
        if(D_DIST_P>D_RENDER)
        {
            PawnRender(false);
            self.think="wI2";
            return;
        }
    } ]
    wI2[ ()
    {
        self.ThinkTime=1.0;
        if(DistanceBetweenEntities("Player",self.EntityName,true)<D_RENDER)
        {
            PawnRender(true);
            self.think="Opened";
            return;
        }
    } ]
}
I hope you find it usefull, too. :)

Posted: Wed Nov 22, 2006 7:45 am
by Veleran
I have a script for chest pawns that opens with a sound when you hit it and do damage 20 points,then it fades.

The trigger name in the seteventstate is used to spawn traps or treasure.

Maybe someone newbiew might want it.



{
Spawn[ ()
{
Console(false);
BoxWidth(44); // set bounding box width/depth
AttributeOrder("health", 20, "Open");
} ]

Wait[ ()
{
PlaySound("");
} ]

Open[ ()
{
AnimateStop("Open","2","creak1.wav");
SetEventState("Chest1Trigger", true);
SetNoCollision();
FadeOut(1,0);
Remove(true);
} ]

}