Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <a_mysql>
- #define Color_Grey 0xAFAFAFAA
- #define Color_Green 0x33AA33AA
- #define Color_Red 0xAA3333AA
- #define MySql_Database "Bitte_Anpassen"
- enum fCarDealer
- {
- fModel,
- fName[32],
- fPrice,
- Float: fX,
- Float: fY,
- Float: fZ,
- Float: fR,
- fVehid,
- }
- new fCarDealerCars[2][fCarDealer] = {
- {411,"Infernus",5000,1489.6309,2838.5767,10.5474,180.6838,-1},
- {560,"Sultan",5000,1484.5950,2838.9211,10.5474,179.9544,-1}
- };
- enum fCars
- {
- fModel,
- Float: fX,
- Float: fY,
- Float: fZ,
- Float: fR,
- fc1,
- fc2,
- fFaction,
- fSQLid,
- fVehid,
- bool:fExist,
- }
- new FactionCars[100][fCars];
- public OnFilterScriptInit()
- {
- LoadFactionCars();
- for(new i = 0; i < sizeof(fCarDealerCars); i++)
- {
- new c1 = random(126), c2 = random(126);
- fCarDealerCars[i][fVehid] = CreateVehicle(fCarDealerCars[i][fModel], fCarDealerCars[i][fX], fCarDealerCars[i][fY], fCarDealerCars[i][fZ], fCarDealerCars[i][fR], c1, c2, 60000);
- }
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new string[128];
- if(strcmp(cmdtext, "/buyfcar", true) == 0)
- {
- new vehid = GetPlayerVehicleID(playerid), car = IsPlayerInAFBuyAbleCar(vehid);
- if(car != -1)
- {
- new Leader = CallRemoteFunction("GetPlayerLeaderID", "d", playerid);
- if(Leader != 0)
- {
- if(GetPlayerMoney(playerid) >= fCarDealerCars[car][fPrice])
- {
- new Slot = GetFreeFactionCarSlot();
- if(Slot != -1)
- {
- FactionCars[Slot][fModel] = fCarDealerCars[car][fModel];
- FactionCars[Slot][fFaction] = Leader;
- FactionCars[Slot][fExist] = true;
- mysql_query("INSERT INTO `factioncars`(`model`) VALUES (1)");
- mysql_query("SELECT max(id) FROM `factioncars`");
- mysql_store_result();
- mysql_fetch_row_format(string);
- FactionCars[Slot][fSQLid] = strval(string);
- FactionCars[Slot][fVehid] = CreateVehicle(FactionCars[Slot][fModel], 0.0, 0.0, 0.0, 0.0, 0, 0, 0);
- UpdateFactionCar(Slot);
- format(string, sizeof(string),"Info: Du hast dieses Fahrzeug für %d$ gekauft.", fCarDealerCars[car][fPrice]);
- SendClientMessage(playerid, Color_Green, string);
- GivePlayerMoney(playerid, -fCarDealerCars[car][fPrice]);
- return 1;
- }
- }
- else
- {
- format(string, sizeof(string), "Info: Du hast nicht genügend Geld. Dieses Fahrzeug kostet: %d$", fCarDealerCars[car][fPrice]);
- SendClientMessage(playerid, Color_Red, string);
- }
- }
- else return SendClientMessage(playerid, Color_Red, "Info: Du bist kein Leader einer Fraktion.");
- }
- else return SendClientMessage(playerid, Color_Red, "Info: Du befindest dich nicht in einem Kaufbaren Fahrzeug.");
- }
- if(strcmp(cmdtext, "/fpark", true) == 0)
- {
- new car = IsPlayerInAFactionCar(GetPlayerVehicleID(playerid));
- if(car != -1)
- {
- new Leader = CallRemoteFunction("GetPlayerLeaderID", "d", playerid);
- if(Leader != 0)
- {
- if(Leader == FactionCars[car][fFaction])
- {
- new Float: X, Float: Y, Float: Z, Float: R;
- GetPlayerPos(playerid, X, Y, Z);
- GetPlayerFacingAngle(playerid, R);
- FactionCars[car][fX] = X;
- FactionCars[car][fY] = Y;
- FactionCars[car][fZ] = Z;
- FactionCars[car][fR] = R;
- UpdateFactionCar(car);
- SendClientMessage(playerid, Color_Green, "Info: Fahrzeug geparkt.");
- return 1;
- }
- else return SendClientMessage(playerid, Color_Red, "Info: Dieses Fahrzeug gehört nicht zu deiner Fraktion.");
- }
- else return SendClientMessage(playerid, Color_Red, "Info: Du bist kein Leader.");
- }
- else return SendClientMessage(playerid, Color_Red, "Info: Du befindest dich in keinem Fraktion´s Fahrzeug.");
- }
- if(strcmp(cmdtext, "/fsellcar", true) == 0)
- {
- new car = IsPlayerInAFactionCar(GetPlayerVehicleID(playerid));
- if(car != -1)
- {
- new Leader = CallRemoteFunction("GetPlayerLeaderID", "d", playerid);
- if(Leader != 0)
- {
- if(Leader == FactionCars[car][fFaction])
- {
- for(new i = 0; i < sizeof(fCarDealerCars); i++)
- {
- if(GetVehicleModel(GetPlayerVehicleID(playerid)) == fCarDealerCars[i][fModel])
- {
- GivePlayerMoney(playerid, fCarDealerCars[i][fPrice]/2);
- DestroyVehicle(GetPlayerVehicleID(playerid));
- FactionCars[car][fExist] = false;
- SendClientMessage(playerid, Color_Green, "Info: Du hast dieses Fahrzeug für die hälfte des neupreises verkauft.");
- format(string, sizeof(string), "DELETE FROM `%s`.`factioncars` WHERE `factioncars`.`id` = %d", MySql_Database, FactionCars[car][fSQLid]);
- mysql_query(string);
- return 1;
- }
- }
- return 1;
- }
- else return SendClientMessage(playerid, Color_Red, "Info: Dieses Fahrzeug gehört nicht zu deiner Fraktion.");
- }
- else return SendClientMessage(playerid, Color_Red, "Info: Du bist kein Leader.");
- }
- else return SendClientMessage(playerid, Color_Red, "Info: Du befindest dich in keinem Fraktion´s Fahrzeug.");
- }
- return 0;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- new string[128];
- if(newstate == PLAYER_STATE_DRIVER)
- {
- new vehid = GetPlayerVehicleID(playerid), car = IsPlayerInAFBuyAbleCar(vehid);
- if(car != -1)
- {
- new Leader = CallRemoteFunction("GetPlayerLeaderID", "d", playerid);
- if(Leader != 0)
- {
- SendClientMessage(playerid, Color_Green, "==============[ Fraktion´s Autohaus ]===============");
- format(string, sizeof(string), "Model: %s", fCarDealerCars[car][fName]);
- SendClientMessage(playerid, Color_Grey, string);
- format(string, sizeof(string), "Preis: %d$", fCarDealerCars[car][fPrice]);
- SendClientMessage(playerid, Color_Grey, string);
- SendClientMessage(playerid, Color_Grey, "Du kannst dieses Fahrzeug mit \"/buyfcar\" kaufen oder einfach wieder verlassen.");
- SendClientMessage(playerid, Color_Green, "====================================================");
- return 1;
- }
- else
- {
- SendClientMessage(playerid, Color_Red, "Info: Du bist kein Leader einer Fraktion.");
- RemovePlayerFromVehicle(playerid);
- return 1;
- }
- }
- car = IsPlayerInAFactionCar(vehid);
- if(car != -1)
- {
- new Faction = CallRemoteFunction("GetPlayerFactionID", "d", playerid);
- if(Faction != FactionCars[car][fFaction])
- {
- SendClientMessage(playerid, Color_Red, "Info: Du befindest dich nicht in der richtigen Fraktion.");
- RemovePlayerFromVehicle(playerid);
- return 1;
- }
- }
- }
- return 1;
- }
- stock IsPlayerInAFBuyAbleCar(carid)
- {
- for(new i = 0; i < sizeof(fCarDealerCars); i++)
- {
- if(carid == fCarDealerCars[i][fVehid])
- {
- return i;
- }
- }
- return -1;
- }
- stock IsPlayerInAFactionCar(carid)
- {
- for(new i = 0; i < sizeof(FactionCars); i++)
- {
- if(FactionCars[i][fExist] == true && FactionCars[i][fVehid] == carid)
- {
- return i;
- }
- }
- return -1;
- }
- stock GetFreeFactionCarSlot()
- {
- for(new i = 0; i < sizeof(FactionCars); i++)
- {
- if(FactionCars[i][fExist]==false)return i;
- }
- return -1;
- }
- stock LoadFactionCars()
- {
- new Load[16], idx;
- mysql_query("SELECT * FROM factioncars");
- mysql_store_result();
- while(mysql_retrieve_row())
- {
- mysql_fetch_field_row(Load, "Model");
- FactionCars[idx][fModel] = strval(Load);
- mysql_fetch_field_row(Load, "X");
- FactionCars[idx][fX] = floatstr(Load);
- mysql_fetch_field_row(Load, "Y");
- FactionCars[idx][fY] = floatstr(Load);
- mysql_fetch_field_row(Load, "Z");
- FactionCars[idx][fZ] = floatstr(Load);
- mysql_fetch_field_row(Load, "R");
- FactionCars[idx][fR] = floatstr(Load);
- mysql_fetch_field_row(Load, "C1");
- FactionCars[idx][fc1] = strval(Load);
- mysql_fetch_field_row(Load, "C2");
- FactionCars[idx][fc2] = strval(Load);
- mysql_fetch_field_row(Load, "Faction");
- FactionCars[idx][fFaction] = strval(Load);
- mysql_fetch_field_row(Load, "id");
- FactionCars[idx][fSQLid] = strval(Load);
- FactionCars[idx][fVehid] = CreateVehicle(FactionCars[idx][fModel], FactionCars[idx][fX], FactionCars[idx][fY], FactionCars[idx][fZ], FactionCars[idx][fR], FactionCars[idx][fc1], FactionCars[idx][fc2], 60000);
- idx ++;
- }
- mysql_free_result();
- }
- stock UpdateFactionCar(id)
- {
- new Query[128];
- if(FactionCars[id][fExist] == true)
- {
- format(Query, sizeof(Query), "UPDATE factioncars SET `Model` = '%d' WHERE `id` = '%d'", FactionCars[id][fModel], FactionCars[id][fSQLid]);
- mysql_query(Query);
- format(Query, sizeof(Query), "UPDATE factioncars SET `X` = '%f' WHERE `id` = '%d'", FactionCars[id][fX], FactionCars[id][fSQLid]);
- mysql_query(Query);
- format(Query, sizeof(Query), "UPDATE factioncars SET `Y` = '%f' WHERE `id` = '%d'", FactionCars[id][fY], FactionCars[id][fSQLid]);
- mysql_query(Query);
- format(Query, sizeof(Query), "UPDATE factioncars SET `Z` = '%f' WHERE `id` = '%d'", FactionCars[id][fZ], FactionCars[id][fSQLid]);
- mysql_query(Query);
- format(Query, sizeof(Query), "UPDATE factioncars SET `R` = '%f' WHERE `id` = '%d'", FactionCars[id][fR], FactionCars[id][fSQLid]);
- mysql_query(Query);
- format(Query, sizeof(Query), "UPDATE factioncars SET `C1` = '%d' WHERE `id` = '%d'", FactionCars[id][fc1], FactionCars[id][fSQLid]);
- mysql_query(Query);
- format(Query, sizeof(Query), "UPDATE factioncars SET `C2` = '%d' WHERE `id` = '%d'", FactionCars[id][fc2], FactionCars[id][fSQLid]);
- mysql_query(Query);
- format(Query, sizeof(Query), "UPDATE factioncars SET `Faction` = '%d' WHERE `id` = '%d'", FactionCars[id][fFaction], FactionCars[id][fSQLid]);
- mysql_query(Query);
- }
- return 1;
- }
- /*
- forward GetPlayerFactionID(playerid);
- public GetPlayerFactionID(playerid)
- {
- if(PlayerInfo[playerid][pLeader]!=0)return PlayerInfo[playerid][pLeader];
- else if(PlayerInfo[playerid][pMember]!=0)return PlayerInfo[playerid][pMember];
- }
- forward GetPlayerLeaderID(playerid);
- public GetPlayerLeaderID(playerid)
- {
- return PlayerInfo[playerid][pLeader];
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement