We all know that there is a script command LeftCopy that copys xxx letters from the left side of a string. I would like to have one that copys xxx letters from the right end of the script.
I need it for this script, which is a generic script for chests. It would allow to specify a chest that can be opened with right-clicking on it. The EntityName would then contain all the information about what is in the chest:
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 [true]
D_DIST_P [0]
D_INT [30]
D_RENDER [512]
CHEST []
INCHEST []
AMOUNT []
Setup[ ()
{
Console(CONSOLE);
Gravity(false);
LowLevel("Init");
} ]
Init[ ()
{
CHEST = RightCopy(self.EntityName,GetStringLength(self.EntityName)-5);
INCHEST = LeftCopy(CHEST,GetStringLength(INCHEST)-4);
AMOUNT = RightCopy(CHEST,4);
self.think="Idle";
} ]
Idle[ () //Normal rendering; check if player gets close or far
{
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[ () //near enough to interact
{
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("chest_open");
self.think="Open";
}
}
} ]
wI[ () //far away, no need for rendering, wait until player comes nearer
{
self.ThinkTime=1.0;
if(DistanceBetweenEntities("Player",self.EntityName,true)<D_RENDER)
{
PawnRender(true);
self.think="Idle";
return;
}
} ]
Open[ ()
{
ModifyAttribute(INCHEST,AMOUNT,"Player");
ShowText(0, "Player", "", "I got" # AMOUNT # " " # INCHEST ".", 0, "", 0, -100,"Centre", 255);
HighLevel("Opened");
} ]
Opened[ ()
{
FadeOut(2.0,0);
LowLevel("Opened2");
} ]
Opened2[ ()
{
RemoveText(0);
HighLevel("Opened3");
} ]
Opened3[ ()
{
Remove(true);
} ]
}
Thanks in advance