Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //===========================Section: Includes==================================
- #include <a_samp>
- //===========================Section: Definations===============================
- #define COLOR_GRAD1 0xB4B5B7FF
- #define COLOR_GRAD2 0xBFC0C2FF
- #define COLOR_GRAD3 0xCBCCCEFF
- #define COLOR_GRAD4 0xD8D8D8FF
- #define COLOR_GRAD5 0xE3E3E3FF
- #define COLOR_GRAD6 0xF0F0F0FF
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_GREY 0xAFAFAFAA
- #define COLOR_WHITE 0xFFFFFFAA
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_YELLOW2 0xF5DEB3AA
- #define COLOR_BLUE 0x2641FEAA
- //===========================Section: Forwards==================================
- forward split(const strsrc[], strdest[][], delimiter);
- forward LoadCar();
- forward CheckOwner(playerid);
- forward SaveCars();
- forward testfahrt(playerid);
- forward setz(playerid);
- //===========================Section: Variables=================================
- new mission[MAX_PLAYERS];
- enum pInfo
- {
- pCarKey,
- }
- new Menu:examplemenu;
- new PlayerInfo[256][pInfo];
- enum cInfo
- {
- cModel,
- Float:cLocationx,
- Float:cLocationy,
- Float:cLocationz,
- Float:cAngle,
- cColorOne,
- cColorTwo,
- cOwner[MAX_PLAYER_NAME],
- cDescription[MAX_PLAYER_NAME],
- cValue,
- cLicense,
- cRegistration,
- cOwned,
- cLock,
- ownedvehicle,
- };
- new CarInfo[84][cInfo];
- new currentveh;
- new CarAutolock[999]; // Variable for Autolocking Car Doors
- new cartrack[256];
- new CarOffered[256];
- //===========================Section: strtok & split============================
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- public split(const strsrc[], strdest[][], delimiter)
- {
- new i, li;
- new aNum;
- new len;
- while(i <= strlen(strsrc)){
- if(strsrc[i]==delimiter || i==strlen(strsrc)){
- len = strmid(strdest[aNum], strsrc, li, i, 128);
- strdest[aNum][len] = 0;
- li = i+1;
- aNum++;
- }
- i++;
- }
- return 1;
- }
- //===========================Section: Callbacks & Functions=====================
- public OnFilterScriptInit()
- {
- printf("Filterscript [FS]CarOwnership.amx Initiated\n");
- LoadCar();
- for(new i = 1; i < sizeof(CarInfo); i++)
- {
- CarInfo[i][ownedvehicle] = CreateVehicle(CarInfo[i][cModel],CarInfo[i][cLocationx],CarInfo[i][cLocationy],CarInfo[i][cLocationz],CarInfo[i][cAngle],CarInfo[i][cColorOne],CarInfo[i][cColorTwo],300000);
- }
- SetTimer("SaveCars",60000,1);
- SetTimer("CheckOwner",5000,1);
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- for(new i = 1; i < sizeof(CarInfo); i++)
- {
- ChangeVehicleColor(CarInfo[i][ownedvehicle],CarInfo[vehicleid][cColorOne],CarInfo[vehicleid][cColorTwo]);
- }
- return 1;
- }
- public CheckOwner(playerid)
- {
- if(IsPlayerConnected(playerid))
- {
- for(new i = 1; i < sizeof(CarInfo); i++)
- {
- new playername[MAX_PLAYER_NAME];
- GetPlayerName(playerid,playername,sizeof(playername));
- if(strcmp(playername,CarInfo[i][cOwner],true)==0)
- {
- PlayerInfo[playerid][pCarKey] = i;
- return i;
- }
- }
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- PlayerInfo[playerid][pCarKey] = 0;
- CheckOwner(playerid);
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new idx;
- new string[256];
- new cmd[256];
- new tmp[256];
- new sendername[MAX_PLAYER_NAME];
- cmd = strtok(cmdtext, idx);
- if(strcmp(cmd,"/car",true)==0)
- {
- new playername[MAX_PLAYER_NAME];
- GetPlayerName(playerid,playername,sizeof(playername));
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp))
- {
- SendClientMessage(playerid,COLOR_WHITE,"(( Koristi /car manual za pomoc ))");
- return 1;
- }
- if(strcmp(tmp,"exit",true)==0)
- {
- CarOffered[playerid]=0;
- RemovePlayerFromVehicle(playerid);
- TogglePlayerControllable(playerid, 1);
- return 1;
- }
- if(strcmp(tmp, "manual", true) == 0)
- {
- if(IsPlayerConnected(playerid))
- {
- if(PlayerInfo[playerid][pCarKey]!=0)
- {
- format(string,sizeof(string),"________________%s________________",CarInfo[CheckOwner(playerid)][cDescription]);
- SendClientMessage(playerid, COLOR_GREEN,string);
- SendClientMessage(playerid, COLOR_GRAD2,"** /car sell - Prodajete auto");
- SendClientMessage(playerid, COLOR_GRAD2,"** /car manual - pokazuje ovu listu");
- SendClientMessage(playerid, COLOR_GRAD2,"** /car exit - Izlazi iz auta");
- SendClientMessage(playerid, COLOR_GRAD2,"** /car locate - Lokacija auta");
- SendClientMessage(playerid, COLOR_GRAD2,"** /car lock - zakljucavate auto");
- SendClientMessage(playerid, COLOR_GRAD2,"** /car unlock - otkljucavate auto");
- SendClientMessage(playerid, COLOR_GRAD2,"** /car autolock - Zakljucava auto automatski kada izadjete iz njega");
- SendClientMessage(playerid, COLOR_GRAD2,"** /car park - Parkira auto na ovu poziciju");
- return 1;
- }
- else
- {
- SendClientMessage(playerid,COLOR_GRAD2,"** Ne posjedujes auto! **");
- return 1;
- }
- }
- return 1;
- }
- if(strcmp(tmp, "park", true) == 0)
- {
- if(PlayerInfo[playerid][pCarKey] == 0)
- {
- SendClientMessage(playerid, COLOR_GREY, "Ne posjedujes auto.");
- return 1;
- }
- new keycar = PlayerInfo[playerid][pCarKey];
- new Float:z_rot;
- new currentveh2;
- currentveh2 = GetPlayerVehicleID(playerid);
- GetVehicleZAngle(currentveh2, z_rot);
- new Float:vehx, Float:vehy, Float:vehz;
- GetVehiclePos(currentveh2, vehx, vehy, vehz);
- if(currentveh2 == CarInfo[keycar][ownedvehicle])
- {
- CarInfo[keycar][cLocationx] = vehx;
- CarInfo[keycar][cLocationy] = vehy;
- CarInfo[keycar][cLocationz] = vehz;
- CarInfo[keycar][cAngle]= z_rot;
- SendClientMessage(playerid,COLOR_GRAD1,"Auto parkirano");
- }
- else
- {
- SendClientMessage(playerid,COLOR_GRAD1,"Ne sjedis u svom autu");
- }
- return 1;
- }
- if(strcmp(tmp, "sell", true) == 0)
- {
- if(IsPlayerConnected(playerid))
- {
- GetPlayerName(playerid, playername, sizeof(playername));
- if(PlayerInfo[playerid][pCarKey] == 0)
- {
- SendClientMessage(playerid, COLOR_GREY, "Ne posjedujes auto.");
- return 1;
- }
- if(PlayerInfo[playerid][pCarKey] != 0 && strcmp(playername, CarInfo[PlayerInfo[playerid][pCarKey]][cOwner], true) == 0)
- {
- new car = PlayerInfo[playerid][pCarKey];
- CarInfo[car][cOwned] = 0;
- GetPlayerName(playerid, sendername, sizeof(sendername));
- strmid(CarInfo[car][cOwner], "Dealership", 0, strlen("Dealership"), 999);
- GivePlayerMoney(playerid,CarInfo[car][cValue]);
- PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
- format(string, sizeof(string), "~w~Prodao si svoje auto za ~n~~g~$%d ~w~", CarInfo[car][cValue]);
- GameTextForPlayer(playerid, string, 10000, 3);
- RemovePlayerFromVehicle(playerid);
- TogglePlayerControllable(playerid, 1);
- PlayerInfo[playerid][pCarKey] = 999;
- return 1;
- }
- }
- return 1;
- }
- if(strcmp(tmp, "locate", true) == 0)
- {
- if(!IsPlayerConnected(playerid)) { return 1; }
- if(PlayerInfo[playerid][pCarKey] == 0) { GameTextForPlayer(playerid, "~w~Ne posjedujes auto", 2500, 3); return 1; }
- if(cartrack[playerid]==0)
- {
- SendClientMessage(playerid,COLOR_WHITE,"On-Star: This is On-Star's automated vehicle tracking system");
- SendClientMessage(playerid,COLOR_WHITE,"On-Star: Please enter your PIN # and password now");
- SendClientMessage(playerid,COLOR_WHITE,"On-Star: Your vehicle's location is now uploaded to your phone");
- SetPlayerCheckpoint(playerid,CarInfo[PlayerInfo[playerid][pCarKey]][cLocationx], CarInfo[PlayerInfo[playerid][pCarKey]][cLocationy], CarInfo[PlayerInfo[playerid][pCarKey]][cLocationz], 5.0);
- cartrack[playerid] = 1;
- return 1;
- }
- else
- {
- SendClientMessage(playerid,COLOR_WHITE,"On-Star: This is On-Star's automated vehicle tracking system");
- SendClientMessage(playerid,COLOR_WHITE,"On-Star: The tracking on your vehicle has been canceled");
- DisablePlayerCheckpoint(playerid);
- cartrack[playerid] = 0;
- return 1;
- }
- }
- if(strcmp(tmp, "lock", true) == 0)
- {
- new keycar = PlayerInfo[playerid][pCarKey];
- if(IsPlayerConnected(playerid))
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- SetVehicleParamsForPlayer(CarInfo[keycar][ownedvehicle],i,0,1);
- }
- format(string, sizeof(string), "~w~Auto~n~~r~zakljucano");
- GameTextForPlayer(playerid, string, 10000, 3);
- CarInfo[keycar][cLock] = 1;
- return 1;
- }
- }
- if(strcmp(tmp, "unlock", true) == 0)
- {
- new keycar = PlayerInfo[playerid][pCarKey];
- if(IsPlayerConnected(playerid))
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- SetVehicleParamsForPlayer(CarInfo[keycar][ownedvehicle],i,0,0);
- }
- format(string, sizeof(string), "~w~Auto~n~~g~otkljucano");
- GameTextForPlayer(playerid, string, 10000, 3);
- CarInfo[keycar][cLock] = 0;
- return 1;
- }
- }
- if(strcmp(tmp, "autolock", true) == 0)
- {
- new keycar = PlayerInfo[playerid][pCarKey];
- if(CarAutolock[CarInfo[keycar][ownedvehicle]] == 0) { CarAutolock[CarInfo[keycar][ownedvehicle]] = 1; format(string, sizeof(string), "~w~Car Autolock~n~~r~Engaged"); return 1; }
- if(CarAutolock[CarInfo[keycar][ownedvehicle]] == 1) { CarAutolock[CarInfo[keycar][ownedvehicle]] = 0; format(string, sizeof(string), "~w~Car Autolock~n~~g~Disengaged"); return 1; }
- GameTextForPlayer(playerid, string, 10000, 3);
- return 1;
- }
- }
- return 0;
- }
- /*----------Car Save Functions----------*/
- public LoadCar()
- {
- new arrCoords[13][64];
- new strFromFile2[256];
- new File: file = fopen("autos.cfg", io_read);
- if (file)
- {
- new idx = 0;
- while (idx < sizeof(CarInfo))
- {
- fread(file, strFromFile2);
- split(strFromFile2, arrCoords, ',');
- CarInfo[idx][cModel] = strval(arrCoords[0]);
- CarInfo[idx][cLocationx] = floatstr(arrCoords[1]);
- CarInfo[idx][cLocationy] = floatstr(arrCoords[2]);
- CarInfo[idx][cLocationz] = floatstr(arrCoords[3]);
- CarInfo[idx][cAngle] = floatstr(arrCoords[4]);
- CarInfo[idx][cColorOne] = strval(arrCoords[5]);
- CarInfo[idx][cColorTwo] = strval(arrCoords[6]);
- strmid(CarInfo[idx][cOwner], arrCoords[7], 0, strlen(arrCoords[7]), 255);
- strmid(CarInfo[idx][cDescription], arrCoords[8], 0, strlen(arrCoords[8]), 255);
- CarInfo[idx][cValue] = strval(arrCoords[9]);
- CarInfo[idx][cLicense] = strval(arrCoords[10]);
- CarInfo[idx][cOwned] = strval(arrCoords[11]);
- CarInfo[idx][cLock] = strval(arrCoords[12]);
- printf("CarInfo: %d Owner:%s LicensePlate %s",idx,CarInfo[idx][cOwner],CarInfo[idx][cLicense]);
- idx++;
- }
- }
- return 1;
- }
- public SaveCars()
- {
- new idx;
- new File: file2;
- while (idx < sizeof(CarInfo))
- {
- new coordsstring[256];
- format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%f,%d,%d,%s,%s,%d,%s,%d,%d\n",
- CarInfo[idx][cModel],
- CarInfo[idx][cLocationx],
- CarInfo[idx][cLocationy],
- CarInfo[idx][cLocationz],
- CarInfo[idx][cAngle],
- CarInfo[idx][cColorOne],
- CarInfo[idx][cColorTwo],
- CarInfo[idx][cOwner],
- CarInfo[idx][cDescription],
- CarInfo[idx][cValue],
- CarInfo[idx][cLicense],
- CarInfo[idx][cOwned],
- CarInfo[idx][cLock]);
- if(idx == 0)
- {
- file2 = fopen("autos.cfg", io_write);
- }
- else
- {
- file2 = fopen("autos.cfg", io_append);
- }
- fwrite(file2, coordsstring);
- idx++;
- fclose(file2);
- }
- return 1;
- }
- public OnVehicleRespray(playerid,vehicleid, color1, color2)
- {
- for(new i = 0; i < sizeof(CarInfo); i++)
- {
- if(vehicleid == CarInfo[i][ownedvehicle])
- {
- CarInfo[i][cColorOne] = color1;
- CarInfo[i][cColorTwo] = color2;
- printf("CarOwnership report");
- printf("** Car %s[%d] painted %d and %d",CarInfo[i][cDescription],i,color1,color2);
- }
- }
- return 1;
- }
- public OnPlayerExitVehicle(playerid, vehicleid)
- {
- DestroyMenu(examplemenu);
- if(IsPlayerConnected(playerid))
- {
- for(new i = 0; i < sizeof(CarInfo); i++)
- {
- if(vehicleid == CarInfo[i][ownedvehicle])
- {
- DestroyMenu(examplemenu);
- /* new Float:x,Float:y,Float:z;
- new Float:a;
- GetVehiclePos(vehicleid, x, y, z);
- GetVehicleZAngle(vehicleid, a);
- CarInfo[i][cLocationx] = x;
- CarInfo[i][cLocationy] = y;
- CarInfo[i][cLocationz] = z;
- CarInfo[i][cAngle] = a;*/
- }
- if(CarAutolock[vehicleid] == 1)
- {
- for(new j = 0; j < MAX_PLAYERS; i++)
- {
- if (IsPlayerConnected(j))
- {
- SetVehicleParamsForPlayer(vehicleid,j,0,1);
- GameTextForPlayer(playerid,"~w~Vozilo~n~~r~Auto-zakljucano",2500,3);
- return 1;
- }
- }
- }
- }
- }
- if(mission[playerid] == 1)
- {
- SetTimerEx("setz", 4000, false, "x", playerid);
- PutPlayerInVehicle(playerid,currentveh,0);
- SendClientMessage(playerid,COLOR_GREY,"U toku tesz voznje nemozete napustiti auto");
- return 1;
- }
- DestroyMenu(examplemenu);
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- new vehicle = GetPlayerVehicleID(playerid);
- //new keycar = PlayerInfo[playerid][pCarKey];
- new string[256];
- if(newstate==2)
- {
- for(new i = 0; i < sizeof(CarInfo); i++)
- {
- new newcar = GetPlayerVehicleID(playerid);
- if(newcar == CarInfo[i][ownedvehicle])
- {
- if(CarInfo[i][cOwned]==0)
- {
- examplemenu = CreateMenu("Auto salon", 5, 200.0, 100.0, 150.0, 150.0);
- TogglePlayerControllable(playerid, 0);
- CarOffered[playerid]=1;
- format(string,sizeof(string),"Model: %s",CarInfo[i][cDescription]);
- AddMenuItem(examplemenu, 0, string);
- format(string,sizeof(string),"Cijena: %d$",CarInfo[i][cValue]);
- AddMenuItem(examplemenu, 0, string);
- AddMenuItem(examplemenu, 0, "Kupi");
- AddMenuItem(examplemenu, 0, "Izadji");
- AddMenuItem(examplemenu, 0, "Test voznja (3min)");
- ShowMenuForPlayer(examplemenu, playerid);
- }
- }
- }
- }
- for(new i = 0; i < sizeof(CarInfo); i++)
- {
- if(newstate==2)
- {
- if(CarInfo[vehicle][cOwned]==1)
- {
- format(string,sizeof(string),"Ovaj auto je registrovan na %s",CarInfo[vehicle][cOwner]);
- SendClientMessage(playerid, COLOR_BLUE, string);
- return 1;
- }
- }
- }
- return 1;
- }
- public OnPlayerEnterCheckpoint(playerid)
- {
- if(cartrack[playerid]!=0)
- {
- SendClientMessage(playerid,COLOR_YELLOW,"SMS: On-Star: Our sensors show that you have come within 5.0 metres of your vehicle");
- DisablePlayerCheckpoint(playerid);
- cartrack[playerid] = 0;
- }
- return 1;
- }
- public OnPlayerSelectedMenuRow(playerid, row)
- {
- new sendername[MAX_PLAYER_NAME];
- new vehid = GetPlayerVehicleID(playerid);
- new Menu:current;
- current = GetPlayerMenu(playerid);
- if(current == examplemenu)
- {
- switch(row)
- {
- case 0:ShowMenuForPlayer(examplemenu, playerid);
- case 1:ShowMenuForPlayer(examplemenu, playerid);
- case 2:
- if(IsPlayerConnected(playerid))
- {
- for(new i = 0; i < sizeof(CarInfo); i++)
- {
- if(CarInfo[i][ownedvehicle] == vehid)
- {
- if(PlayerInfo[playerid][pCarKey]!=0)
- {
- SendClientMessage(playerid, COLOR_GREY, "Vec posjedujes jedan auto!");
- RemovePlayerFromVehicle(playerid);
- TogglePlayerControllable(playerid, 1);
- return 1;
- }
- if(CarInfo[i][cOwned]==1)
- {
- SendClientMessage(playerid, COLOR_GREY, "Ovo auto nije na prodaju!");
- TogglePlayerControllable(playerid, 1);
- RemovePlayerFromVehicle(playerid);
- return 1;
- }
- if(GetPlayerMoney(playerid) >= CarInfo[i][cValue])
- {
- PlayerInfo[playerid][pCarKey] = i;
- CarInfo[i][cOwned] = 1;
- CarOffered[playerid]=0;
- GetPlayerName(playerid, sendername, sizeof(sendername));
- strmid(CarInfo[i][cOwner], sendername, 0, strlen(sendername), 999);
- GivePlayerMoney(playerid,-CarInfo[i][cValue]);
- GameTextForPlayer(playerid, "~w~Cestitamo~n~Ovo je sada vas auto!", 5000, 3);
- SendClientMessage(playerid, COLOR_GRAD2, "Cestitamo na novoj kupovini!");
- SendClientMessage(playerid, COLOR_GRAD2, "kucaj /car manual za pomoc vozila");
- TogglePlayerControllable(playerid, 1);
- SaveCars();
- return 1;
- }
- else
- {
- SendClientMessage(playerid, COLOR_GREY, " Nemate dovoljno novca!");
- TogglePlayerControllable(playerid, 1);
- RemovePlayerFromVehicle(playerid);
- return 1;
- }
- }
- }
- return 1;
- }
- case 3: RemovePlayerFromVehicle(playerid) && TogglePlayerControllable(playerid, 1) && SendClientMessage(playerid,COLOR_GREY,"besuchen sie uns wieder!");
- case 4:
- for(new i = 0; i < sizeof(CarInfo); i++)
- {
- new currentveh3;
- currentveh3 = GetPlayerVehicleID(playerid);
- if(CarInfo[i][ownedvehicle] == currentveh3)
- {
- SetTimerEx("testfahrt", 180000, false, "x", playerid);
- TogglePlayerControllable(playerid, 1);
- mission[playerid] =1; CarInfo[i][cOwned] = 1;
- SendClientMessage(playerid,COLOR_GREY," Imas 3 minute vremena da testiras auto");
- return 1;
- }
- }
- }
- return 1;
- }
- return 1;
- }
- public OnPlayerExitedMenu(playerid)
- {
- RemovePlayerFromVehicle(playerid);
- TogglePlayerControllable(playerid,1); // unfreeze the player when they exit a menu
- return 1;
- }
- public testfahrt(playerid)
- {
- if(IsPlayerConnected(playerid))
- {
- for(new i = 0; i < sizeof(CarInfo); i++)
- {
- // new Float: x,Float: y,Float: z;
- currentveh = GetPlayerVehicleID(playerid);
- if(CarInfo[i][ownedvehicle] == currentveh)
- {
- new Float: x,Float: y,Float: z;
- CarInfo[currentveh][cOwned] = 0;
- mission[playerid] =0;
- SetVehicleToRespawn(currentveh);
- GetVehiclePos(currentveh,x,y,z);
- SetPlayerPos(playerid,x,y,z+5);
- SendClientMessage(playerid,COLOR_GREY,"Test voznja istekla!");
- return 1;
- }
- return 1;
- }
- }
- return 1;
- }
- public setz(playerid)
- {
- if(IsPlayerConnected(playerid))
- {
- PutPlayerInVehicle(playerid,currentveh,0);
- }
- return 1;
- }
Add Comment
Please, Sign In to add comment