Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- new GPSTimer[MAX_PLAYERS];
- new bool:HaveGPS[MAX_PLAYERS];
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- stock GetDistanceBetweenPlayers(playerid,playerid2){
- new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
- new Float:dis;
- GetPlayerPos(playerid,x1,y1,z1);
- GetPlayerPos(playerid2,x2,y2,z2);
- dis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
- return floatround(dis);
- }
- forward GPSUpdate(playerid,playerid2);
- public GPSUpdate(playerid,playerid2){
- if(IsPlayerConnected(playerid2)){
- new Float:Distnace;
- Distnace = GetDistanceBetweenPlayers(playerid,playerid2);
- new Float:X,Float:Y,Float:Z;
- GetPlayerPos(playerid2,X,Y,Z);
- DisablePlayerCheckpoint(playerid);
- SetPlayerCheckpoint(playerid,X,Y,Z,0.1);
- new string[128];
- format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~p~Distancia: ~r~%.1f ~y~m",Distnace);
- GameTextForPlayer(playerid, string, 1100, 5);
- if(Distnace <= 4.0) {
- DisablePlayerCheckpoint(playerid);
- KillTimer(GPSTimer[playerid]);
- HaveGPS[playerid] = false;
- GPSTimer[playerid] = 0;
- }
- }else{
- DisablePlayerCheckpoint(playerid);
- KillTimer(GPSTimer[playerid]);
- HaveGPS[playerid] = false;
- GPSTimer[playerid] = 0;
- SendClientMessage(playerid, 0xFF0000AA, "GPS: N�o encontrado.");
- }
- return 1;
- }
- public OnFilterScriptInit()
- {
- print("\n* GPS by Jefff carregado...\n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- print("\n* GPS by Jefff desligado...\n");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- GPSTimer[playerid] = 0;
- HaveGPS[playerid] = false;
- SendClientMessage(playerid, 0xFFFFFFAA, "Este servidor usa um sistema de GPS feito por Jefff (/gps)");
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(HaveGPS[playerid]) {
- KillTimer(GPSTimer[playerid]);
- HaveGPS[playerid] = false;
- GPSTimer[playerid] = 0;
- }
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- if(HaveGPS[playerid]) {
- KillTimer(GPSTimer[playerid]);
- HaveGPS[playerid] = false;
- GPSTimer[playerid] = 0;
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[64],tmp[64],idx;
- cmd = strtok(cmdtext,idx);
- if(!strcmp(cmd, "/gps", true))
- {
- tmp = strtok(cmdtext,idx);
- if(!strlen(tmp)) return SendClientMessage(playerid, 0xFFFFFFAA, "Use: /gps [playerid / off]");
- if(!strcmp(tmp, "off", true)) {
- if(HaveGPS[playerid]) {
- KillTimer(GPSTimer[playerid]);
- HaveGPS[playerid] = false;
- GPSTimer[playerid] = 0;
- DisablePlayerCheckpoint(playerid);
- SendClientMessage(playerid, 0xFFFF00AA, "GPS: Desligado.");
- }else SendClientMessage(playerid, 0xFF0000AA, "GPS: Seu GPS est� desligado !");
- return 1;
- }
- if(IsPlayerConnected(strval(tmp))) {
- if(strval(tmp) != playerid) {
- if(HaveGPS[playerid]) {
- KillTimer(GPSTimer[playerid]);
- HaveGPS[playerid] = false;
- GPSTimer[playerid] = 0;
- }
- GPSTimer[playerid] = SetTimerEx("GPSUpdate", 500, true, "dd", playerid,strval(tmp));
- HaveGPS[playerid] = true;
- new str[128],nick[24];
- GetPlayerName(strval(tmp),nick,24);
- format(str,128,"GPS: Ligado, alvo: %s (ID: %d)",nick,strval(tmp));
- SendClientMessage(playerid, 0xFFFF00AA, str);
- }else SendClientMessage(playerid, 0xFF0000AA, "GPS: Use corretamente o seu GPS !");
- }else SendClientMessage(playerid, 0xFF0000AA, "GPS: Alvo n�o encontrado(ID errado) !");
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement