Jump to content

Masurarea Kilometrilor


Recommended Posts

La cererea lui GooGleTM am facut acest tutorial in care va voi explica cum sa masurati kilometrii.

Sa incepem.

Mai intai avem nevoie de cateva coordonate unde vom stoca distantele parcurse de vehicul.

[pawn]new Float:VehicleKM[MAX_VEHICLES],








Al doilea pas este sa creeam o functie care sa exprime distanta dintre doua puncte parcurse de vehicul(inceput - sfarsit)


forward km_counter(vehicleid);

public km_counter(vehicleid)


        //inlocuim valorile noi cu cele vechi

        x1[vehicleid] = x2[vehicleid];

        y1[vehicleid] = y2[vehicleid];

        z1[vehicleid] = z2[vehicleid];


        //stocam noile valori

        GetVehiclePos(v, x2[vehicleid], y2[vehicleid], z2[vehicleid]);


        //calculam distanta dintre cele doua punce vehciul punct si cel nou

        x1[vehicleid] -= x2[vehicleid];

        y1[vehicleid] -= y2[vehicleid];

        z1[vehicleid] -= z2[vehicleid];


        //acum il transformam in kilometrii(deoarece distanta este in metrii) impartind la 1000.0

        VehicleKM[vehicleid] += floatsqroot((x1*x1)+(y1*y1)+(z1*z1)) / 1000.0;



Acum pentru a activa aceasta functie avem nevoie de callback-ul OnPlayerStateChange

[pawn]public OnPlayerStateChange(playerid, newstate, oldstate)


    new string[50];

    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)


        timerkm[GetPlayerVehicleID(playerid)] = SetTimerEx("km_counter", 1000, 1, "d", GetPlayerVehicleID(playerid));//pornim acel timer care masoara kilometrii parcursi


    iif(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT )


        format(string, sizeof(string), "Vehiculul are in total %d kilometrii parcursi",VehicleKM[vehicleid]);//afisam cati kilometrii are parcursi

        SendClientMessage(playerid, -1, string);

        KillTimer(timerkm[GetPlayerVehicleID(playerid)]);//omoram acel timer care masoara kilometrii deoarece nu mai e nici un sofer in ea


    return 1;


Acesta este tutorialul sper ca ati inteles ceva. M-am inspirat de [url=http://pastebin.com/f50b4709b]aici




Link to comment
Share on other sites

  • 8 months later...
  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.