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;
}
} ]
}