Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <streamer>
- #include <sscanf2>
- #include <colours>
- #include <foreach>
- #include <YSI\y_va>
- #include <formatex>
- #include "../scripts/System/PlayerFunctions.pwn"
- #undef MAX_PLAYERS
- #define MAX_PLAYERS 16
- #define VEHICLE_INDEX_FILE "vehicles/index.ini"
- #define VEHICLE_DATA_FILE "vehicles/%s.dat"
- #define GRID_DIVIDE 16
- #define GRID_TOTAL (GRID_DIVIDE * GRID_DIVIDE)
- #define MAX_STREAMED_VEHICLES (MAX_VEHICLES / MAX_PLAYERS)
- #define VEHICLE_STREAM_RANGE 100.0
- #define MAX_PERSONAL_VEHICLE 16
- #define PERSONAL_VEHICLE_DATA "vehicles/special/player.dat"
- enum
- {
- VEHICLE_GROUP_NONE = -1,
- VEHICLE_GROUP_CASUAL, // 0
- VEHICLE_GROUP_CASUAL_DESERT, // 1
- VEHICLE_GROUP_CASUAL_COUNTRY, // 2
- VEHICLE_GROUP_SPORT, // 3
- VEHICLE_GROUP_OFFROAD, // 4
- VEHICLE_GROUP_BIKE, // 5
- VEHICLE_GROUP_FASTBIKE, // 6
- VEHICLE_GROUP_MILITARY, // 7
- VEHICLE_GROUP_POLICE, // 8
- VEHICLE_GROUP_BIGPLANE, // 9
- VEHICLE_GROUP_SMALLPLANE, // 10
- VEHICLE_GROUP_HELICOPTER, // 11
- VEHICLE_GROUP_BOAT // 12
- }
- enum E_VEHICLE_DATA
- {
- v_id,
- v_model,
- Float:v_posX,
- Float:v_posY,
- Float:v_posZ,
- Float:v_rot,
- v_spawnArea
- }
- new
- TotalVehicles,
- TotalPersonalVehicles,
- gVehicleData[GRID_TOTAL+1][MAX_STREAMED_VEHICLES][E_VEHICLE_DATA],
- gAreaData[GRID_TOTAL+1],
- gVehicleCount[GRID_TOTAL+1],
- gAreaStreamed[GRID_TOTAL+1],
- gLoadingVehicles,
- gPlayerCurrentArea[MAX_PLAYERS];
- new gModelGroup[13][68]=
- {
- // VEHICLE_GROUP_CASUAL
- {
- 404,442,479,549,600,496,496,401,
- 410,419,436,439,517,518,401,410,
- 419,436,439,474,491,496,517,518,
- 526,527,533,545,549,580,589,600,
- 602,400,404,442,458,479,489,505,
- 579,405,421,426,445,466,467,492,
- 507,516,529,540,546,547,550,551,
- 566,585,587,412,534,535,536,567,
- 575,576, 0, ...
- },
- // VEHICLE_GROUP_CASUAL_DESERT,
- {
- 404,479,445,542,466,467,549,540,
- 424,400,500,505,489,499,422,600,
- 515,543,554,443,508,525, 0, ...
- },
- // VEHICLE_GROUP_CASUAL_COUNTRY,
- {
- 499,422,498,609,455,403,414,514,
- 600,413,515,440,543,531,478,456,
- 554,445,518,401,527,542,546,410,
- 549,508,525, 0, ...
- },
- // VEHICLE_GROUP_SPORT,
- {
- 558,559,560,561,562,565,411,451,
- 477,480,494,502,503,506,541, 0, ...
- },
- // VEHICLE_GROUP_OFFROAD,
- {
- 400,505,579,422,478,543,554, 0, ...
- },
- // VEHICLE_GROUP_BIKE,
- {
- 509,481,510,462,448,463,586,468,
- 471, 0, ...
- },
- // VEHICLE_GROUP_FASTBIKE,
- {
- 581,522,461,521, 0, ...
- },
- // VEHICLE_GROUP_MILITARY,
- {
- 433,432,601,470, 0, ...
- },
- // VEHICLE_GROUP_POLICE,
- {
- 523,596,598,597,599,490,528,427
- },
- // VEHICLE_GROUP_BIGPLANE,
- {
- 519,553,577,592, 0, ...
- },
- // VEHICLE_GROUP_SMALLPLANE,
- {
- 460,476,511,512,513,593, 0, ...
- },
- // VEHICLE_GROUP_HELICOPTER,
- {
- 548,487,417,487,488,487,497,487,
- 563,477,469,487, 0, ...
- },
- // VEHICLE_GROUP_BOAT,
- {
- 472,473,493,595,484,430,453,452,
- 446,454, 0, ...
- }
- };
- public OnFilterScriptInit()
- {
- new
- Float:xMax,
- Float:xMin,
- Float:yMax,
- Float:yMin,
- xLoop,
- yLoop,
- idx;
- while(idx < GRID_DIVIDE * GRID_DIVIDE)
- {
- xMin = ((6000 / GRID_DIVIDE) * xLoop) - 3000.0;
- xMax = ((6000 / GRID_DIVIDE) * (xLoop+1)) - 3000.0;
- yMin = ((6000 / GRID_DIVIDE) * yLoop) - 3000.0;
- yMax = ((6000 / GRID_DIVIDE) * (yLoop+1)) - 3000.0;
- gAreaData[idx] = CreateDynamicRectangle(xMin, yMin, xMax, yMax, -1, 0);
- xLoop++;
- idx++;
- if(xLoop == GRID_DIVIDE)
- {
- xLoop = 0;
- yLoop++;
- }
- }
- LoadAllVehicles();
- LoadStaticVehiclesFromFile("vehicles/special/trains.dat");
- for(new i;i<MAX_PLAYERS;i++)gPlayerCurrentArea[i] = -1;
- printf("Total Dynamic Vehicles: %d", TotalVehicles);
- }
- public OnFilterScriptExit()
- {
- for(new i; i < GRID_TOTAL; i++)
- {
- for(new j; j < MAX_STREAMED_VEHICLES; j++)
- {
- if(IsValidVehicle(gVehicleData[i][j][v_id]))
- DestroyVehicle(gVehicleData[i][j][v_id]);
- }
- }
- }
- LoadAllVehicles()
- {
- gLoadingVehicles = true; // Don't try to spawn vehicles while this is loading!
- new
- File:f=fopen(VEHICLE_INDEX_FILE, io_read),
- line[128],
- str[128];
- while(fread(f, line))
- {
- if(line[strlen(line)-2] == '\r')line[strlen(line) - 2] = EOS;
- format(str, 128, VEHICLE_DATA_FILE, line);
- LoadVehiclesFromFile(str);
- }
- fclose(f);
- gLoadingVehicles = false;
- }
- LoadStaticVehiclesFromFile(file[])
- {
- if(!fexist(file))return print("VEHICLE FILE NOT FOUND");
- new
- File:f=fopen(file, io_read),
- line[128],
- Float:tmp_posX,
- Float:tmp_posY,
- Float:tmp_posZ,
- Float:tmp_rot,
- tmp_model;
- while(fread(f, line))
- {
- if(!sscanf(line, "p<,>ffffD(0)", tmp_posX, tmp_posY, tmp_posZ, tmp_rot, tmp_model))
- {
- AddStaticVehicle(tmp_model, tmp_posX, tmp_posY, tmp_posZ, tmp_rot, -1, -1);
- }
- }
- fclose(f);
- return 1;
- }
- new gCurModelGroup;
- LoadVehiclesFromFile(file[])
- {
- if(!fexist(file))return print("VEHICLE FILE NOT FOUND");
- new
- File:f=fopen(file, io_read),
- line[128],
- Float:tmp_posX,
- Float:tmp_posY,
- Float:tmp_posZ,
- Float:tmp_rot,
- tmp_model,
- idx;
- while(fread(f, line))
- {
- idx = 0;
- if(!sscanf(line, "p<,>ffffD(0)", tmp_posX, tmp_posY, tmp_posZ, tmp_rot, tmp_model))
- {
- while(idx < GRID_TOTAL)
- {
- if(IsPointInDynamicArea(gAreaData[idx], tmp_posX, tmp_posY, tmp_posZ))break;
- idx++;
- }
- if(tmp_model == 0)tmp_model = PickRandomVehicleFromGroup(gCurModelGroup);
- if( gVehicleData[idx][gVehicleCount[idx]][v_model] == 403 ||
- gVehicleData[idx][gVehicleCount[idx]][v_model] == 443 ||
- gVehicleData[idx][gVehicleCount[idx]][v_model] == 514 ||
- gVehicleData[idx][gVehicleCount[idx]][v_model] == 515)tmp_posZ+=2.0;
- gVehicleData[idx][gVehicleCount[idx]][v_model] = tmp_model;
- gVehicleData[idx][gVehicleCount[idx]][v_posX] = tmp_posX;
- gVehicleData[idx][gVehicleCount[idx]][v_posY] = tmp_posY;
- gVehicleData[idx][gVehicleCount[idx]][v_posZ] = tmp_posZ;
- gVehicleData[idx][gVehicleCount[idx]][v_rot] = tmp_rot;
- gVehicleData[idx][gVehicleCount[idx]][v_spawnArea] = idx;
- gVehicleCount[idx]++;
- TotalVehicles++;
- idx++;
- }
- else if(sscanf(line, "'MODELGROUP:'d", gCurModelGroup) && strlen(line) > 3)print("LINE ERROR");
- }
- printf("\t-Loaded %d vehicles from %s", idx, file);
- fclose(f);
- return 1;
- }
- PickRandomVehicleFromGroup(group)
- {
- new idx;
- while(gModelGroup[group][idx] != 0)idx++;
- return gModelGroup[group][random(idx)];
- }
- public OnPlayerEnterDynamicArea(playerid, areaid)
- {
- if(gPlayerCurrentArea[playerid] == -1)
- {
- for(new i; i < GRID_TOTAL; i++)
- {
- if(IsPlayerInDynamicArea(playerid, gAreaData[i]))
- {
- OnPlayerChangeArea(playerid, i, -1);
- return 1;
- }
- }
- }
- return 1;
- }
- public OnPlayerLeaveDynamicArea(playerid, areaid)
- {
- for(new i; i < GRID_TOTAL; i++)
- {
- if(IsPlayerInDynamicArea(playerid, gAreaData[i]))
- {
- OnPlayerChangeArea(playerid, i, gPlayerCurrentArea[playerid]);
- return 1;
- }
- }
- CreateAreaVehicles(GRID_TOTAL);
- gPlayerCurrentArea[playerid] = GRID_TOTAL;
- return 1;
- }
- OnPlayerChangeArea(playerid, newareaid, oldareaid)
- {
- if(gLoadingVehicles)return 1;
- if(GetPlayersInDynamicArea(gAreaData[newareaid]) == 1)
- {
- gPlayerCurrentArea[playerid] = newareaid;
- if(-1 < newareaid < GRID_TOTAL)CreateAreaVehicles(newareaid);
- }
- if(-1 < oldareaid < GRID_TOTAL)
- {
- if(GetPlayersInDynamicArea(gAreaData[oldareaid]) == 0)
- {
- gPlayerCurrentArea[playerid] = newareaid;
- DestroyAreaVehicles(oldareaid, newareaid);
- }
- }
- return 1;
- }
- CreateAreaVehicles(area)
- {
- if(gAreaStreamed[area])return 0;
- gAreaStreamed[area] = true;
- for(new i; i < gVehicleCount[area]; i++)
- {
- if(gVehicleData[area][i][v_model] == 0)continue;
- if(gVehicleData[area][i][v_spawnArea] != area)
- {
- ShiftVehicleToNextAreaIndex(i, area, gVehicleData[area][i][v_spawnArea]);
- continue;
- }
- gVehicleData[area][i][v_id] = CreateVehicle(
- gVehicleData[area][i][v_model],
- gVehicleData[area][i][v_posX],
- gVehicleData[area][i][v_posY],
- gVehicleData[area][i][v_posZ],
- gVehicleData[area][i][v_rot],
- -1, -1, -1);
- SetVehicleNumberPlate(gVehicleData[area][i][v_id], RandomNumberPlateString());
- }
- return 1;
- }
- DestroyAreaVehicles(area, newarea)
- {
- if(!gAreaStreamed[area])return 0;
- gAreaStreamed[area] = false;
- for(new i; i < gVehicleCount[area]; i++)
- {
- if(IsAnyPlayerInVehicle(gVehicleData[area][i][v_id]))
- ShiftVehicleToNextAreaIndex(i, area, newarea);
- if(IsValidVehicle(gVehicleData[area][i][v_id]))
- DestroyVehicle(gVehicleData[area][i][v_id]);
- }
- return 0;
- }
- GetPlayersInDynamicArea(area)
- {
- new count;
- for(new i;i<MAX_PLAYERS;i++)if(IsPlayerConnected(i))if(IsPlayerInDynamicArea(i, area))count++;
- return count;
- }
- IsAnyPlayerInVehicle(vehicleid)
- {
- for(new i;i<MAX_PLAYERS;i++)if(IsPlayerInVehicle(i, vehicleid))return 1;
- return 0;
- }
- ShiftVehicleToNextAreaIndex(index, oldarea, newarea)
- {
- new newindex;
- while(gVehicleData[newarea][newindex][v_model] != 0)newindex++;
- gVehicleData[newarea][newindex] = gVehicleData[oldarea][index];
- gVehicleData[oldarea][index][v_id] = -1;
- gVehicleData[oldarea][index][v_model] = 0;
- gVehicleData[oldarea][index][v_posX] = 0.0;
- gVehicleData[oldarea][index][v_posY] = 0.0;
- gVehicleData[oldarea][index][v_posZ] = 0.0;
- gVehicleData[oldarea][index][v_rot] = 0.0;
- gVehicleCount[oldarea]--;
- gVehicleCount[newarea]++;
- }
- RandomNumberPlateString()
- {
- new str[9];
- for(new c;c<8;c++)
- {
- if(c<4)str[c] = 'A' + random(26);
- else if(c>4)str[c] = '0' + random(10);
- str[4] = ' ';
- }
- return str;
- }
Add Comment
Please, Sign In to add comment