Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- GPS - GPSigation System
- by BOSS
- ~ Features ~
- * You can easily add your locations by typing {"Location Name", X, Y, Z} in the location list below.
- * You can open and use the GPSigation by typing /GPS if not working do /nav in the game.
- * 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.
- * You can also see how much distance to the destination with textdraw, which is shown on the screen.
- * GPSigation closes when you get out of the car, when you type /GPSclose or when you reach the destination.
- */
- #include <a_samp>
- #include <zcmd>
- new
- ok[MAX_PLAYERS],
- pGPSState[MAX_PLAYERS],
- pGPSID[MAX_PLAYERS],
- pGPSTimer[MAX_PLAYERS],
- PlayerText:GPSpTD[MAX_PLAYERS],
- Text:GPSTD[2]
- ;
- enum GPS_DATA {
- GPS_NAME[32],
- Float:GPS_X,
- Float:GPS_Y,
- Float:GPS_Z
- };
- new const GPSData[][GPS_DATA] = { // Location list in GPSigation:
- {"Construction Worker Job", 1266.3311,-1260.1604,13.2039}, // {"Location Name", X, Y, Z}
- {"Ammunation", 1365.3500,-1279.0601,13.5469}, // You can add your locations like this.
- {"Courier job", 2011.3181,-2219.6333,13.5469}, // Make sure that no comma at the end of the last one.
- {"Pay And Spray", 2073.4626,-1826.2062,13.5469} //For making more just copy this line and replace x,y,z
- };
- public OnFilterScriptInit()
- {
- print("\n+----------------------------------------------------+");
- print("| |");
- print("| Gps - GPS System ~ Loaded! |");
- print("| by BOSS |");
- print("| |");
- print("+----------------------------------------------------+\n");
- GPSTD[0] = TextDrawCreate(404.319183, 409.916809, "box");
- TextDrawLetterSize(GPSTD[0], 0.000000, 1.941436);
- TextDrawTextSize(GPSTD[0], 498.000000, 0.000000);
- TextDrawAlignment(GPSTD[0], 1);
- TextDrawColor(GPSTD[0], -1);
- TextDrawUseBox(GPSTD[0], 1);
- TextDrawBoxColor(GPSTD[0], 100);
- TextDrawSetShadow(GPSTD[0], 0);
- TextDrawSetOutline(GPSTD[0], 0);
- TextDrawBackgroundColor(GPSTD[0], 255);
- TextDrawFont(GPSTD[0], 1);
- TextDrawSetProportional(GPSTD[0], 1);
- TextDrawSetShadow(GPSTD[0], 0);
- GPSTD[1] = TextDrawCreate(404.787597, 399.999847, "GPSigation Info");
- TextDrawLetterSize(GPSTD[1], 0.299736, 1.115833);
- TextDrawAlignment(GPSTD[1], 1);
- TextDrawColor(GPSTD[1], -5963521);
- TextDrawSetShadow(GPSTD[1], 1);
- TextDrawSetOutline(GPSTD[1], 0);
- TextDrawBackgroundColor(GPSTD[1], 255);
- TextDrawFont(GPSTD[1], 0);
- TextDrawSetProportional(GPSTD[1], 1);
- TextDrawSetShadow(GPSTD[1], 1);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- GPSpTD[playerid] = CreatePlayerTextDraw(playerid, 405.724487, 415.166564, "Distance Left: ~y~0000.00m");
- PlayerTextDrawLetterSize(playerid, GPSpTD[playerid], 0.179326, 1.109999);
- PlayerTextDrawAlignment(playerid, GPSpTD[playerid], 1);
- PlayerTextDrawColor(playerid, GPSpTD[playerid], -1);
- PlayerTextDrawSetShadow(playerid, GPSpTD[playerid], 0);
- PlayerTextDrawSetOutline(playerid, GPSpTD[playerid], 0);
- PlayerTextDrawBackgroundColor(playerid, GPSpTD[playerid], 255);
- PlayerTextDrawFont(playerid, GPSpTD[playerid], 2);
- PlayerTextDrawSetProportional(playerid, GPSpTD[playerid], 1);
- PlayerTextDrawSetShadow(playerid, GPSpTD[playerid], 0);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(pGPSState[playerid])
- {
- KillTimer(pGPSTimer[playerid]);
- DestroyObject(ok[playerid]);
- DisablePlayerCheckpoint(playerid);
- pGPSState[playerid] = 0;
- }
- return 1;
- }
- CMD:GPS(playerid, params[])
- {
- if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{FF0000}<!> You must be in a vehicle to use GPSigation!");
- static string[sizeof(GPSData) * 64];
- if (string[0] == EOS)
- {
- for (new i; i < sizeof(GPSData); i++)
- {
- format(string, sizeof string, "%s{f4a442}ยป {f7f5bb}%s\n", string, GPSData[i][GPS_NAME]);
- }
- }
- ShowPlayerDialog(playerid, 112, DIALOG_STYLE_LIST, "[GPSigation] Locations", string, "Select", "Close");
- return 1;
- }
- CMD:GPSclose(playerid, params[])
- {
- if(pGPSState[playerid])
- {
- KillTimer(pGPSTimer[playerid]);
- DestroyObject(ok[playerid]);
- for(new i; i<sizeof(GPSTD); i++) TextDrawHideForPlayer(playerid, GPSTD[i]);
- PlayerTextDrawHide(playerid, GPSpTD[playerid]);
- PlayerPlaySound(playerid,1137,0.0,0.0,0.0);
- DisablePlayerCheckpoint(playerid);
- pGPSState[playerid] = 0;
- SendClientMessage(playerid, -1, "{FF0000}<!> GPSigation cancelled!");
- } else SendClientMessage(playerid, -1, "{FF0000}<!> GPSigation is already off!");
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(pGPSState[playerid])
- {
- KillTimer(pGPSTimer[playerid]);
- DestroyObject(ok[playerid]);
- for(new i; i<sizeof(GPSTD); i++) TextDrawHideForPlayer(playerid, GPSTD[i]);
- PlayerTextDrawHide(playerid, GPSpTD[playerid]);
- PlayerPlaySound(playerid,1150,0.0,0.0,0.0);
- DisablePlayerCheckpoint(playerid);
- pGPSState[playerid] = 0;
- SendClientMessage(playerid, -1, "{FF0000}<!> GPSigation is cancelled because you are off the vehicle!");
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == 112)
- {
- if(response)
- {
- if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{FF0000}<!> You must be in a vehicle to use GPSigation!");
- pGPSID[playerid] = listitem;
- new str[128];
- SetPlayerCheckpoint(playerid, GPSData[pGPSID[playerid]][GPS_X], GPSData[pGPSID[playerid]][GPS_Y], GPSData[pGPSID[playerid]][GPS_Z], 3.0);
- format(str, 128, "{00FF00}<!> Destination is set to {FFA500}%s", GPSData[pGPSID[playerid]][GPS_NAME]);
- SendClientMessage(playerid, -1, str);
- SendClientMessage(playerid, -1, "{00FF00}<!> You can type {FF7D0A}/GPSclose {00FF00}to cancel the GPSigation.");
- if(IsValidObject(ok[playerid])) DestroyObject(ok[playerid]);
- ok[playerid] = CreateObject(19134, 0, 0, 0, 0, 0, 0);
- Refresh(playerid);
- KillTimer(pGPSTimer[playerid]);
- pGPSTimer[playerid] = SetTimerEx("Refresh", 100, true, "d", playerid);
- for(new i; i<sizeof(GPSTD); i++) TextDrawShowForPlayer(playerid, GPSTD[i]);
- PlayerTextDrawShow(playerid, GPSpTD[playerid]);
- PlayerPlaySound(playerid,1139,0.0,0.0,0.0);
- pGPSState[playerid] = 1;
- }
- }
- return 1;
- }
- stock Float:PointAngle(playerid, Float:xa, Float:ya, Float:xb, Float:yb) // Don't know the owner.
- {
- new Float:carangle;
- new Float:xc, Float:yc;
- new Float:angle;
- xc = floatabs(floatsub(xa,xb));
- yc = floatabs(floatsub(ya,yb));
- if (yc == 0.0 || xc == 0.0)
- {
- if(yc == 0 && xc > 0) angle = 0.0;
- else if(yc == 0 && xc < 0) angle = 180.0;
- else if(yc > 0 && xc == 0) angle = 90.0;
- else if(yc < 0 && xc == 0) angle = 270.0;
- else if(yc == 0 && xc == 0) angle = 0.0;
- }
- else
- {
- angle = atan(xc/yc);
- if(xb > xa && yb <= ya) angle += 90.0;
- else if(xb <= xa && yb < ya) angle = floatsub(90.0, angle);
- else if(xb < xa && yb >= ya) angle -= 90.0;
- else if(xb >= xa && yb > ya) angle = floatsub(270.0, angle);
- }
- GetVehicleZAngle(GetPlayerVehicleID(playerid), carangle);
- return floatadd(angle, -carangle);
- }
- forward Refresh(playerid);
- public Refresh(playerid)
- {
- new Float:pos[3], Float:pPos[3];
- pPos[0] = GPSData[pGPSID[playerid]][GPS_X];
- pPos[1] = GPSData[pGPSID[playerid]][GPS_Y];
- pPos[2] = GPSData[pGPSID[playerid]][GPS_Z];
- GetVehiclePos(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[2]);
- new Float:rot = PointAngle(playerid, pos[0], pos[1], pPos[0], pPos[1]);
- AttachObjectToVehicle(ok[playerid], GetPlayerVehicleID(playerid), 0.000000, 0.000000, 1.399998, 0.000000, 90.0, rot + 180);
- new Float:mesafe, str[32];
- mesafe = GetPlayerDistanceFromPoint(playerid, pPos[0], pPos[1], pPos[2]);
- format(str, sizeof(str), "Distance Left: ~y~%0.2fm", mesafe);
- PlayerTextDrawSetString(playerid, GPSpTD[playerid], str);
- if(IsPlayerInRangeOfPoint(playerid, 10.0, pPos[0], pPos[1], pPos[2]))
- {
- KillTimer(pGPSTimer[playerid]);
- DestroyObject(ok[playerid]);
- for(new i; i<sizeof(GPSTD); i++) TextDrawHideForPlayer(playerid, GPSTD[i]);
- PlayerTextDrawHide(playerid, GPSpTD[playerid]);
- DisablePlayerCheckpoint(playerid);
- PlayerPlaySound(playerid,1137,0.0,0.0,0.0);
- pGPSState[playerid] = 0;
- SendClientMessage(playerid, -1, "{00FF00}<!> You have reached your destination!");
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement