Guest User

vStreamerEx v0.2

a guest
Jul 23rd, 2013
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <a_samp.inc>
  2. #include <YSI\y_hooks>
  3.  
  4. new GlobalString[32];
  5.  
  6. /*
  7.  
  8.  
  9.     Vehicle Streamer
  10.         - AddVehicle (modelid, color_1, color_2, Float:params[4], respawntime)  [TimeCreated - Unix]
  11.         - LoadVehicles (only = -1, skip = -1)
  12.         - DeleteVehicle(modelid, color_1, color_2, , Float:params[4])
  13.         - ReloadVehicles ()
  14.  
  15.  
  16.  
  17. */
  18.  
  19. #define MAX_LOAD_VEHICLES   100000  //This is for testing purposes only
  20.  
  21. enum _vs_zone{
  22.     _vs_pZone[2]
  23. }
  24.  
  25. new _vs_PlayerZone[MAX_PLAYERS][_vs_zone];
  26.  
  27. enum _vehinfos {
  28.     _vModelID, // (400-611)
  29.     _vColor1,
  30.     _vColor2,
  31.     Float:_vParams[4], // (X, Y, Z, Rot)
  32.     Float:_vTMPParams[4],
  33.     bool:_vTMPLoc,
  34.     _vRespawnTime, // (Sec),
  35.     _vLinkerID,
  36.     bool:_vSpawned
  37. }
  38.  
  39. new _vs_CreatedVehicles = 0;
  40.  
  41. enum _curvehs {
  42.     _cInfoID,
  43.     _cPlayers,
  44.     bool:_cStreamed
  45. }
  46.  
  47. new _vs_LinkerLoader[12][12];
  48. new _vs_VehicleInfosLinker[12][12][MAX_VEHICLES];
  49. new _vs_VehicleInfos[MAX_LOAD_VEHICLES][_vehinfos];
  50.  
  51. new _vs_CurrentVehicles[MAX_VEHICLES][_curvehs];
  52.  
  53. native IsValidVehicle(vehicleid);
  54.  
  55. forward _vs_CheckTimer();
  56. forward _vs_CheckPlayerPosition(playerid);
  57. forward AddVehicle(modelid, color_1, color_2, Float:params[4], respawntime);
  58. forward GetVehicleIDEx(vehicleid);
  59.  
  60. public GetVehicleIDEx(vehicleid){
  61.     return _vs_CurrentVehicles[vehicleid][_cInfoID];
  62. }
  63.  
  64. public AddVehicle(modelid, color_1, color_2, Float:params[4], respawntime) {
  65.  
  66.     new Con[2];
  67.  
  68.     if (modelid >= 400 && modelid <= 611){
  69.         if (_vs_CreatedVehicles == MAX_LOAD_VEHICLES)
  70.             return false;
  71.  
  72.         _vs_VehicleInfos[_vs_CreatedVehicles][_vModelID] = modelid;
  73.         _vs_VehicleInfos[_vs_CreatedVehicles][_vColor1] = color_1;
  74.         _vs_VehicleInfos[_vs_CreatedVehicles][_vColor2] = color_2;
  75.  
  76.         _vs_VehicleInfos[_vs_CreatedVehicles][_vParams][0] = params[0]; // X
  77.         _vs_VehicleInfos[_vs_CreatedVehicles][_vParams][1] = params[1]; // Y
  78.         _vs_VehicleInfos[_vs_CreatedVehicles][_vParams][2] = params[2]; // Z
  79.         _vs_VehicleInfos[_vs_CreatedVehicles][_vParams][3] = params[3]; // Rotation
  80.        
  81.         _vs_VehicleInfos[_vs_CreatedVehicles][_vRespawnTime] = respawntime;
  82.  
  83.         _vs_VehicleInfos[_vs_CreatedVehicles][_vSpawned] = false;
  84.         _vs_VehicleInfos[_vs_CreatedVehicles][_vTMPLoc] = false;
  85.        
  86.         Con[0] = floatround(params[0], floatround_ceil);
  87.         Con[1] = floatround(params[1], floatround_ceil);
  88.        
  89.         GetZone(Con, Con[0], Con[1]);
  90.  
  91.         _vs_VehicleInfos[_vs_CreatedVehicles][_vLinkerID] = _vs_LinkerLoader[Con[0]][Con[1]];
  92.  
  93.         _vs_VehicleInfosLinker[Con[0]][Con[1]][_vs_VehicleInfos[_vs_CreatedVehicles][_vLinkerID]] = _vs_CreatedVehicles;
  94.        
  95.         _vs_LinkerLoader[Con[0]][Con[1]]++; //Increasing Linker ID
  96.        
  97.         _vs_CreatedVehicles++//Increasing Streamed ID
  98.        
  99.     }
  100.  
  101.     return true;
  102. }
  103.  
  104. stock GetZone(params[2], &zone1, &zone2){
  105.     if (params[0] < -2500)
  106.         zone1 = 0;
  107.     else if (params[0] >= -2500 && params[0] < -2000)
  108.         zone1 = 1;
  109.     else if (params[0] >= -2000 && params[0] < -1500)
  110.         zone1 = 2;
  111.     else if (params[0] >= -1500 && params[0] < -1000)
  112.         zone1 = 3;
  113.     else if (params[0] >= -1000 && params[0] < -500)
  114.         zone1 = 4;
  115.     else if (params[0] >= -500 && params[0] < 0)
  116.         zone1 = 5;
  117.     else if (params[0] >= 0 && params[0] < 500)
  118.         zone1 = 6;
  119.     else if (params[0] >= 500 && params[0] < 1000)
  120.         zone1 = 7;
  121.     else if (params[0] >= 1000 && params[0] < 1500)
  122.         zone1 = 8;
  123.     else if (params[0] >= 1500 && params[0] < 2000)
  124.         zone1 = 9;
  125.     else if (params[0] >= 2000 && params[0] < 2500)
  126.         zone1 = 10;
  127.     else if (params[0] >= 2500 && params[0] < 3000)
  128.         zone1 = 11;
  129.     else
  130.         zone1 = -1;
  131.        
  132.     if (params[1] < -2500)
  133.         zone2 = 0;
  134.     else if (params[1] >= -2500 && params[1] < -2000)
  135.         zone2 = 1;
  136.     else if (params[1] >= -2000 && params[1] < -1500)
  137.         zone2 = 2;
  138.     else if (params[1] >= -1500 && params[1] < -1000)
  139.         zone2 = 3;
  140.     else if (params[1] >= -1000 && params[1] < -500)
  141.         zone2 = 4;
  142.     else if (params[1] >= -500 && params[1] < 0)
  143.         zone2 = 5;
  144.     else if (params[1] >= 0 && params[1] < 500)
  145.         zone2 = 6;
  146.     else if (params[1] >= 500 && params[1] < 1000)
  147.         zone2 = 7;
  148.     else if (params[1] >= 1000 && params[1] < 1500)
  149.         zone2 = 8;
  150.     else if (params[1] >= 1500 && params[1] < 2000)
  151.         zone2 = 9;
  152.     else if (params[1] >= 2000 && params[1] < 2500)
  153.         zone2 = 10;
  154.     else if (params[1] >= 2500 && params[1] < 3000)
  155.         zone2 = 11;
  156.     else
  157.         zone2 = -1;
  158.        
  159.     return true;
  160. }
  161.  
  162. public _vs_CheckPlayerPosition(playerid){
  163.     new Float:Pos[4], Zone[18], newv, cid, Zones[2];
  164.     if (IsPlayerConnected(playerid)){
  165.         GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  166.        
  167.         Zone[0] = floatround(Pos[0], floatround_ceil);
  168.         Zone[1] = floatround(Pos[1], floatround_ceil);
  169.        
  170.         Zones[0] = Zone[0];
  171.         Zones[1] = Zone[1];
  172.        
  173.         GetZone(Zones, Zone[0], Zone[1]);
  174.        
  175.         Zone[2] = floatround(Pos[0] - 300, floatround_ceil);
  176.         Zone[3] = floatround(Pos[1] - 300, floatround_ceil);
  177.        
  178.         Zones[0] = Zone[2];
  179.         Zones[1] = Zone[3];
  180.        
  181.         GetZone(Zones, Zone[2], Zone[3]);
  182.        
  183.         Zone[4] = floatround(Pos[0], floatround_ceil);
  184.         Zone[5] = floatround(Pos[1] - 300, floatround_ceil);
  185.        
  186.         Zones[0] = Zone[4];
  187.         Zones[1] = Zone[5];
  188.        
  189.         GetZone(Zones, Zone[4], Zone[5]);
  190.        
  191.         Zone[6] = floatround(Pos[0] + 300, floatround_ceil);
  192.         Zone[7] = floatround(Pos[1] - 300, floatround_ceil);
  193.        
  194.         Zones[0] = Zone[6];
  195.         Zones[1] = Zone[7];
  196.        
  197.         GetZone(Zones, Zone[6], Zone[7]);
  198.        
  199.         Zone[8] = floatround(Pos[0] - 300, floatround_ceil);
  200.         Zone[9] = floatround(Pos[1], floatround_ceil);
  201.        
  202.         Zones[0] = Zone[8];
  203.         Zones[1] = Zone[9];
  204.        
  205.         GetZone(Zones, Zone[8], Zone[9]);
  206.        
  207.         Zone[10] = floatround(Pos[0] + 300, floatround_ceil);
  208.         Zone[11] = floatround(Pos[1], floatround_ceil);
  209.        
  210.         Zones[0] = Zone[10];
  211.         Zones[1] = Zone[11];
  212.        
  213.         GetZone(Zones, Zone[10], Zone[11]);
  214.        
  215.         Zone[12] = floatround(Pos[0] - 300, floatround_ceil);
  216.         Zone[13] = floatround(Pos[1] + 300, floatround_ceil);
  217.        
  218.         Zones[0] = Zone[12];
  219.         Zones[1] = Zone[13];
  220.        
  221.         GetZone(Zones, Zone[12], Zone[13]);
  222.        
  223.         Zone[14] = floatround(Pos[0], floatround_ceil);
  224.         Zone[15] = floatround(Pos[1] + 300, floatround_ceil);
  225.        
  226.         Zones[0] = Zone[14];
  227.         Zones[1] = Zone[15];
  228.        
  229.         GetZone(Zones, Zone[14], Zone[15]);
  230.        
  231.         Zone[16] = floatround(Pos[0] + 300, floatround_ceil);
  232.         Zone[17] = floatround(Pos[1] + 300, floatround_ceil);
  233.        
  234.         Zones[0] = Zone[16];
  235.         Zones[1] = Zone[17];
  236.        
  237.         GetZone(Zones, Zone[16], Zone[17]);
  238.        
  239.         if (Zone[0] != _vs_PlayerZone[playerid][_vs_pZone][0] || Zone[1] != _vs_PlayerZone[playerid][_vs_pZone][1]){
  240.            
  241.             _vs_PlayerZone[playerid][_vs_pZone][0] = Zone[0];
  242.             _vs_PlayerZone[playerid][_vs_pZone][1] = Zone[1];
  243.            
  244.             for (new _vs_lv=0;_vs_lv<_vs_LinkerLoader[Zone[0]][Zone[1]];_vs_lv++){
  245.                 cid = _vs_VehicleInfosLinker[Zone[0]][Zone[1]][_vs_lv];
  246.                 if (NearVehicle(playerid, cid, Pos[0], Pos[1], Pos[2], Pos[3])){
  247.                     if (!_vs_VehicleInfos[cid][_vSpawned]){
  248.                         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){
  249.                             _vs_CurrentVehicles[newv][_cInfoID] = cid;
  250.  
  251.                             format (GlobalString, sizeof (GlobalString), "ID %d created, dID %d", newv, cid);   // Remove
  252.                             SendClientMessageToAll(0xFFFF00AA, GlobalString);   // Remove
  253.  
  254.                             _vs_VehicleInfos[cid][_vSpawned] = true;
  255.                         }
  256.                     }
  257.                 }
  258.             }
  259.         }
  260.     }
  261. }
  262.  
  263. stock NearVehicle(playerid, vehicleid, &Float:X, &Float:Y, &Float:Z, &Float:Angle){
  264. //  new Float:Range, stream_distance[4];
  265.     if (_vs_VehicleInfos[vehicleid][_vTMPLoc]){
  266.         X = _vs_VehicleInfos[vehicleid][_vTMPParams][0];
  267.         Y = _vs_VehicleInfos[vehicleid][_vTMPParams][1];
  268.         Z = _vs_VehicleInfos[vehicleid][_vTMPParams][2];
  269.         Angle = _vs_VehicleInfos[vehicleid][_vTMPParams][3];
  270.     } else {
  271.         X = _vs_VehicleInfos[vehicleid][_vParams][0];
  272.         Y = _vs_VehicleInfos[vehicleid][_vParams][1];
  273.         Z = _vs_VehicleInfos[vehicleid][_vParams][2];
  274.         Angle = _vs_VehicleInfos[vehicleid][_vParams][3];
  275.     }
  276.    
  277. //  GetServerVarAsString(stream_distance, "stream_distance", sizeof (stream_distance));
  278. //  Range = floatstr(stream_distance);
  279.    
  280.     if (IsPlayerInRangeOfPoint(playerid, 300.0, X, Y, Z)){
  281.         return true;
  282.     }
  283.     return false;
  284. }
  285.  
  286. hook:OnVehicleStreamIn(vehicleid, forplayerid){
  287.     _vs_CurrentVehicles[vehicleid][_cPlayers]++;
  288. }
  289.  
  290. hook:OnVehicleStreamOut(vehicleid, forplayerid){
  291.     new soParams[2], Float:Position[4];
  292.     _vs_CurrentVehicles[vehicleid][_cPlayers]--;
  293.     if (_vs_CurrentVehicles[vehicleid][_cPlayers] <= 0){
  294.         _vs_CurrentVehicles[vehicleid][_cPlayers] = 0;
  295.        
  296.         format (GlobalString, sizeof (GlobalString), "ID %d deleted, dID", vehicleid);  // Remove
  297.        
  298.         GetVehiclePos(vehicleid, Position[0], Position[1], Position[2]);
  299.         GetVehicleZAngle(vehicleid, Position[3]);
  300.        
  301.         DestroyVehicle(vehicleid);
  302.         vehicleid = _vs_CurrentVehicles[vehicleid][_cInfoID];
  303.        
  304.         format (GlobalString, sizeof (GlobalString), "%s %d", GlobalString, vehicleid); // Remove
  305.        
  306.         _vs_VehicleInfos[vehicleid][_vSpawned] = false;
  307.        
  308.         if (!_vs_VehicleInfos[vehicleid][_vTMPLoc]){
  309.  
  310.             _vs_VehicleInfos[vehicleid][_vTMPLoc] = true;
  311.             soParams[0] = floatround(_vs_VehicleInfos[vehicleid][_vParams][0], floatround_ceil);
  312.             soParams[1] = floatround(_vs_VehicleInfos[vehicleid][_vParams][1], floatround_ceil);
  313.  
  314.         } else {
  315.        
  316.             soParams[0] = floatround(_vs_VehicleInfos[vehicleid][_vTMPParams][0], floatround_ceil);
  317.             soParams[1] = floatround(_vs_VehicleInfos[vehicleid][_vTMPParams][1], floatround_ceil);
  318.  
  319.         }
  320.  
  321.         GetZone(soParams, soParams[0], soParams[1]);
  322.        
  323.         _vs_LinkerLoader[soParams[0]][soParams[1]]--;
  324.         _vs_VehicleInfosLinker[soParams[0]][soParams[1]][_vs_VehicleInfos[vehicleid][_vLinkerID]] = -1;
  325.  
  326.         _vs_VehicleInfos[vehicleid][_vTMPParams][0] = Position[0];
  327.         _vs_VehicleInfos[vehicleid][_vTMPParams][1] = Position[1];
  328.         _vs_VehicleInfos[vehicleid][_vTMPParams][2] = Position[2];
  329.         _vs_VehicleInfos[vehicleid][_vTMPParams][3] = Position[3];
  330.  
  331.         soParams[0] = floatround(_vs_VehicleInfos[vehicleid][_vTMPParams][0], floatround_ceil);
  332.         soParams[1] = floatround(_vs_VehicleInfos[vehicleid][_vTMPParams][1], floatround_ceil);
  333.  
  334.         GetZone(soParams, soParams[0], soParams[1]);
  335.  
  336.         _vs_VehicleInfos[vehicleid][_vLinkerID] = _vs_LinkerLoader[soParams[0]][soParams[1]];
  337.  
  338.         _vs_VehicleInfosLinker[soParams[0]][soParams[1]][_vs_VehicleInfos[vehicleid][_vLinkerID]] = vehicleid;
  339.         _vs_LinkerLoader[soParams[0]][soParams[1]]++;
  340.  
  341.         SendClientMessageToAll(0xFFFF00AA, GlobalString);   // Remove
  342.     }
  343. }
  344.  
  345.  
  346. public _vs_CheckTimer(){
  347.     new playerid = 0;
  348.     do {
  349.         if (IsPlayerConnected(playerid)){
  350.             _vs_CheckPlayerPosition(playerid);
  351.         }
  352.         playerid++;
  353.     } while (playerid < MAX_PLAYERS);
  354. }
  355.  
  356. hook:OnGameModeInit(){
  357.     print("Loading vStreamex");
  358.     for(new i=0;i<MAX_VEHICLES;i++){
  359.         _vs_CurrentVehicles[i][_cInfoID] = INVALID_VEHICLE_ID;
  360.         _vs_CurrentVehicles[i][_cPlayers] = 0;
  361.         _vs_CurrentVehicles[i][_cStreamed] = false;
  362.         if (IsValidVehicle(i)){
  363.             DestroyVehicle(i);
  364.         }
  365.     }
  366.  
  367.     new a = 0;
  368.  
  369.     while (a < MAX_LOAD_VEHICLES){
  370.         _vs_VehicleInfos[a][_vModelID] = -1;
  371.         a++;
  372.     }
  373.    
  374.     for(new z=0;z<12;z++){
  375.         for(new y=0;y<12;y++){
  376.             _vs_LinkerLoader[z][y] = 0;
  377.         }
  378.     }
  379.     SetTimer("_vs_CheckTimer", 1000, true);
  380.     print("vStreamex loaded.");
  381. }
Add Comment
Please, Sign In to add comment