daily pastebin goal
57%
SHARE
TWEET

jGarage - Dynamic garages [V1.0b]

Jstylezzz Jan 16th, 2014 2,893 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. *                                                                                                                       jGarage V1.0b
  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. #include <zcmd> //Credits to Zeex
  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. CMD:garagehelp(playerid,params[])
  198. {
  199.         SendClientMessage(playerid, COLOR_ORANGE, "jGarage commands:");
  200.         if(!IsPlayerAdmin(playerid))
  201.         {
  202.                 SendClientMessage(playerid, COLOR_LIGHTBLUE, "/genter | /gexit | /lockgarage | /buygarage | /sellgarage");
  203.         }
  204.         else
  205.         {
  206.                 SendClientMessage(playerid, COLOR_LIGHTBLUE, "/creategarage | /removegarage | /garagetypes | /genter | /gexit | /lockgarage | /buygarage | /sellgarage");
  207.         }
  208.         return 1;
  209. }
  210. CMD:garagetypes(playerid,params[])
  211. {
  212.     if(!IsPlayerAdmin(playerid)) return 0;
  213.     SendClientMessage(playerid, COLOR_ORANGE, "jGarage info - Garage types");
  214.         SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 0: Small garage");
  215.         SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 1: Medium garage");
  216.         SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 2: Big garage");
  217.         return 1;
  218. }
  219. CMD:creategarage(playerid,params[])
  220. {
  221.         if(!IsPlayerAdmin(playerid)) return 0;
  222.         if(garageCount == MAX_GARAGES) return SendClientMessage(playerid, COLOR_USAGE, "The max. amount of garages is reached. Increase the limit in the jGarage filterscript.");
  223.         new price, type;
  224.         if(sscanf(params,"dd",price, type)) return SendClientMessage(playerid, COLOR_USAGE, "Usage: /creategarage <price> <type>  || Use /garagetypes for a list of garage types.");
  225.         new Float:X, Float:Y, Float:Z;
  226.         GetPlayerPos(playerid, X,Y,Z);
  227.         format(gInfo[garageCount][Owner],24,"the State");
  228.         gInfo[garageCount][Owned] = 0;
  229.         gInfo[garageCount][Price] = price;
  230.         gInfo[garageCount][Interior] = type;
  231.         gInfo[garageCount][UID] = garageCount;
  232.         gInfo[garageCount][PosX] = X;
  233.         gInfo[garageCount][PosY] = Y;
  234.         gInfo[garageCount][PosZ] = Z;
  235.         gInfo[garageCount][Locked] = 1;
  236.         new path[128];
  237.         format(path,sizeof(path),"garages/%d.ini",garageCount); //Format the path with the filenumber
  238.         dini_Create(path);
  239.         Save_Garage(garageCount);
  240.         UpdateGarageInfo(garageCount);
  241.         garageCount++;
  242.         SendClientMessage(playerid,COLOR_SUCCESS,"Garage created!");
  243.         return 1;
  244. }
  245. CMD:removegarage(playerid,params[])
  246. {
  247.     if(!IsPlayerAdmin(playerid)) return 0;
  248.     for(new i=0; i < garageCount+1; i++)
  249.         {
  250.             if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  251.             {
  252.                 format(gInfo[i][Owner],24,"REMOVED");
  253.                         gInfo[i][Owned] = -999;
  254.                         gInfo[i][Price] = -999;
  255.                         gInfo[i][Interior] = -999;
  256.                         gInfo[i][UID] = -999;
  257.                         gInfo[i][PosX] = -999;
  258.                         gInfo[i][PosY] = -999;
  259.                         gInfo[i][PosZ] = -999;
  260.                         gInfo[i][Locked] = -999;
  261.                         DestroyDynamic3DTextLabel(garageLabel[i]);
  262.                 DestroyDynamicPickup(garagePickup[i]);
  263.                         new path[128];
  264.                         format(path,sizeof(path),"garages/%d.ini",i); //Format the path with the filenumber
  265.                         dini_Remove(path);
  266.                         SendClientMessage(playerid, COLOR_SUCCESS, "You have removed this garage.");
  267.                         return 1;
  268.                 }
  269.         }
  270.         SendClientMessage(playerid, COLOR_ERROR,"Error: You're not near any garage.");
  271.         return 1;
  272. }
  273. CMD:genter(playerid,params[])
  274. {
  275.         for(new i=0; i < garageCount+1; i++)
  276.         {
  277.             if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  278.             {
  279.            
  280.                 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.");
  281.                 new gtype = gInfo[i][Interior];
  282.                 if(!IsPlayerInAnyVehicle(playerid))
  283.                         {
  284.                                 SetPlayerVirtualWorld(playerid,gInfo[i][UID]);
  285.                                 SetPlayerInterior(playerid,floatround(GarageInteriors[gtype][4]));
  286.                                 SetPlayerPos(playerid,GarageInteriors[gtype][0],GarageInteriors[gtype][1],GarageInteriors[gtype][2]);
  287.                                 lastGarage[playerid] = i;
  288.                         }
  289.                         else
  290.                         {
  291.                                 new vid = GetPlayerVehicleID(playerid);
  292.                             LinkVehicleToInterior(vid,floatround(GarageInteriors[gtype][4]));
  293.                             SetVehicleVirtualWorld(vid,gInfo[i][UID]);
  294.                 SetPlayerVirtualWorld(playerid,gInfo[i][UID]);
  295.                                 SetPlayerInterior(playerid,floatround(GarageInteriors[gtype][4]));
  296.                                 SetVehiclePos(vid,GarageInteriors[gtype][0],GarageInteriors[gtype][1],GarageInteriors[gtype][2]);
  297.                                 lastGarage[playerid] = i;
  298.                         }
  299.                         return 1;
  300.  
  301.                 }
  302.         }
  303.         SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage. ");
  304.         return 1;
  305. }
  306. CMD:gexit(playerid,params[])
  307. {
  308.         if(lastGarage[playerid] >= 0)
  309.         {
  310.             new lg = lastGarage[playerid];
  311.             if(!IsPlayerInAnyVehicle(playerid))
  312.             {
  313.                 SetPlayerPos(playerid,gInfo[lg][PosX],gInfo[lg][PosY],gInfo[lg][PosZ]);
  314.                 SetPlayerInterior(playerid,0);
  315.                 SetPlayerVirtualWorld(playerid,0);
  316.                 }
  317.                 else
  318.                 {
  319.                     new vid = GetPlayerVehicleID(playerid);
  320.                         LinkVehicleToInterior(vid,0);
  321.                         SetVehicleVirtualWorld(vid,0);
  322.                         SetVehiclePos(vid,gInfo[lg][PosX],gInfo[lg][PosY],gInfo[lg][PosZ]);
  323.                     SetPlayerVirtualWorld(playerid,0);
  324.                     SetPlayerInterior(playerid,0);
  325.                 }
  326.                 lastGarage[playerid] = -999;
  327.         }
  328.         else return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not in any garage.");
  329.         return 1;
  330. }
  331.                    
  332. CMD:buygarage(playerid, params[])
  333. {
  334.     for(new i=0; i < garageCount+1; i++)
  335.         {
  336.                 if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  337.                 {
  338.                         if(gInfo[i][Owned] == 1) return SendClientMessage(playerid, COLOR_ERROR,"Error: This garage is already owned.");
  339.                         if(GetPlayerMoney(playerid) < gInfo[i][Price]) return SendClientMessage(playerid,COLOR_ERROR,"Error: You don't have enough money to buy this garage.");
  340.                         GivePlayerMoney(playerid,-gInfo[i][Price]);
  341.                         gInfo[i][Price]-= random(5000); //Take some money off of the original price
  342.                         format(gInfo[i][Owner],24,"%s",GetPlayerNameEx(playerid));
  343.                         gInfo[i][Owned] = 1;
  344.                         Save_Garage(i);
  345.                         UpdateGarageInfo(i);
  346.                         SendClientMessage(playerid,COLOR_SUCCESS,"You have successfully bought this garage.");
  347.                         return 1;
  348.                 }
  349.         }
  350.         SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage.");
  351.         return 1;
  352. }
  353. CMD:lockgarage(playerid,params[])
  354. {
  355.         for(new i=0; i < garageCount+1; i++)
  356.         {
  357.                 if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  358.                 {
  359.                         if(strcmp(gInfo[i][Owner],GetPlayerNameEx(playerid))) return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not the owner of this garage.");
  360.                         if(gInfo[i][Locked] == 1)
  361.                         {
  362.                             gInfo[i][Locked] = 0;
  363.                             UpdateGarageInfo(i);
  364.                             Save_Garage(i);
  365.                 SendClientMessage(playerid,COLOR_SUCCESS,"You have unlocked your garage.");
  366.                             return 1;
  367.                         }
  368.                         else
  369.                         {
  370.                             gInfo[i][Locked] = 1;
  371.                             UpdateGarageInfo(i);
  372.                 Save_Garage(i);
  373.                 SendClientMessage(playerid,COLOR_SUCCESS,"You have locked your garage.");
  374.                             return 1;
  375.                         }
  376.                 }
  377.         }
  378.         SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage.");
  379.         return 1;
  380. }
  381. CMD:sellgarage(playerid,params[])
  382. {
  383.         for(new i=0; i < garageCount+1; i++)
  384.         {
  385.                 if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
  386.         {
  387.                         if(strcmp(gInfo[i][Owner],GetPlayerNameEx(playerid))) return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not the owner of this garage.");
  388.                         GivePlayerMoney(playerid,gInfo[i][Price]-random(500));
  389.                         gInfo[i][Owned] = 0;
  390.                         format(gInfo[i][Owner],24,"the State");
  391.                         gInfo[i][Locked] = 1;
  392.                         UpdateGarageInfo(i);
  393.                         Save_Garage(i);
  394.                         SendClientMessage(playerid, COLOR_SUCCESS,"You have successfully sold your garage.");
  395.                         return 1;
  396.                   }
  397.         }
  398.         SendClientMessage(playerid, COLOR_ERROR,"You're not near any garage.");
  399.         return 1;
  400. }
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
 
Top