Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * jGarage V1.0b strcmp version
- * by Jstylezzz
- *
- *
- *
- * To create garages, log in as Rcon and use the command '/creategarage'. To remove a garage use '/removegarage' when standing on it's pickup.
- * Use '/garagehelp' to view the available commands. If the server crashes when creating a garage, you probably forgot the 'garages' folder
- * in the scriptfiles folder. Create it.
- * 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!
- *
- *
- */
- //=== INCLUDES ===//
- #include <a_samp> //Credits to the SA-MP Team
- #include <dini> //Credits to Dracoblue
- #include <streamer> //Credits to Incognito
- #include <sscanf2> //Credits to Y_Less
- //=== DEFINES ===//
- //Config defines, change to your likings
- #define MAX_GARAGES 100 //Max garages to be created in the server
- #define GARAGE_OWNED_PICKUP 1559 //Change this to the pickup model you prefer. Default: White arrow (diamond)
- #define GARAGE_FREE_PICKUP 1273 //Change this to the pickup model you prefer. Default: Green house
- #define GARAGE_OWNED_TEXT "Owner: %s\nLocked: %s" //This text will appear at all owned garages
- #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
- #define DD 200.0 //The streamdistance for the textlabels
- #define TXTCOLOR 0xF9C50FFF //The textcolor for the textlabels
- #define COLOR_USAGE 0xBB4D4DFF //The textcolor for the 'command usage' message
- #define COLOR_SUCCESS 0x00AE00FF //The textcolor for the 'command sucessfull' message
- #define COLOR_ERROR 0xFF0000FF //The textcolor for the 'error' message
- #define COLOR_ORANGE 0xFFA500FF //The color orange
- #define COLOR_LIGHTBLUE 0xADD8E6FF //The color light blue
- //System defines, no need to change stuff here
- #define SCRIPT_VERSION "V1.0b"
- //=== ENUMS ===//
- enum garageInfo{
- Owner[24], //Holds the name of the owner
- Owned, //Holds the owned value (1 if owned, 0 if for sale)
- Locked, //The locked status of the garage (0 unlocked, 1 locked)
- Price, //The price of the garage
- Float:PosX, //The outside X position of the garage
- Float:PosY, //The outside Y position of the garage
- Float:PosZ, //The outside Z position of the garage
- Interior, //The internal interior number of the garage
- UID //Unique ID, keeps a unique ID of the garages so the virtualworld doesn't mix up when deleting and reloading garages
- }
- //=== NEWS ===//
- new gInfo[MAX_GARAGES][garageInfo]; //This is used to access variable from our enumerator
- new garageCount; //This will hold the total of loaded garages
- new Float:GarageInteriors[][] = //This array holds the coordinates, facing angle and interior ID of the garages.
- {
- {616.4642, -124.4003, 997.5993, 90.0, 3.0}, // Small garage
- {617.0011, -74.6962, 997.8426, 90.0, 2.0}, // Medium garage
- {606.4268, -9.9375, 1000.7485, 270.0, 1.0} //Big garage
- };
- new Text3D:garageLabel[MAX_GARAGES]; //Will hold the garage label
- new garagePickup[MAX_GARAGES]; //Will hold the garage pickup
- new lastGarage[MAX_PLAYERS]; //Will hold the last garage ID the player went in to
- //=== NATIVE PUBLICS ===//
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- printf(" jGarage %s by Jstylezzz loading..",SCRIPT_VERSION);
- print("--------------------------------------\n");
- Load_Garages();
- return 1;
- }
- public OnFilterScriptExit()
- {
- Save_Garages();
- Remove_PickupsAndLabels();
- return 1;
- }
- //=== STOCKS ===//
- stock Load_Garages() //Loads all garages
- {
- garageCount = 1;
- new path[128];
- for(new i=0; i < MAX_GARAGES; i++) //Loop trough all garage slots
- {
- format(path,sizeof(path),"garages/%d.ini",i); //Format the path with the filenumber
- if(dini_Exists(path)) //If the file exists, load the data
- {
- format(gInfo[i][Owner],24,"%s",dini_Get(path,"Owner"));
- gInfo[i][Owned] = dini_Int(path,"Owned");
- gInfo[i][Locked] = dini_Int(path,"Locked");
- gInfo[i][Price] = dini_Int(path,"Price");
- gInfo[i][PosX] = dini_Float(path,"PosX");
- gInfo[i][PosY] = dini_Float(path,"PosY");
- gInfo[i][PosZ] = dini_Float(path,"PosZ");
- gInfo[i][UID] = dini_Int(path,"UID");
- UpdateGarageInfo(i);
- garageCount++;
- }
- }
- printf("[jGarage]: Loaded %d garages.",garageCount);
- garageCount++; //To prevent overwriting/not detecting of garages
- }
- stock Save_Garages() //Saves all the garages
- {
- new path[128];
- for(new i=0; i < garageCount+1; i++)
- {
- format(path,sizeof(path),"garages/%d.ini",i); //Format the path with the filenumber
- if(dini_Exists(path)) //If the file exists, save the data
- {
- dini_Set(path,"Owner",gInfo[i][Owner]);
- dini_IntSet(path,"Owned",gInfo[i][Owned]);
- dini_IntSet(path,"Locked",gInfo[i][Locked]);
- dini_IntSet(path,"Price",gInfo[i][Price]);
- dini_FloatSet(path,"PosX",gInfo[i][PosX]);
- dini_FloatSet(path,"PosY",gInfo[i][PosY]);
- dini_FloatSet(path,"PosZ",gInfo[i][PosZ]);
- dini_IntSet(path,"UID",gInfo[i][UID]);
- }
- }
- }
- stock Save_Garage(gid) //Saves a specific garage
- {
- new path[128];
- format(path,sizeof(path),"garages/%d.ini",gid); //Format the path with the filenumber
- if(dini_Exists(path)) //If the file exists, save the data
- {
- dini_Set(path,"Owner",gInfo[gid][Owner]);
- dini_IntSet(path,"Owned",gInfo[gid][Owned]);
- dini_IntSet(path,"Locked",gInfo[gid][Locked]);
- dini_IntSet(path,"Price",gInfo[gid][Price]);
- dini_FloatSet(path,"PosX",gInfo[gid][PosX]);
- dini_FloatSet(path,"PosY",gInfo[gid][PosY]);
- dini_FloatSet(path,"PosZ",gInfo[gid][PosZ]);
- dini_IntSet(path,"UID",gInfo[gid][UID]);
- }
- }
- stock UpdateGarageInfo(gid) //Updates/creates the garage text and label
- {
- //Get rid of the old label and pickup (if existing)
- DestroyDynamic3DTextLabel(garageLabel[gid]);
- DestroyDynamicPickup(garagePickup[gid]);
- //Re-create them with the correct data
- new ltext[128];
- if(gInfo[gid][Owned] == 1) //If the garage is owned
- {
- format(ltext,128,GARAGE_OWNED_TEXT,gInfo[gid][Owner],GetLockedStatus(gInfo[gid][Locked]));
- garageLabel[gid] = CreateDynamic3DTextLabel(ltext, TXTCOLOR, gInfo[gid][PosX],gInfo[gid][PosY],gInfo[gid][PosZ]+0.1,DD);
- garagePickup[gid] = CreateDynamicPickup(GARAGE_OWNED_PICKUP,1,gInfo[gid][PosX],gInfo[gid][PosY],gInfo[gid][PosZ]+0.2);
- }
- if(gInfo[gid][Owned] == 0)
- {
- format(ltext,128,GARAGE_FREE_TEXT,gInfo[gid][Price]);
- garageLabel[gid] = CreateDynamic3DTextLabel(ltext, TXTCOLOR, gInfo[gid][PosX],gInfo[gid][PosY],gInfo[gid][PosZ]+0.1,DD);
- garagePickup[gid] = CreateDynamicPickup(GARAGE_FREE_PICKUP,1,gInfo[gid][PosX],gInfo[gid][PosY],gInfo[gid][PosZ]);
- }
- }
- stock GetLockedStatus(value) //Returns 'Locked' or 'Unlocked' according to the value given
- {
- new out[64];
- if(value == 1)
- {
- out = "Yes";
- }
- else
- {
- out = "No";
- }
- return out;
- }
- stock GetPlayerNameEx(playerid)
- {
- new pName[24];
- GetPlayerName(playerid,pName,24);
- return pName;
- }
- stock Remove_PickupsAndLabels()
- {
- for(new i=0; i < garageCount+1; i++)
- {
- DestroyDynamic3DTextLabel(garageLabel[i]);
- DestroyDynamicPickup(garagePickup[i]);
- }
- }
- //=== COMMANDS ===//
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if(strcmp("/garagehelp", cmdtext, true, 11) == 0)
- {
- SendClientMessage(playerid, COLOR_ORANGE, "jGarage commands:");
- if(!IsPlayerAdmin(playerid))
- {
- SendClientMessage(playerid, COLOR_LIGHTBLUE, "/genter | /gexit | /lockgarage | /buygarage | /sellgarage");
- }
- else
- {
- SendClientMessage(playerid, COLOR_LIGHTBLUE, "/creategarage | /removegarage | /garagetypes | /genter | /gexit | /lockgarage | /buygarage | /sellgarage");
- }
- return 1;
- }
- if(strcmp("/garagetypes", cmdtext, true, 12) == 0)
- {
- if(!IsPlayerAdmin(playerid)) return 0;
- SendClientMessage(playerid, COLOR_ORANGE, "jGarage info - Garage types");
- SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 0: Small garage");
- SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 1: Medium garage");
- SendClientMessage(playerid, COLOR_LIGHTBLUE, "Type 2: Big garage");
- return 1;
- }
- if(strcmp("/creategarage", cmdtext, true, 13) == 0)
- {
- if(!IsPlayerAdmin(playerid)) return 0;
- if(garageCount == MAX_GARAGES) return SendClientMessage(playerid, COLOR_USAGE, "The max. amount of garages is reached. Increase the limit in the jGarage filterscript.");
- new price, type;
- if(sscanf(cmdtext[14],"dd",price, type)) return SendClientMessage(playerid, COLOR_USAGE, "Usage: /creategarage <price> <type> || Use /garagetypes for a list of garage types.");
- new Float:X, Float:Y, Float:Z;
- GetPlayerPos(playerid, X,Y,Z);
- format(gInfo[garageCount][Owner],24,"the State");
- gInfo[garageCount][Owned] = 0;
- gInfo[garageCount][Price] = price;
- gInfo[garageCount][Interior] = type;
- gInfo[garageCount][UID] = garageCount;
- gInfo[garageCount][PosX] = X;
- gInfo[garageCount][PosY] = Y;
- gInfo[garageCount][PosZ] = Z;
- gInfo[garageCount][Locked] = 1;
- new path[128];
- format(path,sizeof(path),"garages/%d.ini",garageCount); //Format the path with the filenumber
- dini_Create(path);
- Save_Garage(garageCount);
- UpdateGarageInfo(garageCount);
- garageCount++;
- SendClientMessage(playerid,COLOR_SUCCESS,"Garage created!");
- return 1;
- }
- if(strcmp("/removegarage", cmdtext, true, 13) == 0)
- {
- if(!IsPlayerAdmin(playerid)) return 0;
- for(new i=0; i < garageCount+1; i++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
- {
- format(gInfo[i][Owner],24,"REMOVED");
- gInfo[i][Owned] = -999;
- gInfo[i][Price] = -999;
- gInfo[i][Interior] = -999;
- gInfo[i][UID] = -999;
- gInfo[i][PosX] = -999;
- gInfo[i][PosY] = -999;
- gInfo[i][PosZ] = -999;
- gInfo[i][Locked] = -999;
- DestroyDynamic3DTextLabel(garageLabel[i]);
- DestroyDynamicPickup(garagePickup[i]);
- new path[128];
- format(path,sizeof(path),"garages/%d.ini",i); //Format the path with the filenumber
- dini_Remove(path);
- SendClientMessage(playerid, COLOR_SUCCESS, "You have removed this garage.");
- return 1;
- }
- }
- SendClientMessage(playerid, COLOR_ERROR,"Error: You're not near any garage.");
- return 1;
- }
- if(strcmp("/genter", cmdtext, true, 7) == 0)
- {
- for(new i=0; i < garageCount+1; i++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
- {
- 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.");
- new gtype = gInfo[i][Interior];
- if(!IsPlayerInAnyVehicle(playerid))
- {
- SetPlayerVirtualWorld(playerid,gInfo[i][UID]);
- SetPlayerInterior(playerid,floatround(GarageInteriors[gtype][4]));
- SetPlayerPos(playerid,GarageInteriors[gtype][0],GarageInteriors[gtype][1],GarageInteriors[gtype][2]);
- lastGarage[playerid] = i;
- }
- else
- {
- new vid = GetPlayerVehicleID(playerid);
- LinkVehicleToInterior(vid,floatround(GarageInteriors[gtype][4]));
- SetVehicleVirtualWorld(vid,gInfo[i][UID]);
- SetPlayerVirtualWorld(playerid,gInfo[i][UID]);
- SetPlayerInterior(playerid,floatround(GarageInteriors[gtype][4]));
- SetVehiclePos(vid,GarageInteriors[gtype][0],GarageInteriors[gtype][1],GarageInteriors[gtype][2]);
- lastGarage[playerid] = i;
- }
- return 1;
- }
- }
- SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage. ");
- return 1;
- }
- if(strcmp("/gexit", cmdtext, true, 6) == 0)
- {
- if(lastGarage[playerid] >= 0)
- {
- new lg = lastGarage[playerid];
- if(!IsPlayerInAnyVehicle(playerid))
- {
- SetPlayerPos(playerid,gInfo[lg][PosX],gInfo[lg][PosY],gInfo[lg][PosZ]);
- SetPlayerInterior(playerid,0);
- SetPlayerVirtualWorld(playerid,0);
- }
- else
- {
- new vid = GetPlayerVehicleID(playerid);
- LinkVehicleToInterior(vid,0);
- SetVehicleVirtualWorld(vid,0);
- SetVehiclePos(vid,gInfo[lg][PosX],gInfo[lg][PosY],gInfo[lg][PosZ]);
- SetPlayerVirtualWorld(playerid,0);
- SetPlayerInterior(playerid,0);
- }
- lastGarage[playerid] = -999;
- }
- else return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not in any garage.");
- return 1;
- }
- if(strcmp("/buygarage", cmdtext, true, 10) == 0)
- {
- for(new i=0; i < garageCount+1; i++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
- {
- if(gInfo[i][Owned] == 1) return SendClientMessage(playerid, COLOR_ERROR,"Error: This garage is already owned.");
- if(GetPlayerMoney(playerid) < gInfo[i][Price]) return SendClientMessage(playerid,COLOR_ERROR,"Error: You don't have enough money to buy this garage.");
- GivePlayerMoney(playerid,-gInfo[i][Price]);
- gInfo[i][Price]-= random(5000); //Take some money off of the original price
- format(gInfo[i][Owner],24,"%s",GetPlayerNameEx(playerid));
- gInfo[i][Owned] = 1;
- Save_Garage(i);
- UpdateGarageInfo(i);
- SendClientMessage(playerid,COLOR_SUCCESS,"You have successfully bought this garage.");
- return 1;
- }
- }
- SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage.");
- return 1;
- }
- if(strcmp("/lockgarage", cmdtext, true, 10) == 0)
- {
- for(new i=0; i < garageCount+1; i++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
- {
- if(strcmp(gInfo[i][Owner],GetPlayerNameEx(playerid))) return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not the owner of this garage.");
- if(gInfo[i][Locked] == 1)
- {
- gInfo[i][Locked] = 0;
- UpdateGarageInfo(i);
- Save_Garage(i);
- SendClientMessage(playerid,COLOR_SUCCESS,"You have unlocked your garage.");
- return 1;
- }
- else
- {
- gInfo[i][Locked] = 1;
- UpdateGarageInfo(i);
- Save_Garage(i);
- SendClientMessage(playerid,COLOR_SUCCESS,"You have locked your garage.");
- return 1;
- }
- }
- }
- SendClientMessage(playerid,COLOR_ERROR,"Error: You're not near any garage.");
- return 1;
- }
- if(strcmp("/sellgarage", cmdtext, true, 11) == 0)
- {
- for(new i=0; i < garageCount+1; i++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 3.0, gInfo[i][PosX], gInfo[i][PosY], gInfo[i][PosZ]))
- {
- if(strcmp(gInfo[i][Owner],GetPlayerNameEx(playerid))) return SendClientMessage(playerid,COLOR_ERROR,"Error: You're not the owner of this garage.");
- GivePlayerMoney(playerid,gInfo[i][Price]-random(500));
- gInfo[i][Owned] = 0;
- format(gInfo[i][Owner],24,"the State");
- gInfo[i][Locked] = 1;
- UpdateGarageInfo(i);
- Save_Garage(i);
- SendClientMessage(playerid, COLOR_SUCCESS,"You have successfully sold your garage.");
- return 1;
- }
- }
- SendClientMessage(playerid, COLOR_ERROR,"You're not near any garage.");
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement