Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // |||||||| ||| ||| || ||
- // || ||| ||| ||| |||
- // |||||||| |||||| ||| |||
- // || ||| ||| ||| |||
- // |||||||| ||| ||| || ||
- //
- // ================================================================================================================================
- // Skriptas: automobilių nuoma
- // ================================================================================================================================
- // [+] Nuomos laikotarpis yra 1val.
- // [+] Nuoma tęsiasi žaidėjui atsijungus
- // [+] Greitas automobilių pridėjimas į nuomojamų sąrašą
- // [+] 1 galimas nuomojamas automobilis per žaidėją
- // [+] 3D teksto užrašai
- // ================================================================================================================================
- #include <a_samp>
- #define FILTERSCRIPT
- // {model_id, x, y, z, facing_angle, color_a, color_b, NUOMOS_KAINA}
- new Float:nuomos_auto[][] =
- {
- {541.0, 2039.9009, 1337.6685, 10.2535, 0.0000, 0.0, 0.0, 300.0},
- {541.0, 2039.9009, 1331.6685, 10.2535, 0.0000, 0.0, 0.0, 300.0},
- {541.0, 2039.9009, 1325.6685, 10.2535, 0.0000, 0.0, 0.0, 300.0}
- };
- // Nuomojamų automobilių informacija
- enum nAuto_info
- {
- Auto_ID,
- Kaina,
- Nuomininkas[MAX_PLAYER_NAME],
- NuomosPabaiga,
- Float:X,
- Float:Y,
- Float:Z,
- Float:Angle
- };
- new nAuto[sizeof(nuomos_auto)][nAuto_info];
- new Text3D:nAutoLabel[sizeof(nuomos_auto)];
- new nAutoID[MAX_PLAYERS];
- // Keletas teksto spalvų
- #define ORANDZINE 0xEDB409FF
- #define RAUDONA 0xCF5D30FF
- // Dialog IDs
- #define DIALOG_AUTO_NUOMA 9001
- #define DIALOG_AUTO_NUOMA_INFO 9002
- public OnFilterScriptInit()
- {
- printf("\n");
- print("----------------------------------------");
- print(" Car Rental System v 1.0 ");
- print(" Successfully loaded ");
- print("----------------------------------------");
- print("\n");
- // [Nuomojami automobiliai]
- for(new i = 0; i < sizeof(nuomos_auto); i++)
- {
- nAuto[i][Kaina] = floatround(nuomos_auto[i][7]);
- format(nAuto[i][Nuomininkas], MAX_PLAYER_NAME, "niekas");
- nAuto[i][X] = nuomos_auto[i][1];
- nAuto[i][Y] = nuomos_auto[i][2];
- nAuto[i][Z] = nuomos_auto[i][3];
- nAuto[i][Angle] = nuomos_auto[i][4];
- new model = floatround(nuomos_auto[i][0]);
- new spalva_a = floatround(nuomos_auto[i][5]);
- new spalva_b = floatround(nuomos_auto[i][6]);
- nAuto[i][Auto_ID] = CreateVehicle(model, nuomos_auto[i][1], nuomos_auto[i][2], nuomos_auto[i][3], nuomos_auto[i][4], spalva_a, spalva_b, -1);
- new label_text[50];
- format(label_text, sizeof(label_text), "{EDB409}Nuomojamas automobilis\nKaina: {FFFFFF}%i {EDB409}per val.", nAuto[i][Kaina]);
- nAutoLabel[i] = Create3DTextLabel(label_text, 0xFFFFFFFF, 0.0, 0.0, 0.0, 15.0, 0);
- Attach3DTextLabelToVehicle(nAutoLabel[i], nAuto[i][Auto_ID], 0.0, 0.0, 0.0);
- }
- // Nuomojamų automobilių timer'is (tikrina, ar nepasibaigė nuoma)
- SetTimer("TikrintiNuoma", 1000*60, true);
- return 1;
- }
- public OnFilterScriptExit()
- {
- printf("\n");
- print("----------------------------------------");
- print(" Car Rental System v 1.0 ");
- print(" Successfully unloaded ");
- print("----------------------------------------");
- print("\n");
- for(new i = 0; i < sizeof(nuomos_auto); i++)
- {
- DestroyVehicle(nAuto[i][Auto_ID]);
- Delete3DTextLabel(nAutoLabel[i]);
- }
- return 1;
- }
- forward TikrintiNuoma();
- public TikrintiNuoma()
- {
- // Šis timer'is tikrins ar nepasibaigė automobilių nuomos laikas (tikrins visus nuomojamus automobilius)
- // Callback kviečiamas kas 1min.
- for(new i = 0; i < sizeof(nuomos_auto); i++)
- {
- if(strcmp(nAuto[i][Nuomininkas], "niekas", true) && nAuto[i][NuomosPabaiga] <= gettime())
- {
- new playerid = GetPlayerID(nAuto[i][Nuomininkas]);
- if(playerid != INVALID_PLAYER_ID)
- {
- SendClientMessage(playerid, RAUDONA, "Jūsų automobilio nuoma pasibaigė.");
- }
- format(nAuto[i][Nuomininkas], MAX_PLAYER_NAME, "niekas");
- SetVehicleToRespawn(nAuto[i][Auto_ID]);
- }
- }
- return 1;
- }
- public OnVehicleStreamIn(vehicleid, forplayerid)
- {
- for(new i = 0; i < sizeof(nuomos_auto); i++)
- {
- if(vehicleid == nAuto[i][Auto_ID])
- {
- new vardas[MAX_PLAYER_NAME];
- GetPlayerName(forplayerid, vardas, MAX_PLAYER_NAME);
- if(strcmp(nAuto[i][Nuomininkas], "niekas", true) && strcmp(nAuto[i][Nuomininkas], vardas, true))
- {
- SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1);
- }
- }
- }
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(newstate == PLAYER_STATE_DRIVER)
- {
- for(new i = 0; i < sizeof(nuomos_auto); i++)
- {
- if(GetPlayerVehicleID(playerid) == nAuto[i][Auto_ID])
- {
- new vardas[MAX_PLAYER_NAME], string[125];
- GetPlayerName(playerid, vardas, MAX_PLAYER_NAME);
- if(!strcmp(nAuto[i][Nuomininkas], vardas, true))
- {
- new likes_laikas = nAuto[i][NuomosPabaiga] - gettime();
- new liko_min = floatround(likes_laikas/60, floatround_floor);
- format(string, sizeof(string), "{EDB409}Jūs nuomojates šį automobilį.\nLikęs nuomos laikas: {FFFFFF}%i {EDB409}min.", liko_min);
- ShowPlayerDialog(playerid, DIALOG_AUTO_NUOMA_INFO, DIALOG_STYLE_MSGBOX, "{FFFFFF}Automobilių nuoma", string, "Gerai", "");
- }
- else
- {
- nAutoID[playerid] = i;
- format(string, sizeof(string), "{EDB409}Šis automobilis yra nuomojamas.\nNuomos kaina: {FFFFFF}%i {EDB409}per val.\nAr norite nuomotis šį automobilį?", nAuto[i][Kaina]);
- ShowPlayerDialog(playerid, DIALOG_AUTO_NUOMA, DIALOG_STYLE_MSGBOX, "{FFFFFF}Automobilių nuoma", string, "Taip", "Ne");
- }
- }
- }
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DIALOG_AUTO_NUOMA)
- {
- new id = nAutoID[playerid];
- if(response)
- {
- if(GetPlayerMoney(playerid) < nAuto[id][Kaina])
- {
- SendClientMessage(playerid, RAUDONA, "Neturite pakankamai pinigų.");
- if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleID(playerid) == nAuto[id][Auto_ID])
- {
- SetVehicleToRespawn(nAuto[id][Auto_ID]);
- }
- }
- else
- {
- new vardas[MAX_PLAYER_NAME];
- GetPlayerName(playerid, vardas, MAX_PLAYER_NAME);
- for(new i = 0; i < sizeof(nuomos_auto); i++)
- {
- if(!strcmp(nAuto[i][Nuomininkas], vardas, true))
- {
- SendClientMessage(playerid, RAUDONA, "Jūs jau nuomojates vieną automobilį. Daugiau nuomotis negalite.");
- return 1;
- }
- }
- // Išnuomojame automobilį
- GivePlayerMoney(playerid, - nAuto[id][Kaina]);
- format(nAuto[id][Nuomininkas], MAX_PLAYER_NAME, vardas);
- nAuto[id][NuomosPabaiga] = gettime() + 60*60;
- // Užrakiname automobilį visiems kitiems žaidėjams
- // (dėl atsargumo, jei žaidėjams jau yra rodomas automobilis)
- for(new p = 0; p <= GetPlayerPoolSize(); p++)
- {
- SetVehicleParamsForPlayer(nAuto[id][Auto_ID], p, 0, 1);
- }
- }
- }
- else
- {
- SetVehicleToRespawn(nAuto[id][Auto_ID]);
- }
- }
- return 1;
- }
- stock GetPlayerID(vardas[])
- {
- new z_vardas[MAX_PLAYER_NAME];
- for(new p = 0; p <= GetPlayerPoolSize(); p++)
- {
- GetPlayerName(p, z_vardas, MAX_PLAYER_NAME);
- if(!strcmp(vardas, z_vardas, true))
- {
- return p;
- }
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement