Advertisement
JeffryUGP

[FS] Advanced Taxi System by Jeffry

Jul 24th, 2013
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.71 KB | None | 0 0
  1. /*======================================================================================================*
  2. * This Taxi System is made by Jeffry!                                                                   *
  3. *                                                                                                       *
  4. *                                                                                                       *
  5. * Made in April 2010.                                                                                   *
  6. *                                                                                                       *
  7. * Your Rights:                                                                                          *
  8. *                                                                                                       *
  9. * -You are allowed to modify this Filterscript, aslong as you DO NOT remove credits or re-upload it.    *
  10. *                                                                                                       *
  11. * -You are NOT allowed to re-upload this Filterscript.                                                  *
  12. * -You are NOT allowed to claim this as your own.                                                       *
  13. * -You are NOT allowed to remove any credits.                                                           *
  14. *                                                                                                       *
  15. * Thank you.                                                                                            *
  16. * Have fun. I would be happy if you give me /credits.  :D                                               *
  17. *                                                                                                       *
  18. *=======================================================================================================*/
  19.  
  20. #include <a_samp>
  21. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  22.  
  23. //========================================================================================================================
  24. //-------------------------Definitions that you may change----------------------------------------------------------------
  25. //------------------------------------------------------------------------------------------------------------------------
  26. #define MAX_TAXI_LOCATIONS 200     // Change this if you have more.
  27. #define MAX_TAXI_NAME 100         // This is the Maximum lenght of the taxi name. Changing is not advised.
  28. #define PRICE_PER_KM 10.60655    // I decided to make it to 10.60655$ as it will cost 90 000$ from one end to the other.
  29. #define MINIMUM_PRICE 10000     // I made it to 10 000$ so it fills the Max price over map (-3000 => 3000) to 100 000$
  30. #define PRINT_ON               // Add the "//" infront of it, to disable the printed message when a Taxi is created.
  31. //------------------------------------------------------------------------------------------------------------------------
  32. //-------------------------End of the Definitions-------------------------------------------------------------------------
  33. //========================================================================================================================
  34.  
  35. new TaxiID;
  36. new Float:Taxi_X[MAX_TAXI_LOCATIONS];
  37. new Float:Taxi_Y[MAX_TAXI_LOCATIONS];
  38. new Float:Taxi_Z[MAX_TAXI_LOCATIONS];
  39. new Float:Taxi_Ang[MAX_TAXI_LOCATIONS];
  40. new Taxi_Int[MAX_TAXI_LOCATIONS];
  41. new Taxi_Name[MAX_TAXI_LOCATIONS][MAX_TAXI_NAME];
  42. new Taxi_Exists[MAX_TAXI_LOCATIONS];
  43. new Float:PricePerKM;
  44. new MiniPrice;
  45.  
  46. public OnFilterScriptInit()
  47. {
  48.     print("\n--------------------------------------");
  49.     print(" [FS] Advanced Taxi System by Jeffry");
  50.     print("--------------------------------------\n");
  51.     PricePerKM=PRICE_PER_KM;
  52.     MiniPrice=MINIMUM_PRICE;
  53.    
  54.     // Put your Taxi-Locations here. You find them in: .../scriptfiles/Saved_Taxi_Locs.txt
  55.     // I have also added some locations, if you want to use them, you find them in:  Some_Locations.txt
  56.     // Now....have fun with the Taxi! :D
  57.     AddTaxi("The Ship", 2000.6123, 1524.4371, 18.1923, 0.0000, 0);
  58.    
  59.     return 1;
  60. }
  61.  
  62. public OnFilterScriptExit()
  63. {
  64.     print("\n--------------------------------------");
  65.     print(" The Taxi System has been unloaded.");
  66.     print("--------------------------------------\n");
  67.     return 1;
  68. }
  69.  
  70. //===========The Commands============================================================================================================================================
  71. dcmd_taxi(playerid,params[])
  72. {
  73.     new taxi, string[128];
  74.     taxi=strval(params[0]);
  75.     if(!strlen(params)) return SendClientMessage(playerid, 0xFF0000AA, "USAGE: /taxi [Number]");
  76.     if(taxi>TaxiID-1 || taxi<0) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: This location does not exist!");
  77.     if(!IsNumeric(params[0])) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: This location does not exist!");
  78.     new Float:px,Float:py,Float:pz;
  79.     GetPlayerPos(playerid,px,py,pz);
  80.     new Float:price=floatsqroot( ( (Taxi_X[taxi]-px)*(Taxi_X[taxi]-px) ) + ( (Taxi_Y[taxi]-py)*(Taxi_Y[taxi]-py) ) + ( (Taxi_Z[taxi]-pz)*(Taxi_Z[taxi]-pz) ) );
  81.     new price2=(floatround(price*PricePerKM, floatround_round))+MiniPrice;
  82.     if(price2>GetPlayerMoney(playerid))
  83.     {
  84.         format(string,sizeof(string),"ERROR: You don't have enough money.  Price: %d $ | Have: %d $ | %d $ more needed.", price2,GetPlayerMoney(playerid), price2-GetPlayerMoney(playerid));
  85.         return SendClientMessage(playerid, 0xFF0000AA, string);
  86.     }
  87.     SetPlayerPos(playerid, Taxi_X[taxi], Taxi_Y[taxi], Taxi_Z[taxi]);
  88.     SetPlayerFacingAngle(playerid, Taxi_Ang[taxi]);
  89.     SetPlayerInterior(playerid, Taxi_Int[taxi]);
  90.     SetCameraBehindPlayer(playerid);
  91.     GivePlayerMoney(playerid, -price2);
  92.    
  93.     format(string,sizeof(string),"Thank you for the %d $. Enjoy your stay at ''%s''", price2,Taxi_Name[taxi]);
  94.     SendClientMessage(playerid, 0xFFFF6EFF, string);
  95.     return 1;
  96. }
  97.  
  98. dcmd_tsave(playerid,params[])
  99. {
  100.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You need to be a RCON-Admin to save Taxi-Locations.");
  101.     if(!strlen(params)) return SendClientMessage(playerid, 0xFF0000AA, "USAGE: /tsave [Locationname]");
  102.     new string[128], name[MAX_TAXI_NAME], Index;
  103.     name=strtok(params, Index);
  104.     new Float:px,Float:py,Float:pz, Float:A, Int, File:SaveLog;
  105.     GetPlayerPos(playerid,px,py,pz);
  106.     GetPlayerFacingAngle(playerid, A);
  107.     Int=GetPlayerInterior(playerid);
  108.     format(string,sizeof(string),"Taxi %d added:  Name: %s | X: %0.4f | Y: %0.4f | Z: %0.4f | Angle: %0.4f | Interior: %d", TaxiID, params[0], px, py, pz, A, Int);
  109.     SendClientMessage(playerid, 0xFF9900AA, string);
  110.     format(string,sizeof(string),"Taxi %d saved to ''Saved_Taxi_Locs.txt''. Add it to Taxi.pwn !", TaxiID);
  111.     SendClientMessage(playerid, 0xFFFFFFFF, string);
  112.     format(string, sizeof(string), "AddTaxi(\"%s\", %0.4f, %0.4f, %0.4f, %0.4f, %d);\r\n", params[0], px, py, pz, A, Int);
  113.     SaveLog=fopen("Saved_Taxi_Locs.txt", io_append);
  114.     fwrite(SaveLog, string);
  115.     fclose(SaveLog);
  116.     AddTaxi(name, px, py, pz, A, Int);
  117.     return 1;
  118. }
  119.  
  120. dcmd_locations(playerid,params[])
  121. {
  122.     if(!strlen(params)) return SendClientMessage(playerid, 0xFF0000AA, "USAGE: /locations [Page]");
  123.     new taxi = strval(params[0]); new string[128], name[MAX_TAXI_NAME];
  124.     if(taxi<0) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: Invalid Page.");
  125.     if(taxi>(MAX_TAXI_LOCATIONS/8) || Taxi_Exists[taxi*8]!=1) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: Invalid Page.");
  126.     if(!IsNumeric(params[0])) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: Invalid Page.");
  127.     format(string, sizeof(string), "Welcome to the Taxi-Locations [Page: %d]", taxi);
  128.     SendClientMessage(playerid, 0xFF0000AA, string);
  129.     for(new i=(taxi*8); i<(taxi*8)+8; i++)
  130.     {
  131.         if(i>MAX_TAXI_LOCATIONS || Taxi_Exists[i]!=1)
  132.         {
  133.             format(string, sizeof(string), "Type /locations %d to see the previous page.",taxi-1);
  134.             SendClientMessage(playerid, 0xFF9900AA, string);
  135.             return 1;
  136.         }
  137.         name=Taxi_Name[i];
  138.         new Float:px,Float:py,Float:pz;
  139.         GetPlayerPos(playerid,px,py,pz);
  140.         new Float:price=floatsqroot( ( (Taxi_X[i]-px)*(Taxi_X[i]-px) ) + ( (Taxi_Y[i]-py)*(Taxi_Y[i]-py) ) + ( (Taxi_Z[i]-pz)*(Taxi_Z[i]-pz) ) );
  141.         new price2=(floatround(price*PricePerKM, floatround_round))+MiniPrice;
  142.         format(string, sizeof(string), "[%d] %s   (Price: %d $)", i, name, price2);
  143.         SendClientMessage(playerid, 0xFFFFFFFF, string);
  144.         if(i<=7 && Taxi_Exists[i+1]!=1)
  145.         {
  146.             return 1;
  147.         }
  148.         if(i==(taxi*8)+7 && Taxi_Exists[i+1]!=1)
  149.         {
  150.             format(string, sizeof(string), "Type /locations %d to see the previous page.",taxi-1);
  151.             SendClientMessage(playerid, 0xFF9900AA, string);
  152.             return 1;
  153.         }
  154.         if(i==7)
  155.         {
  156.             format(string, sizeof(string), "Type /locations %d to see the next page.",taxi+1);
  157.             SendClientMessage(playerid, 0xFF9900AA, string);
  158.             return 1;
  159.         }
  160.     }
  161.     format(string, sizeof(string), "Type /locations %d to see the next page. Type /locations %d to see the previous page.", taxi+1,taxi-1);
  162.     SendClientMessage(playerid, 0xFF9900AA, string);
  163.     return 1;
  164. }
  165.  
  166. dcmd_setkmprice(playerid,params[])
  167. {
  168.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: Only RCON-Admins can change the kilometer price.");
  169.     if(!strlen(params)) return SendClientMessage(playerid, 0xFF0000AA, "USAGE: /setkmprice [Price]");
  170.     if(params[0]>10000000 || params[0]<0) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: Invalid Price!");
  171.     PricePerKM=strval(params[0]);
  172.     new string[128], name[MAX_PLAYER_NAME];
  173.     GetPlayerName(playerid, name, sizeof(name));
  174.     format(string,sizeof(string),"[TAXI] Administrator %s (ID:%d) has set the Kilometer Price to %0.0f $ .", name, playerid, PricePerKM);
  175.     SendClientMessage(playerid, 0xFF9900AA, string);
  176.     return 1;
  177. }
  178.  
  179. dcmd_setminimum(playerid,params[])
  180. {
  181.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: Only RCON-Admins can change the minimum price.");
  182.     if(!strlen(params)) return SendClientMessage(playerid, 0xFF0000AA, "USAGE: /setminimum [Price]");
  183.     if(params[0]>10000000 || params[0]<0) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: Invalid Price!");
  184.     MiniPrice=strval(params[0]);
  185.     new string[128], name[MAX_PLAYER_NAME];
  186.     GetPlayerName(playerid, name, sizeof(name));
  187.     format(string,sizeof(string),"[TAXI] Administrator %s (ID:%d) has set the Minimum Price to %d $ .", name, playerid, MiniPrice);
  188.     SendClientMessage(playerid, 0xFF9900AA, string);
  189.     return 1;
  190. }
  191. //==================================================================================================================================================================
  192.  
  193. public OnPlayerCommandText(playerid, cmdtext[])
  194. {
  195.     dcmd(taxi,4,cmdtext);
  196.     dcmd(tsave,5,cmdtext);
  197.     dcmd(locations,9,cmdtext);
  198.     dcmd(setkmprice,10,cmdtext);
  199.     dcmd(setminimum,10,cmdtext);
  200.     return 0;
  201. }
  202.  
  203. /*
  204.  * First version released by mike, this one created by DracoBlue
  205.  * Has also a fix to use "-" and "+" in the beginning of the number.
  206.  */
  207. stock IsNumeric(const string[]) {
  208.     new length=strlen(string);
  209.     if (length==0) return false;
  210.     for (new i = 0; i < length; i++) {
  211.         if (
  212.         (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
  213.         || (string[i]=='-' && i!=0)                                             // A '-' but not at first.
  214.         || (string[i]=='+' && i!=0)                                             // A '+' but not at first.
  215.         ) return false;
  216.     }
  217.     if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
  218.     return true;
  219. }
  220. /*
  221.  * Originally created by mabako, tuned by DracoBlue
  222.  */
  223.  
  224. AddTaxi(Name[MAX_TAXI_NAME], Float:TaxiX, Float:TaxiY, Float:TaxiZ, Float:TaxiAng, TaxiInt)
  225. {
  226.     Taxi_Name[TaxiID]=Name;
  227.     Taxi_X[TaxiID]=TaxiX;
  228.     Taxi_Y[TaxiID]=TaxiY;
  229.     Taxi_Z[TaxiID]=TaxiZ;
  230.     Taxi_Ang[TaxiID]=TaxiAng;
  231.     Taxi_Int[TaxiID]=TaxiInt;
  232.     Taxi_Exists[TaxiID]=1;
  233.     #if defined PRINT_ON
  234.     print("------------------------------Taxi--------------------------------------");
  235.     printf("Taxi %d (%s) sucessfully created!", TaxiID, Name);
  236.     printf("X: %0.4f | Y: %0.4f | Z: %0.4f | Angle: %0.4f | Interior: %d", TaxiX, TaxiY, TaxiZ, TaxiAng, TaxiInt);
  237.     print("------------------------------------------------------------------------");
  238.     print(" ");
  239.     #endif
  240.     TaxiID++;
  241. }
  242.  
  243. strtok(const string[], &index)
  244. {
  245.     new length = strlen(string);
  246.     while ((index < length) && (string[index] <= ' '))
  247.     {
  248.         index++;
  249.     }
  250.  
  251.     new offset = index;
  252.     new result[20];
  253.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  254.     {
  255.         result[index - offset] = string[index];
  256.         index++;
  257.     }
  258.     result[index - offset] = EOS;
  259.     return result;
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement