I am working on my own persistent cache system. A player, using a shovel, can dig a hole, put something in a hole, and then anyone digging in roughly the same spot can dig it up again. That is the idea.
One problem is how to store the location as a label in the bioware database. The BioDB has a limit of 32 characters for the label. Presently I am using NBDE's Hash function as a fail safe for that, although I will want to learn how to generate a unique Hash of my own soon enough. I don't understand what Knat did with all those bitwise operators.
The second problem is that I want to limit the x and y coordinate information to 3 characters each in the string. And to limit location to a 2meter by 2meter square. As long as someone digs within the 2x2 area, they dig up the same hole. Here's how I generate an ID for that:
[color="#00ff00"]string GetCacheID(location lHole)
{
// generate ID of cache from location
vector vHole = GetPositionFromLocation(lHole);
object oArea = GetAreaFromLocation(lHole);
string sX = IntToString(FloatToInt(vHole.x/2.0));
int nsX = GetStringLength(sX);
if(nsX<2)
sX = "00"+sX;
else if(nsX<3)
sX = "0"+sX;
string sY = IntToString(FloatToInt(vHole.y/2.0));
int nsY = GetStringLength(sY);
if(nsY<2)
sY = "00"+sY;
else if(nsY<3)
sY = "0"+sY;
string sCoord = "HL"+GetTag(oArea)
+sX // X position in area divided by 2 - max 3 characters
+sY; // Y position in area divided by 2 - max 3 characters
return IntToString(NBDE_Hash(sCoord));
}[/color]
The part I want help with right now is how I am handling padding. Is there a better way to do this? Presently I am checking length of the string of each coord, and adding zero's in front to ensure that the coord is 3 characters long. Any recommendations on a better way to do this?
Modifié par henesua, 23 octobre 2012 - 02:16 .