Advertisement
Guest User

CreateObjectSurface by Emilijo "Correlli" Lovrich

a guest
Mar 9th, 2015
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.50 KB | None | 0 0
  1. /*  surface.inc
  2.  *
  3.  *  (c) Copyright 2015, Emilijo "Correlli" Lovrich
  4.  *
  5.  *  Credits: - Incognito for streamer plugin.
  6. */
  7.  
  8. #define OBJ_DBG_MSG
  9.  
  10. new
  11.         g_Count;
  12.  
  13. stock CreateObjectSurface(object_model, Float:x_off, Float:y_off, Float:height, Float:x_start, Float:y_start, Float:x_end = 0.0, Float:y_end = 0.0, Float:x_rot = 0.0, Float:y_rot = 0.0, Float:z_rot = 0.0, world = -1, interior = -1, player = -1, Float:d_stream = 200.0, Float:d_draw = 0.0, m_index = 0, txd_model = 0, txd_name[] = "", texture_name[] = "", m_color = 0)
  14. {
  15.     /*
  16.  
  17.     * Example (this covers the whole San Andreas map with breakable glass objects (model: 1649)):
  18.  
  19.     * -3000.0 -> 3000.0 (3000.0 + 3000.0 = 6000.0)
  20.  
  21.     * x_off = 4.4
  22.     * 6000.0 / 4.4 = 1363.636 ~= 1364
  23.  
  24.     * y_off = 3.31
  25.     * 6000.0 / 3.31 = 1812.6888 ~= 1813
  26.  
  27.     * 1364 x 1813 = 2472932 objects in total
  28.  
  29.     */
  30.  
  31.     if(!x_end)
  32.     {
  33.         if(x_start < 0.0)   x_end = floatabs(x_start);
  34.         else                x_end = -x_start;
  35.     }
  36.  
  37.     if(!y_end)
  38.     {
  39.         if(y_start < 0.0)   y_end = floatabs(y_start);
  40.         else                y_end = -y_start;
  41.     }
  42.  
  43.     if(x_start == x_end || y_start == y_end)
  44.     {
  45.         return
  46.             printf("Error at \"CreateObjectSurface\" function for model %i - one of the starting and ending positions (X: %0.2f, Y: %0.2f) is the same.",
  47.                 object_model,
  48.                 x_start,
  49.                 y_start
  50.             )
  51.         ;
  52.     }
  53.  
  54.     new
  55.             Float:coord[2], bool:calculate[2], loop[2], object;
  56.  
  57.     if(x_start < 0.0)
  58.     {
  59.         // -3000.0, -4000.0 -> 1000.0
  60.         // -4000.0, -3000.0 -> 1000.0
  61.         if(x_end < 0.0)
  62.         {
  63.             if(x_start > x_end)
  64.                 calculate[0] = true;
  65.             coord[0] = floatabs(x_start + floatabs(x_end));
  66.         }
  67.         // -3000.0, 4000.0 -> 7000.0
  68.         else
  69.             coord[0] = floatabs(x_start) + x_end;
  70.     }
  71.     else
  72.     {
  73.         // 3000.0, -4000.0 -> 7000.0
  74.         if(x_end < 0.0)
  75.         {
  76.             calculate[0] = true;
  77.             coord[0] = x_start + floatabs(x_end);
  78.         }
  79.         // 3000.0, 4000.0 -> 1000.0
  80.         // 4000.0, 3000.0 -> 1000.0
  81.         else
  82.         {
  83.             if(x_start > x_end)
  84.                 calculate[0] = true;
  85.             coord[0] = floatabs(x_start - x_end);
  86.         }
  87.     }
  88.  
  89.     if(y_start < 0.0)
  90.     {
  91.         // -3000.0, -4000.0 -> 1000.0
  92.         // -4000.0, -3000.0 -> 1000.0
  93.         if(y_end < 0.0)
  94.         {
  95.             if(y_start > y_end)
  96.                 calculate[1] = true;
  97.             coord[1] = floatabs(y_start + floatabs(y_end));
  98.         }
  99.         // -3000.0, 4000.0 -> 7000.0
  100.         else
  101.             coord[1] = floatabs(y_start) + y_end;
  102.     }
  103.     else
  104.     {
  105.         // 3000.0, -4000.0 -> 7000.0
  106.         if(y_end < 0.0)
  107.         {
  108.             calculate[1] = true;
  109.             coord[1] = y_start + floatabs(y_end);
  110.         }
  111.         // 3000.0, 4000.0 -> 1000.0
  112.         // 4000.0, 3000.0 -> 1000.0
  113.         else
  114.         {
  115.             if(y_start > y_end)
  116.                 calculate[1] = true;
  117.             coord[1] = floatabs(y_start - y_end);
  118.         }
  119.     }
  120.  
  121.     loop[0] = floatround(coord[0] / x_off, floatround_ceil);
  122.     loop[1] = floatround(coord[1] / y_off, floatround_ceil);
  123.  
  124.     g_Count = 0;
  125.  
  126.     for(new a = 0; a < loop[0]; a++)
  127.     {
  128.         for(new b = 0; b < loop[1]; b++)
  129.         {
  130.             if(calculate[0])    coord[0] = x_start - (x_off * a);
  131.             else                coord[0] = x_start + (x_off * a);
  132.  
  133.             if(calculate[1])    coord[1] = y_start - (y_off * b);
  134.             else                coord[1] = y_start + (y_off * b);
  135.  
  136.             object = CreateDynamicObject(
  137.                 object_model,
  138.                 coord[0],
  139.                 coord[1],
  140.                 height,
  141.                 x_rot,
  142.                 y_rot,
  143.                 z_rot,
  144.                 world,
  145.                 interior,
  146.                 player,
  147.                 d_stream,
  148.                 d_draw
  149.             );
  150.  
  151.             g_Count++;
  152.  
  153.             if(txd_model)
  154.                 SetDynamicObjectMaterial(object, m_index, txd_model, txd_name, texture_name, m_color);
  155.         }
  156.     }
  157.  
  158.     #if defined OBJ_DBG_MSG
  159.         printf("Created %i objects at \"CreateObjectSurface\" function for model %i.",
  160.             g_Count,
  161.             object_model
  162.         );
  163.     #endif
  164.  
  165.     return g_Count;
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement