#include "x0_i0_position"
// Get a random location in a given area based on a given object,
// the specified distance away.
// If no object is given, will use a random object in the area.
// If that is not available, will use the roughly-center point
// of the area.
// If distance is set to 0.0, a random distance will be used.
location GetRandomLocation(object oArea, object oSource=OBJECT_INVALID, float fDist=0.0);
location GetRandomLocation(object oArea, object oSource=OBJECT_INVALID, float fDist=0.0)
{
location lStart;
if (!GetIsObjectValid(oSource)) {
lStart = GetCenterPointOfArea(oArea);
} else {
lStart = GetLocation(oSource);
}
float fAngle; float fOrient;
if (fDist == 0.0) {
int nRoll = Random(3);
switch (nRoll) {
case 0:
fDist = DISTANCE_MEDIUM; break;
case 1:
fDist = DISTANCE_LARGE; break;
case 2:
fDist = DISTANCE_HUGE; break;
}
}
fAngle = IntToFloat(Random(140) + 40);
fOrient = IntToFloat(Random(360));
return GenerateNewLocationFromLocation(lStart,
fDist,
fAngle,
fOrient);
}
For those who are looking for a random teleport code, this is very good
It makes no sense with my objective that was to find out how to define a distance of 10 meters from the target if the distance is greater. However I discovered that it would not be possible, could give bug and I still do not know how to teleport 10 meters away from an angle that was chosen by activating item.
Modifié par WhiteTiger, 07 août 2014 - 12:23 .