SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 02/01/2013, 08:02 PM   #1
EditPawn
Gangsta
 
EditPawn's Avatar
 
Join Date: May 2012
Posts: 966
Reputation: 67
Default eDistance System

• eDistance System •

Introduction

It is an include that lets you check the distance a vehicle has traveled in being Meters, Kilometers or Miles.


Natives

• GetMeters(vehicleid);.........................Checks the distance traveled in meters
• GetKilometers(vehicleid);...............Checks the distance traveled in kilometers
• GetMiles(vehicleid);..............................Checks the distance traveled in miles
• ResetMetersTraveled(vehicleid);.............Reset the footage covered the vehicle


Method of Use

• GetMeters(vehicleid) - returns the integer numbers, or:
pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) {
    static String[56]; //We define a string with 56 cells

    format(String, sizeof(String), "The vehicle %d traveled %d meters.", vehicleid, GetMeters(vehicleid));
    //We formatted string showing the ID of the vehicle and walked footage

    SendClientMessage(playerid, -1, String); //We show the player the message

    return true;
}
Example: The vehicle 542 traveled 1265 meters.

...

• GetKilometers(vehicleid) - returns the floating numbers, or:
pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) {
    static String[56]; //We define a string with 56 cells

    format(String, sizeof(String), "The vehicle %d traveled %0.3f kilometers.", vehicleid, GetKilometers(vehicleid));
    //We formatted string showing the ID and vehicle mileage

    SendClientMessage(playerid, -1, String); //We show the player the message

    return true;
}
Example: The vehicle 542 traveled 1.265 kilometers. (Equivalent to 1265m)

...

• GetKilometers(vehicleid) - returns the floating numbers, or:
pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) {
    static String[56]; //We define a string with 56 cells

    format(String, sizeof(String), "The vehicle %d traveled %0.3f miles.", vehicleid, GetMiles(vehicleid));
    //We formatted string showing the ID of the vehicle and the miles traveled

    SendClientMessage(playerid, -1, String); //We show the player the message

    return true;
}
Example: The vehicle 542 traveled 0.786 miles. (Equivalent to 1265m)


Bugs / Questions / Suggestions

Comment below


Download

pawn Code:
///////////////////////////////////////////////////////////////////////////////////
//
//                 |*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|
//                 |*|      eDistance System     |*|
//                 |*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|
//
//               =====================================
//                           INTRODUCTION
//               =====================================
//
//               This allows you to check include
//               as a vehicle traveled in meters,
//               Kilometers or Miles.
//
//               =====================================
//                             NATIVES
//               =====================================
//
//               native GetMeters(vehicleid);
//               native GetKilometers(vehicleid);
//               native GetMiles(vehicleid);
//                       native ResetMetersTraveled(vehicleid);
//
//               =====================================
//                      EXAMPLES (METHOD OF USE)
//               =====================================
//
//                    *-- | METERS TRAVELED | --*
//               format(string, sizeof(string), "This vehicle traveled %d Meters Traveled.", GetMeters(GetPlayerVehicleID(playerid)));
//               SendClientMessage(playerid, -1, string);
//
//                    *-- | KILOMETERS TRAVELED | --*
//               format(string, sizeof(string), "This vehicle traveled %s Kilometers Traveled.", GetKilometers(GetPlayerVehicleID(playerid)));
//               SendClientMessage(playerid, -1, string);
//
//                    *-- | MILES TRAVELED | --*
//               format(string, sizeof(string), "This vehicle traveled %s Miles Traveled.", GetMiles(GetPlayerVehicleID(playerid)));
//               SendClientMessage(playerid, -1, string);
//
//               =====================================
//                              CREDITS
//               =====================================
//
//                  * Include Built by EditPawn *
//       * BlueX Paulor and for helping me with some functions *
//        * Lordz tutorial by calling Functions and Callbacks *
//
//               =====================================
//                  BUGS, SUGGESTIONS AND QUESTIONS
//               =====================================
//
//                   Visit: [url]http://forum.sa-mp.com[/url]
//
//
///////////////////////////////////////////////////////////////////////////////////

/* ----- INCLUDE ----- */
#include    a_samp

/* ----- VARS ----- */
new E@_R[MAX_VEHICLES] = 0,
    Float:v@_P[3],
    E@_Timer[MAX_PLAYERS],
    E@_S[12];

/* ----- DEFINES ----- */
#define   GetMeters(%0)              E@_R[%0]
#define   GetKilometers(%0)         (E@_R[%0] * 0.001)
#define   GetMiles(%0)              (E@_R[%0] * 0.000621)
#define   ResetMetersTraveled(%0)    E@_R[%0] = 0;

