SHARE
TWEET

jGarage [V1.0b][strcmp version]

Jstylezzz Mar 24th, 2014 152 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. *                                                                                                                       jGarage V1.0b strcmp version
  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. */
  14.  
  15. //=== INCLUDES ===//
  16. #include <a_samp> //Credits to the SA-MP Team
  17. #include <dini> //Credits to Dracoblue
  18. #include <streamer> //Credits to Incognito
  19. #include <sscanf2> //Credits to Y_Less
  20.  
  21. //=== DEFINES ===//
  22.  
  23. //Config defines, change to your likings
  24. #define MAX_GARAGES 100 //Max garages to be created in the server
  25. #define GARAGE_OWNED_PICKUP 1559 //Change this to the pickup model you prefer. Default: White arrow (diamond)
  26. #define GARAGE_FREE_PICKUP 1273 //Change this to the pickup model you prefer. Default: Green house
  27. #define GARAGE_OWNED_TEXT "Owner: %s\nLocked: %s" //This text will appear at all owned garages
  28. #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
  29. #define DD 200.0 //The streamdistance for the textlabels
  30. #define TXTCOLOR 0xF9C50FFF //The textcolor for the textlabels
  31. #define COLOR_USAGE 0xBB4D4DFF //The textcolor for the 'command usage' message
  32. #define COLOR_SUCCESS 0x00AE00FF //The textcolor for the 'command sucessfull' message
  33. #define COLOR_ERROR 0xFF0000FF //The textcolor for the 'error' message
  34. #define COLOR_ORANGE 0xFFA500FF //The color orange
  35. #define COLOR_LIGHTBLUE 0xADD8E6FF //The color light blue
  36.  
  37. //System defines, no need to change stuff here
  38. #define SCRIPT_VERSION "V1.0b"
  39.  
  40. //=== ENUMS ===//
  41. enum garageInfo{
  42.  
  43.         Owner[24], //Holds the name of the owner
  44.         Owned, //Holds the owned value (1 if owned, 0 if for sale)
  45.         Locked, //The locked status of the garage (0 unlocked, 1 locked)
  46.         Price, //The price of the garage
  47.         Float:PosX, //The outside X position of the garage
  48.         Float:PosY, //The outside Y position of the garage
  49.         Float:PosZ, //The outside Z position of the garage
  50.         Interior, //The internal interior number of the garage
  51.         UID //Unique ID, keeps a unique ID of the garages so the virtualworld doesn't mix up when deleting and reloading garages
  52. }
  53.  
  54.  
  55. //=== NEWS ===//
  56. new gInfo[MAX_GARAGES][garageInfo]; //This is used to access variable from our enumerator
  57. new garageCount; //This will hold the total of loaded garages
  58. new Float:GarageInteriors[][] = //This array holds the coordinates, facing angle and interior ID of the garages.
  59. {
  60.         {616.4642, -124.4003, 997.5993, 90.0, 3.0}, // Small garage
  61.     {617.0011, -74.6962, 997.8426, 90.0, 2.0}, // Medium garage
  62.     {606.4268, -9.9375, 1000.7485, 270.0, 1.0} //Big garage
  63.  
  64. };
  65. new Text3D:garageLabel[MAX_GARAGES]; //Will hold the garage label
  66. new garagePickup[MAX_GARAGES]; //Will hold the garage pickup
  67. new lastGarage[MAX_PLAYERS]; //Will hold the last garage ID the player went in to
  68.  
  69. //=== NATIVE PUBLICS ===//
  70.  
  71. public OnFilterScriptInit()
  72. {
  73.         print("\n--------------------------------------");
  74.         printf(" jGarage %s by Jstylezzz loading..",SCRIPT_VERSION);
  75.         print("--------------------------------------\n");
  76.         Load_Garages();
  77.         return 1;
  78. }
  79.  
  80. public OnFilterScriptExit()
  81. {
  82.         Save_Garages();
  83.         Remove_PickupsAndLabels();
  84.         return 1;
  85. }
  86.  
  87. //=== STOCKS ===//
  88. stock Load_Garages() //Loads all garages
  89. {
  90.         garageCount = 1;
  91.         new path[128];
  92.         for(new i=0; i < MAX_GARAGES; i++) //Loop trough all garage slots
  93.         {
  94.             format(path,sizeof(path),"garages/%d.ini",i); //Format the path with the filenumber
  95.             if(dini_Exists(path)) //If the file exists, load the data
  96.             {
  97.                 format(gInfo[i][Owner],24,"%s",dini_Get(path,"Owner"));
  98.                 gInfo[i][Owned] = dini_Int(path,"Owned");
  99.                 gInfo[i][Locked] = dini_Int(path,"Locked");
  100.                 gInfo[i][Price] = dini_Int(path,"Price");
  101.                     gInfo[i][PosX] = dini_Float(path,"PosX");
  102.                     gInfo[i][PosY] = dini_Float(path,"PosY");
  103.                     gInfo[i][PosZ] = dini_Float(path,"PosZ");
  104.                     gInfo[i][UID] = dini_Int(path,"UID");
  105.                     UpdateGarageInfo(i);
  106.                     garageCount++;
  107.                 }
  108.         }
  109.         printf("[jGarage]: Loaded %d garages.",garageCount);
  110.         garageCount++; //To prevent overwriting/not detecting of garages
  111. }
  112. stock Save_Garages() //Saves all the garages
  113. {
  114.         new path[128];
  115.         for(new i=0; i < garageCount+1; i++)
  116.         {
  117.             format(path,sizeof(path),"garages/%d.ini",i); //Format the path with the filenumber
  118.             if(dini_Exists(path)) //If the file exists, save the data
  119.             {
  120.                 dini_Set(path,"Owner",gInfo[i][Owner]);
  121.                         dini_IntSet(path,"Owned",gInfo[i][Owned]);
  122.                         dini_IntSet(path,"Locked",gInfo[i][Locked]);
  123.                         dini_IntSet(path,"Price",gInfo[i][Price]);
  124.                         dini_FloatSet(path,"PosX",gInfo[i][PosX]);
  125.                         dini_FloatSet(path,"PosY",gInfo[i][PosY]);
  126.                         dini_FloatSet(path,"PosZ",gInfo[i][PosZ]);
  127.                         dini_IntSet(path,"UID",gInfo[i][UID]);
  128.                 }
  129.         }
  130. }
  131. stock Save_Garage(gid) //Saves a specific garage
  132. {
  133.         new path[128];
  134.         format(path,sizeof(path),"garages/%d.ini",gid); //Format the path with the filenumber
  135.         if(dini_Exists(path)) //If the file exists, save the data
  136.     {
  137.         dini_Set(path,"Owner",gInfo[gid][Owner]);
  138.                 dini_IntSet(path,"Owned",gInfo[gid][Owned]);
  139.                 dini_IntSet(path,"Locked",gInfo[gid][Locked]);
  140.                 dini_IntSet(path,"Price",gInfo[gid][Price]);
  141.                 dini_FloatSet(path,"PosX",gInfo[gid][PosX]);
  142.                 dini_FloatSet(path,"PosY",gInfo[gid][PosY]);
  143.                 dini_FloatSet(path,"PosZ",gInfo[gid][PosZ]);
  144.                 dini_IntSet(path,"UID",gInfo[gid][UID]);
  145.         }
  146.  
  147. }
  148. stock UpdateGarageInfo(gid) //Updates/creates the garage text and label
  149. {
  150.         //Get rid of the old label and pickup (if existing)
  151.         DestroyDynamic3DTextLabel(garageLabel[gid]);
  152.         DestroyDynamicPickup(garagePickup[gid]);
  153.  
  154.         //Re-create them with the correct data
  155.         new ltext[128];
  156.         if(gInfo[gid][Owned] == 1) //If the garage is owned
  157.         {
  158.             format(ltext,128,GARAGE_OWNED_TEXT,gInfo[gid][Owner],GetLockedStatus(gInfo[gid][Locked]));
  159.             garageLabel[gid] = CreateDynamic3DTextLabel(ltext, TXTCOLOR, gInfo[gid][PosX],gInfo[gid][PosY],gInfo[gid][PosZ]+0.1,DD);
  160.             garagePickup[gid] = CreateDynamicPickup(GARAGE_OWNED_PICKUP,1,gInfo[gid][PosX],gInfo[gid][PosY],gInfo[gid][PosZ]+0.2);
  161.         }
  162.         if(gInfo[gid][Owned] == 0)
  163.         {
  164.             format(ltext,128,GARAGE_FREE_TEXT,gInfo[gid][Price]);
  165.             garageLabel[gid] = CreateDynamic3DTextLabel(ltext, TXTCOLOR, gInfo[gid][PosX],gInfo[gid][PosY],gInfo[gid][PosZ]+0.1,DD);
  166.             garagePickup[gid] = CreateDynamicPickup(GARAGE_FREE_PICKUP,1,gInfo[gid][PosX],gInfo[gid][PosY],gInfo[gid][PosZ]);
  167.         }
  168. }
  169. stock GetLockedStatus(value) //Returns 'Locked' or 'Unlocked' according to the value given
  170. {
  171.         new out[64];
  172.         if(value == 1)
  173.         {
  174.             out = "Yes";
  175.         }
  176.         else
  177.         {
  178.             out = "No";
  179.         }
  180.         return out;
  181. }
  182. stock GetPlayerNameEx(playerid)
  183. {
  184.         new pName[24];
  185.         GetPlayerName(playerid,pName,24);
  186.         return pName;
  187. }
  188. stock Remove_PickupsAndLabels()
  189. {
  190.         for(new i=0; i < garageCount+1; i++)
  191.         {
  192.             DestroyDynamic3DTextLabel(garageLabel[i]);
  193.             DestroyDynamicPickup(garagePickup[i]);
  194.         }
  195. }
  196. //=== COMMANDS ===//
  197. public OnPlayerCommandText(playerid, cmdtext[])
  198. {
  199.         if(strcmp("/garagehelp", cmdtext, true, 11) == 0)
  200.         {
  201.                 SendClientMessage(playerid, COLOR_ORANGE, "jGarage commands:");
  202.                 if(!IsPlayerAdmin(playerid))
  203.                 {
  204.                         SendClientMessage(playerid, COLOR_LIGHTBLUE, "/genter | /gexit | /lockgarage | /buygarage | /sellgarage");
  205.                 }
  206.                 else
  207.                 {
  208.                         SendClientMessage(playerid, COLOR_LIGHTBLUE, "/creategarage | /removegarage | /garagetypes | /genter | /gexit | /lockgarage | /buygarage | /sellgarage");
  209.                 }
  210.                 return 1;
  211.         }
  212.         if(strcmp("/garagetypes", cmdtext, true, 12) == 0)
  213.         {
  214.             if(!IsPlayerAdmin(playerid)) return 0;
  215.             SendClientMessage(playerid, COLOR_ORANGE, "jGarage info - Garage types");
  216.                 SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 0: Small garage");
  217.                 SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 1: Medium garage");
  218.                 SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 2: Big garage");
  219.                 return 1;
  220.         }
  221.         if(strcmp("/creategarage", cmdtext, true, 13) == 0)
  222.         {
  223.                 if(!IsPlayerAdmin(playerid)) return 0;
  224.                 if(garageCount == MAX_GARAGES) return SendClientMessage(playerid, COLOR_USAGE, "The max. amount of garages is reached. Increase the limit in the jGarage filterscript.");
  225.                 new price, type;
  226.                 if(sscanf(cmdtext[14],"dd",price, type)) return SendClientMessage(playerid, COLOR_USAGE, "Usage: /creategarage <price> <type>  || Use /garagetypes for a list of garage types.");
  227.                 new Float:X, Float:Y, Float:Z;
  228.                 GetPlayerPos(playerid, X,Y,Z);
  229.                 format(gInfo[garageCount][Owner],24,"the State");
  230.                 gInfo[garageCount][Owned] = 0;
  231.                 gInfo[garageCount][Price] = price;
  232.                 gInfo[garageCount][Interior] = type;
  233.                 gInfo[garageCount][UID] = garageCount;
  234.                 gInfo[garageCount][PosX] = X;
  235.                 gInfo[garageCount][PosY] = Y;
  236.                 gInfo[garageCount][PosZ] = Z;
  237.                 gInfo[garageCount][Locked] = 1;
  238.                 new path[128];
  239.                 format(path,sizeof(path),"garages/%d.ini",garageCount); //Format the path with the filenumber
  240.                 dini_Create(path);
  241.                 Save_Garage(garageCount);
  242.                 UpdateGarageInfo(garageCount);
  243.                 garageCount++;
  244.                 SendClientMessage(playerid,COLOR_SUCCESS,"Garage created!");
  245.                 return 1;
  246.         }
  247.         if(strcmp("/removegarage", cmdtext, true, 13) == 0)
  248.         {
  249.             if(!IsPlayerAdmin(playerid)) return 0;
  250.             for(new i=0; i < garageCount+1; i++)
  251.                 {
  252.                     if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  253.                     {
  254.                         format(gInfo[i][Owner],24,"REMOVED");
  255.                                 gInfo[i][Owned] = -999;
  256.                                 gInfo[i][Price] = -999;
  257.                                 gInfo[i][Interior] = -999;
  258.                                 gInfo[i][UID] = -999;
  259.                                 gInfo[i][PosX] = -999;
  260.                                 gInfo[i][PosY] = -999;
  261.                                 gInfo[i][PosZ] = -999;
  262.                                 gInfo[i][Locked] = -999;
  263.                                 DestroyDynamic3DTextLabel(garageLabel[i]);
  264.                         DestroyDynamicPickup(garagePickup[i]);
  265.                                 new path[128];
  266.                                 format(path,sizeof(path),"garages/%d.ini",i); //Format the path with the filenumber
  267.                                 dini_Remove(path);
  268.                                 SendClientMessage(playerid, COLOR_SUCCESS, "You have removed this garage.");
  269.                                 return 1;
  270.                         }
  271.                 }
  272.                 SendClientMessage(playerid, COLOR_ERROR,"Error: You're not near any garage.");
  273.                 return 1;
  274.         }
  275.         if(strcmp("/genter", cmdtext, true, 7) == 0)
  276.         {
  277.                 for(new i=0; i < garageCount+1; i++)
  278.                 {
  279.                     if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  280.                     {
  281.  
  282.                         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.");
  283.                         new gtype = gInfo[i][Interior];
  284.                         if(!IsPlayerInAnyVehicle(playerid))
  285.                                 {
  286.                                         SetPlayerVirtualWorld(playerid,gInfo[i][UID]);
  287.                                         SetPlayerInterior(playerid,floatround(GarageInteriors[gtype][4]));
  288.                                         SetPlayerPos(playerid,GarageInteriors[gtype][0],GarageInteriors[gtype][1],GarageInteriors[gtype][2]);
  289.                                         lastGarage[playerid] = i;
  290.                                 }
  291.                                 else
  292.                                 {
  293.                                         new vid = GetPlayerVehicleID(playerid);
  294.                                     LinkVehicleToInterior(vid,floatround(GarageInteriors[gtype][4]));
  295.                                     SetVehicleVirtualWorld(vid,gInfo[i][UID]);
  296.                         SetPlayerVirtualWorld(playerid,gInfo[i][UID]);
  297.                                         SetPlayerInterior(playerid,floatround(GarageInteriors[gtype][4]));
  298.                                         SetVehiclePos(vid,GarageInteriors[gtype][0],GarageInteriors[gtype][1],GarageInteriors[gtype][2]);
  299.                                         lastGarage[playerid] = i;
  300.                                 }
  301.                                 return 1;
  302.  
  303.                         }
  304.                 }
  305.                 SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage. ");
  306.                 return 1;
  307.         }
  308.         if(strcmp("/gexit", cmdtext, true, 6) == 0)
  309.         {
  310.                 if(lastGarage[playerid] >= 0)
  311.                 {
  312.                     new lg = lastGarage[playerid];
  313.                     if(!IsPlayerInAnyVehicle(playerid))
  314.                     {
  315.                         SetPlayerPos(playerid,gInfo[lg][PosX],gInfo[lg][PosY],gInfo[lg][PosZ]);
  316.                         SetPlayerInterior(playerid,0);
  317.                         SetPlayerVirtualWorld(playerid,0);
  318.                         }
  319.                         else
  320.                         {
  321.                             new vid = GetPlayerVehicleID(playerid);
  322.                                 LinkVehicleToInterior(vid,0);
  323.                                 SetVehicleVirtualWorld(vid,0);
  324.                                 SetVehiclePos(vid,gInfo[lg][PosX],gInfo[lg][PosY],gInfo[lg][PosZ]);
  325.                             SetPlayerVirtualWorld(playerid,0);
  326.                             SetPlayerInterior(playerid,0);
  327.                         }
  328.                         lastGarage[playerid] = -999;
  329.                 }
  330.                 else return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not in any garage.");
  331.                 return 1;
  332.         }
  333.  
  334.         if(strcmp("/buygarage", cmdtext, true, 10) == 0)
  335.         {
  336.             for(new i=0; i < garageCount+1; i++)
  337.                 {
  338.                         if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  339.                         {
  340.                                 if(gInfo[i][Owned] == 1) return SendClientMessage(playerid, COLOR_ERROR,"Error: This garage is already owned.");
  341.                                 if(GetPlayerMoney(playerid) < gInfo[i][Price]) return SendClientMessage(playerid,COLOR_ERROR,"Error: You don't have enough money to buy this garage.");
  342.                                 GivePlayerMoney(playerid,-gInfo[i][Price]);
  343.                                 gInfo[i][Price]-= random(5000); //Take some money off of the original price
  344.                                 format(gInfo[i][Owner],24,"%s",GetPlayerNameEx(playerid));
  345.                                 gInfo[i][Owned] = 1;
  346.                                 Save_Garage(i);
  347.                                 UpdateGarageInfo(i);
  348.                                 SendClientMessage(playerid,COLOR_SUCCESS,"You have successfully bought this garage.");
  349.                                 return 1;
  350.                         }
  351.                 }
  352.                 SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage.");
  353.                 return 1;
  354.         }
  355.         if(strcmp("/lockgarage", cmdtext, true, 10) == 0)
  356.         {
  357.                 for(new i=0; i < garageCount+1; i++)
  358.                 {
  359.                         if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  360.                         {
  361.                                 if(strcmp(gInfo[i][Owner],GetPlayerNameEx(playerid))) return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not the owner of this garage.");
  362.                                 if(gInfo[i][Locked] == 1)
  363.                                 {
  364.                                     gInfo[i][Locked] = 0;
  365.                                     UpdateGarageInfo(i);
  366.                                     Save_Garage(i);
  367.                         SendClientMessage(playerid,COLOR_SUCCESS,"You have unlocked your garage.");
  368.                                     return 1;
  369.                                 }
  370.                                 else
  371.                                 {
  372.                                     gInfo[i][Locked] = 1;
  373.                                     UpdateGarageInfo(i);
  374.                         Save_Garage(i);
  375.                         SendClientMessage(playerid,COLOR_SUCCESS,"You have locked your garage.");
  376.                                     return 1;
  377.                                 }
  378.                         }
  379.                 }
  380.                 SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage.");
  381.                 return 1;
  382.         }
  383.         if(strcmp("/sellgarage", cmdtext, true, 11) == 0)
  384.         {
  385.                 for(new i=0; i < garageCount+1; i++)
  386.                 {
  387.                         if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  388.                 {
  389.                                 if(strcmp(gInfo[i][Owner],GetPlayerNameEx(playerid))) return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not the owner of this garage.");
  390.                                 GivePlayerMoney(playerid,gInfo[i][Price]-random(500));
  391.                                 gInfo[i][Owned] = 0;
  392.                                 format(gInfo[i][Owner],24,"the State");
  393.                                 gInfo[i][Locked] = 1;
  394.                                 UpdateGarageInfo(i);
  395.                                 Save_Garage(i);
  396.                                 SendClientMessage(playerid, COLOR_SUCCESS,"You have successfully sold your garage.");
  397.                                 return 1;
  398.                           }
  399.                 }
  400.                 SendClientMessage(playerid, COLOR_ERROR,"You're not near any garage.");
  401.                 return 1;
  402.         }
  403.         return 0;
  404. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top