Here's my latest rev of the code:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->bool DoLocWrite(float magForward, float magUp)
{
ref pchar = GetMainCharacter();
int numdigits = 5;
if(FindLoadedLocation() == -1) return false; //if not in loc mode, return
float x, y, z, ay, xx, xz, zx, zz;
GetCharacterPos(pchar, &x, &y, &z); // get pos
GetCharacterAy(pchar, &ay); // get angle
if(!CheckAttribute(pchar, "locwrite"))
{
Logit("Locator coordinate writing (LOCWRITE). This assumes the bed will have the head to your right.");
Logit("If this is the case, press F12 again now. If this is not the case--the head is to your left--turn around first and then press F12 again.");
Logit("If you don't want to write this position as the locators, move somewhere else before hitting F12 and it will clear.");
pchar.locwrite = true;
pchar.locwrite.x = x;
pchar.locwrite.z = z;
pchar.locwrite.ay = ay;
return false;
}
else
{
float lx, lz, lay, firstay, seconday, side;
lx = stf(pchar.locwrite.x);
lz = stf(pchar.locwrite.z);
lay = stf(pchar.locwrite.ay);
DeleteAttribute(&pchar, "locwrite");
bool bx, bz, ba;
bx = false; bz = false; ba = false;
/*if(lx * 0.999 <= x && lx * 1.001 >= x) bx = true;
if(lz * 0.999 <= z && lz * 1.001 >= z) bz = true;*/
if(lx == x) bx = true;
if(lz == z) bz = true;
if(clampangle(lay) * 0.999 <= clampangle(ay) && clampangle(lay) * 1.001 >= clampangle(ay)) ba = true;
if(bx && bz)
{
if(ba) { seconday = lay + PId2}
else { seconday = lay - PId2;}
}
else
{
logit("LOCWRITE: Positions not the same, clearing...");
//trace("old pchar pos: " + lx + ", "+ lz +"; new pos " + x + ", " + z);
return false;
}
ref loc = &Locations[FindLoadedLocation()];
string locname = "locatormodel: Resource\\models\\" + loc.filespath.models + "\\" + loc.models.always.locators + ".gm";
// angle components
xx = sin(lay+PI);
zz = xx;
xz = cos(lay+PI);
zx = -1.0 * xz;
trace(locname);
trace("goto,upfrombed,"+floattostring(xx, numdigits)+",0,"+floattostring(xz, numdigits)+",0,1,0,"+floattostring(zx, numdigits)+",0,"+floattostring(zz, numdigits)+","+floattostring(x, numdigits)+","+floattostring(y, numdigits)+","+floattostring(z, numdigits)+",1,0,0,0,0,0,0,0,0,");
// change for bed
z += cos(lay) * magForward;
x += sin(lay) * magForward;
y += magUp;
xx = sin(seconday);
zz = xx;
xz = cos(seconday);
zx = -1.0 * xz;
trace("reload,onbed,"+floattostring(xx, numdigits)+",0,"+floattostring(xz, numdigits)+",0,1,0,"+floattostring(zx, numdigits)+",0,"+floattostring(zz, numdigits)+","+floattostring(x, numdigits)+","+floattostring(y, numdigits)+","+floattostring(z, numdigits)+",1,0,0,0,0,0,0,0,0,");
logit("LOCWRITE: Writing complete. The head of the bed was to your " + stringret(ba, "right", "left"));
//TeleportCharacterToPos(pchar, x, y, z); // move char
//GetCharacterPos(pchar, &x, &y, &z);
//Logit("Pos After: (" + x + ", " + y + ", " + z + ")");
return true;
}
}<!--c2--></div><!--ec2-->
With correct locator names and with magF and magU as args.