My Script Contains a GPS Function with Distance and Direction...
Anywhere on the script under the defines:
pawn Код:
stock SetPlayerRouting(playerid, Float:x1, Float:y1, Float:z1)
{
if(IsPlayerInAnyVehicle(playerid) && Gps[playerid] == 1)
{
new string[128];
new textstring[200];
new Float:x2, Float:y2, Float:z2;
new Float:angle2;
GetVehiclePos(GetPlayerVehicleID(playerid), x2, y2, z2);
GetVehicleZAngle(GetPlayerVehicleID(playerid), angle2);
new Float:dist;
dist = floatsqroot(floatpower(floatabs(floatsub(x1,x2)),2)+floatpower(floatabs(floatsub(y1,y2)),2)+floatpower(floatabs(floatsub(z1,z2)),2));
new Float:angle1;
if( (y1-y2) >= 0.0) angle1 = acos((x1-x2)/dist) - 90;
else angle1 = 270 - acos((x1-x2)/dist);
new Float:offset;
offset = 360.0 - angle2 + angle1;
if(offset >= 360.0) offset = offset - 360.0;
else if(offset < 0.0) offset = offset + 360.0;
if(offset >= 330.0 || offset < 30.0) format(string, sizeof(string), "~u~ ~w~%d ~u~", floatround(dist));
else if(offset >= 30.0 && offset < 60.0) format(string, sizeof(string), "~<~ ~w~%d", floatround(dist));
else if(offset >= 60.0 && offset < 100.0) format(string, sizeof(string), "~<~~<~ ~w~%d", floatround(dist));
else if(offset >= 100.0 && offset < 150.0) format(string, sizeof(string), "~d~~<~ ~w~%d", floatround(dist));
else if(offset >= 150.0 && offset < 210.0) format(string, sizeof(string), "~d~ ~w~%d ~d~", floatround(dist));
else if(offset >= 210.0 && offset < 260.0) format(string, sizeof(string), "~w~%d ~>~~d~", floatround(dist));
else if(offset >= 260.0 && offset < 300.0) format(string, sizeof(string), "~w~%d ~>~~>~", floatround(dist));
else if(offset >= 300.0 && offset < 330.0) format(string, sizeof(string), "~w~%d ~>~", floatround(dist));
format(textstring,sizeof(textstring),"~r~Global Positionating System ~n~~n~~y~Now Tracking Coordinates: ~w~~n~X %.01f - Y %.01f - Z %.01f ~n~~n~ ~y~Distance & Direction: ~n~%s", x1, y1, z1, string);
TextDrawSetString(Textdraw53[playerid],textstring);
TelePosGps[playerid][tX] = x1;
TelePosGps[playerid][tY] = y1;
TelePosGps[playerid][tZ] = z1;
}
return 1;
}
Onplayercommandtext:
pawn Код:
dcmd(gpsfind, 7, cmdtext);
anywhere:
pawn Код:
dcmd_gpsfind(playerid, params[])
{
new Float:x, Float:y, Float:z;
new string[100];
if (sscanf(params, "fff", x, y, z))
{
SendClientMessage(playerid, 0xBBBBBBAA, "TIP: /gpsfind <X> <Y> <Z>");
SendClientMessage(playerid, 0xBBBBBBAA, "TIP: /gpsfind 0 0 0 To turn it off.");
return 1;
}
else
{
if((x == 0 && y == 0 && z == 0) && Gps[playerid] == 1)
{
Gps[playerid] = 0;
SendClientMessage(playerid, 0xFFFFFFFF, "You have Turned off your GPS");
TextDrawHideForPlayer(playerid, Textdraw53[playerid]);
KillTimer(gpstimer[playerid]);
}
else
{
if(IsPlayerInAnyVehicle(playerid))
{
Gps[playerid] = 1;
SetPlayerRouting(playerid, x,y,z);
format(string, sizeof(string), "You've set your coord to %f, %f, %f", x, y, z);
SendClientMessage(playerid, 0xFFFFFFFF, string);
TextDrawShowForPlayer(playerid, Textdraw53[playerid]);
}
else
{
SendClientMessage(playerid, COLOR_GREY, "* You are not in a vehicle");
return 1;
}
}
}
return 1;
}
at top of script under defines:
pawn Код:
new Gps[MAX_PLAYERS];
new gpstimer[MAX_PLAYERS];
enum TelePosEnum
{
Float:tX,
Float:tY,
Float:tZ
};
new Float:TelePosGps[MAX_PLAYERS][TelePosEnum];
Onplayerentervehicle:
pawn Код:
if(Gps[playerid] == 1)
{
TextDrawShowForPlayer(playerid, Textdraw53[playerid]);
}
onplayerconnect:
pawn Код:
gpstimer[playerid] = SetTimerEx("GpsCheck",1250,true,"i",playerid);
Gps[playerid] = 0;
Textdraw53[playerid] = TextDrawCreate(320.000000, 341.000000, " "); // GPS
TextDrawAlignment(Textdraw53[playerid], 2);
TextDrawBackgroundColor(Textdraw53[playerid], 255);
TextDrawFont(Textdraw53[playerid], 2);
TextDrawLetterSize(Textdraw53[playerid], 0.400000, 1.500000);
TextDrawColor(Textdraw53[playerid], -1);
TextDrawSetOutline(Textdraw53[playerid], 1);
TextDrawSetProportional(Textdraw53[playerid], 1);
Onplayerexitvehicle:
pawn Код:
KillTimer(gpstimer[playerid]);
TextDrawDestroy(Textdraw53[playerid]);
onplayerdeath:
pawn Код:
KillTimer(gpstimer[playerid]);
anywhere:
pawn Код:
forward GpsCheck(playerid);
public GpsCheck(playerid)
{
if(IsPlayerInAnyVehicle(playerid))
{
SetPlayerRouting(playerid,TelePosGps[playerid][tX],TelePosGps[playerid][tY],TelePosGps[playerid][tZ]);
}
return 1;
}
anywhere 1 sec timer.
pawn Код:
SetPlayerRouting(i,TelePosGps[i][tX],TelePosGps[i][tY],TelePosGps[i][tZ]);
Use wiki if you don't know where to place