Advertisement
Guest User

arrow.inc

a guest
Jul 27th, 2013
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 23.08 KB | None | 0 0
  1. /**************************************************************************
  2.     Copyright 2013 Ian Goodwin
  3.  
  4.     Licensed under the Apache License, Version 2.0 (the "License");
  5.     you may not use this file except in compliance with the License.
  6.     You may obtain a copy of the License at
  7.  
  8.        http://www.apache.org/licenses/LICENSE-2.0
  9.  
  10.     Unless required by applicable law or agreed to in writing, software
  11.     distributed under the License is distributed on an "AS IS" BASIS,
  12.     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.     See the License for the specific language governing permissions and
  14.     limitations under the License.
  15.    
  16. *//////////////////////////////////////////////////////////////////////////
  17.  
  18. /*
  19.     Credits:
  20.         Incognito   - Streamer Plugin
  21.         Antonio144  - GetYRotation function
  22.         SA:MP Team  - For SA:MP
  23.  
  24.        
  25.        
  26.     Changelog:
  27.         <insert date v1.3> 
  28.             * Values returned by CreateArrow now have the Arrow: tag, to avoid confusion with normal objectids.
  29.             * All function headers expecting an arrowid have changed to accept the new Arrow: tag.
  30.             * Added functions:
  31.                 SetArrowRot
  32.                 SetPlayerArrowRot
  33.                
  34.             * Fixed more comment errors.
  35.                
  36.         24/07/13 v1.2:
  37.             *Player arrows added.
  38.             * Added functions:
  39.                 CreatePlayerArrow
  40.                 PointPlayerArrowAtPoint
  41.                 DestroyPlayerArrow
  42.                 SetPlayerArrowPos
  43.                 GetPlayerArrowPos
  44.                 GetPlayerArrowRot
  45.                 PointPlayerArrowAtPlayer
  46.                 PointPlayerArrowAtVehicle
  47.                 PointPlayerArrowAtObject
  48.                 PointPlayerArrowAtPlayerObject
  49.                 SetPlayerArrowColor
  50.                
  51.             *Functions changed
  52.                 PointArrowAtPoint   - No loner does rotation calculations if the arrow isn't a valid object. And returns 0 on failure.
  53.            
  54.             *Fixed some comment errors.
  55.                
  56.         23/07/13 v1.1:
  57.             *Arrows now rotate along the Y-Axis, so they an point vertically. (Antonio144)
  58.         22/07/13 v1.0:
  59.             *Initial release.
  60. */
  61.  
  62.  
  63.  
  64. /*
  65. //global arrows
  66. native Arrow:CreateArrow(Float: x, Float: y, Float: z, Float: target_x, Float: target_y, Float: target_z, Float: stream_dist = DEFAULT_ARROW_DRAW_DISTANCE);
  67. native PointArrowAtPoint(Arrow:arrowid, Float: x, Float: y, Float: z);
  68. native DestroyArrow(Arrow:arrowid);
  69. native SetArrowPos(Arrow:arrowid, Float: x, Float: y, Float: z);
  70. native GetArrowPos(Arrow:arrowid, &Float: x, &Float: y, &Float: z);
  71. native GetArrowRot(Arrow:arrowid, &Float: rx, &Float: ry, &Float: rz);
  72. native SetArrowRot(Arrow:arrowid, Float: rx, Float: ry, Float: rz);
  73. native PointArrowAtPlayer(Arrow:arrowid, playerid);
  74. native PointArrowAtVehicle(Arrow:arrowid, vehicleid);
  75. native PointArrowAtObject(Arrow:arrowid, objectid);
  76. native SetArrowColor(Arrow:arrowid, argb_color);
  77. //player arrows
  78. native Arrow:CreatePlayerArrow(playerid, Float: x, Float: y, Float: z, Float: target_x, Float: target_y, Float: target_z, Float: stream_dist = DEFAULT_ARROW_DRAW_DISTANCE);
  79. native PointPlayerArrowAtPoint(playerid, Arrow:arrowid, Float: x, Float: y, Float: z);
  80. native DestroyPlayerArrow(playerid, Arrow:arrowid);
  81. native SetPlayerArrowPos(playerid, Arrow:arrowid, Float: x, Float: y, Float: z);
  82. native GetPlayerArrowPos(playerid, Arrow:arrowid, &Float: x, &Float: y, &Float: z);
  83. native GetPlayerArrowRot(playerid, Arrow:arrowid, &Float: rx, &Float: ry, &Float: rz);
  84. native SetPlayerArrowRot(playerid, Arrow:arrowid, Float: rx, Float: ry, Float: rz);
  85. native PointPlayerArrowAtPlayer(playerid, Arrow:arrowid, playerid);
  86. native PointPlayerArrowAtVehicle(playerid, Arrow:arrowid, vehicleid);
  87. native PointPlayerArrowAtObject(playerid, Arrow:arrowid, objectid);
  88. native PointPlayerArrowAtPlayerObject(playerid, Arrow:arrowid, targetplayerid, targetobjectid);
  89. native SetPlayerArrowColor(playerid, Arrow:arrowid, argb_color);
  90. */
  91.  
  92. #include <a_samp>
  93.  
  94. #if !defined ARROW_NO_STREAMER
  95.     #tryinclude <streamer>
  96.     #if !defined CreateDynamicObject
  97.         #error streamer include not found, have you got streamer.inc in your includes folder?
  98.     #endif
  99. #endif
  100.  
  101. #define ARW_OBJECT_ID                       (1318)
  102. #define ARW_Z_ROT_OFFSET                    (90.0)
  103. #define DEFAULT_ARROW_DRAW_DISTANCE         (200.0)
  104. #define INVALID_ARROW_ID                    Arrow:INVALID_OBJECT_ID
  105.  
  106. forward Float:arw_PointToPoint(Float:X, Float:Y, Float:PointX, Float:PointY);
  107. forward Float:arw_GetYRotation(Float:x,Float:y,Float:z, Float:ax, Float:ay, Float:az);
  108.  
  109. /*
  110.     Function:
  111.         CreateArrow
  112.     Description:
  113.         Creates an arrow at the given point, pointing to a target location.
  114.     Param(s):
  115.         x, y, z      - Position to create the arrow.
  116.         target_x/y/z - Position to point the arrow at
  117.         stream_dist  - stream distance for the arrow (default DEFAULT_ARROW_DRAW_DISTANCE)
  118.     Returns:
  119.         Arrowid for the newly created arrow. (returned by CreateObject or CreateDynamicObject
  120.  
  121. */
  122. stock Arrow:CreateArrow(Float: x, Float: y, Float: z, Float: target_x, Float: target_y, Float: target_z, Float:
  123.     stream_dist = DEFAULT_ARROW_DRAW_DISTANCE)
  124. {
  125.     #if !defined ARROW_NO_STREAMER
  126.         return Arrow:CreateDynamicObject( ARW_OBJECT_ID, x, y, z,
  127.             0.0,
  128.             arw_GetYRotation(x, y, z, target_x, target_y, target_z),
  129.             arw_PointToPoint(x, y, target_x, target_y)+ARW_Z_ROT_OFFSET,
  130.             .streamdistance = stream_dist
  131.         );
  132.     #else
  133.         return Arrow:CreateObject( ARW_OBJECT_ID, x, y, z, 0.0,
  134.             arw_GetYRotation(x, y, z, target_x, target_y, target_z),
  135.             arw_PointToPoint(x, y, target_x, target_y)+ARW_Z_ROT_OFFSET,
  136.             stream_dist
  137.         );
  138.     #endif
  139. }
  140.  
  141. /*
  142.     Function:
  143.         CreatePlayerArrow
  144.     Description:
  145.         Creates an arrow for playerid at the given point, pointing to a target location.
  146.     Param(s):
  147.         playerid     - The player to show the arrow.
  148.         x, y, z      - Position to create the arrow.
  149.         target_x/y/z - Position to point the arrow at
  150.         stream_dist  - stream distance for the arrow (default DEFAULT_ARROW_DRAW_DISTANCE)
  151.     Returns:
  152.         *Arrowid for the newly created arrow. (returned by CreateObject or CreateDynamicObject
  153.        
  154.         -1 if the player isn't connected.
  155.  
  156. */
  157. stock Arrow:CreatePlayerArrow(playerid, Float: x, Float: y, Float: z,
  158.     Float: target_x, Float: target_y, Float: target_z, Float: stream_dist = DEFAULT_ARROW_DRAW_DISTANCE)
  159. {
  160.     if( IsPlayerConnected( playerid ) )
  161.     {
  162.         #if !defined ARROW_NO_STREAMER
  163.             return Arrow:CreateDynamicObject( ARW_OBJECT_ID, x, y, z,
  164.                 0.0,
  165.                 arw_GetYRotation(x, y, z, target_x, target_y, target_z),
  166.                 arw_PointToPoint(x, y, target_x, target_y)+ARW_Z_ROT_OFFSET,
  167.                 .streamdistance = stream_dist,
  168.                 .playerid = playerid
  169.             );
  170.         #else
  171.             return Arrow:CreatePlayerObject( playerid, ARW_OBJECT_ID, x, y, z, 0.0,
  172.                 arw_GetYRotation(x, y, z, target_x, target_y, target_z),
  173.                 arw_PointToPoint(x, y, target_x, target_y)+ARW_Z_ROT_OFFSET,
  174.                 stream_dist
  175.             );
  176.         #endif
  177.     }
  178.     return INVALID_ARROW_ID;
  179. }
  180.  
  181. /*
  182.     Function:
  183.         DestroyArrow
  184.     Description:
  185.         Destroys the given arrow.
  186.     Param(s):
  187.         arrowid - The arrowid returned by "CreateArrow" function
  188.     Returns:
  189.         Value returned by DestroyObject or DestroyDynamicObject
  190.  
  191. */
  192. stock DestroyArrow(Arrow:arrowid)
  193. {
  194.     #if !defined ARROW_NO_STREAMER
  195.         return DestroyDynamicObject( _:arrowid );
  196.     #else
  197.         return DestroyObject( _:arrowid );
  198.     #endif
  199. }
  200.  
  201. /*
  202.     Function:
  203.         DestroyPlayerArrow
  204.     Description:
  205.         Destroys the given player arrow.
  206.     Param(s):
  207.         playerid - The player who the arrow is streamed for.
  208.         arrowid  - The arrowid returned by "CreatePlayerArrow" function
  209.     Returns:
  210.         Value returned by DestroyPlayerObject or DestroyDynamicObject
  211.  
  212. */
  213. stock DestroyPlayerArrow(playerid, Arrow:arrowid)
  214. {
  215.     #pragma unused playerid
  216.     #if !defined ARROW_NO_STREAMER
  217.         return DestroyDynamicObject( _:arrowid );
  218.     #else
  219.         return DestroyPlayerObject( playerid, _:arrowid );
  220.     #endif
  221. }
  222.  
  223. /*
  224.     Function:
  225.         SetArrowPos
  226.     Description:
  227.         Sets a new position for the given arrow.
  228.     Param(s):
  229.         arrowid - The arrowid returned by "CreateArrow" function.
  230.         x, y, z - The new position for the arrow to be placed.
  231.     Returns:
  232.         Value returned by SetObjectPos or SetDynamicObjectPos
  233.  
  234. */
  235. stock SetArrowPos(Arrow:arrowid, Float: x, Float: y, Float: z)
  236. {
  237.     #if !defined ARROW_NO_STREAMER
  238.         return SetDynamicObjectPos( _:arrowid, x, y, z );
  239.     #else
  240.         return SetObjectPos( _:arrowid, x, y, z );
  241.     #endif
  242. }
  243.  
  244. /*
  245.     Function:
  246.         SetPlayerArrowPos
  247.     Description:
  248.         Sets a new position for the given player arrow.
  249.     Param(s):
  250.         playerid  - The player who the arrow is streamed for.
  251.         arrowid   - The arrowid returned by "CreatePlayerArrow" function.
  252.         x, y, z   - The new position for the arrow to be placed.
  253.     Returns:
  254.         Value returned by SetPlayerObjectPos or SetDynamicObjectPos
  255.  
  256. */
  257. stock SetPlayerArrowPos(playerid, Arrow:arrowid, Float: x, Float: y, Float: z)
  258. {
  259.     #pragma unused playerid
  260.     #if !defined ARROW_NO_STREAMER
  261.         return SetDynamicObjectPos( _:arrowid, x, y, z );
  262.     #else
  263.         return SetPlayerObjectPos( playerid, _:arrowid, x, y, z );
  264.     #endif
  265. }
  266.  
  267. /*
  268.     Function:
  269.         GetArrowPos
  270.     Description:
  271.         Gets the current position for the given arrow.
  272.     Param(s):
  273.         arrowid - The arrowid returned by "CreateArrow" function.
  274.         x, y, z - Variables to store the position of the arrow, passed by reference.
  275.     Returns:
  276.         Value returned by GetObjectPos or GetDynamicObjectPos
  277.  
  278. */
  279. stock GetArrowPos(Arrow:arrowid, &Float: x, &Float: y, &Float: z)
  280. {
  281.     #if !defined ARROW_NO_STREAMER
  282.         return GetDynamicObjectPos( _:arrowid, x, y, z );
  283.     #else
  284.         return GetObjectPos( _:arrowid, x, y, z );
  285.     #endif
  286. }
  287.  
  288. /*
  289.     Function:
  290.         GetPlayerArrowPos
  291.     Description:
  292.         Gets the current position for the given player arrow.
  293.     Param(s):
  294.         playerid - The player whoi the arrow is streamed for.
  295.         arrowid  - The arrowid returned by "CreatePlayerArrow" function.
  296.         x, y, z  - Variables to store the position of the arrow, passed by reference.
  297.     Returns:
  298.         Value returned by GetPlayerObjectPos or GetDynamicObjectPos
  299.  
  300. */
  301. stock GetPlayerArrowPos(playerid, Arrow:arrowid, &Float: x, &Float: y, &Float: z)
  302. {
  303.     #pragma unused playerid
  304.     #if !defined ARROW_NO_STREAMER
  305.         return GetDynamicObjectPos( _:arrowid, x, y, z );
  306.     #else
  307.         return GetPlayerObjectPos( playerid, _:arrowid, x, y, z );
  308.     #endif
  309. }
  310.  
  311. /*
  312.     Function:
  313.         GetArrowRot
  314.     Description:
  315.         Gets the current rotation for the given arrow.
  316.     Param(s):
  317.         arrowid     - The arrowid returned by "CreateArrow" function.
  318.         rx, ry, rz  - Variables to store the rotation of the arrow, passed by reference.
  319.     Returns:
  320.         Value returned by GetObjectRot or GetDynamicObjectRot
  321.  
  322. */
  323. stock GetArrowRot(Arrow:arrowid, &Float: rx, &Float: ry, &Float: rz)
  324. {
  325.     #if !defined ARROW_NO_STREAMER
  326.         return GetDynamicObjectRot( _:arrowid, rx, ry, rz );
  327.     #else
  328.         return GetObjectRot( _:arrowid, rx, ry, rz );
  329.     #endif
  330. }
  331.  
  332. /*
  333.     Function:
  334.         GetPlayerArrowRot
  335.     Description:
  336.         Gets the current rotation for the given player arrow.
  337.     Param(s):
  338.         playerid    - The player who the object is streamed for.
  339.         arrowid     - The arrowid returned by "CreatePlayerArrow" function.
  340.         rx, ry, rz  - Variables to store the rotation of the arrow, passed by reference.
  341.     Returns:
  342.         Value returned by GetPlayerObjectRot or GetDynamicObjectRot
  343.  
  344. */
  345. stock GetPlayerArrowRot(playerid, Arrow:arrowid, &Float: rx, &Float: ry, &Float: rz)
  346. {
  347.     #pragma unused playerid
  348.     #if !defined ARROW_NO_STREAMER
  349.         return GetDynamicObjectRot( _:arrowid, rx, ry, rz );
  350.     #else
  351.         return GetPlayerObjectRot( playerid, _:arrowid, rx, ry, rz );
  352.     #endif
  353. }
  354.  
  355. /*
  356.     Function:
  357.         SetArrowRot
  358.     Description:
  359.         Sets the rotation for the given arrow.
  360.     Param(s):
  361.         arrowid     - The arrowid returned by "CreateArrow" function.
  362.         rx, ry, rz  - New rotation values for the arrow.
  363.     Returns:
  364.         Value returned by SetObjectRot or SetDynamicObjectRot
  365.  
  366. */
  367. stock SetArrowRot(Arrow:arrowid, Float: rx, Float: ry, Float: rz)
  368. {
  369.     #if !defined ARROW_NO_STREAMER
  370.         return SetDynamicObjectRot( _:arrowid, rx, ry, rz );
  371.     #else
  372.         return SetObjectRot( _:arrowid, rx, ry, rz );
  373.     #endif
  374. }
  375.  
  376. /*
  377.     Function:
  378.         SetPlayerArrowRot
  379.     Description:
  380.         Sets the rotation for the given arrow.
  381.     Param(s):
  382.         playerid    - The player who the arrow is streamed for
  383.         arrowid     - The arrowid returned by "CreateArrow" function.
  384.         rx, ry, rz  - New rotation values for the arrow.
  385.     Returns:
  386.         Value returned by SetObjectRot or SetDynamicObjectRot
  387.  
  388. */
  389. stock SetPlayerArrowRot(playerid, Arrow:arrowid, Float: rx, Float: ry, Float: rz)
  390. {
  391.     #pragma unused playerid
  392.     #if !defined ARROW_NO_STREAMER
  393.         return SetDynamicObjectRot( _:arrowid, rx, ry, rz );
  394.     #else
  395.         return SetPlayerObjectRot( playerid, _:arrowid, rx, ry, rz );
  396.     #endif
  397. }
  398.  
  399. /*
  400.     Function:
  401.         SetArrowColor
  402.     Description:
  403.         Sets a new color for the arrow
  404.     Param(s):
  405.         arrowid - The arrowid returned by "CreateArrow" function.
  406.         argb_color - New color for the arrow, NOTE: ARGB format not RGBA
  407.     Returns:
  408.         Value returned by SetObjectMaterial or SetDynamicObjectMaterial
  409.  
  410. */
  411. stock SetArrowColor(Arrow:arrowid, argb_color)
  412. {
  413.     #if !defined ARROW_NO_STREAMER
  414.         return SetDynamicObjectMaterial(_:arrowid, 0, -1, "none", "none", argb_color);
  415.     #else
  416.         return SetObjectMaterial(_:arrowid, 0, -1, "none", "none", argb_color);
  417.     #endif
  418. }
  419.  
  420. /*
  421.     Function:
  422.         SetPlayerArrowColor
  423.     Description:
  424.         Sets a new color for the player arrow.
  425.     Param(s):
  426.         playerid    - The player the arrow is streamed for.
  427.         arrowid     - The arrowid returned by "CreateArrow" function.
  428.         argb_color  - New color for the arrow, NOTE: ARGB format not RGBA
  429.     Returns:
  430.         Value returned by SetObjectMaterial or SetDynamicObjectMaterial
  431.  
  432. */
  433. stock SetPlayerArrowColor(playerid, Arrow:arrowid, argb_color)
  434. {
  435.     #pragma unused playerid
  436.     #if !defined ARROW_NO_STREAMER
  437.         return SetDynamicObjectMaterial(_:arrowid, 0, -1, "none", "none", argb_color);
  438.     #else
  439.         return SetPlayerObjectMaterial(playerid, _:arrowid, 0, -1, "none", "none", argb_color);
  440.     #endif
  441. }
  442.  
  443.  
  444. /*
  445.     Function:
  446.         PointArrowAtPlayer
  447.     Description:
  448.         Points the given arrow at the given playerid
  449.     Param(s):
  450.         arrowid  - The arrowid returned by "CreateArrow" function.
  451.         playerid - ID of the player to point at.
  452.     Returns:
  453.         1 if playerid is connected.
  454.         0 otherwise.
  455.  
  456. */
  457. stock PointArrowAtPlayer(Arrow:arrowid, playerid)
  458. {
  459.     new
  460.         Float: fTargetX, Float: fTargetY, Float: fTargetZ
  461.     ;
  462.    
  463.     if( GetPlayerPos(playerid, fTargetX, fTargetY, fTargetZ) )
  464.     {
  465.         PointArrowAtPoint(arrowid, fTargetX, fTargetY, fTargetZ);
  466.         return 1;
  467.     }
  468.     return 0;
  469. }
  470.  
  471. /*
  472.     Function:
  473.         PointArrowAtPlayer
  474.     Description:
  475.         Points the given arrow at the given playerid
  476.     Param(s):
  477.         playerid - Player who the arrow is streamed for
  478.         arrowid  - The arrowid returned by "CreateArrow" function.
  479.         targetplayerid - ID of the player to point at.
  480.     Returns:
  481.         1 if playerid is connected.
  482.         0 otherwise.
  483.  
  484. */
  485. stock PointPlayerArrowAtPlayer(playerid, Arrow:arrowid, targetplayerid)
  486. {
  487.     new
  488.         Float: fTargetX, Float: fTargetY, Float: fTargetZ
  489.     ;
  490.    
  491.     if( GetPlayerPos(targetplayerid, fTargetX, fTargetY, fTargetZ) )
  492.     {
  493.         PointPlayerArrowAtPoint(playerid, arrowid, fTargetX, fTargetY, fTargetZ);
  494.         return 1;
  495.     }
  496.     return 0;
  497. }
  498.  
  499. /*
  500.     Function:
  501.         PointArrowAtVehicle
  502.     Description:
  503.         Points the given arrow at the given vehicle
  504.     Param(s):
  505.         arrowid  - The arrowid returned by "CreateArrow" function.
  506.         vehicleid - ID of the vehicle to point at.
  507.     Returns:
  508.         1 if vehicleid is found.
  509.         0 otherwise.
  510.  
  511. */
  512. stock PointArrowAtVehicle(Arrow:arrowid, vehicleid)
  513. {
  514.     new
  515.         Float: fTargetX, Float: fTargetY, Float: fTargetZ
  516.     ;
  517.    
  518.     if( GetVehiclePos(vehicleid, fTargetX, fTargetY, fTargetZ) )
  519.     {
  520.         PointArrowAtPoint(arrowid, fTargetX, fTargetY, fTargetZ);
  521.         return 1;
  522.     }
  523.     return 0;
  524. }
  525.  
  526. /*
  527.     Function:
  528.         PointPlayerArrowAtVehicle
  529.     Description:
  530.         Points the given arrow at the given vehicle
  531.     Param(s):
  532.         playerid  - Player who the arrow is streamed for.
  533.         arrowid   - The arrowid returned by "CreateArrow" function.
  534.         vehicleid - ID of the vehicle to point at.
  535.     Returns:
  536.         1 if vehicleid is found.
  537.         0 otherwise.
  538.  
  539. */
  540. stock PointPlayerArrowAtVehicle(playerid, Arrow:arrowid, vehicleid)
  541. {
  542.     new
  543.         Float: fTargetX, Float: fTargetY, Float: fTargetZ
  544.     ;
  545.    
  546.     if( GetVehiclePos(vehicleid, fTargetX, fTargetY, fTargetZ) )
  547.     {
  548.         PointPlayerArrowAtPoint(playerid, arrowid, fTargetX, fTargetY, fTargetZ);
  549.         return 1;
  550.     }
  551.     return 0;
  552. }
  553.  
  554. /*
  555.     Function:
  556.         PointArrowAtObject
  557.     Description:
  558.         Points the given arrow at the given object
  559.     Param(s):
  560.         arrowid  - The arrowid returned by "CreateArrow" function.
  561.         objectid - ID of the object to point at.
  562.     Returns:
  563.         1 if objectid is found.
  564.         0 otherwise.
  565.  
  566. */
  567. stock PointArrowAtObject(Arrow:arrowid, objectid)
  568. {
  569.     new
  570.         Float: fTargetX, Float: fTargetY, Float: fTargetZ
  571.     ;
  572.    
  573.     #if !defined ARROW_NO_STREAMER
  574.         if( GetDynamicObjectPos(objectid, fTargetX, fTargetY, fTargetZ) )
  575.         {
  576.             PointArrowAtPoint(arrowid, fTargetX, fTargetY, fTargetZ);
  577.             return 1;
  578.         }
  579.     #else
  580.         if( GetObjectPos(objectid, fTargetX, fTargetY, fTargetZ) )
  581.         {
  582.             PointArrowAtPoint(arrowid, fTargetX, fTargetY, fTargetZ);
  583.             return 1;
  584.         }
  585.     #endif
  586.    
  587.     return 0;
  588. }
  589.  
  590. /*
  591.     Function:
  592.         PointArrowAtPlayerObject
  593.     Description:
  594.         Points the given arrow at the given object
  595.     Param(s):
  596.         playerid - The player who the arrow is streamed for.
  597.         arrowid  - The arrowid returned by "CreateArrow" function.
  598.         objectid - ID of the object to point at.
  599.     Returns:
  600.         1 if objectid is found.
  601.         0 otherwise.
  602.  
  603. */
  604. stock PointPlayerArrowAtObject(playerid, Arrow:arrowid, objectid)
  605. {
  606.     new
  607.         Float: fTargetX, Float: fTargetY, Float: fTargetZ
  608.     ;
  609.    
  610.     #if !defined ARROW_NO_STREAMER
  611.         if( GetDynamicObjectPos(objectid, fTargetX, fTargetY, fTargetZ) )
  612.         {
  613.             PointPlayerArrowAtPoint(playerid, _:arrowid, fTargetX, fTargetY, fTargetZ);
  614.             return 1;
  615.         }
  616.     #else
  617.         if( GetObjectPos(objectid, fTargetX, fTargetY, fTargetZ) )
  618.         {
  619.             PointPlayerArrowAtPoint(playerid, arrowid, fTargetX, fTargetY, fTargetZ);
  620.             return 1;
  621.         }
  622.     #endif
  623.    
  624.     return 0;
  625. }
  626.  
  627. /*
  628.     Function:
  629.         PointArrowAtPlayerObject
  630.     Description:
  631.         Points the given arrow at the given object
  632.     Param(s):
  633.         playerid        - The player who the arrow is streamed for.
  634.         arrowid         - The arrowid returned by "CreateArrow" function.
  635.         targetplayerid  - The player who the target object is streamed for.
  636.         targetobjectid  - ID of the player object to point at.
  637.     Returns:
  638.         1 if player objectid is found.
  639.         0 otherwise.
  640.  
  641. */
  642. stock PointPlayerArrowAtPlayerObject(playerid, Arrow:arrowid, targetplayerid, targetobjectid)
  643. {
  644.     new
  645.         Float: fTargetX, Float: fTargetY, Float: fTargetZ
  646.     ;
  647.    
  648.     #if !defined ARROW_NO_STREAMER
  649.         if( GetDynamicObjectPos(targetobjectid, fTargetX, fTargetY, fTargetZ) )
  650.         {
  651.             PointPlayerArrowAtPoint(playerid, arrowid, fTargetX, fTargetY, fTargetZ);
  652.             return 1;
  653.         }
  654.     #else
  655.         if( GetPlayerObjectPos(targetplayerid, targetobjectid, fTargetX, fTargetY, fTargetZ) )
  656.         {
  657.             PointPlayerArrowAtPoint(playerid, arrowid, fTargetX, fTargetY, fTargetZ);
  658.             return 1;
  659.         }
  660.     #endif
  661.    
  662.     return 0;
  663. }
  664.  
  665. /*
  666.     Function:
  667.         PointArrowAtPoint
  668.     Description:
  669.         Points the given arrow at the given point
  670.     Param(s):
  671.         arrowid  - The arrowid returned by "CreateArrow" function.
  672.         x, y, z  - The point, to point the arrow at
  673.     Returns:
  674.         This function returns 1 if the object is valid. 0 otherwise.
  675.  
  676. */
  677. stock PointArrowAtPoint(Arrow:arrowid, Float: x, Float: y, Float: z)
  678. {
  679.     new Float: fArrX, Float: fArrY, Float: fArrZ;
  680.    
  681.     #if !defined ARROW_NO_STREAMER
  682.         if( GetDynamicObjectPos(arrowid, fArrX, fArrY, fArrZ) )
  683.         {
  684.             SetDynamicObjectRot(arrowid, 0.0,
  685.                 arw_GetYRotation(fArrX, fArrY, fArrZ, x, y, z),
  686.                 arw_PointToPoint(fArrX, fArrY, x, y)+ARW_Z_ROT_OFFSET
  687.             );
  688.             return 1;
  689.         }
  690.         return 0;
  691.     #else
  692.         if( GetObjectPos(arrowid, fArrX, fArrY, fArrZ) )
  693.         {
  694.             SetObjectRot(arrowid, 0.0,
  695.                 arw_GetYRotation(fArrX, fArrY, fArrZ, x, y, z),
  696.                 arw_PointToPoint(fArrX, fArrY, x, y)+ARW_Z_ROT_OFFSET
  697.             );
  698.             return 1;
  699.         }
  700.         return 0;
  701.     #endif
  702. }
  703.  
  704. /*
  705.     Function:
  706.         PointPlayerArrowAtPoint
  707.     Description:
  708.         Points the given player arrow at the given point
  709.     Param(s):
  710.         playerid - The player who the arrow is streamed for.
  711.         arrowid  - The arrowid returned by "CreateArrow" function.
  712.         x, y, z  - The point, to point the player arrow at.
  713.     Returns:
  714.         This function returns 1 if the object is valid. 0 otherwise.
  715.  
  716. */
  717. stock PointPlayerArrowAtPoint(playerid, Arrow:arrowid, Float: x, Float: y, Float: z)
  718. {
  719.     #pragma unused playerid
  720.     new Float: fArrX, Float: fArrY, Float: fArrZ;
  721.    
  722.     #if !defined ARROW_NO_STREAMER
  723.         if( GetDynamicObjectPos(_:arrowid, fArrX, fArrY, fArrZ) )
  724.         {
  725.             SetDynamicObjectRot(_:arrowid, 0.0,
  726.                 arw_GetYRotation(fArrX, fArrY, fArrZ, x, y, z),
  727.                 arw_PointToPoint(fArrX, fArrY, x, y)+ARW_Z_ROT_OFFSET
  728.             );
  729.             return 1;
  730.         }
  731.         return 0;
  732.     #else
  733.         if( GetPlayerObjectPos(playerid, _:arrowid, fArrX, fArrY, fArrZ) )
  734.         {
  735.             SetPlayerObjectRot(playerid, _:arrowid, 0.0,
  736.                 arw_GetYRotation(fArrX, fArrY, fArrZ, x, y, z),
  737.                 arw_PointToPoint(fArrX, fArrY, x, y)+ARW_Z_ROT_OFFSET
  738.             );
  739.             return 1;
  740.         }
  741.         return 0;
  742.     #endif
  743. }
  744.  
  745. stock Float:arw_PointToPoint(Float:X, Float:Y, Float:PointX, Float:PointY)
  746. {
  747.     new Float:fAngle;
  748.     if(X > PointX && Y > PointY)
  749.         fAngle = floatabs(atan2(floatsub(PointX, X), floatsub(PointY, Y)));
  750.     if(X > PointX && Y <= PointY)
  751.         fAngle = floatadd(floatabs(atan2(floatsub(Y, PointY), floatsub(PointX, X))), 270.0);
  752.     if(X <= PointX && Y > PointY)
  753.         fAngle = floatadd(floatabs(atan2(floatsub(PointY, Y), floatsub(X, PointX))), 90.0);
  754.     if(X <= PointX && Y <= PointY)
  755.         fAngle = floatadd(floatabs(atan2(floatsub(X, PointX), floatsub(Y, PointY))), 180.0);
  756.     return fAngle >= 360.0 ? floatsub(fAngle, 360.0) : fAngle;
  757. }
  758.  
  759. stock Float:arw_GetYRotation(Float:x,Float:y,Float:z, Float:ax, Float:ay, Float:az)
  760. {
  761.     new Float:xd = ax - x;
  762.     new Float:yd = ay - y;
  763.     new Float:dist = floatsqroot(xd*xd+yd*yd);
  764.     new Float:Yoff = atan((z-az)/dist);
  765.     return Yoff-90;
  766. }
  767.  
  768. //The following 2 functions wont work with this object model id unfortunatly
  769. /*
  770.     Function:
  771.         SetArrowMaterial
  772.     Description:
  773.         Sets a new material for the arrow
  774.     Param(s):
  775.         arrowid         - The arrowid returned by "CreateArrow" function.
  776.         objectid        - The object modelid with the replacement material
  777.         txd_name[]      - Name of the TXD file that holds the material.
  778.         texturename[]   - Name of the texture to use as a replacement
  779.     Returns:
  780.         Value returned by SetObjectMaterial or SetDynamicObjectMaterial
  781.  
  782.  
  783. stock SetArrowMaterial(Arrow:arrowid, objectid, txd_name[], texturename[], objcolor=0)
  784. {
  785.     #if !defined ARROW_NO_STREAMER
  786.         return SetDynamicObjectMaterial(_:arrowid, 0, objectid, txd_name, texturename, objcolor);
  787.     #else
  788.         return SetObjectMaterial(_:arrowid, 0, objectid, txd_name, texturename, objcolor);
  789.     #endif
  790. }
  791. */
  792. /*
  793.     Function:
  794.         SetPlayerArrowMaterial
  795.     Description:
  796.         Sets a new material for the arrow
  797.     Param(s):
  798.         playerid        - The player who the arrow is streamed for.
  799.         arrowid         - The arrowid returned by "CreateArrow" function.
  800.         objectid        - The object modelid with the replacement material
  801.         txd_name[]      - Name of the TXD file that holds the material.
  802.         texturename[]   - Name of the texture to use as a replacement
  803.     Returns:
  804.         Value returned by SetObjectMaterial or SetDynamicObjectMaterial
  805.  
  806.  
  807. stock SetPlayerArrowMaterial(playerid, Arrow:arrowid, objectid, txd_name[], texturename[], objcolor=0)
  808. {
  809.     #pragma unused playerid
  810.     #if !defined ARROW_NO_STREAMER
  811.         return SetDynamicObjectMaterial(_:arrowid, 0, objectid, txd_name, texturename, objcolor);
  812.     #else
  813.         return SetPlayerObjectMaterial(playerid, _:arrowid, 0, objectid, txd_name, texturename, objcolor);
  814.     #endif
  815. }
  816. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement