SHARE
TWEET

AutoMove.inc

a guest Oct 22nd, 2017 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //made by lokii
  2.  
  3. /*-------------------------
  4. V2:
  5.     Changelog:
  6.         Now supports rotations, virtual world, interiors added 2 function OpenAutoObject and CloseAutoObject to open and close manually
  7.                                                                                                   and added 2 callback OnAutoObjectOpen and OnAutoObjectClose
  8. -------------------------*/
  9.  
  10. /*
  11. C2.1:
  12.     Now supports NPC'S
  13. -------------------------*/
  14.  
  15. #if defined _AutoMove_included
  16.       #endinput
  17. #define _AutoMove_included
  18. #endif
  19.  
  20. /*
  21. 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);
  22. native OpenAutoObject(id);
  23. native CloseAutoObject(id)
  24. native DestroyAutoObject(id);
  25. native DestroyAllAutoObjects();
  26. */
  27.  
  28. #include <streamer>
  29. #include <YSI\y_hooks>
  30.  
  31. #define AutoMoveVersion "2.1"
  32.  
  33. #define MAX_AUTO_OBJECTS 1000
  34.  
  35. enum I_AutoMoveX
  36. {
  37.     Float:am_posx,
  38.     Float:am_posy,
  39.     Float:am_posz,
  40.     Float:am_posrx,
  41.     Float:am_posry,
  42.     Float:am_posrz,
  43.     Float:am_postox,
  44.     Float:am_postoy,
  45.     Float:am_postoz,
  46.     Float:am_postorx,
  47.     Float:am_postory,
  48.     Float:am_postorz,
  49.     Float:am_speed,
  50.     am_areaid,
  51.     am_objectid,
  52.     bool:am_used,
  53.     bool:am_exist,
  54.     am_count
  55. }
  56. new I_AutoMove[MAX_AUTO_OBJECTS][I_AutoMoveX];
  57.  
  58. 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)
  59. {
  60.      DestroyDynamicObject(I_AutoMove[id][am_objectid]);
  61.      I_AutoMove[id][am_posx] = x;
  62.      I_AutoMove[id][am_posy] = y;
  63.      I_AutoMove[id][am_posz] = z;
  64.      I_AutoMove[id][am_posrx] = rx;
  65.      I_AutoMove[id][am_posry] = ry;
  66.      I_AutoMove[id][am_posrz] = rz;
  67.      I_AutoMove[id][am_postox] = tox;
  68.      I_AutoMove[id][am_postoy] = toy;
  69.      I_AutoMove[id][am_postoz] = toz;
  70.      I_AutoMove[id][am_postorx] = torx;
  71.      I_AutoMove[id][am_postory] = tory;
  72.      I_AutoMove[id][am_postorz] = torz;
  73.      I_AutoMove[id][am_speed] = move_speed;
  74.      I_AutoMove[id][am_objectid] = CreateDynamicObject(modelid, x, y, z, rx, ry, rz, worldid, interiorid, -1, stream_distance);
  75.      I_AutoMove[id][am_areaid] = CreateDynamicSphere(x, y, z, move_distance, worldid, interiorid);
  76.      I_AutoMove[id][am_count] = 0;
  77.      I_AutoMove[id][am_exist] = true;
  78.      return 1;
  79. }
  80.  
  81. stock OpenAutoObject(id)
  82. {
  83.     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]);
  84.     I_AutoMove[id][am_used] = true;
  85.     return 1;
  86. }
  87.  
  88. stock CloseAutoObject(id)
  89. {
  90.     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]);
  91.     I_AutoMove[id][am_used] = false;
  92.     return 1;
  93. }
  94.  
  95. stock DestroyAutoObject(id)
  96. {
  97.      DestroyDynamicObject(I_AutoMove[id][am_objectid]);
  98.      DestroyDynamicArea(I_AutoMove[id][am_areaid]);
  99.      I_AutoMove[id][am_count] = 0;
  100.      I_AutoMove[id][am_exist] = false;
  101.      return 1;
  102. }
  103.  
  104. stock DestroyAllAutoObjects()
  105. {
  106.      for(new lll_i = 0; lll_i < MAX_AUTO_OBJECTS; lll_i ++)
  107.      {
  108.          if(!I_AutoMove[lll_i][am_exist]) continue;
  109.          DestroyAutoObject(lll_i);
  110.      }
  111.      return 1;
  112. }
  113.  
  114. forward OnAutoObjectOpen(playerid, auto_objectid);
  115.  
  116. forward OnAutoObjectClose(playerid, auto_objectid);
  117.  
  118. hook OnPlayerEnterDynamicArea(playerid, areaid)
  119. {
  120.       if(IsPlayerConnected(playerid))
  121.       {
  122.             for(new j = 0; j < MAX_AUTO_OBJECTS;j++)
  123.             if(areaid == I_AutoMove[j][am_areaid])
  124.             {
  125.                 if(!I_AutoMove[j][am_used])
  126.                 {
  127.                     I_AutoMove[j][am_count] ++;
  128.                     if(I_AutoMove[j][am_count] < 2)
  129.                     {
  130.                         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]);
  131.                         CallLocalFunction("OnAutoObjectOpen", "ii", playerid, j);
  132.                         I_AutoMove[j][am_used] = true;
  133.                         break;
  134.                     }
  135.                 }
  136.             }
  137.       }
  138.       return 1;
  139. }
  140.  
  141. hook OnPlayerLeaveDynamicArea(playerid, areaid)
  142. {
  143.       if(IsPlayerConnected(playerid))
  144.       {
  145.             for(new j = 0; j < MAX_AUTO_OBJECTS;j++)
  146.             if(areaid == I_AutoMove[j][am_areaid])
  147.             {
  148.                 if(I_AutoMove[j][am_used])
  149.                 {
  150.                     I_AutoMove[j][am_count] --;
  151.                     if(I_AutoMove[j][am_count] < 1)
  152.                     {
  153.                             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]);
  154.                             CallLocalFunction("OnAutoObjectClose", "ii", playerid, j);
  155.                             I_AutoMove[j][am_used] = false;
  156.                             break;
  157.                     }
  158.                 }
  159.             }
  160.       }
  161.       return 1;
  162. }
  163.  
  164. #if defined FILTERSCRIPT
  165.  
  166. hook OnFilterScriptExit()
  167. {
  168.      DestroyAllAutoObjects();
  169.      return 1;
  170. }
  171.  
  172. #else
  173.  
  174. hook OnGameModeExit()
  175. {
  176.      DestroyAllAutoObjects();
  177.      return 1;
  178. }
  179.  
  180. #endif
  181.  
  182.  
  183. //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