Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp.inc>
- #include <YSI\y_hooks>
- new GlobalString[32];
- /*
- Vehicle Streamer
- - AddVehicle (modelid, color_1, color_2, Float:params[4], respawntime) [TimeCreated - Unix]
- - LoadVehicles (only = -1, skip = -1)
- - DeleteVehicle(modelid, color_1, color_2, , Float:params[4])
- - ReloadVehicles ()
- */
- #define MAX_LOAD_VEHICLES 100000 //This is for testing purposes only
- enum _vs_zone{
- _vs_pZone[2]
- }
- new _vs_PlayerZone[MAX_PLAYERS][_vs_zone];
- enum _vehinfos {
- _vModelID, // (400-611)
- _vColor1,
- _vColor2,
- Float:_vParams[4], // (X, Y, Z, Rot)
- Float:_vTMPParams[4],
- bool:_vTMPLoc,
- _vRespawnTime, // (Sec),
- _vLinkerID,
- bool:_vSpawned
- }
- new _vs_CreatedVehicles = 0;
- enum _curvehs {
- _cInfoID,
- _cPlayers,
- bool:_cStreamed
- }
- new _vs_LinkerLoader[12][12];
- new _vs_VehicleInfosLinker[12][12][MAX_VEHICLES];
- new _vs_VehicleInfos[MAX_LOAD_VEHICLES][_vehinfos];
- new _vs_CurrentVehicles[MAX_VEHICLES][_curvehs];
- native IsValidVehicle(vehicleid);
- forward _vs_CheckTimer();
- forward _vs_CheckPlayerPosition(playerid);
- forward AddVehicle(modelid, color_1, color_2, Float:params[4], respawntime);
- forward GetVehicleIDEx(vehicleid);
- public GetVehicleIDEx(vehicleid){
- return _vs_CurrentVehicles[vehicleid][_cInfoID];
- }
- public AddVehicle(modelid, color_1, color_2, Float:params[4], respawntime) {
- new Con[2];
- if (modelid >= 400 && modelid <= 611){
- if (_vs_CreatedVehicles == MAX_LOAD_VEHICLES)
- return false;
- _vs_VehicleInfos[_vs_CreatedVehicles][_vModelID] = modelid;
- _vs_VehicleInfos[_vs_CreatedVehicles][_vColor1] = color_1;
- _vs_VehicleInfos[_vs_CreatedVehicles][_vColor2] = color_2;
- _vs_VehicleInfos[_vs_CreatedVehicles][_vParams][0] = params[0]; // X
- _vs_VehicleInfos[_vs_CreatedVehicles][_vParams][1] = params[1]; // Y
- _vs_VehicleInfos[_vs_CreatedVehicles][_vParams][2] = params[2]; // Z
- _vs_VehicleInfos[_vs_CreatedVehicles][_vParams][3] = params[3]; // Rotation
- _vs_VehicleInfos[_vs_CreatedVehicles][_vRespawnTime] = respawntime;
- _vs_VehicleInfos[_vs_CreatedVehicles][_vSpawned] = false;
- _vs_VehicleInfos[_vs_CreatedVehicles][_vTMPLoc] = false;
- Con[0] = floatround(params[0], floatround_ceil);
- Con[1] = floatround(params[1], floatround_ceil);
- GetZone(Con, Con[0], Con[1]);
- _vs_VehicleInfos[_vs_CreatedVehicles][_vLinkerID] = _vs_LinkerLoader[Con[0]][Con[1]];
- _vs_VehicleInfosLinker[Con[0]][Con[1]][_vs_VehicleInfos[_vs_CreatedVehicles][_vLinkerID]] = _vs_CreatedVehicles;
- _vs_LinkerLoader[Con[0]][Con[1]]++; //Increasing Linker ID
- _vs_CreatedVehicles++; //Increasing Streamed ID
- }
- return true;
- }
- stock GetZone(params[2], &zone1, &zone2){
- if (params[0] < -2500)
- zone1 = 0;
- else if (params[0] >= -2500 && params[0] < -2000)
- zone1 = 1;
- else if (params[0] >= -2000 && params[0] < -1500)
- zone1 = 2;
- else if (params[0] >= -1500 && params[0] < -1000)
- zone1 = 3;
- else if (params[0] >= -1000 && params[0] < -500)
- zone1 = 4;
- else if (params[0] >= -500 && params[0] < 0)
- zone1 = 5;
- else if (params[0] >= 0 && params[0] < 500)
- zone1 = 6;
- else if (params[0] >= 500 && params[0] < 1000)
- zone1 = 7;
- else if (params[0] >= 1000 && params[0] < 1500)
- zone1 = 8;
- else if (params[0] >= 1500 && params[0] < 2000)
- zone1 = 9;
- else if (params[0] >= 2000 && params[0] < 2500)
- zone1 = 10;
- else if (params[0] >= 2500 && params[0] < 3000)
- zone1 = 11;
- else
- zone1 = -1;
- if (params[1] < -2500)
- zone2 = 0;
- else if (params[1] >= -2500 && params[1] < -2000)
- zone2 = 1;
- else if (params[1] >= -2000 && params[1] < -1500)
- zone2 = 2;
- else if (params[1] >= -1500 && params[1] < -1000)
- zone2 = 3;
- else if (params[1] >= -1000 && params[1] < -500)
- zone2 = 4;
- else if (params[1] >= -500 && params[1] < 0)
- zone2 = 5;
- else if (params[1] >= 0 && params[1] < 500)
- zone2 = 6;
- else if (params[1] >= 500 && params[1] < 1000)
- zone2 = 7;
- else if (params[1] >= 1000 && params[1] < 1500)
- zone2 = 8;
- else if (params[1] >= 1500 && params[1] < 2000)
- zone2 = 9;
- else if (params[1] >= 2000 && params[1] < 2500)
- zone2 = 10;
- else if (params[1] >= 2500 && params[1] < 3000)
- zone2 = 11;
- else
- zone2 = -1;
- return true;
- }
- public _vs_CheckPlayerPosition(playerid){
- new Float:Pos[4], Zone[18], newv, cid, Zones[2];
- if (IsPlayerConnected(playerid)){
- GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
- Zone[0] = floatround(Pos[0], floatround_ceil);
- Zone[1] = floatround(Pos[1], floatround_ceil);
- Zones[0] = Zone[0];
- Zones[1] = Zone[1];
- GetZone(Zones, Zone[0], Zone[1]);
- Zone[2] = floatround(Pos[0] - 300, floatround_ceil);
- Zone[3] = floatround(Pos[1] - 300, floatround_ceil);
- Zones[0] = Zone[2];
- Zones[1] = Zone[3];
- GetZone(Zones, Zone[2], Zone[3]);
- Zone[4] = floatround(Pos[0], floatround_ceil);
- Zone[5] = floatround(Pos[1] - 300, floatround_ceil);
- Zones[0] = Zone[4];
- Zones[1] = Zone[5];
- GetZone(Zones, Zone[4], Zone[5]);
- Zone[6] = floatround(Pos[0] + 300, floatround_ceil);
- Zone[7] = floatround(Pos[1] - 300, floatround_ceil);
- Zones[0] = Zone[6];
- Zones[1] = Zone[7];
- GetZone(Zones, Zone[6], Zone[7]);
- Zone[8] = floatround(Pos[0] - 300, floatround_ceil);
- Zone[9] = floatround(Pos[1], floatround_ceil);
- Zones[0] = Zone[8];
- Zones[1] = Zone[9];
- GetZone(Zones, Zone[8], Zone[9]);
- Zone[10] = floatround(Pos[0] + 300, floatround_ceil);
- Zone[11] = floatround(Pos[1], floatround_ceil);
- Zones[0] = Zone[10];
- Zones[1] = Zone[11];
- GetZone(Zones, Zone[10], Zone[11]);
- Zone[12] = floatround(Pos[0] - 300, floatround_ceil);
- Zone[13] = floatround(Pos[1] + 300, floatround_ceil);
- Zones[0] = Zone[12];
- Zones[1] = Zone[13];
- GetZone(Zones, Zone[12], Zone[13]);
- Zone[14] = floatround(Pos[0], floatround_ceil);
- Zone[15] = floatround(Pos[1] + 300, floatround_ceil);
- Zones[0] = Zone[14];
- Zones[1] = Zone[15];
- GetZone(Zones, Zone[14], Zone[15]);
- Zone[16] = floatround(Pos[0] + 300, floatround_ceil);
- Zone[17] = floatround(Pos[1] + 300, floatround_ceil);
- Zones[0] = Zone[16];
- Zones[1] = Zone[17];
- GetZone(Zones, Zone[16], Zone[17]);
- if (Zone[0] != _vs_PlayerZone[playerid][_vs_pZone][0] || Zone[1] != _vs_PlayerZone[playerid][_vs_pZone][1]){
- _vs_PlayerZone[playerid][_vs_pZone][0] = Zone[0];
- _vs_PlayerZone[playerid][_vs_pZone][1] = Zone[1];
- for (new _vs_lv=0;_vs_lv<_vs_LinkerLoader[Zone[0]][Zone[1]];_vs_lv++){
- cid = _vs_VehicleInfosLinker[Zone[0]][Zone[1]][_vs_lv];
- if (NearVehicle(playerid, cid, Pos[0], Pos[1], Pos[2], Pos[3])){
- if (!_vs_VehicleInfos[cid][_vSpawned]){
- if ((newv = CreateVehicle(_vs_VehicleInfos[cid][_vModelID], Pos[0], Pos[1], Pos[2], Pos[3], _vs_VehicleInfos[cid][_vColor1], _vs_VehicleInfos[cid][_vColor2], _vs_VehicleInfos[cid][_vRespawnTime])) != INVALID_VEHICLE_ID){
- _vs_CurrentVehicles[newv][_cInfoID] = cid;
- format (GlobalString, sizeof (GlobalString), "ID %d created, dID %d", newv, cid); // Remove
- SendClientMessageToAll(0xFFFF00AA, GlobalString); // Remove
- _vs_VehicleInfos[cid][_vSpawned] = true;
- }
- }
- }
- }
- }
- }
- }
- stock NearVehicle(playerid, vehicleid, &Float:X, &Float:Y, &Float:Z, &Float:Angle){
- // new Float:Range, stream_distance[4];
- if (_vs_VehicleInfos[vehicleid][_vTMPLoc]){
- X = _vs_VehicleInfos[vehicleid][_vTMPParams][0];
- Y = _vs_VehicleInfos[vehicleid][_vTMPParams][1];
- Z = _vs_VehicleInfos[vehicleid][_vTMPParams][2];
- Angle = _vs_VehicleInfos[vehicleid][_vTMPParams][3];
- } else {
- X = _vs_VehicleInfos[vehicleid][_vParams][0];
- Y = _vs_VehicleInfos[vehicleid][_vParams][1];
- Z = _vs_VehicleInfos[vehicleid][_vParams][2];
- Angle = _vs_VehicleInfos[vehicleid][_vParams][3];
- }
- // GetServerVarAsString(stream_distance, "stream_distance", sizeof (stream_distance));
- // Range = floatstr(stream_distance);
- if (IsPlayerInRangeOfPoint(playerid, 300.0, X, Y, Z)){
- return true;
- }
- return false;
- }
- hook:OnVehicleStreamIn(vehicleid, forplayerid){
- _vs_CurrentVehicles[vehicleid][_cPlayers]++;
- }
- hook:OnVehicleStreamOut(vehicleid, forplayerid){
- new soParams[2], Float:Position[4];
- _vs_CurrentVehicles[vehicleid][_cPlayers]--;
- if (_vs_CurrentVehicles[vehicleid][_cPlayers] <= 0){
- _vs_CurrentVehicles[vehicleid][_cPlayers] = 0;
- format (GlobalString, sizeof (GlobalString), "ID %d deleted, dID", vehicleid); // Remove
- GetVehiclePos(vehicleid, Position[0], Position[1], Position[2]);
- GetVehicleZAngle(vehicleid, Position[3]);
- DestroyVehicle(vehicleid);
- vehicleid = _vs_CurrentVehicles[vehicleid][_cInfoID];
- format (GlobalString, sizeof (GlobalString), "%s %d", GlobalString, vehicleid); // Remove
- _vs_VehicleInfos[vehicleid][_vSpawned] = false;
- if (!_vs_VehicleInfos[vehicleid][_vTMPLoc]){
- _vs_VehicleInfos[vehicleid][_vTMPLoc] = true;
- soParams[0] = floatround(_vs_VehicleInfos[vehicleid][_vParams][0], floatround_ceil);
- soParams[1] = floatround(_vs_VehicleInfos[vehicleid][_vParams][1], floatround_ceil);
- } else {
- soParams[0] = floatround(_vs_VehicleInfos[vehicleid][_vTMPParams][0], floatround_ceil);
- soParams[1] = floatround(_vs_VehicleInfos[vehicleid][_vTMPParams][1], floatround_ceil);
- }
- GetZone(soParams, soParams[0], soParams[1]);
- _vs_LinkerLoader[soParams[0]][soParams[1]]--;
- _vs_VehicleInfosLinker[soParams[0]][soParams[1]][_vs_VehicleInfos[vehicleid][_vLinkerID]] = -1;
- _vs_VehicleInfos[vehicleid][_vTMPParams][0] = Position[0];
- _vs_VehicleInfos[vehicleid][_vTMPParams][1] = Position[1];
- _vs_VehicleInfos[vehicleid][_vTMPParams][2] = Position[2];
- _vs_VehicleInfos[vehicleid][_vTMPParams][3] = Position[3];
- soParams[0] = floatround(_vs_VehicleInfos[vehicleid][_vTMPParams][0], floatround_ceil);
- soParams[1] = floatround(_vs_VehicleInfos[vehicleid][_vTMPParams][1], floatround_ceil);
- GetZone(soParams, soParams[0], soParams[1]);
- _vs_VehicleInfos[vehicleid][_vLinkerID] = _vs_LinkerLoader[soParams[0]][soParams[1]];
- _vs_VehicleInfosLinker[soParams[0]][soParams[1]][_vs_VehicleInfos[vehicleid][_vLinkerID]] = vehicleid;
- _vs_LinkerLoader[soParams[0]][soParams[1]]++;
- SendClientMessageToAll(0xFFFF00AA, GlobalString); // Remove
- }
- }
- public _vs_CheckTimer(){
- new playerid = 0;
- do {
- if (IsPlayerConnected(playerid)){
- _vs_CheckPlayerPosition(playerid);
- }
- playerid++;
- } while (playerid < MAX_PLAYERS);
- }
- hook:OnGameModeInit(){
- print("Loading vStreamex");
- for(new i=0;i<MAX_VEHICLES;i++){
- _vs_CurrentVehicles[i][_cInfoID] = INVALID_VEHICLE_ID;
- _vs_CurrentVehicles[i][_cPlayers] = 0;
- _vs_CurrentVehicles[i][_cStreamed] = false;
- if (IsValidVehicle(i)){
- DestroyVehicle(i);
- }
- }
- new a = 0;
- while (a < MAX_LOAD_VEHICLES){
- _vs_VehicleInfos[a][_vModelID] = -1;
- a++;
- }
- for(new z=0;z<12;z++){
- for(new y=0;y<12;y++){
- _vs_LinkerLoader[z][y] = 0;
- }
- }
- SetTimer("_vs_CheckTimer", 1000, true);
- print("vStreamex loaded.");
- }
Add Comment
Please, Sign In to add comment