/* ----- FORWARDS ----- */
forward E@_OnPlayerDisconnect(playerid, reason);
forward E@_OnPlayerStateChange(playerid, newstate, oldstate);
forward E@_At(playerid);

/* ----- CALLBACKS ----- */
public OnPlayerDisconnect(playerid, reason) {
    KillTimer(E@_Timer[playerid]);
    return CallLocalFunction("E@_OnPlayerDisconnect", "id", playerid, reason);
}

public OnPlayerExitVehicle(playerid, vehicleid) {
    KillTimer(E@_Timer[playerid]);
    return CallLocalFunction("E@_OnPlayerExitVehicle", "id", playerid, vehicleid);
}

public E@_At(playerid) {
    if(GetVehicleDistanceFromPoint(GetPlayerVehicleID(playerid), v@_P[0], v@_P[1], v@_P[2]) <= 100) {
        E@_R[GetPlayerVehicleID(playerid)] += floatround(GetVehicleDistanceFromPoint(GetPlayerVehicleID(playerid), v@_P[0], v@_P[1], v@_P[2]));
    }
    GetVehiclePos(GetPlayerVehicleID(playerid), v@_P[0], v@_P[1], v@_P[2]);
/*
    OBS: If you want to test, just abilite this part will appear and all forms of distance that the vehicle is running.

    new E@_Str[129];
    format(E@_Str, sizeof(E@_Str), "(%d) Meters - (%s) Kilometers - (%s) Miles", GetMeters(GetPlayerVehicleID(playerid)), GetKilometers(GetPlayerVehicleID(playerid)), GetMiles(GetPlayerVehicleID(playerid)));
    SendClientMessage(playerid, -1, E@_Str);
*/

}

public OnPlayerStateChange(playerid, newstate, oldstate) {
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER) {
        GetVehiclePos(GetPlayerVehicleID(playerid), v@_P[0], v@_P[1], v@_P[2]);
        E@_Timer[playerid] = SetTimerEx("E@_At", 1000, true, "i", playerid);
    }
    else if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT) KillTimer(E@_Timer[playerid]);
    return CallLocalFunction("E@_OnPlayerStateChange", "idd", playerid, newstate, oldstate);
}

/* ----- HOOKS ----- */
#if defined _ALS_OnPlayerDisconnect
    #undef OnPlayerDisconnect
#else
    #define _ALS_OnPlayerDisconnect
#endif
#define OnPlayerDisconnect E@_OnPlayerDisconnect

#if defined _ALS_OnPlayerStateChange
    #undef OnPlayerStateChange
#else
    #define _ALS_OnPlayerStateChange
#endif
#define OnPlayerStateChange E@_OnPlayerStateChange

#if defined _ALS_OnPlayerExitVehicle
    #undef OnPlayerExitVehicle
#endif
#define OnPlayerExitVehicle E@_OnPlayerExitVehicle
Pastebin


Comments

¹It took me a few minutes to create and 1 day to test and improve the optimization of some codes.
²This is my first include that do, may contain errors or inattention to, if it contains something you do not agree please comment below.
³I'm not good at English because I'm Brazilian so I translate to a better understanding to post my project to you.
IMPORTANT: Save as e_km.inc


Credits

Include created by EditPawn
Paulor e BlueX for helping me in some functions
Lordz tutorial by connecting Functions and Callbacks http://forum.sa-mp.com/showthread.php?t=392061
Source of Calculations: http://www.convertworld.com/pt/comprimento/


Hope you enjoy
__________________
Usando zCmd/sscanf/SQLite
Voltando com pawn e novo Projeto a caminho.

Projetos:
[Tutorial] DOF2 - Registro/Login
[GameMode] Brasil Zombie Games LS - BASE
[FilterScript] E_Anims v2.0
[Include] eDistance System

Code:
Se não houver crítica não haverá evolução!

Last edited by EditPawn; 03/01/2013 at 08:19 PM.
EditPawn is offline   Reply With Quote
Old 03/01/2013, 04:17 AM   #2
Kar
High-roller
 
Kar's Avatar
 
Join Date: May 2010
Location: Black Asylum
Posts: 3,184
Reputation: 506
Default Re: eDistance System

no feet?
Kar is offline   Reply With Quote
Old 03/01/2013, 04:31 AM   #3
TugaBR
Huge Clucker
 
TugaBR's Avatar
 
