Advertisement
Jstylezzz

[SQLite][y_ini][Dini][MySQL Un-Threaded]jGarage - V1.1

May 12th, 2014
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 35.30 KB | None | 0 0
  1. /*
  2. *                                                           jGarage V1.1
  3. *                                                       by Jstylezzz
  4. *
  5. *
  6. *
  7. *   To create garages, log in as Rcon and use the command '/creategarage'. To remove a garage use '/removegarage' when standing on it's pickup.
  8. *       Use '/garagehelp' to view the available commands. If the server crashes when creating a garage, you probably forgot the 'garages' folder
  9. *   in the scriptfiles folder. Create it.
  10. *   If you have any questions suggestions or if you find bugs, please post in the release thread. Also, keep the credits, that's all I ask. Thanks!
  11. *
  12. *
  13. *       What's new in version 1.1?
  14. *
  15. *           * Merged all saving systems into one script, now it's easy for me to update system code without having to do it 4 times
  16. *           * Added SQLite support
  17. *           * Added y_Ini support
  18. *           * Fixed some minor bugs
  19. *           * Added autosave timer (toggle on/off in the systematic config below)
  20. *           * Added ownable garage limit (configurable in the systematic config below)
  21. *           * Made the config section a little more clear
  22. *           * Added some comments here and there
  23. *           * Added 'strcmp command' and 'zcmd' mode (configurable in the systematic config)
  24. */
  25.  
  26. //=== INCLUDES ===//
  27. #include <a_samp> //Credits to the SA-MP Team
  28. #include <streamer> //Credits to Incognito
  29. #include <sscanf2> //Credits to Y_Less
  30.  
  31.  
  32.  
  33. //====================-- SCRIPT CONFIGURATION --=====================================//
  34. #define COMMAND_SYS 1 //Set to '1' for zcmd, change to '2' for strcmp
  35. #define SAVING_SYS 4//Change this to the number of the saving system you want.
  36.  
  37. /*
  38.     Number      System
  39.         1         y_ini (y_ini include by Y_Less needed)
  40.         2         Dini (Dini include by Dracoblue needed)
  41.         3         MySQL R6 !unthreaded! (MySQL plugin/include by BlueG needed, R6, unthreaded queries)
  42.         4         SQLite (sampdb include by the SA-MP Team needed)
  43. */
  44.  
  45. //-- SYSTEMATIC CONFIGURATION --//
  46. #define MAX_OWNED_GARAGES 5 //Set this to the max. number of garages that a player should be able to own
  47. #define AUTOSAVE true //Set to false if you don't want the script to autosave
  48. #define AUTOSAVE_INTERVAL 10 //Set this to the amount of <~!~> MINUTES <~!~> you want the autosave function to be called (if enabled)
  49. #define MAX_GARAGES 100 //Max garages to be created in the server
  50.  
  51. //-- PICKUPS AND TEXTLABELS --//
  52. #define GARAGE_OWNED_PICKUP 1559 //Change this to the pickup model you prefer. Default: White arrow (diamond)
  53. #define GARAGE_FREE_PICKUP 1273 //Change this to the pickup model you prefer. Default: Green house
  54. #define GARAGE_OWNED_TEXT "Owner: %s\nLocked: %s" //This text will appear at all owned garages
  55. #define GARAGE_FREE_TEXT "FOR SALE!\n Price: %d\n\nUse /buygarage to buy this garage." //This text will appear at all garages that are for sale
  56. #define DD 200.0 //The streamdistance for the textlabels
  57.  
  58. //-- COLORS --//
  59. #define TXTCOLOR 0xF9C50FFF //The textcolor for the textlabels
  60. #define COLOR_USAGE 0xBB4D4DFF //The textcolor for the 'command usage' message
  61. #define COLOR_SUCCESS 0x00AE00FF //The textcolor for the 'command sucessfull' message
  62. #define COLOR_ERROR 0xFF0000FF //The textcolor for the 'error' message
  63. #define COLOR_ORANGE 0xFFA500FF //The color orange
  64. #define COLOR_LIGHTBLUE 0xADD8E6FF //The color light blue
  65.  
  66. ////-- MySQL database/connection info. Only needed when using saving system number 3, MySQL. You can ignore this otherwise --////
  67. #define HOST "localhost"
  68. #define USER "root"
  69. #define PASS ""
  70. #define DataB "SAMP"
  71. //
  72.  
  73.  
  74. //System defines, no need to change stuff here, unless your includes are located elsewhere. Change with care.
  75.  
  76. #if SAVING_SYS == 1
  77.     #include <YSI\y_ini> //Credits to Y_Less
  78. #endif
  79. #if SAVING_SYS == 2
  80.     #include <Dini> //Credits to Dracoblue
  81. #endif
  82. #if SAVING_SYS == 3
  83.     #include <a_mysql> //Credits to BlueG
  84. #endif
  85. #if SAVING_SYS == 4
  86.     #include <a_sampdb> //Credits to the SA-MP Team
  87. #endif
  88. #if COMMAND_SYS == 1
  89.     #include <zcmd> //Credits to Zeex
  90. #endif
  91.  
  92. //For my reference, no need to change
  93. #define SCRIPT_VERSION "V1.1"
  94. //
  95.  
  96.  
  97. //=== ENUMS ===//
  98. enum garageInfo{
  99.  
  100.     Owner[24], //Holds the name of the owner
  101.     Owned, //Holds the owned value (1 if owned, 0 if for sale)
  102.     Locked, //The locked status of the garage (0 unlocked, 1 locked)
  103.     Price, //The price of the garage
  104.     Float:PosX, //The outside X position of the garage
  105.     Float:PosY, //The outside Y position of the garage
  106.     Float:PosZ, //The outside Z position of the garage
  107.     Interior, //The internal interior number of the garage
  108.     UID //Unique ID, keeps a unique ID of the garages so the virtualworld doesn't mix up when deleting and reloading garages
  109. }
  110.  
  111. //=== NEWS ===//
  112. new gInfo[MAX_GARAGES][garageInfo]; //This is used to access variable from our enumerator
  113. new garageCount; //This will hold the total of loaded garages
  114. new Float:GarageInteriors[][] = //This array holds the coordinates, facing angle and interior ID of the garages.
  115. {
  116.     {616.4642, -124.4003, 997.5993, 90.0, 3.0}, // Small garage
  117.     {617.0011, -74.6962, 997.8426, 90.0, 2.0}, // Medium garage
  118.     {606.4268, -9.9375, 1000.7485, 270.0, 1.0} //Big garage
  119.  
  120. };
  121. new Text3D:garageLabel[MAX_GARAGES]; //Will hold the garage label
  122. new garagePickup[MAX_GARAGES]; //Will hold the garage pickup
  123. new lastGarage[MAX_PLAYERS]; //Will hold the last garage ID the player went in to
  124. #if SAVING_SYS == 4 //To prevent 'variable not used' warnings and such
  125.     new DB:Garages;
  126. #endif
  127. //=== PUBLICS ===//
  128.  
  129. public OnFilterScriptInit()
  130. {
  131.     print("\n--------------------------------------");
  132.     printf(" jGarage %s by Jstylezzz loading..",SCRIPT_VERSION);
  133.     print("                  ---                 \n");
  134.     printf("    Initializing saving system %d      ",SAVING_SYS);
  135.     print("\n--------------------------------------");
  136.     DoConnect(); //Connects the script to a database (if needed, automatically detected)
  137.     Load_Garages(); //Loads all garages
  138.     return 1;
  139. }
  140.  
  141. public OnFilterScriptExit()
  142. {
  143.     Save_Garages();
  144.     Remove_PickupsAndLabels();
  145.     return 1;
  146. }
  147. forward Save_Garages();
  148. public Save_Garages() //Saves all the garages, changed to a public because of the autosave timer
  149. {
  150.     #if SAVING_SYS == 1
  151.  
  152.         for(new i=0; i < garageCount+1; i++)
  153.         {
  154.             if(strcmp(gInfo[i][Owner],"REMOVED")) //If the garage is not deleted, save it.
  155.             {
  156.                 new path[64];
  157.                 format(path,sizeof(path),"jgarage/y_ini/%d.ini",i);
  158.                 new INI:gfile = INI_Open(path);
  159.                 INI_WriteString(gfile, "Owner", gInfo[i][Owner]);
  160.                 INI_WriteInt(gfile, "Owned", gInfo[i][Owned]);
  161.                 INI_WriteInt(gfile, "Locked", gInfo[i][Locked]);
  162.                 INI_WriteInt(gfile, "Price", gInfo[i][Price]);
  163.                 INI_WriteFloat(gfile, "PosX", gInfo[i][PosX]);
  164.                 INI_WriteFloat(gfile, "PosY", gInfo[i][PosY]);
  165.                 INI_WriteFloat(gfile, "PosZ", gInfo[i][PosZ]);
  166.                 INI_WriteInt(gfile,"Interior", gInfo[i][Interior]);
  167.                 INI_WriteInt(gfile, "UID", gInfo[i][UID]);
  168.                 INI_Close(gfile);
  169.             }
  170.         }
  171.  
  172.     #endif
  173.  
  174.     #if SAVING_SYS == 2
  175.  
  176.         new path[64];
  177.         for(new i=0; i < garageCount+1; i++)
  178.         {
  179.             if(strcmp(gInfo[i][Owner],"REMOVED")) //If the garage is not deleted, save it.
  180.             {
  181.                 format(path,sizeof(path),"jgarage/dini/%d.ini",i); //Format the path with the filenumber
  182.                 if(dini_Exists(path)) //If the file exists, save the data
  183.                 {
  184.                     dini_Set(path,"Owner",gInfo[i][Owner]);
  185.                     dini_IntSet(path,"Owned",gInfo[i][Owned]);
  186.                     dini_IntSet(path,"Locked",gInfo[i][Locked]);
  187.                     dini_IntSet(path,"Price",gInfo[i][Price]);
  188.                     dini_FloatSet(path,"PosX",gInfo[i][PosX]);
  189.                     dini_FloatSet(path,"PosY",gInfo[i][PosY]);
  190.                     dini_FloatSet(path,"PosZ",gInfo[i][PosZ]);
  191.                     dini_IntSet(path,"Interior",gInfo[i][Interior]);
  192.                     dini_IntSet(path,"UID",gInfo[i][UID]);
  193.                 }
  194.             }
  195.         }
  196.  
  197.     #endif
  198.  
  199.     #if SAVING_SYS == 3
  200.  
  201.         for(new i=0; i < garageCount+1; i++)
  202.         {
  203.             new sql[256];
  204.             format(sql,sizeof(sql),"UPDATE `garages` SET \
  205.             `Owner`='%s',\
  206.             `Owned`='%d',\
  207.             `Locked`='%d',\
  208.             `Price`='%d',\
  209.             `PosX`='%f',\
  210.             `PosY`='%f',\
  211.             `PosZ`='%f',\
  212.             `Interior`='%d',\
  213.             `UID`='%d'\
  214.             WHERE `UID`='%d'",
  215.             gInfo[i][Owner],
  216.             gInfo[i][Owned],
  217.             gInfo[i][Locked],
  218.             gInfo[i][Price],
  219.             gInfo[i][PosX],
  220.             gInfo[i][PosY],
  221.             gInfo[i][PosZ],
  222.             gInfo[i][Interior],
  223.             gInfo[i][UID],
  224.             gInfo[i][UID]);
  225.             mysql_query(sql);
  226.         }
  227.     #endif
  228.  
  229.     #if SAVING_SYS == 4
  230.  
  231.         for(new i=0; i < garageCount+1; i++)
  232.         {
  233.             new sql[256];
  234.             format(sql,sizeof(sql),"UPDATE `garages` SET \
  235.             `Owner`='%s',\
  236.             `Owned`='%d',\
  237.             `Locked`='%d',\
  238.             `Price`='%d',\
  239.             `PosX`='%f',\
  240.             `PosY`='%f',\
  241.             `PosZ`='%f',\
  242.             `Interior`='%d',\
  243.             `UID`='%d'\
  244.             WHERE `UID`='%d'",
  245.             gInfo[i][Owner],
  246.             gInfo[i][Owned],
  247.             gInfo[i][Locked],
  248.             gInfo[i][Price],
  249.             gInfo[i][PosX],
  250.             gInfo[i][PosY],
  251.             gInfo[i][PosZ],
  252.             gInfo[i][Interior],
  253.             gInfo[i][UID],
  254.             gInfo[i][UID]);
  255.             db_free_result(db_query(Garages, sql));
  256.         }
  257.     #endif
  258.  
  259. }
  260. //=== STOCKS ===//
  261. stock DoConnect()
  262. {
  263.     #if SAVING_SYS == 3
  264.         mysql_debug(1);
  265.         mysql_connect(HOST,USER,DataB,PASS);
  266.     #endif
  267.  
  268.     #if SAVING_SYS == 4
  269.         Garages = db_open("jgarage/garages.db");
  270.     #endif
  271. }
  272. stock CreateGarage(gid)
  273. {
  274.     #if SAVING_SYS == 1
  275.         Save_Garage(gid); //y_ini creates the file automatically, so we'll just call the save function here.
  276.     #endif
  277.     #if SAVING_SYS == 2
  278.         new path[64];
  279.         format(path,sizeof(path),"jgarage/dini/%d.ini",gid); //Format the path with the filenumber
  280.         dini_Create(path);
  281.     #endif
  282.     #if SAVING_SYS == 3
  283.         new sql[128];
  284.         format(sql,sizeof(sql),"INSERT INTO `garages` (UID) VALUES ('%d')",gid); //Insert the UID into the SQL database, and save the data based on the UID
  285.         mysql_query(sql);
  286.     #endif
  287.     #if SAVING_SYS == 4
  288.         new sql[128];
  289.         format(sql,sizeof(sql),"INSERT INTO `garages` (UID) VALUES ('%d')",gid); //Insert the UID into the SQL database, and save the data based on the UID
  290.         db_free_result(db_query(Garages,sql));
  291.     #endif
  292.  
  293. }
  294.  
  295. stock RemoveGarage(gid)
  296. {
  297.     #if SAVING_SYS == 1
  298.         new path[64];
  299.         format(path,sizeof(path),"jgarage/y_ini/%d.ini",gInfo[gid][UID]); //Format the path with the filenumber
  300.         if(fexist(path)) fremove(path);
  301.     #endif
  302.     #if SAVING_SYS == 2
  303.         new path[64];
  304.         format(path,sizeof(path),"jgarage/dini/%d.ini",gInfo[gid][UID]); //Format the path with the filenumber
  305.         dini_Remove(path);
  306.     #endif
  307.     #if SAVING_SYS == 3
  308.         new sql[128];
  309.         format(sql,sizeof(sql),"DELETE FROM `garages` WHERE `UID`='%d'",gInfo[gid][UID]); //Format the removal query
  310.         mysql_query(sql);
  311.     #endif
  312.     #if SAVING_SYS == 4
  313.         new sql[128];
  314.         format(sql,sizeof(sql),"DELETE FROM `garages` WHERE `UID`='%d'",gInfo[gid][UID]); //Format the removal query
  315.         db_query(Garages,sql);
  316.     #endif
  317.  
  318. }
  319. stock CheckGarageAmount(playerid)
  320. {
  321.     new pName[MAX_PLAYER_NAME];
  322.     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  323.     new found = 0;
  324.     for(new i=0; i < MAX_GARAGES; i++)
  325.     {
  326.         if(!strcmp(gInfo[i][Owner],pName)) //If the player owns garage 'i', continue
  327.         {
  328.             found++;
  329.         }
  330.     }
  331.     if(found == MAX_OWNED_GARAGES) //If the player owns the max. amount of garages
  332.     {
  333.         new out[128];
  334.         format(out, 128,"Error: you already own %d garages!",MAX_OWNED_GARAGES);
  335.         SendClientMessage(playerid, COLOR_ERROR,out);
  336.         return 1;
  337.     }
  338.     return 0;
  339. }
  340.  
  341. stock Load_Garages() //Loads all garages
  342. {
  343.     garageCount = 1; //Make a debug garage
  344.     #if SAVING_SYS == 1
  345.    
  346.         new path[64];
  347.         for(new i=1; i < MAX_GARAGES; i++) //Loop trough all garage slots
  348.         {
  349.                 format(path, sizeof(path), "jgarage/y_ini/%d.ini",i);
  350.                 INI_ParseFile(path, "YINI_LoadGarageData", .bExtra = true, .extra = garageCount);
  351.                 if(fexist(path)) //To prevent unneeded action
  352.                 {
  353.                     //printf("DEBUG: %s %d %d %d %f %f %f %d %d",gInfo[garageCount][Owner],gInfo[garageCount][Owned],gInfo[garageCount][Locked],gInfo[garageCount][Price],gInfo[garageCount][PosX],gInfo[garageCount][PosY],gInfo[garageCount][PosZ],gInfo[garageCount][Interior],gInfo[garageCount][UID]);
  354.                     UpdateGarageInfo(garageCount);
  355.                     garageCount++;
  356.                 }
  357.  
  358.         }
  359.     #endif
  360.    
  361.     #if SAVING_SYS == 2
  362.  
  363.        
  364.         new path[64];
  365.         for(new i=1; i < MAX_GARAGES; i++) //Loop trough all garage slots
  366.         {
  367.             format(path,sizeof(path),"jgarage/dini/%d.ini",i); //Format the path with the filenumber
  368.             if(dini_Exists(path)) //If the file exists, load the data
  369.             {
  370.                 format(gInfo[i][Owner],24,"%s",dini_Get(path,"Owner"));
  371.                 gInfo[i][Owned] = dini_Int(path,"Owned");
  372.                 gInfo[i][Locked] = dini_Int(path,"Locked");
  373.                 gInfo[i][Price] = dini_Int(path,"Price");
  374.                 gInfo[i][PosX] = dini_Float(path,"PosX");
  375.                 gInfo[i][PosY] = dini_Float(path,"PosY");
  376.                 gInfo[i][PosZ] = dini_Float(path,"PosZ");
  377.                 gInfo[i][Interior] = dini_Int(path,"Interior");
  378.                 gInfo[i][UID] = dini_Int(path,"UID");
  379.                 //printf("DEBUG: %s %d %d %d %f %f %f %d %d",gInfo[i][Owner],gInfo[i][Owned],gInfo[i][Locked],gInfo[i][Price],gInfo[i][PosX],gInfo[i][PosY],gInfo[i][PosZ],gInfo[i][Interior],gInfo[i][UID]);
  380.                 UpdateGarageInfo(i);
  381.                 garageCount++;
  382.             }
  383.         }
  384.  
  385.     #endif
  386.  
  387.    
  388.     #if SAVING_SYS == 3
  389.    
  390.         new sql[128] = "SELECT * FROM `garages`";
  391.         new i;
  392.         mysql_query(sql);
  393.         mysql_store_result();
  394.         while(mysql_fetch_row(sql))
  395.         {
  396.  
  397.             sscanf(sql, "e<p<|>s[24]dddfffdd>", gInfo[i]);
  398.             //printf("DEBUG: %s %d %d %d %f %f %f %d %d",gInfo[i][Owner],gInfo[i][Owned],gInfo[i][Locked],gInfo[i][Price],gInfo[i][PosX],gInfo[i][PosY],gInfo[i][PosZ],gInfo[i][Interior],gInfo[i][UID]);
  399.             UpdateGarageInfo(i);
  400.             garageCount++;
  401.             i++;
  402.  
  403.         }
  404.         mysql_free_result();
  405.        
  406.     #endif
  407.    
  408.     #if SAVING_SYS == 4
  409.  
  410.         new DBResult: Result;
  411.         new Query[128] = "SELECT * FROM `garages`";
  412.         Result = db_query(Garages, Query);
  413.         new amnt = db_num_rows(Result);
  414.        
  415.         for(new i=1; i < amnt; i++)
  416.         {
  417.            
  418.                 db_get_field_assoc(Result,"Owner", Query, sizeof(Query));
  419.                 format(gInfo[i][Owner],MAX_PLAYER_NAME,"%s",Query);
  420.                 db_get_field_assoc(Result,"Owned", Query, sizeof(Query));
  421.                 gInfo[i][Owned] = strval(Query);
  422.                 db_get_field_assoc(Result,"Locked", Query, sizeof(Query));
  423.                 gInfo[i][Locked] = strval(Query);
  424.                 db_get_field_assoc(Result,"Price", Query, sizeof(Query));
  425.                 gInfo[i][Price] = strval(Query);
  426.                 db_get_field_assoc(Result,"PosX", Query, sizeof(Query));
  427.                 gInfo[i][PosX] = floatstr(Query);
  428.                 db_get_field_assoc(Result,"PosY", Query, sizeof(Query));
  429.                 gInfo[i][PosY] = floatstr(Query);
  430.                 db_get_field_assoc(Result,"PosZ", Query, sizeof(Query));
  431.                 gInfo[i][PosZ] = floatstr(Query);
  432.                 db_get_field_assoc(Result,"Interior", Query, sizeof(Query));
  433.                 gInfo[i][Interior] = strval(Query);
  434.                 db_get_field_assoc(Result,"UID", Query, sizeof(Query));
  435.                 gInfo[i][UID] = strval(Query);
  436.                 //printf("DEBUG: %s %d %d %d %f %f %f %d %d",gInfo[i][Owner],gInfo[i][Owned],gInfo[i][Locked],gInfo[i][Price],gInfo[i][PosX],gInfo[i][PosY],gInfo[i][PosZ],gInfo[i][Interior],gInfo[i][UID]);
  437.                 UpdateGarageInfo(i);
  438.                 garageCount++;
  439.                 db_next_row(Result);
  440.         }
  441.         db_free_result(Result);
  442.  
  443.     #endif
  444.     printf("[jGarage]: Loaded %d garages.",garageCount-1); //The debug garage isn't a real garage, so we take 1 away
  445.     garageCount++; //To prevent overwriting/not detecting of garages
  446.    
  447.     #if AUTOSAVE == true
  448.         SetTimer("Save_Garages",AUTOSAVE_INTERVAL*1000,true); //Start the autosave timer if enabled
  449.     #endif
  450. }
  451. #if SAVING_SYS == 1
  452.  
  453.     forward YINI_LoadGarageData(garageID, name[], value[]);
  454.     public YINI_LoadGarageData(garageID, name[], value[])
  455.     {
  456.        
  457.         INI_String("Owner",gInfo[garageID][Owner], MAX_PLAYER_NAME);
  458.         INI_Int("Owned", gInfo[garageID][Owned]);
  459.         INI_Int("Locked", gInfo[garageID][Locked]);
  460.         INI_Int("Price", gInfo[garageID][Price]);
  461.         INI_Float("PosX",  gInfo[garageID][PosX]);
  462.         INI_Float("PosY",  gInfo[garageID][PosY]);
  463.         INI_Float("PosZ",  gInfo[garageID][PosZ]);
  464.         INI_Int("Interior", gInfo[garageID][Interior]);
  465.         INI_Int("UID", gInfo[garageID][UID]);
  466.         return 1;
  467.     }
  468.  
  469. #endif
  470.  
  471. stock Save_Garage(gid) //Saves a specific garage
  472. {
  473.     #if SAVING_SYS == 1
  474.  
  475.         new path[64];
  476.         format(path,sizeof(path),"jgarage/y_ini/%d.ini",gid);
  477.         new INI:gfile = INI_Open(path);
  478.         INI_WriteString(gfile, "Owner", gInfo[gid][Owner]);
  479.         INI_WriteInt(gfile, "Owned", gInfo[gid][Owned]);
  480.         INI_WriteInt(gfile, "Locked", gInfo[gid][Locked]);
  481.         INI_WriteInt(gfile, "Price", gInfo[gid][Price]);
  482.         INI_WriteFloat(gfile, "PosX", gInfo[gid][PosX]);
  483.         INI_WriteFloat(gfile, "PosY", gInfo[gid][PosY]);
  484.         INI_WriteFloat(gfile, "PosZ", gInfo[gid][PosZ]);
  485.         INI_WriteInt(gfile,"Interior", gInfo[gid][Interior]);
  486.         INI_WriteInt(gfile, "UID", gInfo[gid][UID]);
  487.         INI_Close(gfile);
  488.  
  489.     #endif
  490.    
  491.     #if SAVING_SYS == 2
  492.  
  493.         new path[64];
  494.         format(path,sizeof(path),"jgarage/dini/%d.ini",gid); //Format the path with the filenumber
  495.         if(dini_Exists(path)) //If the file exists, save the data
  496.         {
  497.             dini_Set(path,"Owner",gInfo[gid][Owner]);
  498.             dini_IntSet(path,"Owned",gInfo[gid][Owned]);
  499.             dini_IntSet(path,"Locked",gInfo[gid][Locked]);
  500.             dini_IntSet(path,"Price",gInfo[gid][Price]);
  501.             dini_FloatSet(path,"PosX",gInfo[gid][PosX]);
  502.             dini_FloatSet(path,"PosY",gInfo[gid][PosY]);
  503.             dini_FloatSet(path,"PosZ",gInfo[gid][PosZ]);
  504.             dini_IntSet(path,"Interior",gInfo[gid][Interior]);
  505.             dini_IntSet(path,"UID",gInfo[gid][UID]);
  506.         }
  507.     #endif
  508.    
  509.     #if SAVING_SYS == 3
  510.    
  511.         new sql[256];
  512.         format(sql,sizeof(sql),"UPDATE `garages` SET \
  513.         `Owner`='%s',\
  514.         `Owned`='%d',\
  515.         `Locked`='%d',\
  516.         `Price`='%d',\
  517.         `PosX`='%f',\
  518.         `PosY`='%f',\
  519.         `PosZ`='%f',\
  520.         `Interior`='%d',\
  521.         `UID`='%d'\
  522.         WHERE `UID`='%d'",
  523.         gInfo[gid][Owner],
  524.         gInfo[gid][Owned],
  525.         gInfo[gid][Locked],
  526.         gInfo[gid][Price],
  527.         gInfo[gid][PosX],
  528.         gInfo[gid][PosY],
  529.         gInfo[gid][PosZ],
  530.         gInfo[gid][Interior],
  531.         gInfo[gid][UID],
  532.         gInfo[gid][UID]);
  533.         mysql_query(sql);
  534.        
  535.     #endif
  536.    
  537.     #if SAVING_SYS == 4
  538.  
  539.         new sql[256];
  540.         format(sql,sizeof(sql),"UPDATE `garages` SET \
  541.         `Owner`='%s',\
  542.         `Owned`='%d',\
  543.         `Locked`='%d',\
  544.         `Price`='%d',\
  545.         `PosX`='%f',\
  546.         `PosY`='%f',\
  547.         `PosZ`='%f',\
  548.         `Interior`='%d',\
  549.         `UID`='%d'\
  550.         WHERE `UID`='%d'",
  551.         gInfo[gid][Owner],
  552.         gInfo[gid][Owned],
  553.         gInfo[gid][Locked],
  554.         gInfo[gid][Price],
  555.         gInfo[gid][PosX],
  556.         gInfo[gid][PosY],
  557.         gInfo[gid][PosZ],
  558.         gInfo[gid][Interior],
  559.         gInfo[gid][UID],
  560.         gInfo[gid][UID]);
  561.         db_free_result(db_query(Garages, sql));
  562.        
  563.     #endif
  564. }
  565. stock UpdateGarageInfo(gid) //Updates/creates the garage text and label
  566. {
  567.     //Get rid of the old label and pickup (if existing)
  568.     DestroyDynamic3DTextLabel(garageLabel[gid]);
  569.     DestroyDynamicPickup(garagePickup[gid]);
  570.  
  571.     //Re-create them with the correct data
  572.     new ltext[128];
  573.     if(gInfo[gid][Owned] == 1) //If the garage is owned
  574.     {
  575.         format(ltext,128,GARAGE_OWNED_TEXT,gInfo[gid][Owner],GetLockedStatus(gInfo[gid][Locked]));
  576.         garageLabel[gid] = CreateDynamic3DTextLabel(ltext, TXTCOLOR, gInfo[gid][PosX],gInfo[gid][PosY],gInfo[gid][PosZ]+0.1,DD);
  577.         garagePickup[gid] = CreateDynamicPickup(GARAGE_OWNED_PICKUP,1,gInfo[gid][PosX],gInfo[gid][PosY],gInfo[gid][PosZ]+0.2);
  578.     }
  579.     if(gInfo[gid][Owned] == 0)
  580.     {
  581.         format(ltext,128,GARAGE_FREE_TEXT,gInfo[gid][Price]);
  582.         garageLabel[gid] = CreateDynamic3DTextLabel(ltext, TXTCOLOR, gInfo[gid][PosX],gInfo[gid][PosY],gInfo[gid][PosZ]+0.1,DD);
  583.         garagePickup[gid] = CreateDynamicPickup(GARAGE_FREE_PICKUP,1,gInfo[gid][PosX],gInfo[gid][PosY],gInfo[gid][PosZ]);
  584.     }
  585. }
  586. stock GetLockedStatus(value) //Returns 'Locked' or 'Unlocked' according to the value given
  587. {
  588.     new out[64];
  589.     if(value == 1)
  590.     {
  591.         out = "Yes";
  592.     }
  593.     else
  594.     {
  595.         out = "No";
  596.     }
  597.     return out;
  598. }
  599. stock GetPlayerNameEx(playerid)
  600. {
  601.     new pName[24];
  602.     GetPlayerName(playerid,pName,24);
  603.     return pName;
  604. }
  605. stock Remove_PickupsAndLabels()
  606. {
  607.     for(new i=0; i < garageCount+1; i++)
  608.     {
  609.         DestroyDynamic3DTextLabel(garageLabel[i]);
  610.         DestroyDynamicPickup(garagePickup[i]);
  611.     }
  612. }
  613. //=== COMMANDS ===//
  614.  
  615. #if COMMAND_SYS == 1
  616.  
  617.     CMD:garagehelp(playerid,params[])
  618.     {
  619.         SendClientMessage(playerid, COLOR_ORANGE, "jGarage commands:");
  620.         if(!IsPlayerAdmin(playerid))
  621.         {
  622.             SendClientMessage(playerid, COLOR_LIGHTBLUE, "/genter | /gexit | /lockgarage | /buygarage | /sellgarage");
  623.         }
  624.         else
  625.         {
  626.             SendClientMessage(playerid, COLOR_LIGHTBLUE, "/creategarage | /removegarage | /garagetypes | /genter | /gexit | /lockgarage | /buygarage | /sellgarage");
  627.         }
  628.         return 1;
  629.     }
  630.     CMD:garagetypes(playerid,params[])
  631.     {
  632.         if(!IsPlayerAdmin(playerid)) return 0;
  633.         SendClientMessage(playerid, COLOR_ORANGE, "jGarage info - Garage types");
  634.         SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 0: Small garage");
  635.         SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 1: Medium garage");
  636.         SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 2: Big garage");
  637.         return 1;
  638.     }
  639.     CMD:creategarage(playerid,params[])
  640.     {
  641.         if(!IsPlayerAdmin(playerid)) return 0;
  642.         if(garageCount == MAX_GARAGES) return SendClientMessage(playerid, COLOR_USAGE, "The max. amount of garages is reached. Increase the limit in the jGarage filterscript.");
  643.         new price, type;
  644.         if(sscanf(params,"dd",price, type)) return SendClientMessage(playerid, COLOR_USAGE, "Usage: /creategarage <price> <type>  || Use /garagetypes for a list of garage types.");
  645.         new Float:X, Float:Y, Float:Z;
  646.         GetPlayerPos(playerid, X,Y,Z);
  647.         format(gInfo[garageCount][Owner],24,"the State");
  648.         gInfo[garageCount][Owned] = 0;
  649.         gInfo[garageCount][Price] = price;
  650.         gInfo[garageCount][Interior] = type;
  651.         gInfo[garageCount][UID] = garageCount;
  652.         gInfo[garageCount][PosX] = X;
  653.         gInfo[garageCount][PosY] = Y;
  654.         gInfo[garageCount][PosZ] = Z;
  655.         gInfo[garageCount][Locked] = 1;
  656.         CreateGarage(garageCount);
  657.         Save_Garage(garageCount);
  658.         UpdateGarageInfo(garageCount);
  659.         garageCount++;
  660.         SendClientMessage(playerid,COLOR_SUCCESS,"Garage created!");
  661.         return 1;
  662.     }
  663.     CMD:removegarage(playerid,params[])
  664.     {
  665.         if(!IsPlayerAdmin(playerid)) return 0;
  666.         for(new i=0; i < garageCount+1; i++)
  667.         {
  668.             if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  669.             {
  670.                 RemoveGarage(i);
  671.                 format(gInfo[i][Owner],24,"REMOVED");
  672.                 gInfo[i][Owned] = -999;
  673.                 gInfo[i][Price] = -999;
  674.                 gInfo[i][Interior] = -999;
  675.                 gInfo[i][UID] = -999;
  676.                 gInfo[i][PosX] = -999;
  677.                 gInfo[i][PosY] = -999;
  678.                 gInfo[i][PosZ] = -999;
  679.                 gInfo[i][Locked] = -999;
  680.                 DestroyDynamic3DTextLabel(garageLabel[i]);
  681.                 DestroyDynamicPickup(garagePickup[i]);
  682.                 SendClientMessage(playerid, COLOR_SUCCESS, "You have removed this garage.");
  683.                 return 1;
  684.             }
  685.         }
  686.         SendClientMessage(playerid, COLOR_ERROR,"Error: You're not near any garage.");
  687.         return 1;
  688.     }
  689.     CMD:genter(playerid,params[])
  690.     {
  691.         for(new i=0; i < garageCount+1; i++)
  692.         {
  693.             if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  694.             {
  695.  
  696.                 if(gInfo[i][Locked] == 1 && strcmp(GetPlayerNameEx(playerid),gInfo[i][Owner])) return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not the owner of this garage. It's locked, you can't enter.");
  697.                 new gtype = gInfo[i][Interior];
  698.                 if(!IsPlayerInAnyVehicle(playerid))
  699.                 {
  700.                     SetPlayerVirtualWorld(playerid,gInfo[i][UID]);
  701.                     SetPlayerInterior(playerid,floatround(GarageInteriors[gtype][4]));
  702.                     SetPlayerPos(playerid,GarageInteriors[gtype][0],GarageInteriors[gtype][1],GarageInteriors[gtype][2]);
  703.                     lastGarage[playerid] = i;
  704.                 }
  705.                 else
  706.                 {
  707.                     new vid = GetPlayerVehicleID(playerid);
  708.                     LinkVehicleToInterior(vid,floatround(GarageInteriors[gtype][4]));
  709.                     SetVehicleVirtualWorld(vid,gInfo[i][UID]);
  710.                     SetPlayerVirtualWorld(playerid,gInfo[i][UID]);
  711.                     SetPlayerInterior(playerid,floatround(GarageInteriors[gtype][4]));
  712.                     SetVehiclePos(vid,GarageInteriors[gtype][0],GarageInteriors[gtype][1],GarageInteriors[gtype][2]);
  713.                     lastGarage[playerid] = i;
  714.                 }
  715.                 return 1;
  716.  
  717.             }
  718.         }
  719.         SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage. ");
  720.         return 1;
  721.     }
  722.     CMD:gexit(playerid,params[])
  723.     {
  724.         if(lastGarage[playerid] >= 0)
  725.         {
  726.             new lg = lastGarage[playerid];
  727.             if(!IsPlayerInAnyVehicle(playerid))
  728.             {
  729.                 SetPlayerPos(playerid,gInfo[lg][PosX],gInfo[lg][PosY],gInfo[lg][PosZ]);
  730.                 SetPlayerInterior(playerid,0);
  731.                 SetPlayerVirtualWorld(playerid,0);
  732.             }
  733.             else
  734.             {
  735.                 new vid = GetPlayerVehicleID(playerid);
  736.                 LinkVehicleToInterior(vid,0);
  737.                 SetVehicleVirtualWorld(vid,0);
  738.                 SetVehiclePos(vid,gInfo[lg][PosX],gInfo[lg][PosY],gInfo[lg][PosZ]);
  739.                 SetPlayerVirtualWorld(playerid,0);
  740.                 SetPlayerInterior(playerid,0);
  741.             }
  742.             lastGarage[playerid] = -999;
  743.         }
  744.         else return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not in any garage.");
  745.         return 1;
  746.     }
  747.  
  748.     CMD:buygarage(playerid, params[])
  749.     {
  750.         for(new i=0; i < garageCount+1; i++)
  751.         {
  752.             if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  753.             {
  754.                 if(gInfo[i][Owned] == 1) return SendClientMessage(playerid, COLOR_ERROR,"Error: This garage is already owned.");
  755.                 if(CheckGarageAmount(playerid) == 1) return 1; //Check if the player owns the max amount of garages
  756.                 if(GetPlayerMoney(playerid) < gInfo[i][Price]) return SendClientMessage(playerid,COLOR_ERROR,"Error: You don't have enough money to buy this garage.");
  757.                 GivePlayerMoney(playerid,-gInfo[i][Price]);
  758.                 gInfo[i][Price]-= random(5000); //Take some money off of the original price
  759.                 format(gInfo[i][Owner],24,"%s",GetPlayerNameEx(playerid));
  760.                 gInfo[i][Owned] = 1;
  761.                 Save_Garage(i);
  762.                 UpdateGarageInfo(i);
  763.                 SendClientMessage(playerid,COLOR_SUCCESS,"You have successfully bought this garage.");
  764.                 return 1;
  765.             }
  766.         }
  767.         SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage.");
  768.         return 1;
  769.     }
  770.     CMD:lockgarage(playerid,params[])
  771.     {
  772.         for(new i=0; i < garageCount+1; i++)
  773.         {
  774.             if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  775.             {
  776.                 if(strcmp(gInfo[i][Owner],GetPlayerNameEx(playerid))) return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not the owner of this garage.");
  777.                 if(gInfo[i][Locked] == 1)
  778.                 {
  779.                     gInfo[i][Locked] = 0;
  780.                     UpdateGarageInfo(i);
  781.                     Save_Garage(i);
  782.                     SendClientMessage(playerid,COLOR_SUCCESS,"You have unlocked your garage.");
  783.                     return 1;
  784.                 }
  785.                 else
  786.                 {
  787.                     gInfo[i][Locked] = 1;
  788.                     UpdateGarageInfo(i);
  789.                     Save_Garage(i);
  790.                     SendClientMessage(playerid,COLOR_SUCCESS,"You have locked your garage.");
  791.                     return 1;
  792.                 }
  793.             }
  794.         }
  795.         SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage.");
  796.         return 1;
  797.     }
  798.     CMD:sellgarage(playerid,params[])
  799.     {
  800.         for(new i=0; i < garageCount+1; i++)
  801.         {
  802.             if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  803.             {
  804.                 if(strcmp(gInfo[i][Owner],GetPlayerNameEx(playerid))) return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not the owner of this garage.");
  805.                 GivePlayerMoney(playerid,gInfo[i][Price]-random(500));
  806.                 gInfo[i][Owned] = 0;
  807.                 format(gInfo[i][Owner],24,"the State");
  808.                 gInfo[i][Locked] = 1;
  809.                 UpdateGarageInfo(i);
  810.                 Save_Garage(i);
  811.                 SendClientMessage(playerid, COLOR_SUCCESS,"You have successfully sold your garage.");
  812.                 return 1;
  813.               }
  814.         }
  815.         SendClientMessage(playerid, COLOR_ERROR,"You're not near any garage.");
  816.         return 1;
  817.     }
  818. #endif
  819.  
  820. #if COMMAND_SYS == 2
  821.  
  822.     public OnPlayerCommandText(playerid, cmdtext[])
  823.     {
  824.         if(strcmp("/garagehelp", cmdtext, true, 11) == 0)
  825.         {
  826.             SendClientMessage(playerid, COLOR_ORANGE, "jGarage commands:");
  827.             if(!IsPlayerAdmin(playerid))
  828.             {
  829.                 SendClientMessage(playerid, COLOR_LIGHTBLUE, "/genter | /gexit | /lockgarage | /buygarage | /sellgarage");
  830.             }
  831.             else
  832.             {
  833.                 SendClientMessage(playerid, COLOR_LIGHTBLUE, "/creategarage | /removegarage | /garagetypes | /genter | /gexit | /lockgarage | /buygarage | /sellgarage");
  834.             }
  835.             return 1;
  836.         }
  837.         if(strcmp("/garagetypes", cmdtext, true, 12) == 0)
  838.         {
  839.             if(!IsPlayerAdmin(playerid)) return 0;
  840.             SendClientMessage(playerid, COLOR_ORANGE, "jGarage info - Garage types");
  841.             SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 0: Small garage");
  842.             SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 1: Medium garage");
  843.             SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 2: Big garage");
  844.             return 1;
  845.         }
  846.         if(strcmp("/creategarage", cmdtext, true, 13) == 0)
  847.         {
  848.             if(!IsPlayerAdmin(playerid)) return 0;
  849.             if(garageCount == MAX_GARAGES) return SendClientMessage(playerid, COLOR_USAGE, "The max. amount of garages is reached. Increase the limit in the jGarage filterscript.");
  850.             new price, type;
  851.             if(sscanf(cmdtext[14],"dd",price, type)) return SendClientMessage(playerid, COLOR_USAGE, "Usage: /creategarage <price> <type>  || Use /garagetypes for a list of garage types.");
  852.             new Float:X, Float:Y, Float:Z;
  853.             GetPlayerPos(playerid, X,Y,Z);
  854.             format(gInfo[garageCount][Owner],24,"the State");
  855.             gInfo[garageCount][Owned] = 0;
  856.             gInfo[garageCount][Price] = price;
  857.             gInfo[garageCount][Interior] = type;
  858.             gInfo[garageCount][UID] = garageCount;
  859.             gInfo[garageCount][PosX] = X;
  860.             gInfo[garageCount][PosY] = Y;
  861.             gInfo[garageCount][PosZ] = Z;
  862.             gInfo[garageCount][Locked] = 1;
  863.             CreateGarage(garageCount);
  864.             Save_Garage(garageCount);
  865.             UpdateGarageInfo(garageCount);
  866.             garageCount++;
  867.             SendClientMessage(playerid,COLOR_SUCCESS,"Garage created!");
  868.             return 1;
  869.         }
  870.         if(strcmp("/removegarage", cmdtext, true, 13) == 0)
  871.         {
  872.             if(!IsPlayerAdmin(playerid)) return 0;
  873.             for(new i=0; i < garageCount+1; i++)
  874.             {
  875.                 if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  876.                 {
  877.                     format(gInfo[i][Owner],24,"REMOVED");
  878.                     gInfo[i][Owned] = -999;
  879.                     gInfo[i][Price] = -999;
  880.                     gInfo[i][Interior] = -999;
  881.                     gInfo[i][UID] = -999;
  882.                     gInfo[i][PosX] = -999;
  883.                     gInfo[i][PosY] = -999;
  884.                     gInfo[i][PosZ] = -999;
  885.                     gInfo[i][Locked] = -999;
  886.                     DestroyDynamic3DTextLabel(garageLabel[i]);
  887.                     DestroyDynamicPickup(garagePickup[i]);
  888.                     RemoveGarage(i);
  889.                     SendClientMessage(playerid, COLOR_SUCCESS, "You have removed this garage.");
  890.                     return 1;
  891.                 }
  892.             }
  893.             SendClientMessage(playerid, COLOR_ERROR,"Error: You're not near any garage.");
  894.             return 1;
  895.         }
  896.         if(strcmp("/genter", cmdtext, true, 7) == 0)
  897.         {
  898.             for(new i=0; i < garageCount+1; i++)
  899.             {
  900.                 if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  901.                 {
  902.  
  903.                     if(gInfo[i][Locked] == 1 && strcmp(GetPlayerNameEx(playerid),gInfo[i][Owner])) return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not the owner of this garage. It's locked, you can't enter.");
  904.                     new gtype = gInfo[i][Interior];
  905.                     if(!IsPlayerInAnyVehicle(playerid))
  906.                     {
  907.                         SetPlayerVirtualWorld(playerid,gInfo[i][UID]);
  908.                         SetPlayerInterior(playerid,floatround(GarageInteriors[gtype][4]));
  909.                         SetPlayerPos(playerid,GarageInteriors[gtype][0],GarageInteriors[gtype][1],GarageInteriors[gtype][2]);
  910.                         lastGarage[playerid] = i;
  911.                     }
  912.                     else
  913.                     {
  914.                         new vid = GetPlayerVehicleID(playerid);
  915.                         LinkVehicleToInterior(vid,floatround(GarageInteriors[gtype][4]));
  916.                         SetVehicleVirtualWorld(vid,gInfo[i][UID]);
  917.                         SetPlayerVirtualWorld(playerid,gInfo[i][UID]);
  918.                         SetPlayerInterior(playerid,floatround(GarageInteriors[gtype][4]));
  919.                         SetVehiclePos(vid,GarageInteriors[gtype][0],GarageInteriors[gtype][1],GarageInteriors[gtype][2]);
  920.                         lastGarage[playerid] = i;
  921.                     }
  922.                     return 1;
  923.  
  924.                 }
  925.             }
  926.             SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage. ");
  927.             return 1;
  928.         }
  929.         if(strcmp("/gexit", cmdtext, true, 6) == 0)
  930.         {
  931.             if(lastGarage[playerid] >= 0)
  932.             {
  933.                 new lg = lastGarage[playerid];
  934.                 if(!IsPlayerInAnyVehicle(playerid))
  935.                 {
  936.                     SetPlayerPos(playerid,gInfo[lg][PosX],gInfo[lg][PosY],gInfo[lg][PosZ]);
  937.                     SetPlayerInterior(playerid,0);
  938.                     SetPlayerVirtualWorld(playerid,0);
  939.                 }
  940.                 else
  941.                 {
  942.                     new vid = GetPlayerVehicleID(playerid);
  943.                     LinkVehicleToInterior(vid,0);
  944.                     SetVehicleVirtualWorld(vid,0);
  945.                     SetVehiclePos(vid,gInfo[lg][PosX],gInfo[lg][PosY],gInfo[lg][PosZ]);
  946.                     SetPlayerVirtualWorld(playerid,0);
  947.                     SetPlayerInterior(playerid,0);
  948.                 }
  949.                 lastGarage[playerid] = -999;
  950.             }
  951.             else return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not in any garage.");
  952.             return 1;
  953.         }
  954.  
  955.         if(strcmp("/buygarage", cmdtext, true, 10) == 0)
  956.         {
  957.             for(new i=0; i < garageCount+1; i++)
  958.             {
  959.                 if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  960.                 {
  961.                     if(gInfo[i][Owned] == 1) return SendClientMessage(playerid, COLOR_ERROR,"Error: This garage is already owned.");
  962.                     if(GetPlayerMoney(playerid) < gInfo[i][Price]) return SendClientMessage(playerid,COLOR_ERROR,"Error: You don't have enough money to buy this garage.");
  963.                     GivePlayerMoney(playerid,-gInfo[i][Price]);
  964.                     gInfo[i][Price]-= random(5000); //Take some money off of the original price
  965.                     format(gInfo[i][Owner],24,"%s",GetPlayerNameEx(playerid));
  966.                     gInfo[i][Owned] = 1;
  967.                     Save_Garage(i);
  968.                     UpdateGarageInfo(i);
  969.                     SendClientMessage(playerid,COLOR_SUCCESS,"You have successfully bought this garage.");
  970.                     return 1;
  971.                 }
  972.             }
  973.             SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage.");
  974.             return 1;
  975.         }
  976.         if(strcmp("/lockgarage", cmdtext, true, 10) == 0)
  977.         {
  978.             for(new i=0; i < garageCount+1; i++)
  979.             {
  980.                 if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  981.                 {
  982.                     if(strcmp(gInfo[i][Owner],GetPlayerNameEx(playerid))) return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not the owner of this garage.");
  983.                     if(gInfo[i][Locked] == 1)
  984.                     {
  985.                         gInfo[i][Locked] = 0;
  986.                         UpdateGarageInfo(i);
  987.                         Save_Garage(i);
  988.                         SendClientMessage(playerid,COLOR_SUCCESS,"You have unlocked your garage.");
  989.                         return 1;
  990.                     }
  991.                     else
  992.                     {
  993.                         gInfo[i][Locked] = 1;
  994.                         UpdateGarageInfo(i);
  995.                         Save_Garage(i);
  996.                         SendClientMessage(playerid,COLOR_SUCCESS,"You have locked your garage.");
  997.                         return 1;
  998.                     }
  999.                 }
  1000.             }
  1001.             SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage.");
  1002.             return 1;
  1003.         }
  1004.         if(strcmp("/sellgarage", cmdtext, true, 11) == 0)
  1005.         {
  1006.             for(new i=0; i < garageCount+1; i++)
  1007.             {
  1008.                 if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  1009.                 {
  1010.                     if(strcmp(gInfo[i][Owner],GetPlayerNameEx(playerid))) return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not the owner of this garage.");
  1011.                     GivePlayerMoney(playerid,gInfo[i][Price]-random(500));
  1012.                     gInfo[i][Owned] = 0;
  1013.                     format(gInfo[i][Owner],24,"the State");
  1014.                     gInfo[i][Locked] = 1;
  1015.                     UpdateGarageInfo(i);
  1016.                     Save_Garage(i);
  1017.                     SendClientMessage(playerid, COLOR_SUCCESS,"You have successfully sold your garage.");
  1018.                     return 1;
  1019.                   }
  1020.             }
  1021.             SendClientMessage(playerid, COLOR_ERROR,"You're not near any garage.");
  1022.             return 1;
  1023.         }
  1024.         return 0;
  1025.     }
  1026. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement