Advertisement
Jstylezzz

[Universal] jGarage - V1.2 (bug quickfix)

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