Join Date: Dec 2012
Location: SA-MP Ghetto
Posts: 239
Reputation: 38
Default Re: eDistance System

Quote:
Originally Posted by Kar View Post
no feet?
Quote:
This allows you to check include
// as a VEHICLE traveled in meters,
// Kilometers or Miles.
Understand?
__________________
TugaBR is offline   Reply With Quote
Old 03/01/2013, 04:35 AM   #4
Mr.Anonymous
Gangsta
 
Mr.Anonymous's Avatar
 
Join Date: Jul 2011
Location: Every ban list
Posts: 887
Reputation: 178
Default Re: eDistance System

Feet - Wikipedia, the free encyclopedia
Mr.Anonymous is offline   Reply With Quote
Old 03/01/2013, 08:20 PM   #5
EditPawn
Gangsta
 
EditPawn's Avatar
 
Join Date: May 2012
Posts: 966
Reputation: 67
Default Re: eDistance System

No friend, just decided to do in Meters, Kilometers and Miles. Ai depends on the person using the most appropriate way and any way they want.


Topic updated and some bugs fixed.


I noticed that the staff is not very welcoming there, just wanted to show my work to you. But thanks anyway.
__________________
Usando zCmd/sscanf/SQLite
Voltando com pawn e novo Projeto a caminho.

Projetos:
[Tutorial] DOF2 - Registro/Login
[GameMode] Brasil Zombie Games LS - BASE
[FilterScript] E_Anims v2.0
[Include] eDistance System

Code:
Se não houver crítica não haverá evolução!

Last edited by EditPawn; 03/01/2013 at 08:53 PM.
EditPawn is offline   Reply With Quote
Old 04/01/2013, 02:59 AM   #6
Kar
High-roller
 
Kar's Avatar
 
Join Date: May 2010
Location: Black Asylum
Posts: 3,184
Reputation: 506
Default Re: eDistance System

Quote:
Originally Posted by TugaBR View Post
Understand?
In simple terms, I asked why he did not add Feet too, to expand the usage of his include.

UNDERSTAND?
Kar is offline   Reply With Quote
Old 04/01/2013, 11:16 AM   #7
EditPawn
Gangsta
 
EditPawn's Avatar
 
Join Date: May 2012
Posts: 966
Reputation: 67
Default Re: eDistance System

Quote:
Originally Posted by Kar View Post
In simple terms, I asked why he did not add Feet too, to expand the usage of his include.

UNDERSTAND?
But it is very easy my dear.
Only just add these sets:

pawn Code:
#define    GetFeet(%0)    (E@_R[%0] * 3.280)

Example of use:

pawn Code:
static Str[129];
format(Str, sizeof(Str), "Your vehicle traveled %0.3f feet.", GetFeet(vehicleid));

I believe that to be the value from meters to feet.

Thanks for commenting
__________________
Usando zCmd/sscanf/SQLite
Voltando com pawn e novo Projeto a caminho.

Projetos:
[Tutorial] DOF2 - Registro/Login
[GameMode] Brasil Zombie Games LS - BASE
[FilterScript] E_Anims v2.0
[Include] eDistance System

Code:
Se não houver crítica não haverá evolução!
EditPawn is offline   Reply With Quote
Old 04/01/2013, 02:43 PM   #8
emit
Big Clucker
 
Join Date: Dec 2012
Posts: 48
Reputation: 5
Default Re: eDistance System

thanks, good.
__________________
gm
emit is offline   Reply With Quote
Old 17/08/2014, 10:41 AM   #9
AzaMx
Huge Clucker
 
Join Date: Aug 2014
Location: Home.
Posts: 353
Reputation: 63
Default Re: eDistance System

It's doesn't show clientmessage for it. Please anyone help! create me some this
AzaMx is offline   Reply With Quote
Old 17/08/2014, 10:51 PM   #10
Swedky
Banned
 
Join Date: Jun 2013
Location: Argentina.
Posts: 2,076
Reputation: 827
Default Respuesta: eDistance System

You know how use static and new?
Swedky is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] NRank System V1.0 | Advanced Rank System | 5+ Commands | Dialog System [Much More] Nirzor Filterscripts 9 18/04/2014 09:49 PM
[Include] eDistance System EditPawn Lançamentos/Releases 28 04/01/2013 01:46 PM
[FilterScript] Cross Admin System V1.2 [updated] + Added IRC System + Anti Cheat(sscanf, dcmd,y_ini) No.1 Admin System CROSS_Hunter Filterscripts 21 02/01/2013 06:32 PM


All times are GMT. The time now is 04:43 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.