Guest User

Untitled

a guest
May 24th, 2015
1,622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.84 KB | None | 0 0
  1. #include <a_samp>
  2. #include <gps_done>
  3. #include <streamer>
  4. #include <zcmd>
  5.  
  6. new Text:sideCheck[MAX_PLAYERS] = {Text:INVALID_TEXT_DRAW, ...};
  7.  
  8. public OnFilterScriptInit()
  9. {
  10.     for(new i=0;i<MAX_PLAYERS;i++)
  11.     {
  12.         sideCheck[i] = TextDrawCreate(320.000000, 337.000000, " ");
  13.         TextDrawAlignment(sideCheck[i], 2);
  14.         TextDrawBackgroundColor(sideCheck[i], 255);
  15.         TextDrawFont(sideCheck[i], 2);
  16.         TextDrawLetterSize(sideCheck[i], 0.290000, 1.400000);
  17.         TextDrawColor(sideCheck[i], -1);
  18.         TextDrawSetOutline(sideCheck[i], 0);
  19.         TextDrawSetProportional(sideCheck[i], 1);
  20.         TextDrawSetShadow(sideCheck[i], 0);
  21.         TextDrawUseBox(sideCheck[i], 1);
  22.         TextDrawBoxColor(sideCheck[i], 68);
  23.         TextDrawTextSize(sideCheck[i], 71.000000, 90.000000);
  24.     }
  25.     return 1;
  26. }
  27.  
  28. CMD:to(playerid,cmd[])
  29. {
  30.     SetPlayerPos(playerid,-2427.629882,-2474.750000,35.750000);
  31.     return 1;
  32. }
  33.  
  34. CMD:check(playerid,cmd[])
  35. {
  36.     new dbug = strval(cmd);
  37.     new firstNode, secondNode, navi;
  38.     new Float:closest = 9999.0;
  39.     new closestID = -1;
  40.     for(new i=0;i<sizeof(nodes);i++)
  41.     {
  42.         new Float:dist = GetPlayerDistanceFromPoint(playerid,nodes[i][nodeX],nodes[i][nodeY],nodes[i][nodeZ]);
  43.         if(dist < closest)
  44.         {
  45.             closest = dist;
  46.             closestID = i;
  47.         }
  48.     }
  49.     new string[256];
  50.     if(closestID == -1)
  51.     {
  52.         TextDrawSetString(sideCheck[playerid],"No Initial Node Found");
  53.         TextDrawShowForPlayer(playerid,sideCheck[playerid]);
  54.         return 1;
  55.     }
  56.     firstNode = closestID;
  57.    
  58.     closest = 9999.0;
  59.     closestID = -1;
  60.     new linkCount = 0;
  61.     for(new n=0;n<4;n++)
  62.     {
  63.         new link = 3 + (n * 2);
  64.         if(nodes[firstNode][link] != -1)
  65.         {
  66.             linkCount++;
  67.             if(linkCount > 2)
  68.             {
  69.                 TextDrawSetString(sideCheck[playerid],"Intersection, Discarded");
  70.                 TextDrawShowForPlayer(playerid,sideCheck[playerid]);
  71.                 return 1;
  72.             }
  73.             new Float:dist = GetPlayerDistanceFromPoint(playerid,nodes[nodes[firstNode][link]][nodeX],nodes[nodes[firstNode][link]][nodeY],nodes[nodes[firstNode][link]][nodeZ]);
  74.             if(dist < closest)
  75.             {
  76.                 closest = dist;
  77.                 closestID = link;
  78.             }
  79.         }
  80.     }
  81.     if(closestID == -1)
  82.     {
  83.         TextDrawSetString(sideCheck[playerid],"No Connecting Node Found");
  84.         TextDrawShowForPlayer(playerid,sideCheck[playerid]);
  85.         return 1;
  86.     }
  87.     navi = nodes[firstNode][closestID + 1];
  88.     secondNode = nodes[firstNode][closestID];
  89.     if(navi == -1)
  90.     {
  91.         TextDrawSetString(sideCheck[playerid],"No Navi Found For Nodes");
  92.         TextDrawShowForPlayer(playerid,sideCheck[playerid]);
  93.         return 1;
  94.     }
  95.     if(secondNode == -1)
  96.     {
  97.         TextDrawSetString(sideCheck[playerid],"Something Real Wrong Happened Here");
  98.         TextDrawShowForPlayer(playerid,sideCheck[playerid]);
  99.         return 1;
  100.     }
  101.     if(dbug)
  102.     {
  103.         format(string,sizeof(string),"You Are In Between: %d And: %d There Are %d Left Lanes And %d Right",firstNode,secondNode,navis[navi][leftLanes],navis[navi][rightLanes]);
  104.         SendClientMessage(playerid,-1,string);
  105.     }
  106.     new start = navis[navi][from];
  107.     new end = navis[navi][to];
  108.     if(dbug)
  109.     {
  110.         format(string,sizeof(string),"Navi Start: %d End: %d",start,end);
  111.         SendClientMessage(playerid,-1,string);
  112.     }
  113.     new Float:roadAngle;
  114.     GetAngleFrom(roadAngle,nodes[start][nodeX],nodes[start][nodeY],nodes[end][nodeX],nodes[end][nodeY]);
  115.     new Float:playerHeading;
  116.     if(IsPlayerInAnyVehicle(playerid))
  117.     {
  118.         GetVehicleZAngle(GetPlayerVehicleID(playerid),playerHeading);
  119.     }
  120.     else
  121.     {
  122.         GetPlayerFacingAngle(playerid,playerHeading);
  123.     }
  124.     new Float:roadToPlayer;
  125.     new Float:pX, Float:pY, Float:pZ;
  126.     GetPlayerPos(playerid,pX,pY,pZ);
  127.     GetAngleFrom(roadToPlayer,nodes[start][nodeX],nodes[start][nodeY],pX,pY);
  128.     new roadToPlayerDiff;
  129.     GetAngleDifference(roadToPlayerDiff,roadAngle,roadToPlayer);
  130.     if(roadToPlayerDiff > 0)
  131.     {
  132.         //SendClientMessage(playerid,-1,"You Are On The Right Of The Node");
  133.     }
  134.     else
  135.     {
  136.         //SendClientMessage(playerid,-1,"You Are On The Left Of The Node");
  137.     }
  138.     new angleDiff;
  139.     GetAngleDifference(angleDiff,roadAngle,playerHeading);
  140.     if(dbug)
  141.     {
  142.         format(string,sizeof(string),"Road Direction Is: %0.2f, Your Direction Is: %0.2f, Difference: %d, roadToPlayerDiff: %d",roadAngle,playerHeading,angleDiff,roadToPlayerDiff);
  143.         SendClientMessage(playerid,-1,string);
  144.     }
  145.     if(navis[navi][leftLanes] == 1 && navis[navi][rightLanes] == 1)
  146.     {
  147.         if(roadToPlayerDiff > 0)//right of the nodes
  148.         {
  149.             if(angleDiff > -45 && angleDiff < 45)
  150.             {
  151.                 TextDrawSetString(sideCheck[playerid],"Right way");
  152.             }
  153.             else
  154.             {
  155.                 TextDrawSetString(sideCheck[playerid],"Wrong way");
  156.             }
  157.         }
  158.         else//left of the nodes
  159.         {
  160.             if(angleDiff > 135 || angleDiff < -135)
  161.             {
  162.                 TextDrawSetString(sideCheck[playerid],"Right way");
  163.             }
  164.             else
  165.             {
  166.                 TextDrawSetString(sideCheck[playerid],"Wrong way");
  167.             }
  168.         }
  169.     }
  170.     else if(navis[navi][leftLanes] == 2)
  171.     {
  172.         if(angleDiff > 135 || angleDiff < -135)
  173.         {
  174.             TextDrawSetString(sideCheck[playerid],"Right way");
  175.         }
  176.         else
  177.         {
  178.             TextDrawSetString(sideCheck[playerid],"Wrong way");
  179.         }
  180.     }
  181.     else if(navis[navi][rightLanes] == 2)
  182.     {
  183.         if(angleDiff > -45 && angleDiff < 45)
  184.         {
  185.             TextDrawSetString(sideCheck[playerid],"Right way");
  186.         }
  187.         else
  188.         {
  189.             TextDrawSetString(sideCheck[playerid],"Wrong way");
  190.         }
  191.     }
  192.     TextDrawShowForPlayer(playerid,sideCheck[playerid]);
  193.     return 1;
  194. }
  195. stock GetAngleDifference(&a,Float:a1,Float:a2)
  196. {
  197.     //abs((i + 180 - j) mod 360 - 180);
  198.     a = (floatround(a1) + 180 - floatround(a2)) % 360 - 180;
  199. }
  200.  
  201. stock GetAngleFrom(&Float:a,Float:x1,Float:y1,Float:x2,Float:y2)
  202. {
  203.     a = atan2(y2 - y1, x2 - x1) - 90;
  204. }
  205.  
  206. new lastRoadCheck[MAX_PLAYERS];
  207. public OnPlayerUpdate(playerid)
  208. {
  209.     if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  210.     {
  211.         if(lastRoadCheck[playerid] < GetTickCount() - 500)
  212.         {
  213.             lastRoadCheck[playerid] = GetTickCount();
  214.             cmd_check(playerid,"");
  215.         }
  216.     }
  217.     if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  218.     {
  219.         TextDrawHideForPlayer(playerid,sideCheck[playerid]);
  220.     }
  221.     return 1;
  222. }
  223.  
  224. public OnFilterScriptExit()
  225. {
  226.     return 1;
  227. }
  228. //by cessil
Advertisement
Add Comment
Please, Sign In to add comment