Advertisement
Guest User

Pixels

a guest
Jan 19th, 2009
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.19 KB | None | 0 0
  1. /*       (c) 2008 Pixels^      */
  2. /*       To modify or redistribute you need my permission.    */
  3.  
  4. #define Radius 200
  5. #define MAX_STREAM_OBJECTS 1000 //Set at 1000, you can change to whatever you want.
  6.  
  7. enum Management
  8. {
  9.     Float:X,
  10.     Float:Y,
  11.     Float:Z,
  12.     Float:rX,
  13.     Float:rY,
  14.     Float:rZ,
  15.     Model,
  16.     Used,
  17.     PlayerAttach,
  18.     Float:AttachX,
  19.     Float:AttachY,
  20.     Float:AttachZ
  21. }
  22. new Object[MAX_STREAM_OBJECTS][Management];
  23. new Player[MAX_PLAYERS][MAX_STREAM_OBJECTS];
  24. new ObjectTotal;
  25. new ObjectTimer;
  26. new Float:oldposx, Float:oldposy, Float:oldposz;
  27. new Float:tempposx, Float:tempposy, Float:tempposz;
  28. forward p_OnGameModeInit();
  29. forward ObjectStream();
  30.  
  31. stock p_OnGameModeInit()
  32.     ObjectTimer = SetTimer("ObjectStream",500,1);
  33.  
  34. stock p_OnGameModeExit()
  35.     KillTimer(ObjectTimer);
  36.  
  37. stock CreateDynamicObject(modelid, Float:X1, Float:Y1, Float:Z1, Float:rX1, Float:rY1, Float:rZ1)
  38. {
  39.     if(ObjectTotal >= MAX_STREAM_OBJECTS) return -1;
  40.     ObjectTotal += 1;
  41.     Object[ObjectTotal][X] = X1;
  42.     Object[ObjectTotal][Y] = Y1;
  43.     Object[ObjectTotal][Z] = Z1;
  44.     Object[ObjectTotal][rX] = rX1;
  45.     Object[ObjectTotal][rY] = rY1;
  46.     Object[ObjectTotal][rZ] = rZ1;
  47.     Object[ObjectTotal][Model] = modelid;
  48.     Object[ObjectTotal][PlayerAttach] = -1;
  49.     Object[ObjectTotal][Used] = 1;
  50.     return ObjectTotal;
  51. }
  52.  
  53. stock DestroyDynamicObject(dObjectID)
  54. {
  55.     Object[dObjectID][X] = 0;
  56.     Object[dObjectID][Y] = 0;
  57.     Object[dObjectID][Z] = 0;
  58.     Object[dObjectID][rX] = 0;
  59.     Object[dObjectID][rY] = 0;
  60.     Object[dObjectID][rZ] = 0;
  61.     Object[dObjectID][Model] = 0;
  62.     Object[dObjectID][Used] = 0;
  63.     Object[ObjectTotal][PlayerAttach] = -1;
  64.     return 1;
  65. }
  66.  
  67. stock IsValidDynamicObject(dObjectID)
  68.     return Object[dObjectID][Used];
  69.  
  70. stock GetDynamicObjectPos(dObjectID, Float:X2, Float:Y2, Float:Z2)
  71. {
  72.     X2 = Object[dObjectID][X];
  73.     Y2 = Object[dObjectID][Y];
  74.     Z2 = Object[dObjectID][Z];
  75.     return 1;
  76. }
  77.  
  78. stock SetDynamicObjectPos(dObjectID, Float:X2, Float:Y2, Float:Z2)
  79. {
  80.     Object[dObjectID][X] = X2;
  81.     Object[dObjectID][Y] = Y2;
  82.     Object[dObjectID][Z] = Z2;
  83.     for(new i=0; i<MAX_PLAYERS; i++) if(IsPlayerConnected(i))
  84.     {
  85.         if(Player[i][dObjectID] != -1)
  86.         {
  87.             DestroyPlayerObject(i, Player[i][dObjectID]);
  88.             Player[i][dObjectID] = CreatePlayerObject(i, Object[dObjectID][Model],Object[dObjectID][X], Object[dObjectID][Y], Object[dObjectID][Z], Object[dObjectID][rX], Object[dObjectID][rY], Object[dObjectID][rZ]);
  89.         }
  90.     }
  91.     return 1;
  92. }
  93.  
  94. stock AttachDynamicObjectToPlayer(dObjectID, playerid, Float:OffsetX, Float:OffsetY, Float:OffsetZ)
  95. {
  96.     Object[dObjectID][PlayerAttach] = playerid;
  97.     for(new i=0; i<MAX_PLAYERS; i++) if(IsPlayerConnected(i))
  98.     {
  99.         if(Player[i][dObjectID] != -1)
  100.         {
  101.             Object[dObjectID][AttachX] = OffsetX;
  102.             Object[dObjectID][AttachY] = OffsetY;
  103.             Object[dObjectID][AttachZ] = OffsetZ;
  104.             AttachPlayerObjectToPlayer(playerid,Player[i][dObjectID],playerid,OffsetX,OffsetY,OffsetZ,0,0,0);
  105.         }
  106.     }
  107.     return 1;
  108. }
  109.  
  110. stock DetachDynamicObjectFromPlayer(dObjectID, playerid)
  111. {
  112.     Object[dObjectID][PlayerAttach] = -1;
  113.     for(new i=0; i<MAX_PLAYERS; i++) if(IsPlayerConnected(i))
  114.     {
  115.         if(Player[i][dObjectID] != -1)
  116.         {
  117.             DestroyPlayerObject(i,Player[i][dObjectID]);
  118.             Player[i][dObjectID] = -1;
  119.         }
  120.     }
  121.     return 1;
  122. }
  123.  
  124. stock MoveDynamicObject(dObjectID, Float:X2, Float:Y2, Float:Z2, Float:Speed)
  125. {
  126.     Object[dObjectID][X] = X2;
  127.     Object[dObjectID][Y] = Y2;
  128.     Object[dObjectID][Z] = Z2;
  129.     for(new i=0; i<MAX_PLAYERS; i++) if(IsPlayerConnected(i))
  130.     {
  131.         if(Player[i][dObjectID] != -1)
  132.             MovePlayerObject(i, Player[i][dObjectID], X2, Y2, Z2, Speed);
  133.     }
  134. }
  135.  
  136. stock StopDynamicObject(dObjectID)
  137. {
  138.     for(new i=0; i<MAX_PLAYERS; i++) if(IsPlayerConnected(i))
  139.     {
  140.         if(Player[i][dObjectID] != -1)
  141.             StopPlayerObject(i, Player[i][dObjectID]);
  142.     }
  143. }
  144.  
  145. public ObjectStream()
  146. {
  147.     new x;
  148.     for(new i=0; i<MAX_PLAYERS; i++) if(IsPlayerConnected(i))
  149.     {
  150.         for(x=0; x<ObjectTotal; x++)
  151.         {
  152.             if(PlayerToPoint(Radius, i, Object[x][X], Object[x][Y], Object[x][Z]))
  153.             {
  154.                 if(Player[i][x] == -1 && Object[x][Used] == 1 && Object[x][PlayerAttach] == -1)
  155.                     Player[i][x] = CreatePlayerObject(i, Object[x][Model],Object[x][X], Object[x][Y], Object[x][Z], Object[x][rX], Object[x][rY], Object[x][rZ]);
  156.                 else if(Player[i][x] == -1 && Object[x][Used] == 1 && Object[x][PlayerAttach] != -1)
  157.                 {
  158.                     Player[i][x] = CreatePlayerObject(i, Object[x][Model],Object[x][X], Object[x][Y], Object[x][Z], Object[x][rX], Object[x][rY], Object[x][rZ]);
  159.                     AttachPlayerObjectToPlayer(i,Player[i][x],Object[x][PlayerAttach],Object[x][AttachX],Object[x][AttachY],Object[x][AttachZ],0,0,0);
  160.                 }
  161.             }
  162.             if(!PlayerToPoint(Radius, i, Object[x][X], Object[x][Y], Object[x][Z]))
  163.             {
  164.                 if(Player[i][x] != -1 && Object[x][Used] == 1)
  165.                 {
  166.                     DestroyPlayerObject(i, Player[i][x]);
  167.                     Player[i][x] = -1;
  168.                 }
  169.             }
  170.         }
  171.     }
  172. }
  173.  
  174. stock PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
  175. {
  176.     GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  177.     tempposx = (oldposx -x);
  178.     tempposy = (oldposy -y);
  179.     tempposz = (oldposz -z);
  180.     if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  181.         return 1;
  182.     return 0;
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement