Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.59 KB | None | 0 0
  1. /*  Object Streamer
  2.  *
  3.  *  (c) Copyright 2008, Einstein
  4.  */
  5.  
  6. #define YOUPLAYERSLOTS 100   //EDIT HERE THE NUMBER OF YOUR PLAYERSLOTS
  7. #define MAX_STREAM_OBJECTS 10000
  8. #define MAX_STREAM_AT_SAME_TIME 142
  9. #define MAXUPDATES 13
  10.  
  11. forward ObjectCheck(playerid);
  12.  
  13. new ObjectCount[YOUPLAYERSLOTS];
  14. new haveobject[YOUPLAYERSLOTS][MAX_STREAM_OBJECTS];
  15. new ID;
  16. new modelid2[MAX_STREAM_OBJECTS];
  17. new Float:x2[MAX_STREAM_OBJECTS];
  18. new Float:y2[MAX_STREAM_OBJECTS];
  19. new Float:z2[MAX_STREAM_OBJECTS];
  20. new Float:rX2[MAX_STREAM_OBJECTS];
  21. new Float:rY2[MAX_STREAM_OBJECTS];
  22. new Float:rZ2[MAX_STREAM_OBJECTS];
  23. new ViewDistance2[MAX_STREAM_OBJECTS];
  24. new Float:MoveX2[MAX_STREAM_OBJECTS];
  25. new Float:MoveY2[MAX_STREAM_OBJECTS];
  26. new Float:MoveZ2[MAX_STREAM_OBJECTS];
  27. new Float:MoveSpeed2[MAX_STREAM_OBJECTS];
  28. new moved[MAX_STREAM_OBJECTS];
  29. new objectres[YOUPLAYERSLOTS][MAX_STREAM_OBJECTS];
  30. new Float:playerpos2[YOUPLAYERSLOTS][3];
  31. new updatespassed = 0;
  32. new playersonline;
  33.  
  34. //From the Samp Forums: Usual Functions
  35.  
  36. stock IsPlayerInBall(playerid,Float:x,Float:y,Float:z,radius)
  37.     {
  38.     if(GetPlayerDistanceToPoint(playerid,x,y,z) < radius)
  39.         {
  40.         return 1;
  41.         }
  42.     return 0;
  43. }
  44.  
  45. stock GetPlayerDistanceToPoint(playerid,Float:x,Float:y,Float:z)
  46.     {
  47.     new Float:x1,Float:y1,Float:z1;
  48.     new Float:tmpdis;
  49.     GetPlayerPos(playerid,x1,y1,z1);
  50.     tmpdis = floatsqroot(floatpower(floatabs(floatsub(Float:x,x1)),2)+floatpower(floatabs(floatsub(Float:y,y1)),2)+floatpower(floatabs(floatsub(Float:z,z1)),2));
  51.     return floatround(tmpdis);
  52.     }      
  53.  
  54. //ObjectStreamer Functions
  55. stock CreateObjectToStream(modelid, Float:x, Float:y, Float:z, Float:rX, Float:rY, Float:rZ)
  56.     {
  57.     modelid2[ID] = modelid;
  58.     x2[ID] = Float:x;
  59.     y2[ID] = Float:y;
  60.     z2[ID] = Float:z;
  61.     rX2[ID] = Float:rX;
  62.     rY2[ID] = Float:rY;
  63.     rZ2[ID] = Float:rZ;
  64.     ViewDistance2[ID] = 142;
  65.     ID++;
  66.     return ID-1;
  67.     }
  68.  
  69. stock CreatePlayerObjectToStream(playerid ,modelid, Float:x, Float:y, Float:z, Float:rX, Float:rY, Float:rZ) //untested
  70.     {
  71.     modelid2[ID] = modelid;
  72.     x2[ID] = Float:x;
  73.     y2[ID] = Float:y;
  74.     z2[ID] = z;
  75.     rX2[ID] = rX;
  76.     rY2[ID] = rY;
  77.     rZ2[ID] = rZ;
  78.     ViewDistance2[ID] = 142;
  79.     ID++;
  80.     for(new i=0; i<YOUPLAYERSLOTS; i++)
  81.         {
  82.         haveobject[i][ID] = -1;
  83.         }
  84.     haveobject[playerid][ID] = 0;  
  85.     return ID-1;
  86.     }
  87.  
  88. stock DestroyObjectToStream(streamobjectid)
  89.     {
  90.     modelid2[streamobjectid] = 0;
  91.     x2[streamobjectid] = 0;
  92.     y2[streamobjectid] = 0;
  93.     z2[streamobjectid] = -1000;
  94.     rX2[streamobjectid] = 0;
  95.     rY2[streamobjectid] = 0;
  96.     rZ2[streamobjectid] = 0;
  97.     ViewDistance2[streamobjectid] = 0;
  98.     for(new i=0; i<YOUPLAYERSLOTS; i++)
  99.         {
  100.         if(haveobject[i][streamobjectid] == 1)
  101.             {
  102.             DestroyPlayerObject(i, objectres[i][streamobjectid]);
  103.             }
  104.         haveobject[i][streamobjectid] = -1;
  105.         }
  106.     }
  107.  
  108. stock DestroyPlayerObjectToStream(playerid, streamobjectid) //untested
  109.     {
  110.     modelid2[streamobjectid] = 0;
  111.     x2[streamobjectid] = 0;
  112.     y2[streamobjectid] = 0;
  113.     z2[streamobjectid] = -1000;
  114.     rX2[streamobjectid] = 0;
  115.     rY2[streamobjectid] = 0;
  116.     rZ2[streamobjectid] = 0;
  117.     ViewDistance2[streamobjectid] = 0;
  118.     if(haveobject[playerid][streamobjectid] == 1)
  119.         {
  120.         DestroyPlayerObject(playerid, objectres[playerid][streamobjectid]);
  121.         }
  122.     haveobject[playerid][streamobjectid] = -1;
  123.     }
  124.            
  125. stock MoveObjectToStream(streamobjectid, Float:Movex, Float:Movey, Float:Movez, Float:Speed)
  126.     {
  127.     MoveX2[streamobjectid] = Movex;
  128.     MoveY2[streamobjectid] = Movey;
  129.     MoveZ2[streamobjectid] = Movez;
  130.     MoveSpeed2[streamobjectid] = Speed;
  131.     moved[streamobjectid] = 1;
  132.     for(new i=0; i<YOUPLAYERSLOTS; i++)
  133.         {
  134.         if(haveobject[i][streamobjectid] == 1)
  135.             {
  136.             MovePlayerObject(i, objectres[i][streamobjectid], MoveX2[streamobjectid], MoveY2[streamobjectid], MoveZ2[streamobjectid], MoveSpeed2[streamobjectid]);
  137.             }
  138.         }  
  139.     }
  140.    
  141. stock StopObjectToStream(streamobjectid)
  142.     {
  143.     for(new i=0; i<YOUPLAYERSLOTS; i++)
  144.         {
  145.         if(haveobject[i][streamobjectid] == 1)
  146.             {
  147.             StopPlayerObject(i, objectres[i][streamobjectid]);
  148.             }
  149.         }  
  150.     }  
  151.  
  152. stock GetBasePosObjectToStream(streamobjectid, &Float:x, &Float:y, &Float:z) //untested
  153.     {
  154.     x = x2[streamobjectid];
  155.     y = y2[streamobjectid];
  156.     z = z2[streamobjectid];
  157.     }
  158.  
  159. stock GetMovePosObjectToStream(stramobjectid, &Float:x, &Float:y, &Float:z) //untested
  160.     {
  161.     x = MoveX2[streamobjectid];
  162.     y = MoveY2[streamobjectid];
  163.     z = MoveZ2[streamobjectid];
  164.     }
  165.  
  166. stock GetCurrentPosObjectToStream(streamobjectid, &Float:x, &Float:y, &Float:z) //untested
  167.     {
  168.     if(moved[streamobjectid] == 0)
  169.         {
  170.         x = x2[streamobjectid];
  171.         y = y2[streamobjectid];
  172.         z = z2[streamobjectid];
  173.         }
  174.     else if(moved[streamobjectid] == 1)
  175.         {
  176.         x = MoveX2[streamobjectid];
  177.         y = MoveY2[streamobjectid];
  178.         z = MoveZ2[streamobjectid];
  179.         }
  180.     }
  181.  
  182. stock GetCurrentRotObjectToStream(streamobjectid, &Float:Rx, &Float:Ry, &Float:Rz) //untested
  183.     {
  184.     Rx = rX2[streamobjectid];
  185.     Ry = rY2[streamobjectid];
  186.     Rz = rZ2[streamobjectid];
  187.     }  
  188.    
  189. stock SetObjectPosToStream(streamobjectid, Float:x, Float:y, Float:z)
  190.     {
  191.     for(new i=0; i<YOUPLAYERSLOTS; i++)
  192.         {
  193.         if(haveobject[i][streamobjectid] == 1)
  194.             {
  195.             SetPlayerObjectPos(i, objectres[i][streamobjectid], x, y, z);
  196.             }
  197.         }
  198.     x2[streamobjectid] = x;
  199.     y2[streamobjectid] = y;
  200.     z2[streamobjectid] = z;
  201.     }
  202.  
  203. stock SetObjectRotToStream(streamobjectid, Float:rX, Float:rY, Float:rZ)
  204.     {
  205.     for(new i=0; i<YOUPLAYERSLOTS; i++)
  206.         {
  207.         if(haveobject[i][streamobjectid] == 1)
  208.             {                          
  209.             SetPlayerObjectRot(i, objectres[i][streamobjectid], rX, rY, rZ);
  210.             }
  211.         }
  212.     rX2[streamobjectid] = Float:rX;
  213.     rY2[streamobjectid] = Float:rY;
  214.     rZ2[streamobjectid] = Float:rZ;
  215.     }
  216.  
  217. stock SetObjectViewDistanceToStream(streamobjectid, Viewdistance)
  218.     {
  219.     ViewDistance2[streamobjectid] = Viewdistance;
  220.     }
  221.    
  222. stock SetGloabalViewDistanceToStream(Viewdistance)
  223.     {
  224.     for(new Objects=0; Objects<ID; Objects++)
  225.         {
  226.         ViewDistance2[Objects] = Viewdistance;
  227.         }
  228.     }
  229.  
  230. stock SetObjectViewDistanceToStreamEx(streamobjectidMIN, streamobjectidMAX, Viewdistance)
  231.     {
  232.     for(new Objects=streamobjectidMIN; Objects<streamobjectidMAX; Objects++)
  233.         {
  234.         ViewDistance2[Objects] = Viewdistance;
  235.         }
  236.     }
  237.    
  238. /* Not work with the new Movesystem
  239. stock SetObjectMoveSpeedToStream(streamobjectid, Float:Speed)
  240.     {
  241.     MoveSpeed2[streamobjectid] = Speed;
  242.     }  
  243. */ 
  244.  
  245. stock HavePlayerObjectToStream(playerid,streamobjectid)
  246.     {
  247.     if(haveobject[playerid][streamgateid] == 1)
  248.         {
  249.         return 0;
  250.         }
  251.     else if(haveobject[playerid][streamobjectid] == 0)
  252.         {
  253.         return 1;
  254.         }
  255.     }
  256.    
  257. stock HavePlayerAnyObjectToStream(playerid)
  258.     {
  259.     for(new object=0; object<ID; object++)
  260.         {
  261.         if(haveobject[playerid][object] == 1)
  262.             {
  263.             return 0;
  264.             }
  265.         }
  266.     return 1;
  267.     }                  
  268.  
  269. stock HaveObjectAnyPlayerToStream(streamobjectid) //untested
  270.     {
  271.     for(new i=0; i<YOUPLAYERSLOTS< i++)
  272.         {
  273.         if(haveobject[i][streamobjectid] == 1)
  274.             {
  275.             return 0;
  276.             }
  277.         }
  278.     return 1;
  279.     }      
  280.                        
  281.                    
  282. stock StreamObject_OnPlayerUpdate(playerid)
  283.     {
  284.     if( updatespassed == MAXUPDATES)
  285.     {
  286.         ObjectCheck(playerid);
  287.     }
  288.     updatespassed++;
  289.     }
  290.    
  291. stock StreamObject_OnPlayerConnect(playerid)
  292.     {
  293.     for(new k=0; k<ID; k++)
  294.         {
  295.         haveobject[playerid][k] = 0;
  296.         objectres[playerid][k] = -1;
  297.        
  298.         }
  299.     ObjectCount[playerid] = 0; //untested
  300.     }
  301.  
  302. public ObjectCheck(playerid)
  303.     {
  304.     new Float:playerx, Float:playery, Float:playerz;
  305.     GetPlayerPos(playerid, playerx, playery, playerz);
  306.     if(playerpos2[playerid][0] != playerx || playerpos2[playerid][1] != playery || playerpos2[playerid][2] != playerz)
  307.         {
  308.         playerpos2[playerid][0] = playerx;
  309.         playerpos2[playerid][1] = playery;
  310.         playerpos2[playerid][2] = playerz;     
  311.         for(new objects=0; objects<ID; objects++)
  312.             {
  313.             if(IsPlayerInBall(playerid,x2[objects], y2[objects], z2[objects], ViewDistance2[objects]))
  314.                 {
  315.                 if(ObjectCount[playerid] < MAX_STREAM_AT_SAME_TIME)
  316.                     {
  317.                     if(haveobject[playerid][objects] == 0)
  318.                         {
  319.                         if(moved[objects] == 0)
  320.                             {
  321.                             objectres[playerid][objects] = CreatePlayerObject(playerid, modelid2[objects], x2[objects], y2[objects], z2[objects], rX2[objects], rY2[objects], rZ2[objects]);
  322.                             ObjectCount[playerid]++;
  323.                             haveobject[playerid][objects] = 1;
  324.                             }
  325.                         else if(moved[objects] == 1)
  326.                             {
  327.                             objectres[playerid][objects] = CreatePlayerObject(playerid, modelid2[objects], MoveX2[objects], MoveY2[objects], MoveZ2[objects], rX2[objects], rY2[objects], rZ2[objects]);
  328.                             ObjectCount[playerid]++;
  329.                             haveobject[playerid][objects] = 1;
  330.                             }
  331.                         }
  332.                     }
  333.                 }
  334.             else
  335.                 {
  336.                 if(haveobject[playerid][objects] == 1)
  337.                     {
  338.                     DestroyPlayerObject(playerid, objectres[playerid][objects]);
  339.                     ObjectCount[playerid]--;
  340.                     haveobject[playerid][objects] = 0;
  341.                     }
  342.                 }
  343.             }
  344.         }  
  345.     return 1;
  346.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement