XpDeviL

xNavigator - Navigation System

Feb 9th, 2019
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     xNavigator - Navigation System
  3.                             by XpDeviL
  4.                        
  5.        
  6.             ~ Features ~
  7.         * You can easily add your locations by typing {"Location Name", X, Y, Z} in the location list below.
  8.         * You can open and use the navigation by typing /nav in the game.
  9.         * After selecting a location, the selected position is marked on the map, and also you can see the direction of the location by the arrow that appears on the vehicle.
  10.         * You can also see how much distance to the destination with textdraw, which is shown on the screen.
  11.         * Navigation closes when you get out of the car, when you type /navclose or when you reach the destination.
  12.        
  13.     You can visit my personal website for all my releases and more;
  14.     http://xpdevil.com
  15. */
  16.  
  17. #include <a_samp>
  18. #include <zcmd>
  19.  
  20. new
  21.     ok[MAX_PLAYERS],
  22.     pNavState[MAX_PLAYERS],
  23.     pNavID[MAX_PLAYERS],
  24.     pNavTimer[MAX_PLAYERS],
  25.     PlayerText:NAVpTD[MAX_PLAYERS],
  26.     Text:NAVTD[2]
  27. ;
  28.  
  29. enum NAV_DATA {
  30.     NAV_NAME[32],
  31.     Float:NAV_X,
  32.     Float:NAV_Y,
  33.     Float:NAV_Z
  34. };
  35.  
  36. new const NavData[][NAV_DATA] = { // Location list in navigation:
  37.     {"The Strip", 2039.6165, 1343.0740, 10.6719}, // {"Location Name", X, Y, Z}
  38.     {"Come-A-Lot", 2166.6948,1123.8224,12.5687},  // You can add your locations like this.
  39.     {"Las Venturas Airport", 1724.4327,1602.1609,10.0156} // Make sure that no comma at the end of the last one.
  40. };
  41.  
  42. public OnFilterScriptInit()
  43. {
  44.  
  45.     print("\n+----------------------------------------------------+");
  46.     print("|                                                    |");
  47.     print("|      xNavigator - Navigation System ~ Loaded!      |");
  48.     print("|                                      by XpDeviL    |");
  49.     print("|                                                    |");
  50.     print("+----------------------------------------------------+\n");
  51.  
  52.     NAVTD[0] = TextDrawCreate(404.319183, 409.916809, "box");
  53.     TextDrawLetterSize(NAVTD[0], 0.000000, 1.941436);
  54.     TextDrawTextSize(NAVTD[0], 498.000000, 0.000000);
  55.     TextDrawAlignment(NAVTD[0], 1);
  56.     TextDrawColor(NAVTD[0], -1);
  57.     TextDrawUseBox(NAVTD[0], 1);
  58.     TextDrawBoxColor(NAVTD[0], 100);
  59.     TextDrawSetShadow(NAVTD[0], 0);
  60.     TextDrawSetOutline(NAVTD[0], 0);
  61.     TextDrawBackgroundColor(NAVTD[0], 255);
  62.     TextDrawFont(NAVTD[0], 1);
  63.     TextDrawSetProportional(NAVTD[0], 1);
  64.     TextDrawSetShadow(NAVTD[0], 0);
  65.  
  66.     NAVTD[1] = TextDrawCreate(404.787597, 399.999847, "Navigation Info");
  67.     TextDrawLetterSize(NAVTD[1], 0.299736, 1.115833);
  68.     TextDrawAlignment(NAVTD[1], 1);
  69.     TextDrawColor(NAVTD[1], -5963521);
  70.     TextDrawSetShadow(NAVTD[1], 1);
  71.     TextDrawSetOutline(NAVTD[1], 0);
  72.     TextDrawBackgroundColor(NAVTD[1], 255);
  73.     TextDrawFont(NAVTD[1], 0);
  74.     TextDrawSetProportional(NAVTD[1], 1);
  75.     TextDrawSetShadow(NAVTD[1], 1);
  76.     return 1;
  77. }
  78.  
  79. public OnPlayerConnect(playerid)
  80. {
  81.     NAVpTD[playerid] = CreatePlayerTextDraw(playerid, 405.724487, 415.166564, "Distance Left: ~y~0000.00m");
  82.     PlayerTextDrawLetterSize(playerid, NAVpTD[playerid], 0.179326, 1.109999);
  83.     PlayerTextDrawAlignment(playerid, NAVpTD[playerid], 1);
  84.     PlayerTextDrawColor(playerid, NAVpTD[playerid], -1);
  85.     PlayerTextDrawSetShadow(playerid, NAVpTD[playerid], 0);
  86.     PlayerTextDrawSetOutline(playerid, NAVpTD[playerid], 0);
  87.     PlayerTextDrawBackgroundColor(playerid, NAVpTD[playerid], 255);
  88.     PlayerTextDrawFont(playerid, NAVpTD[playerid], 2);
  89.     PlayerTextDrawSetProportional(playerid, NAVpTD[playerid], 1);
  90.     PlayerTextDrawSetShadow(playerid, NAVpTD[playerid], 0);
  91.     return 1;
  92. }
  93.  
  94. public OnPlayerDisconnect(playerid, reason)
  95. {
  96.     if(pNavState[playerid])
  97.     {
  98.         KillTimer(pNavTimer[playerid]);
  99.         DestroyObject(ok[playerid]);
  100.         DisablePlayerCheckpoint(playerid);
  101.         pNavState[playerid] = 0;
  102.     }
  103.     return 1;
  104. }
  105.  
  106. CMD:nav(playerid, params[])
  107. {
  108.     if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{FF0000}<!> You must be in a vehicle to use navigation!");
  109.     static string[sizeof(NavData) * 64];
  110.  
  111.     if (string[0] == EOS)
  112.     {
  113.         for (new i; i < sizeof(NavData); i++)
  114.         {
  115.             format(string, sizeof string, "%s{f4a442}» {f7f5bb}%s\n", string, NavData[i][NAV_NAME]);
  116.         }
  117.     }
  118.     ShowPlayerDialog(playerid, 112, DIALOG_STYLE_LIST, "[Navigation] Locations", string, "Select", "Close");
  119.     return 1;
  120. }
  121.  
  122. CMD:navclose(playerid, params[])
  123. {
  124.     if(pNavState[playerid])
  125.     {
  126.         KillTimer(pNavTimer[playerid]);
  127.         DestroyObject(ok[playerid]);
  128.         for(new i; i<sizeof(NAVTD); i++) TextDrawHideForPlayer(playerid, NAVTD[i]);
  129.         PlayerTextDrawHide(playerid, NAVpTD[playerid]);
  130.         PlayerPlaySound(playerid,1137,0.0,0.0,0.0);
  131.         DisablePlayerCheckpoint(playerid);
  132.         pNavState[playerid] = 0;
  133.         SendClientMessage(playerid, -1, "{FF0000}<!> Navigation cancelled!");
  134.     } else SendClientMessage(playerid, -1, "{FF0000}<!> Navigation is already off!");
  135.     return 1;
  136. }
  137.  
  138. public OnPlayerStateChange(playerid, newstate, oldstate)
  139. {
  140.     if(pNavState[playerid])
  141.     {
  142.         KillTimer(pNavTimer[playerid]);
  143.         DestroyObject(ok[playerid]);
  144.         for(new i; i<sizeof(NAVTD); i++) TextDrawHideForPlayer(playerid, NAVTD[i]);
  145.         PlayerTextDrawHide(playerid, NAVpTD[playerid]);
  146.         PlayerPlaySound(playerid,1150,0.0,0.0,0.0);
  147.         DisablePlayerCheckpoint(playerid);
  148.         pNavState[playerid] = 0;
  149.         SendClientMessage(playerid, -1, "{FF0000}<!> Navigation is cancelled because you are off the vehicle!");
  150.     }
  151.     return 1;
  152. }
  153.  
  154. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  155. {
  156.     if(dialogid == 112)
  157.     {
  158.         if(response)
  159.         {
  160.             if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{FF0000}<!> You must be in a vehicle to use navigation!");
  161.             pNavID[playerid] = listitem;
  162.             new str[128];
  163.             SetPlayerCheckpoint(playerid, NavData[pNavID[playerid]][NAV_X], NavData[pNavID[playerid]][NAV_Y], NavData[pNavID[playerid]][NAV_Z], 3.0);
  164.             format(str, 128, "{00FF00}<!> Destination is set to {FFA500}%s", NavData[pNavID[playerid]][NAV_NAME]);
  165.             SendClientMessage(playerid, -1, str);
  166.             SendClientMessage(playerid, -1, "{00FF00}<!> You can type {FF7D0A}/navclose {00FF00}to cancel the navigation.");
  167.             if(IsValidObject(ok[playerid])) DestroyObject(ok[playerid]);
  168.             ok[playerid] = CreateObject(19134, 0, 0, 0, 0, 0, 0);
  169.             Refresh(playerid);
  170.             KillTimer(pNavTimer[playerid]);
  171.             pNavTimer[playerid] = SetTimerEx("Refresh", 100, true, "d", playerid);
  172.             for(new i; i<sizeof(NAVTD); i++) TextDrawShowForPlayer(playerid, NAVTD[i]);
  173.             PlayerTextDrawShow(playerid, NAVpTD[playerid]);
  174.             PlayerPlaySound(playerid,1139,0.0,0.0,0.0);
  175.             pNavState[playerid] = 1;
  176.         }
  177.     }
  178.     return 1;
  179. }
  180.  
  181. stock Float:PointAngle(playerid, Float:xa, Float:ya, Float:xb, Float:yb) // Don't know the owner.
  182. {
  183.     new Float:carangle;
  184.     new Float:xc, Float:yc;
  185.     new Float:angle;
  186.     xc = floatabs(floatsub(xa,xb));
  187.     yc = floatabs(floatsub(ya,yb));
  188.     if (yc == 0.0 || xc == 0.0)
  189.     {
  190.         if(yc == 0 && xc > 0) angle = 0.0;
  191.         else if(yc == 0 && xc < 0) angle = 180.0;
  192.         else if(yc > 0 && xc == 0) angle = 90.0;
  193.         else if(yc < 0 && xc == 0) angle = 270.0;
  194.         else if(yc == 0 && xc == 0) angle = 0.0;
  195.     }
  196.     else
  197.     {
  198.         angle = atan(xc/yc);
  199.         if(xb > xa && yb <= ya) angle += 90.0;
  200.         else if(xb <= xa && yb < ya) angle = floatsub(90.0, angle);
  201.         else if(xb < xa && yb >= ya) angle -= 90.0;
  202.         else if(xb >= xa && yb > ya) angle = floatsub(270.0, angle);
  203.     }
  204.     GetVehicleZAngle(GetPlayerVehicleID(playerid), carangle);
  205.     return floatadd(angle, -carangle);
  206. }
  207.  
  208. forward Refresh(playerid);
  209. public Refresh(playerid)
  210. {
  211.     new Float:pos[3], Float:pPos[3];
  212.     pPos[0] = NavData[pNavID[playerid]][NAV_X];
  213.     pPos[1] = NavData[pNavID[playerid]][NAV_Y];
  214.     pPos[2] = NavData[pNavID[playerid]][NAV_Z];
  215.     GetVehiclePos(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[2]);
  216.     new Float:rot = PointAngle(playerid, pos[0], pos[1], pPos[0], pPos[1]);
  217.     AttachObjectToVehicle(ok[playerid], GetPlayerVehicleID(playerid), 0.000000, 0.000000, 1.399998, 0.000000, 90.0, rot + 180);
  218.     new Float:mesafe, str[32];
  219.     mesafe = GetPlayerDistanceFromPoint(playerid, pPos[0], pPos[1], pPos[2]);
  220.     format(str, sizeof(str), "Distance Left: ~y~%0.2fm", mesafe);
  221.     PlayerTextDrawSetString(playerid, NAVpTD[playerid], str);
  222.     if(IsPlayerInRangeOfPoint(playerid, 10.0, pPos[0], pPos[1], pPos[2]))
  223.     {
  224.         KillTimer(pNavTimer[playerid]);
  225.         DestroyObject(ok[playerid]);
  226.         for(new i; i<sizeof(NAVTD); i++) TextDrawHideForPlayer(playerid, NAVTD[i]);
  227.         PlayerTextDrawHide(playerid, NAVpTD[playerid]);
  228.         DisablePlayerCheckpoint(playerid);
  229.         PlayerPlaySound(playerid,1137,0.0,0.0,0.0);
  230.         pNavState[playerid] = 0;
  231.         SendClientMessage(playerid, -1, "{00FF00}<!> You have reached your destination!");
  232.     }
  233.     return 1;
  234. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×