Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- forward OnLoadGarages();
- public OnLoadGarages()
- {
- new Cache: result, ID1, rows,countsuccess, countfailed;
- result = mysql_query(MySQLCon,"SELECT * FROM `garages` ORDER BY `ID1` ASC", true);
- rows = cache_num_rows();
- if(rows >= 1)
- {
- for (new row; row < rows; row++)
- {
- ID1 = cache_get_field_content_int(row, "ID1");
- if ((ID1 < 1) || (ID1 >= MAX_GARAGES))
- {
- countfailed++;
- printf("*** ERROR: Invalid ID found in table \"garages\": %i", ID1);
- continue;
- }
- cache_get_field_content(row, "Owner", GarageInfo[ID1][Owner], MAX_PLAYER_NAME);
- GarageInfo[ID1][Owned] = cache_get_field_content_int(row, "Owned");
- //GarageInfo[ID1][Size] = cache_get_field_content_int(row, "Size");
- GarageInfo[ID1][Price] = cache_get_field_content_int(row, "Price");
- GarageInfo[ID1][eX] = cache_get_field_content_float(row, "eX");
- GarageInfo[ID1][eY] = cache_get_field_content_float(row, "eY");
- GarageInfo[ID1][eZ] = cache_get_field_content_float(row, "eZ");
- //edit
- GarageInfo[ID1][GarajVirtual] = cache_get_field_content_int(row, "GarajVirtual");
- GarageInfo[ID1][Iesirex] = cache_get_field_content_float(row, "Iesirex");
- GarageInfo[ID1][Iesirey] = cache_get_field_content_float(row, "Iesirey");
- GarageInfo[ID1][Iesirez] = cache_get_field_content_float(row, "Iesirez");
- OnGarage_Update(ID1);
- countsuccess++;
- }
- }
- printf("*** >>> Garages loaded: %i (successful: %i, failed: %i)", rows, countsuccess, countfailed);
- printf("");
- cache_delete(result);
- }
- forward OnGarage_Update(GarageID);
- public OnGarage_Update(GarageID)
- {
- new Msg[64], Float:x, Float:y, Float:z;
- x = GarageInfo[GarageID][eX];
- y = GarageInfo[GarageID][eY];
- z = GarageInfo[GarageID][eZ];
- if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
- DestroyDynamicPickup(GarageInfo[GarageID][PickupID]);
- if (IsValidDynamicMapIcon(GarageInfo[GarageID][MapiconID]))
- DestroyDynamicMapIcon(GarageInfo[GarageID][MapiconID]);
- if (IsValidDynamic3DTextLabel(GarageInfo[GarageID][Label]))
- DestroyDynamic3DTextLabel(GarageInfo[GarageID][Label]);
- if (GarageInfo[GarageID][Owned] == 1)
- {
- GarageInfo[GarageID][PickupID] = CreateDynamicPickup(1272, 1, x, y, z, 0);
- format(Msg, sizeof(Msg), "ID: %i\nOwned by: %s\n/enter", GarageID, GarageInfo[GarageID][Owner]);
- GarageInfo[GarageID][Label] = CreateDynamic3DTextLabel(Msg, 0x008080FF, x, y, z + 1.0, 50.0);
- }
- else
- {
- GarageInfo[GarageID][PickupID] = CreateDynamicPickup(1273, 1, x, y, z, 0);
- format(Msg, sizeof(Msg), "Garage available for\n$%i\n/buygarage", GarageInfo[GarageID][Price]);
- GarageInfo[GarageID][Label] = CreateDynamic3DTextLabel(Msg, 0x008080FF, x, y, z + 1.0, 50.0);
- // Add a streamed icon to the map (green garage), type = 31, color = 0, world = 0, interior = 0, playerid = -1, drawdist = 150.0
- GarageInfo[GarageID][MapiconID] = CreateDynamicMapIcon(x, y, z, 31, 0, 0, 0, -1, 150.0);
- }
- }
- forward OnGarage_SetOwner(playerid, GarageID);
- public OnGarage_SetOwner(playerid, GarageID)
- {
- if(GarageInfo[GarageID][Owner] == 1)
- {
- new Name1[MAX_PLAYER_NAME], Msg[128];
- GetPlayerName(playerid, Name1, sizeof(Name1));
- GarageInfo[GarageID][Owned] = 1;
- format(GarageInfo[GarageID][Owner], sizeof(Name1), Name1);
- GiveMoney(playerid, -GarageInfo[GarageID][Price]);
- OnGarage_Update(GarageID);
- mysql_format(MySQLCon, Msg, sizeof(Msg), "UPDATE `garages` SET `Owner` = '%e' , `Owned` = 1 WHERE `ID1` = %i" , GarageInfo[GarageID][Owner] , GarageID);
- mysql_tquery(MySQLCon, Msg, "","");
- format(Msg, sizeof(Msg), "You've bought the garage for $%i", GarageInfo[GarageID][Price]);
- SendClientMessage(playerid, -1, Msg);
- }
- else if(GarageInfo[GarageID][Owner] == 0)
- {
- new Name1[MAX_PLAYER_NAME], Msg[128];
- GetPlayerName(playerid, Name1, sizeof(Name1));
- GarageInfo[GarageID][Owned] = 1;
- format(GarageInfo[GarageID][Owner], sizeof(Name1), Name1);
- GiveMoney(playerid, -GarageInfo[GarageID][Price]);
- OnGarage_Update(GarageID);
- mysql_format(MySQLCon, Msg, sizeof(Msg), "UPDATE `garages` SET `Owner` = '%e' , `Owned` = 1 WHERE `ID1` = %i" , GarageInfo[GarageID][Owner] , GarageID);
- mysql_tquery(MySQLCon, Msg, "","");
- format(Msg, sizeof(Msg), "You've bought the garage for $%i", GarageInfo[GarageID][Price]);
- SendClientMessage(playerid, -1, Msg);
- }
- return 1;
- }
- forward OnGarage_PlayerIsOwner(playerid, GarageID);
- public OnGarage_PlayerIsOwner(playerid, GarageID)// This function returns "1" if the given player is the owner of the given garage
- {
- new Name1[MAX_PLAYER_NAME];
- GetPlayerName(playerid, Name1 , MAX_PLAYER_NAME);
- if(strcmp(GarageInfo[GarageID][Owner], Name1, false) == 0)
- return 1;
- return 0;
- }
- CMD:creategarage(playerid,params[])
- {
- if(pInfo[playerid][pAdmin] < 5) return SCM(playerid, -1, "Nu poti vedea comenzile de la acest nivel de admin!");
- new buyprice, ID1, tip;
- if(GetPlayerVehicleID(playerid) != 0) return SendClientMessage(playerid, -1, "You must be on foot to create a garage.");
- for (ID1 = 1; ID1 < MAX_GARAGES; ID1++)
- if (!IsValidDynamicPickup(GarageInfo[ID1][PickupID]))
- break;
- if (ID1 == MAX_GARAGES) return SendClientMessage(playerid, -1, "The maximum amount of garages has been reached.");
- if (!IsValidDynamicPickup(GarageInfo[ID1][PickupID]))
- {
- new Float:x, Float:y, Float:z, Msg[128];
- GetPlayerPos(playerid, x, y, z);
- //edit
- if(unformat(params, "ii", tip, buyprice))
- {
- SendClientMessage(playerid, 0xFF0000AA, "Foloseste: /creategaraj <modelid> <pret>");
- return 1;
- }
- if(!(tip == 1 || tip == 2))
- {
- SendClientMessage(playerid, 0xFF0000AA, "Model-ul pot fi de la 1 la 2");
- return 1;
- }
- if(tip == 1)
- {
- GarageInfo[ID1][Owned] = 0;
- format(GarageInfo[ID1][Owner], MAX_PLAYER_NAME, "None");
- GarageInfo[ID1][eX] = x;
- GarageInfo[ID1][eY] = y;
- GarageInfo[ID1][eZ] = z;
- GarageInfo[ID1][Price] = buyprice;
- //GarageInfo[ID1][Size] = size; Size,
- GarageInfo[ID1][GarajVirtual] = ID1;
- GarageInfo[ID1][Iesirex] = 594.2872; //1
- GarageInfo[ID1][Iesirey] = 1674.7228; //2
- GarageInfo[ID1][Iesirez] = 6.6259; //3
- OnGarage_Update(ID1);
- mysql_format(MySQLCon, Msg, sizeof(Msg), "INSERT INTO `garages` (ID1 , eX , eY, eZ , Owner, Price, GarajVirtual, Iesirex, Iesirey, Iesirez) VALUES (%i , %f , %f, %f , '%e', %i , %i, %f , %f, %f)" , ID1, x, y, z , GarageInfo[ID1][Owner], buyprice);
- mysql_tquery(MySQLCon, Msg, "","");
- format(Msg, sizeof(Msg), "{00FF00}You've succesfully created a garage with ID: {FFFF00}%i", ID1);
- SendClientMessage(playerid, -1, Msg);
- }
- else if(tip == 2)// mare
- {
- GarageInfo[ID1][Owned] = 0;
- format(GarageInfo[ID1][Owner], MAX_PLAYER_NAME, "None");
- GarageInfo[ID1][eX] = x;
- GarageInfo[ID1][eY] = y;
- GarageInfo[ID1][eZ] = z;
- GarageInfo[ID1][Price] = buyprice;
- //GarageInfo[ID1][Size] = size;
- GarageInfo[ID1][GarajVirtual] = ID1;
- GarageInfo[ID1][Iesirex] = 582.9892; //1
- GarageInfo[ID1][Iesirey] = 1675.9623; //2
- GarageInfo[ID1][Iesirez] = 6.6259; //3
- OnGarage_Update(ID1);
- mysql_format(MySQLCon, Msg, sizeof(Msg), "INSERT INTO `garages` (ID1 , eX , eY, eZ , Owner, Price, Iesirex, Iesirey, Iesirez) VALUES (%i , %f , %f, %f , '%e', %i , %i)" , ID1, x, y, z , GarageInfo[ID1][Owner], buyprice);
- mysql_tquery(MySQLCon, Msg, "","");
- format(Msg, sizeof(Msg), "{00FF00}You've succesfully created a garage with ID: {FFFF00}%i", ID1);
- SendClientMessage(playerid, -1, Msg);
- }
- }
- else
- SendClientMessage(playerid, -1, "The maximum amount of garages has been reached");
- return 1;
- }
- CMD:enter(playerid, params[])
- {
- new vehicleid = GetPlayerVehicleID(playerid);
- new GarageID;
- for (GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
- if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
- {
- if(IsPlayerInRangeOfPoint(playerid, 1.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
- {
- if (OnGarage_PlayerIsOwner(playerid, GarageID) == 0)
- {
- SendClientMessage(playerid, -1, "You are not the owner of this garage.");
- return 1;
- }
- if(IsPlayerInAnyVehicle(playerid))
- {
- PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
- SetVehiclePos(vehicleid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
- SetVehicleVirtualWorld(vehicleid, GarageInfo[GarageID][GarajVirtual]); SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);break;
- }
- else
- {
- PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
- SetPlayerPos(playerid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
- SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);break;
- }
- }
- else
- {
- if(GarageInfo[GarageID][GarajVirtual] == 0)
- {
- if(IsPlayerInAnyVehicle(playerid))
- {
- PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
- SetVehiclePos(vehicleid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
- SetVehicleVirtualWorld(vehicleid, GarageInfo[GarageID][GarajVirtual]); SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);
- break;
- }
- else
- {
- PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
- SetPlayerPos(playerid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
- SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);
- break;
- }
- }
- }
- }
- }
- return 0;
- }
- CMD:exitgarage(playerid,params[])
- {
- new vehicleid = GetPlayerVehicleID(playerid);
- new nume1[MAX_PLAYER_NAME];
- GetPlayerName(playerid, nume1, sizeof(nume1));
- new GarageID = PlayerGarageID[playerid];
- if(PlayerGarageID[playerid] != 0)
- if(IsPlayerInRangeOfPoint(playerid, 1.5, GarageInfo[GarageID][eX] , GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
- {
- if(IsPlayerInAnyVehicle(playerid))
- {
- PlayerGarageID[playerid] = 0; SetVehicleVirtualWorld(vehicleid, 0);
- SetVehiclePos(vehicleid, GarageInfo[GarageID][Intrarex], GarageInfo[GarageID][Intrarey], GarageInfo[GarageID][Intrarez]); SetPlayerVirtualWorld(playerid, 0);
- SendClientMessage(playerid, -1 , "You exit the garage.");
- }
- else
- {
- SetPlayerPos(playerid, GarageInfo[GarageID][Intrarex], GarageInfo[GarageID][Intrarey], GarageInfo[GarageID][Intrarez]);
- SetPlayerVirtualWorld(playerid, 0); PlayerGarageID[playerid] = 0;
- SendClientMessage(playerid, -1 , "You exit the garage.");
- }
- }
- else
- {
- SendClientMessage(playerid, 0xFFFFFFFF, "Trebuie sa fii in fata iesirii unui garaj");
- }
- return 1;
- }
- CMD:buygarage(playerid, params[])
- {
- if (GetPlayerVehicleSeat(playerid) == -1)
- {
- for (new GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
- {
- if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
- {
- if (IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
- {
- if (GarageInfo[GarageID][Owned] == 0)
- {
- if (GetPlayerMoney(playerid) >= GarageInfo[GarageID][Price])
- OnGarage_SetOwner(playerid, GarageID);
- else
- SendClientMessage(playerid, -1, "You cannot afford this garage");
- }
- else
- {
- new Msg[128];
- format(Msg, sizeof(Msg), "This garage is already owned by {FFFF00}%s", GarageInfo[GarageID][Owner]);
- SendClientMessage(playerid, -1, Msg);
- }
- return 1;
- }
- }
- }
- SendClientMessage(playerid, -1, "To buy a garage, you have to be near a garage-pickup");
- }
- else
- SendClientMessage(playerid, -1, "You can't buy a garage when you're inside a vehicle");
- return 1;
- }
- CMD:delgarage(playerid, params[])
- {
- if(pInfo[playerid][pAdmin] < 5) return SCM(playerid, -1, "Nu poti vedea comenzile de la acest nivel de admin!");
- new Msg[128], Name1[24];
- if (GetPlayerVehicleSeat(playerid) == -1)
- {
- for (new GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
- {
- if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
- {
- if (IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
- {
- if (GarageInfo[GarageID][Owned] == 1)
- {
- for (new pid = 0 , j = GetPlayerPoolSize(); pid <= j; pid++)
- {
- if (IsPlayerConnected(pid))
- {
- GetPlayerName(pid, Name1, sizeof(Name1));
- if (strcmp(GarageInfo[GarageID][Owner], Name1, false) == 0)
- {
- SendClientMessage(pid, -1, "Your garage is being deleted.");
- }
- }
- }
- }
- GarageInfo[GarageID][Owned] = 0;
- format(GarageInfo[GarageID][Owned] , MAX_PLAYER_NAME , "None");
- GarageInfo[GarageID][eX] = 0.0;
- GarageInfo[GarageID][eY] = 0.0;
- GarageInfo[GarageID][eZ] = 0.0;
- GarageInfo[GarageID][Price] = 0;
- GarageInfo[GarageID][Size] = 0;
- GarajInfo[GarageID][GarajVirtual] = 0;
- GarajInfo[GarageID][Iesirex] = 0; //1
- GarajInfo[GarageID][Iesirey] = 0; //2
- GarajInfo[GarageID][Iesirez] = 0; //3
- DestroyDynamicPickup(GarageInfo[GarageID][PickupID]);
- DestroyDynamicMapIcon(GarageInfo[GarageID][MapiconID]);
- DestroyDynamic3DTextLabel(GarageInfo[GarageID][Label]);
- GarageInfo[GarageID][PickupID] = 0;
- GarageInfo[GarageID][MapiconID] = 0;
- mysql_format(MySQLCon, Msg, sizeof(Msg), "DELETE FROM `garages` WHERE `ID1` = %i LIMIT 1" , GarageID);
- mysql_tquery(MySQLCon, Msg, "","");
- format(Msg, 128, "{00FF00}You have deleted the garage with ID: {FFFF00}%i", GarageID);
- SendClientMessage(playerid, -1, Msg);
- return 1;
- }
- }
- }
- SendClientMessage(playerid, -1, "No garage in range to delete");
- }
- else
- SendClientMessage(playerid, -1, "You must be on foot to delete a garage");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment