Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <gps_done>
- #include <streamer>
- #include <zcmd>
- new Text:sideCheck[MAX_PLAYERS] = {Text:INVALID_TEXT_DRAW, ...};
- public OnFilterScriptInit()
- {
- for(new i=0;i<MAX_PLAYERS;i++)
- {
- sideCheck[i] = TextDrawCreate(320.000000, 337.000000, " ");
- TextDrawAlignment(sideCheck[i], 2);
- TextDrawBackgroundColor(sideCheck[i], 255);
- TextDrawFont(sideCheck[i], 2);
- TextDrawLetterSize(sideCheck[i], 0.290000, 1.400000);
- TextDrawColor(sideCheck[i], -1);
- TextDrawSetOutline(sideCheck[i], 0);
- TextDrawSetProportional(sideCheck[i], 1);
- TextDrawSetShadow(sideCheck[i], 0);
- TextDrawUseBox(sideCheck[i], 1);
- TextDrawBoxColor(sideCheck[i], 68);
- TextDrawTextSize(sideCheck[i], 71.000000, 90.000000);
- }
- return 1;
- }
- CMD:to(playerid,cmd[])
- {
- SetPlayerPos(playerid,-2427.629882,-2474.750000,35.750000);
- return 1;
- }
- CMD:check(playerid,cmd[])
- {
- new dbug = strval(cmd);
- new firstNode, secondNode, navi;
- new Float:closest = 9999.0;
- new closestID = -1;
- for(new i=0;i<sizeof(nodes);i++)
- {
- new Float:dist = GetPlayerDistanceFromPoint(playerid,nodes[i][nodeX],nodes[i][nodeY],nodes[i][nodeZ]);
- if(dist < closest)
- {
- closest = dist;
- closestID = i;
- }
- }
- new string[256];
- if(closestID == -1)
- {
- TextDrawSetString(sideCheck[playerid],"No Initial Node Found");
- TextDrawShowForPlayer(playerid,sideCheck[playerid]);
- return 1;
- }
- firstNode = closestID;
- closest = 9999.0;
- closestID = -1;
- new linkCount = 0;
- for(new n=0;n<4;n++)
- {
- new link = 3 + (n * 2);
- if(nodes[firstNode][link] != -1)
- {
- linkCount++;
- if(linkCount > 2)
- {
- TextDrawSetString(sideCheck[playerid],"Intersection, Discarded");
- TextDrawShowForPlayer(playerid,sideCheck[playerid]);
- return 1;
- }
- new Float:dist = GetPlayerDistanceFromPoint(playerid,nodes[nodes[firstNode][link]][nodeX],nodes[nodes[firstNode][link]][nodeY],nodes[nodes[firstNode][link]][nodeZ]);
- if(dist < closest)
- {
- closest = dist;
- closestID = link;
- }
- }
- }
- if(closestID == -1)
- {
- TextDrawSetString(sideCheck[playerid],"No Connecting Node Found");
- TextDrawShowForPlayer(playerid,sideCheck[playerid]);
- return 1;
- }
- navi = nodes[firstNode][closestID + 1];
- secondNode = nodes[firstNode][closestID];
- if(navi == -1)
- {
- TextDrawSetString(sideCheck[playerid],"No Navi Found For Nodes");
- TextDrawShowForPlayer(playerid,sideCheck[playerid]);
- return 1;
- }
- if(secondNode == -1)
- {
- TextDrawSetString(sideCheck[playerid],"Something Real Wrong Happened Here");
- TextDrawShowForPlayer(playerid,sideCheck[playerid]);
- return 1;
- }
- if(dbug)
- {
- 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]);
- SendClientMessage(playerid,-1,string);
- }
- new start = navis[navi][from];
- new end = navis[navi][to];
- if(dbug)
- {
- format(string,sizeof(string),"Navi Start: %d End: %d",start,end);
- SendClientMessage(playerid,-1,string);
- }
- new Float:roadAngle;
- GetAngleFrom(roadAngle,nodes[start][nodeX],nodes[start][nodeY],nodes[end][nodeX],nodes[end][nodeY]);
- new Float:playerHeading;
- if(IsPlayerInAnyVehicle(playerid))
- {
- GetVehicleZAngle(GetPlayerVehicleID(playerid),playerHeading);
- }
- else
- {
- GetPlayerFacingAngle(playerid,playerHeading);
- }
- new Float:roadToPlayer;
- new Float:pX, Float:pY, Float:pZ;
- GetPlayerPos(playerid,pX,pY,pZ);
- GetAngleFrom(roadToPlayer,nodes[start][nodeX],nodes[start][nodeY],pX,pY);
- new roadToPlayerDiff;
- GetAngleDifference(roadToPlayerDiff,roadAngle,roadToPlayer);
- if(roadToPlayerDiff > 0)
- {
- //SendClientMessage(playerid,-1,"You Are On The Right Of The Node");
- }
- else
- {
- //SendClientMessage(playerid,-1,"You Are On The Left Of The Node");
- }
- new angleDiff;
- GetAngleDifference(angleDiff,roadAngle,playerHeading);
- if(dbug)
- {
- format(string,sizeof(string),"Road Direction Is: %0.2f, Your Direction Is: %0.2f, Difference: %d, roadToPlayerDiff: %d",roadAngle,playerHeading,angleDiff,roadToPlayerDiff);
- SendClientMessage(playerid,-1,string);
- }
- if(navis[navi][leftLanes] == 1 && navis[navi][rightLanes] == 1)
- {
- if(roadToPlayerDiff > 0)//right of the nodes
- {
- if(angleDiff > -45 && angleDiff < 45)
- {
- TextDrawSetString(sideCheck[playerid],"Right way");
- }
- else
- {
- TextDrawSetString(sideCheck[playerid],"Wrong way");
- }
- }
- else//left of the nodes
- {
- if(angleDiff > 135 || angleDiff < -135)
- {
- TextDrawSetString(sideCheck[playerid],"Right way");
- }
- else
- {
- TextDrawSetString(sideCheck[playerid],"Wrong way");
- }
- }
- }
- else if(navis[navi][leftLanes] == 2)
- {
- if(angleDiff > 135 || angleDiff < -135)
- {
- TextDrawSetString(sideCheck[playerid],"Right way");
- }
- else
- {
- TextDrawSetString(sideCheck[playerid],"Wrong way");
- }
- }
- else if(navis[navi][rightLanes] == 2)
- {
- if(angleDiff > -45 && angleDiff < 45)
- {
- TextDrawSetString(sideCheck[playerid],"Right way");
- }
- else
- {
- TextDrawSetString(sideCheck[playerid],"Wrong way");
- }
- }
- TextDrawShowForPlayer(playerid,sideCheck[playerid]);
- return 1;
- }
- stock GetAngleDifference(&a,Float:a1,Float:a2)
- {
- //abs((i + 180 - j) mod 360 - 180);
- a = (floatround(a1) + 180 - floatround(a2)) % 360 - 180;
- }
- stock GetAngleFrom(&Float:a,Float:x1,Float:y1,Float:x2,Float:y2)
- {
- a = atan2(y2 - y1, x2 - x1) - 90;
- }
- new lastRoadCheck[MAX_PLAYERS];
- public OnPlayerUpdate(playerid)
- {
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
- {
- if(lastRoadCheck[playerid] < GetTickCount() - 500)
- {
- lastRoadCheck[playerid] = GetTickCount();
- cmd_check(playerid,"");
- }
- }
- if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
- {
- TextDrawHideForPlayer(playerid,sideCheck[playerid]);
- }
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- //by cessil
Advertisement
Add Comment
Please, Sign In to add comment