SHARE
TWEET

AutoMove.inc

a guest Oct 20th, 2017 275 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.     Removed
  13. -------------------------*/
  14.  
  15. /*-------------------------
  16. V2.2
  17.     Changelog:
  18.         doesnt req y_hooks anymore and also supports npc's
  19. -------------------------*/
  20.  
  21. #if defined _AutoMove_included
  22.       #endinput
  23. #define _AutoMove_included
  24. #endif
  25.  
  26. /*
  27. 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);
  28. native OpenAutoObject(id);
  29. native CloseAutoObject(id)
  30. native DestroyAutoObject(id);
  31. native DestroyAllAutoObjects();
  32. */
  33.  
  34. #include <streamer>
  35.  
  36. #define AutoMoveVersion "2.2"
  37.  
  38. #define MAX_AUTO_OBJECTS 1000
  39.  
  40. enum I_AutoMoveX
  41. {
  42.     Float:am_posx,
  43.     Float:am_posy,
  44.     Float:am_posz,
  45.     Float:am_posrx,
  46.     Float:am_posry,
  47.     Float:am_posrz,
  48.     Float:am_postox,
  49.     Float:am_postoy,
  50.     Float:am_postoz,
  51.     Float:am_postorx,
  52.     Float:am_postory,
  53.     Float:am_postorz,
  54.     Float:am_speed,
  55.     am_areaid,
  56.     am_objectid,
  57.     bool:am_used,
  58.     bool:am_exist,
  59.     am_count
  60. }
  61. new I_AutoMove[MAX_AUTO_OBJECTS][I_AutoMoveX];
  62.  
  63. 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)
  64. {
  65.      DestroyDynamicObject(I_AutoMove[id][am_objectid]);
  66.      I_AutoMove[id][am_posx] = x;
  67.      I_AutoMove[id][am_posy] = y;
  68.      I_AutoMove[id][am_posz] = z;
  69.      I_AutoMove[id][am_posrx] = rx;
  70.      I_AutoMove[id][am_posry] = ry;
  71.      I_AutoMove[id][am_posrz] = rz;
  72.      I_AutoMove[id][am_postox] = tox;
  73.      I_AutoMove[id][am_postoy] = toy;
  74.      I_AutoMove[id][am_postoz] = toz;
  75.      I_AutoMove[id][am_postorx] = torx;
  76.      I_AutoMove[id][am_postory] = tory;
  77.      I_AutoMove[id][am_postorz] = torz;
  78.      I_AutoMove[id][am_speed] = move_speed;
  79.      I_AutoMove[id][am_objectid] = CreateDynamicObject(modelid, x, y, z, rx, ry, rz, worldid, interiorid, -1, stream_distance);
  80.      I_AutoMove[id][am_areaid] = CreateDynamicSphere(x, y, z, move_distance, worldid, interiorid);
  81.      I_AutoMove[id][am_count] = 0;
  82.      I_AutoMove[id][am_exist] = true;
  83.      return 1;
  84. }
  85.  
  86. stock OpenAutoObject(id)
  87. {
  88.     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]);
  89.     I_AutoMove[id][am_used] = true;
  90.     return 1;
  91. }
  92.  
  93. stock CloseAutoObject(id)
  94. {
  95.     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]);
  96.     I_AutoMove[id][am_used] = false;
  97.     return 1;
  98. }
  99.  
  100. stock DestroyAutoObject(id)
  101. {
  102.      DestroyDynamicObject(I_AutoMove[id][am_objectid]);
  103.      DestroyDynamicArea(I_AutoMove[id][am_areaid]);
  104.      I_AutoMove[id][am_count] = 0;
  105.      I_AutoMove[id][am_exist] = false;
  106.      return 1;
  107. }
  108.  
  109. stock DestroyAllAutoObjects()
  110. {
  111.      for(new lll_i = 0; lll_i < MAX_AUTO_OBJECTS; lll_i ++)
  112.      {
  113.          if(!I_AutoMove[lll_i][am_exist]) continue;
  114.          DestroyAutoObject(lll_i);
  115.      }
  116.      return 1;
  117. }
  118.  
  119. forward OnAutoObjectOpen(playerid, auto_objectid);
  120.  
  121. forward OnAutoObjectClose(playerid, auto_objectid);
  122.  
  123. public OnPlayerEnterDynamicArea(playerid, areaid)
  124. {
  125.       if(IsPlayerConnected(playerid))
  126.       {
  127.             for(new j = 0; j < MAX_AUTO_OBJECTS;j++)
  128.             if(areaid == I_AutoMove[j][am_areaid])
  129.             {
  130.                 if(!I_AutoMove[j][am_used])
  131.                 {
  132.                     I_AutoMove[j][am_count] ++;
  133.                     if(I_AutoMove[j][am_count] < 2)
  134.                     {
  135.                         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]);
  136.                         CallLocalFunction("OnAutoObjectOpen", "ii", playerid, j);
  137.                         I_AutoMove[j][am_used] = true;
  138.                         break;
  139.                     }
  140.                 }
  141.             }
  142.       }
  143.       #if defined AM_OnPlayerEnterDynamicArea
  144.         return OnPlayerEnterDynamicArea(playerid, areaid);
  145.     #else
  146.         return 1;
  147.     #endif
  148. }
  149.  
  150. public OnPlayerLeaveDynamicArea(playerid, areaid)
  151. {
  152.       if(IsPlayerConnected(playerid))
  153.       {
  154.             for(new j = 0; j < MAX_AUTO_OBJECTS;j++)
  155.             if(areaid == I_AutoMove[j][am_areaid])
  156.             {
  157.                 if(I_AutoMove[j][am_used])
  158.                 {
  159.                     I_AutoMove[j][am_count] --;
  160.                     if(I_AutoMove[j][am_count] < 1)
  161.                     {
  162.                             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]);
  163.                             CallLocalFunction("OnAutoObjectClose", "ii", playerid, j);
  164.                             I_AutoMove[j][am_used] = false;
  165.                             break;
  166.                     }
  167.                 }
  168.             }
  169.       }
  170.       #if defined AM_OnPlayerLeaveDynamicArea
  171.         return OnPlayerLeaveDynamicArea(playerid, areaid);
  172.     #else
  173.         return 1;
  174.     #endif
  175. }
  176.  
  177. #if defined _ALS_OnPlayerEnterDynamicArea
  178. #undef OnPlayerEnterDynamicArea
  179. #else
  180. #define _ALS_OnPlayerEnterDynamicArea
  181. #endif
  182. #define OnPlayerEnterDynamicArea AM_OnPlayerEnterDynamicArea
  183.  
  184. #if defined AM_OnPlayerEnterDynamicArea
  185. forward AM_OnPlayerEnterDynamicArea(playerid, areaid);
  186. #endif
  187.  
  188. #if defined _ALS_OnPlayerLeaveDynamicArea
  189. #undef OnPlayerLeaveDynamicArea
  190. #else
  191. #define _ALS_OnPlayerLeaveDynamicArea
  192. #endif
  193. #define OnPlayerLeaveDynamicArea AM_OnPlayerLeaveDynamicArea
  194.  
  195. #if defined AM_OnPlayerLeaveDynamicArea
  196. forward AM_OnPlayerLeaveDynamicArea(playerid, areaid);
  197. #endif
  198.  
  199. #if defined FILTERSCRIPT
  200.  
  201. public OnFilterScriptExit()
  202. {
  203.      DestroyAllAutoObjects();
  204.      #if defined AM_OnFilterScriptExit
  205.         return AM_OnFilterScriptExit();
  206.     #else
  207.         return 1;
  208.     #endif
  209. }
  210.  
  211. #if defined _ALS_OnFilterScriptExit
  212. #undef OnFilterScriptExit
  213. #else
  214. #define _ALS_OnFilterScriptExit
  215. #endif
  216. #define OnFilterScriptExit AM_OnFilterScriptExit
  217.  
  218. #if defined AM_OnFilterScriptExit
  219. forward AM_OnFilterScriptExit();
  220. #endif
  221.  
  222. #else
  223.  
  224. public OnGameModeExit()
  225. {
  226.      DestroyAllAutoObjects();
  227.      #if defined AM_OnGameModeExit
  228.         return AM_OnGameModeExit();
  229.     #else
  230.         return 1;
  231.     #endif
  232. }
  233.  
  234. #if defined _ALS_OnGameModeExit
  235. #undef OnGameModeExit
  236. #else
  237. #define _ALS_OnGameModeExit
  238. #endif
  239. #define OnGameModeExit AM_OnGameModeExit
  240.  
  241. #if defined AM_OnGameModeExit
  242. forward AM_OnGameModeExit();
  243. #endif
  244.  
  245. #endif
  246.  
  247.  
  248. //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