24 May 2018 Tagged: eulorac++

Running around exploring various areas, I discovered it’s possible to get into some trouble. Trouble specifically of the 'sail off the edge of the map' variety. In this case there were not dragons there, but there was a lot of falling and more than a few clouds.

I was offered a helpful suggestion to pull myself up by my own bootstraps in a way I hadn’t even considered. In this case, to just change the y coordinate for your avatar.

I had a look around in the code for an appropriate place to do that. After some trial and error I discovered that changes to y alone wern’t going to be enough in this case; I needed a little x and z. Just enough to get my feet back on solid ground. Well, I already knew of one place where I had been typing in coodinates and that was 'Foxy’s autopilot', so I decided to piggy back on that command.

Autopilot works like this: you punch in some coordinates and it faces you in that direction. For example, on occasion, to face toward the trainer, I had been entering:

/pilot 40 0 312

The three parameters are x, y and z. I added a couple lines at the bottom of the existing code to enable a new and optional 4th parameter, the word 'move'.

else if(words[0] == "/pilot")	//point character in the direction of the given coordinates
        if (words.GetCount() < 4)
                return "Usage: /pilot x y z";

        csVector3 currPos;
        csVector3 gotoPos = csVector3(words.GetFloat(1), words.GetFloat(2), words.GetFloat(3));
        float yRot;
        iSector *sector;
        psengine->GetCelClient()->GetMainPlayer()->GetLastPosition(currPos, yRot, sector);
        csVector3 diff = gotoPos - currPos;
        float targetYRot = atan2(-diff.x,-diff.z);

        psengine->GetCelClient()->GetMainPlayer()->Rotate(0, targetYRot, 0);
+       csString s;
+       words.GetString(4, s);
+       if (s.CompareNoCase(csString("move"))) {
+               psengine->GetCelClient()->GetMainPlayer()->SetPosition(gotoPos, 0, sector);
+       }
        return "Foxy's autopilot done.";

When you pass in 'move' as 4th parameter, the client not only faces you in that dirction, but then also moves you to that location. Using this mechanism I was able to nudge myself in the right direction, and back onto the map.

Add a Comment