SHARE
TWEET

AutoMove.inc

a guest Sep 17th, 2017 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //made by lokii
  2.  
  3. #if defined _AutoMove_included
  4.       #endinput
  5. #define _AutoMove_included
  6. #endif
  7.  
  8. /*
  9. native CreateAutoObject(id, modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, worldid = -1, interiorid = -1, Float:stream_distance, Float:move_distance, Float:tox, Float:toy, Float:toz, Float:torx, Float:tory, Float:torz, Float:move_speed);
  10. native OpenAutoObject(id);
  11. native CloseAutoObject(id)
  12. native DestroyAutoObject(id);
  13. native DestroyAllAutoObjects();
  14. */
  15.  
  16. #include <streamer>  //credits to incognito
  17. #include <YSI\y_hooks>  //credits to y_less
  18.  
  19. #define AutoMoveVersion "2.0"
  20.  
  21. #define MAX_AUTO_OBJECTS 1000
  22.  
  23. enum I_AutoMoveX
  24. {
  25.     Float:am_posx,
  26.     Float:am_posy,
  27.     Float:am_posz,
  28.     Float:am_posrx,
  29.     Float:am_posry,
  30.     Float:am_posrz,
  31.     Float:am_postox,
  32.     Float:am_postoy,
  33.     Float:am_postoz,
  34.     Float:am_postorx,
  35.     Float:am_postory,
  36.     Float:am_postorz,
  37.     Float:am_speed,
  38.     am_areaid,
  39.     am_objectid,
  40.     bool:am_used,
  41.     bool:am_exist,
  42.     am_count
  43. }
  44. new I_AutoMove[MAX_AUTO_OBJECTS][I_AutoMoveX];
  45.  
  46. stock CreateAutoObject(id, modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, worldid = -1, interiorid = -1, Float:stream_distance, Float:move_distance, Float:tox, Float:toy, Float:toz, Float:torx, Float:tory, Float:torz, Float:move_speed)
  47. {
  48.      DestroyDynamicObject(I_AutoMove[id][am_objectid]);
  49.      I_AutoMove[id][am_posx] = x;
  50.      I_AutoMove[id][am_posy] = y;
  51.      I_AutoMove[id][am_posz] = z;
  52.      I_AutoMove[id][am_posrx] = rx;
  53.      I_AutoMove[id][am_posry] = ry;
  54.      I_AutoMove[id][am_posrz] = rz;
  55.      I_AutoMove[id][am_postox] = tox;
  56.      I_AutoMove[id][am_postoy] = toy;
  57.      I_AutoMove[id][am_postoz] = toz;
  58.      I_AutoMove[id][am_postorx] = torx;
  59.      I_AutoMove[id][am_postory] = tory;
  60.      I_AutoMove[id][am_postorz] = torz;
  61.      I_AutoMove[id][am_speed] = move_speed;
  62.      I_AutoMove[id][am_objectid] = CreateDynamicObject(modelid, x, y, z, rx, ry, rz, worldid, interiorid, -1, stream_distance);
  63.      I_AutoMove[id][am_areaid] = CreateDynamicSphere(x, y, z, move_distance, worldid, interiorid);
  64.      I_AutoMove[id][am_count] = 0;
  65.      I_AutoMove[id][am_exist] = true;
  66.      return 1;
  67. }
  68.  
  69. stock OpenAutoObject(id)
  70. {
  71.     MoveDynamicObject(I_AutoMove[id][am_objectid], I_AutoMove[id][am_postox], I_AutoMove[id][am_postoy], I_AutoMove[id][am_postoz], I_AutoMove[id][am_speed], I_AutoMove[id][am_postorx], I_AutoMove[id][am_postory], I_AutoMove[id][am_postorz]);
  72.     I_AutoMove[id][am_used] = true;
  73.     return 1;
  74. }
  75.  
  76. stock CloseAutoObject(id)
  77. {
  78.     MoveDynamicObject(I_AutoMove[id][am_objectid], I_AutoMove[id][am_posx], I_AutoMove[id][am_posy], I_AutoMove[id][am_posz], I_AutoMove[id][am_speed], I_AutoMove[id][am_posrx], I_AutoMove[id][am_posry], I_AutoMove[id][am_posrz]);
  79.     I_AutoMove[id][am_used] = false;
  80.     return 1;
  81. }
  82.  
  83. stock DestroyAutoObject(id)
  84. {
  85.      DestroyDynamicObject(I_AutoMove[id][am_objectid]);
  86.      DestroyDynamicArea(I_AutoMove[id][am_areaid]);
  87.      I_AutoMove[id][am_count] = 0;
  88.      I_AutoMove[id][am_exist] = false;
  89.      return 1;
  90. }
  91.  
  92. stock DestroyAllAutoObjects()
  93. {
  94.      for(new lll_i = 0; lll_i < MAX_AUTO_OBJECTS; lll_i ++)
  95.      {
  96.          if(!I_AutoMove[lll_i][am_exist]) continue;
  97.          DestroyAutoObject(lll_i);
  98.      }
  99.      return 1;
  100. }
  101.  
  102. forward OnAutoObjectOpen(playerid, auto_objectid);
  103.  
  104. forward OnAutoObjectClose(playerid, auto_objectid);
  105.  
  106. hook OnPlayerEnterDynamicArea(playerid, areaid)
  107. {
  108.       if(playerid != INVALID_PLAYER_ID && !IsPlayerNPC(playerid))
  109.       {
  110.             for(new j = 0; j < MAX_AUTO_OBJECTS;j++)
  111.             if(areaid == I_AutoMove[j][am_areaid])
  112.             {
  113.                 if(!I_AutoMove[j][am_used])
  114.                 {
  115.                     I_AutoMove[j][am_count] ++;
  116.                     if(I_AutoMove[j][am_count] < 2)
  117.                     {
  118.                         MoveDynamicObject(I_AutoMove[j][am_objectid], I_AutoMove[j][am_postox], I_AutoMove[j][am_postoy], I_AutoMove[j][am_postoz], I_AutoMove[j][am_speed], I_AutoMove[j][am_postorx], I_AutoMove[j][am_postory], I_AutoMove[j][am_postorz]);
  119.                         CallLocalFunction("OnAutoObjectOpen", "ii", playerid, j);
  120.                         I_AutoMove[j][am_used] = true;
  121.                         break;
  122.                     }
  123.                 }
  124.             }
  125.       }
  126.       return 1;
  127. }
  128.  
  129. hook OnPlayerLeaveDynamicArea(playerid, areaid)
  130. {
  131.       if(playerid != INVALID_PLAYER_ID && !IsPlayerNPC(playerid))
  132.       {
  133.             for(new j = 0; j < MAX_AUTO_OBJECTS;j++)
  134.             if(areaid == I_AutoMove[j][am_areaid])
  135.             {
  136.                 if(I_AutoMove[j][am_used])
  137.                 {
  138.                     I_AutoMove[j][am_count] --;
  139.                     if(I_AutoMove[j][am_count] < 1)
  140.                     {
  141.                             MoveDynamicObject(I_AutoMove[j][am_objectid], I_AutoMove[j][am_posx], I_AutoMove[j][am_posy], I_AutoMove[j][am_posz], I_AutoMove[j][am_speed], I_AutoMove[j][am_posrx], I_AutoMove[j][am_posry], I_AutoMove[j][am_posrz]);
  142.                             CallLocalFunction("OnAutoObjectClose", "ii", playerid, j);
  143.                             I_AutoMove[j][am_used] = false;
  144.                             break;
  145.                     }
  146.                 }
  147.             }
  148.       }
  149.       return 1;
  150. }
  151.  
  152. #if defined FILTERSCRIPT
  153.  
  154. hook OnFilterScriptExit()
  155. {
  156.      DestroyAllAutoObjects();
  157.      return 1;
  158. }
  159.  
  160. #else
  161.  
  162. hook OnGameModeExit()
  163. {
  164.      DestroyAllAutoObjects();
  165.      return 1;
  166. }
  167.  
  168. #endif
  169.  
  170. //EOF.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top