Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include < a_samp >
- #include < YSI\y_ini >
- #include < zcmd >
- #include < sscanf2 >
- #define MAX_RENTS 30
- #define RENT_FILE "/Rent/%d.ini"
- enum {
- DIALOG_RENT,
- DIALOG_RENTVREME
- }
- enum RENT_INFO {
- Float:rentX,
- Float:rentY,
- Float:rentZ,
- Text3D:RentLabel,
- rentID
- }
- new RentInfo[ MAX_RENTS ][ RENT_INFO ], IznajmioVozilo[ MAX_PLAYERS ], RentVeh[ MAX_PLAYERS ], RentOdabir[ MAX_PLAYERS ],
- RentVreme[ MAX_PLAYERS ], RentTimer[ MAX_PLAYERS ], Text3D:RentVehLabel[ MAX_VEHICLES ], TipVozila[ MAX_VEHICLES ];
- public OnGameModeInit() {
- for(new i; i < MAX_RENTS; i++) {
- new jFile[ 50 ];
- format(jFile, sizeof(jFile), RENT_FILE, i);
- if(fexist(jFile)) {
- INI_ParseFile(jFile, "LoadRent", .bExtra = true, .extra = i);
- RentInfo[ i ][ rentID ] = CreatePickup(19132, 1, RentInfo[ i ][ rentX ], RentInfo[ i ][ rentY ], RentInfo[ i ][ rentZ ], 0);
- RentInfo[ i ][ RentLabel ] = Create3DTextLabel("[ RENT ]\n{FFFFFF}Da iznajmite vozilo, kucajte\n{0077C7}/rent", 0x0077C7FF, RentInfo[ i ][ rentX ], RentInfo[ i ][ rentY ], RentInfo[ i ][ rentZ ], 10.0, 0, 0);
- }
- }
- return 1;
- }
- forward LoadRent(id, name[], value[]);
- public LoadRent(id, name[], value[]) {
- INI_Float("Lokacija_X", RentInfo[ id ][ rentX ]);
- INI_Float("Lokacija_Y", RentInfo[ id ][ rentY ]);
- INI_Float("Lokacija_Z", RentInfo[ id ][ rentZ ]);
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
- switch(dialogid) {
- case DIALOG_RENT: {
- if(!response) return 1;
- switch(listitem) {
- case 0: {
- RentOdabir[ playerid ] = 1;
- ShowPlayerDialog(playerid, DIALOG_RENTVREME, DIALOG_STYLE_INPUT, "{0077C7}Iznamljivanje {FFFFFF}vozila","{FFFFFF}Unesite vreme na koliko ce te iznajmiti vozilo.\nMinimalno vreme - 1 minut.\nMaksimalno vreme - 30 minuta.\nCena - 1 minut = 100$","U redu","Izlaz");
- }
- case 1: {
- RentOdabir[ playerid ] = 2;
- ShowPlayerDialog(playerid, DIALOG_RENTVREME, DIALOG_STYLE_INPUT, "{0077C7}Iznamljivanje {FFFFFF}vozila","{FFFFFF}Unesite vreme na koliko ce te iznajmiti vozilo.\nMinimalno vreme - 1 minut.\nMaksimalno vreme - 30 minuta.\nCena - 1 minut = 70$","U redu","Izlaz");
- }
- }
- }
- case DIALOG_RENTVREME: {
- if(!response) return 1;
- new i = GetNearestRent(playerid);
- if(RentOdabir[ playerid ] == 1) {
- new vreme;
- if(GetPlayerMoney(playerid) < RentVreme[ playerid ]*100) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Nemate dovoljno novca.");
- if(sscanf(inputtext, "d", vreme)) return ShowPlayerDialog(playerid, DIALOG_RENTVREME, DIALOG_STYLE_INPUT, "{0077C7}Iznamljivanje {FFFFFF}vozila","{FFFFFF}Unesite vreme na koliko ce te iznajmiti vozilo.\nMinimalno vreme - 1 minut.\nMaksimalno vreme - 30 minuta.\nCena - 1 minut = 100$","U redu","Izlaz");
- if(vreme < 1 || vreme > 30) return ShowPlayerDialog(playerid, DIALOG_RENTVREME, DIALOG_STYLE_INPUT, "{0077C7}Iznamljivanje {FFFFFF}vozila","{FFFFFF}Unesite vreme na koliko ce te iznajmiti vozilo.\nMinimalno vreme - 1 minut.\nMaksimalno vreme - 30 minuta.\nCena - 1 minut = 100$","U redu","Izlaz");
- RentVreme[ playerid ] = vreme;
- RentVeh[ playerid ] = CreateVehicle(405, RentInfo[ i ][ rentX ]+2, RentInfo[ i ][ rentY ]+2, RentInfo[ i ][ rentZ ], 0.0, 1, 1, -1);
- PutPlayerInVehicle(playerid, RentVeh[ playerid ], 0);
- IznajmioVozilo[ playerid ] = GetPlayerVehicleID(playerid);
- GivePlayerMoney(playerid, -RentVreme[ playerid ]*100);
- RentTimer[ playerid ] = SetTimerEx("TimerRent", 60000, true, "i", playerid);
- SendClientMessage(playerid, 0x0077C7FF, "[RENT] {FFFFFF}Uspesno ste iznajmili vozilo.");
- RentVehLabel[ RentVeh[ playerid ] ] = Create3DTextLabel("[RENTANO VOZILO]", 0x0077C7FF, RentInfo[ i ][ rentX ]+2, RentInfo[ i ][ rentY ]+2, RentInfo[ i ][ rentZ ], 10.0, 0, 0);
- Attach3DTextLabelToVehicle(RentVehLabel[ RentVeh[ playerid ] ], RentVeh[ playerid ], 0.0, 0.0, 0.0);
- TipVozila[ RentVeh[ playerid ] ] = 1; // 1 - Rent Vozilo
- }
- else if(RentOdabir[ playerid ] == 2) {
- new vreme;
- if(GetPlayerMoney(playerid) < RentVreme[ playerid ]*70) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Nemate dovoljno novca.");
- if(sscanf(inputtext, "d", vreme)) return ShowPlayerDialog(playerid, DIALOG_RENTVREME, DIALOG_STYLE_INPUT, "{0077C7}Iznamljivanje {FFFFFF}vozila","{FFFFFF}Unesite vreme na koliko ce te iznajmiti vozilo.\nMinimalno vreme - 1 minut.\nMaksimalno vreme - 30 minuta.\nCena - 1 minut = 70$","U redu","Izlaz");
- if(vreme < 1 || vreme > 30) return ShowPlayerDialog(playerid, DIALOG_RENTVREME, DIALOG_STYLE_INPUT, "{0077C7}Iznamljivanje {FFFFFF}vozila","{FFFFFF}Unesite vreme na koliko ce te iznajmiti vozilo.\nMinimalno vreme - 1 minut.\nMaksimalno vreme - 30 minuta.\nCena - 1 minut = 70$","U redu","Izlaz");
- RentVreme[ playerid ] = vreme;
- RentVeh[ playerid ] = CreateVehicle(462, RentInfo[ i ][ rentX ]+2, RentInfo[ i ][ rentY ]+2, RentInfo[ i ][ rentZ ], 0.0, 1, 1, -1);
- PutPlayerInVehicle(playerid, RentVeh[ playerid ], 0);
- IznajmioVozilo[ playerid ] = GetPlayerVehicleID(playerid);
- GivePlayerMoney(playerid, -RentVreme[ playerid ]*70);
- RentTimer[ playerid ] = SetTimerEx("TimerRent", 60000, true, "i", playerid);
- SendClientMessage(playerid, 0x0077C7FF, "[RENT] {FFFFFF}Uspesno ste iznajmili vozilo.");
- RentVehLabel[ RentVeh[ playerid ] ] = Create3DTextLabel("[RENTANO VOZILO]", 0x0077C7FF, RentInfo[ i ][ rentX ]+2, RentInfo[ i ][ rentY ]+2, RentInfo[ i ][ rentZ ], 10.0, 0, 0);
- Attach3DTextLabelToVehicle(RentVehLabel[ RentVeh[ playerid ] ], RentVeh[ playerid ], 0.0, 0.0, 0.0);
- TipVozila[ RentVeh[ playerid ] ] = 1; // 1 - Rent Vozilo
- }
- }
- }
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate) {
- if(newstate == PLAYER_STATE_DRIVER) {
- if(TipVozila[ playerid ] == 1 && RentVeh[ playerid ] != GetPlayerVehicleID(playerid)) {
- RemovePlayerFromVehicle(playerid);
- SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Rentano vozilo.");
- }
- }
- return 1;
- }
- forward TimerRent(playerid);
- public TimerRent(playerid) {
- RentVreme[ playerid ]--;
- if(RentVreme[ playerid ] == 0) {
- KillTimer(RentTimer[ playerid ]);
- DestroyVehicle(RentVeh[ playerid ]);
- Delete3DTextLabel(RentVehLabel[ RentVeh[ playerid ] ]);
- IznajmioVozilo[ playerid ] = 0;
- RentOdabir[ playerid ] = 0;
- RentVreme[ playerid ] = 0;
- RentVeh[ playerid ] = 0;
- SendClientMessage(playerid, 0x0077C7FF, "[RENT] {FFFFFF}Isteklo vam je vreme iznamljivanja vozila.");
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason) {
- if(IznajmioVozilo[ playerid ] != 0) {
- KillTimer(RentTimer[ playerid ]);
- DestroyVehicle(RentVeh[ playerid ]);
- Delete3DTextLabel(RentVehLabel[ RentVeh[ playerid ] ]);
- IznajmioVozilo[ playerid ] = 0;
- RentOdabir[ playerid ] = 0;
- RentVreme[ playerid ] = 0;
- RentVeh[ playerid ] = 0;
- }
- return 1;
- }
- CMD:kreirajrent(playerid, params[]) {
- #pragma unused params
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Niste RCON admin.");
- new Float:X, Float:Y, Float:Z, i = NextRentID(MAX_RENTS);
- GetPlayerPos(playerid, X,Y,Z);
- RentInfo[ i ][ rentID ] = CreatePickup(19132, 1, X,Y,Z, 0);
- RentInfo[ i ][ RentLabel ] = Create3DTextLabel("[ RENT ]\n{FFFFFF}Da iznajmite vozilo, kucajte\n{0077C7}/rent", 0x0077C7FF, X, Y, Z, 10.0, 0, 0);
- RentInfo[ i ][ rentX ] = X;
- RentInfo[ i ][ rentY ] = Y;
- RentInfo[ i ][ rentZ ] = Z;
- SaveRent(i);
- return 1;
- }
- CMD:izbrisirent(playerid, params[]) {
- #pragma unused params
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Niste RCON admin.");
- new i = GetNearestRent(playerid), rentFile[ 60 ];
- if(i == -1) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Niste blizu rent pickup-a.");
- DestroyPickup(RentInfo[ i ][ rentID ]);
- Delete3DTextLabel(RentInfo[ i ][ RentLabel ]);
- RentInfo[ i ][ rentX ] = 0.0;
- RentInfo[ i ][ rentY ] = 0.0;
- RentInfo[ i ][ rentZ ] = 0.0;
- format(rentFile, sizeof(rentFile), RENT_FILE, i);
- if(fexist(rentFile)) { fremove(rentFile); }
- return 1;
- }
- // Sentinel 405 Faggio 462
- CMD:rent(playerid, params[]) {
- #pragma unused params
- if(GetNearestRent(playerid) == -1) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Niste blizu rent pickup-a.");
- if(IznajmioVozilo[ playerid ] != 0) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Vec ste iznajmili vozilo.");
- ShowPlayerDialog(playerid, DIALOG_RENT, DIALOG_STYLE_LIST, "{0077C7}Iznamljivanje {FFFFFF}vozila", "Sentinel\nFaggio", "Izaberi","Izlaz");
- return 1;
- }
- CMD:unrent(playerid, params[]) {
- #pragma unused params
- if(IznajmioVozilo[ playerid ] == 0) return SendClientMessage(playerid, 0x0077C7FF, "[ERROR] {FFFFFF}Niste iznajmili vozilo.");
- KillTimer(RentTimer[ playerid ]);
- DestroyVehicle(RentVeh[ playerid ]);
- Delete3DTextLabel(RentVehLabel[ RentVeh[ playerid ] ]);
- IznajmioVozilo[ playerid ] = 0;
- if(RentOdabir[ playerid ] == 1) {
- GivePlayerMoney(playerid, RentVreme[ playerid ]*100);
- new str[ 120 ];
- format(str, sizeof(str), "[UNRENT] {FFFFFF}Uspesno ste vratili iznamljeno vozilo te vam je vraceno %d$", RentVreme[ playerid ]*100);
- SendClientMessage(playerid, 0x0077C7FF, str);
- RentOdabir[ playerid ] = 0;
- RentVreme[ playerid ] = 0;
- RentVeh[ playerid ] = 0;
- }
- else if(RentOdabir[ playerid ] == 2) {
- GivePlayerMoney(playerid, RentVreme[ playerid ]*70);
- new str[ 120 ];
- format(str, sizeof(str), "[UNRENT] {FFFFFF}Uspesno ste vratili iznamljeno vozilo te vam je vraceno %d$", RentVreme[ playerid ]*70);
- SendClientMessage(playerid, 0x0077C7FF, str);
- RentOdabir[ playerid ] = 0;
- RentVreme[ playerid ] = 0;
- RentVeh[ playerid ] = 0;
- }
- return 1;
- }
- GetNearestRent( playerid ) {
- for( new i = 1; i < MAX_RENTS; i++) {
- if( IsPlayerInRangeOfPoint( playerid, 3.0, RentInfo[ i ][ rentX ], RentInfo[ i ][ rentY ], RentInfo[ i ][ rentZ ] ) ) { return i; }
- }
- return -1;
- }
- stock NextRentID(const len) {
- new id = (-1);
- for( new loop = ( 0 ), provjera = ( -1 ), Data_[ 64 ] = "\0"; loop != len; ++ loop ) {
- provjera = ( loop+1 );
- format( Data_, ( sizeof Data_ ), RENT_FILE, provjera );
- if(!fexist(Data_)) {
- id = ( provjera );
- break; } }
- return ( id );
- }
- stock SaveRent(id) {
- new rentFile[ 60 ];
- format(rentFile, sizeof(rentFile), RENT_FILE, id);
- new INI:File = INI_Open(rentFile);
- INI_WriteFloat(File, "Lokacija_X", RentInfo[ id ][ rentX ]);
- INI_WriteFloat(File, "Lokacija_Y", RentInfo[ id ][ rentY ]);
- INI_WriteFloat(File, "Lokacija_Z", RentInfo[ id ][ rentZ ]);
- INI_Close(File);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement