Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.69 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. /*
  20. native CreateArrow(Float: x, Float: y, Float: z, Float: target_x, Float: target_y, Float: stream_dist = DEFAULT_ARROW_DRAW_DISTANCE);
  21. native PointArrowAtPoint(arrowid, Float: x, Float: y);
  22. native DestroyArrow(arrowid);
  23. native SetArrowPos(arrowid, Float: x, Float: y, Float: z);
  24. native GetArrowPos(arrowid, &Float: x, &Float: y, &Float: z);
  25. native GetArrowRot(arrowid, &Float: rx, &Float: ry, &Float: rz);
  26. native PointArrowAtPlayer(arrowid, playerid);
  27. native PointArrowAtVehicle(arrowid, vehicleid);
  28. native PointArrowAtObject(arrowid, objectid);
  29. native SetArrowColor(arrowid, argb_color);
  30. */
  31.  
  32. #define INVALID_ARROW_ID -1
  33.  
  34. #define ARW_OBJECT_ID (1318)
  35.  
  36. #define ARW_Z_ROT_OFFSET (90.0)
  37.  
  38. #define DEFAULT_ARROW_DRAW_DISTANCE (200.0)
  39.  
  40. #define MAX_ARROWS 100
  41.  
  42. #if !defined ARROW_NO_STREAMER
  43. #tryinclude <streamer>
  44. #if !defined CreateDynamicObject
  45. #error streamer include not found, have you got streamer.inc in your includes folder?
  46. #endif
  47. #endif
  48.  
  49. new gArrowObjectID[MAX_ARROWS] = { INVALID_ARROW_ID, ... };
  50.  
  51. forward Float:arw_PointToPoint(Float:X, Float:Y, Float:PointX, Float:PointY);
  52.  
  53. /*
  54. Function:
  55. CreateArrow
  56. Description:
  57. Creates an arrow at the given point, pointing to a target location.
  58. Param(s):
  59. x, y, z - Position to create the arrow.
  60. target_x, tagtet_y - Position to point the arrow at
  61. stream_dist - stream distance for the arrow (default DEFAULT_ARROW_DRAW_DISTANCE)
  62. Returns:
  63. Arrowid for the newly created arrow. (returned by CreateObject or CreateDynamicObject
  64.  
  65. */
  66. stock CreateArrow(Float: x, Float: y, Float: z, Float: target_x, Float: target_y, Float: stream_dist = DEFAULT_ARROW_DRAW_DISTANCE)
  67. {
  68. for(new i = 0; i < MAX_ARROWS; i++)
  69. {
  70. #if !defined ARROW_NO_STREAMER
  71. gArrowObjectID[i] = CreateDynamicObject( ARW_OBJECT_ID, x, y, z,
  72. 0.0, -90, arw_PointToPoint(x, y, target_x, target_y)+ARW_Z_ROT_OFFSET,
  73. .streamdistance = stream_dist);
  74. return i;
  75. #else
  76. gArrowObjectID[i] = CreateObject( ARW_OBJECT_ID, x, y, z,
  77. 0.0, -90, arw_PointToPoint(x, y, target_x, target_y)+ARW_Z_ROT_OFFSET, stream_dist );
  78. return i;
  79. #endif
  80. }
  81. printf("Error: Arrow.inc::CreateArrow()::Tried to create too many arrows");
  82. return INVALID_ARROW_ID;
  83. }
  84.  
  85. /*
  86. Function:
  87. DestroyArrow
  88. Description:
  89. Destroys the given arrow.
  90. Param(s):
  91. arrowid - The arrowid returned by "CreateArrow" function
  92. Returns:
  93. Value returned by CreateObject or CreateDynamicObject
  94.  
  95. */
  96.  
  97. stock DestroyArrow(arrowid)
  98. {
  99. if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
  100. {
  101. #if !defined ARROW_NO_STREAMER
  102. DestroyDynamicObject( gArrowObjectID[arrowid] );
  103. gArrowObjectID[arrowid] = INVALID_ARROW_ID;
  104. return 1;
  105. #else
  106. DestroyObject( gArrowObjectID[arrowid] );
  107. gArrowObjectID[arrowid] = INVALID_ARROW_ID;
  108. return 1;
  109. #endif
  110. }
  111.  
  112. printf("Error: Arrow.inc::DestoyArrow()::Tried access invalid arrow Arrowid: %i", arrowid);
  113. return INVALID_ARROW_ID;
  114. }
  115.  
  116. /*
  117. Function:
  118. SetArrowPos
  119. Description:
  120. Sets a new position for the given arrow.
  121. Param(s):
  122. arrowid - The arrowid returned by "CreateArrow" function.
  123. x, y, z - The new position for the arrow to be placed.
  124. Returns:
  125. Value returned by SetObjectPos or SetDynamicObjectPos
  126.  
  127. */
  128. stock SetArrowPos(arrowid, Float: x, Float: y, Float: z)
  129. {
  130. if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
  131. {
  132. #if !defined ARROW_NO_STREAMER
  133. return SetDynamicObjectPos( gArrowObjectID[arrowid], x, y, z );
  134. #else
  135. return SetObjectPos( gArrowObjectID[arrowid], x, y, z );
  136. #endif
  137. }
  138.  
  139. printf("Error: Arrow.inc::SetArrowPos()::Tried access invalid arrow Arrowid: %i", arrowid);
  140. return INVALID_ARROW_ID;
  141. }
  142.  
  143. /*
  144. Function:
  145. GetArrowPos
  146. Description:
  147. Gets the current position for the given arrow.
  148. Param(s):
  149. arrowid - The arrowid returned by "CreateArrow" function.
  150. x, y, z - Variables to store the position of the arrow, passed by reference.
  151. Returns:
  152. Value returned by GetObjectPos or GetDynamicObjectPos
  153.  
  154. */
  155. stock GetArrowPos(arrowid, &Float: x, &Float: y, &Float: z)
  156. {
  157. if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
  158. {
  159. #if !defined ARROW_NO_STREAMER
  160. return GetDynamicObjectPos( gArrowObjectID[arrowid], x, y, z );
  161. #else
  162. return GetObjectPos( gArrowObjectID[arrowid], x, y, z );
  163. #endif
  164. }
  165.  
  166. printf("Error: Arrow.inc::GetArrowPos()::Tried access invalid arrow Arrowid: %i", arrowid);
  167. return INVALID_ARROW_ID;
  168. }
  169.  
  170. /*
  171. Function:
  172. GetArrowRot
  173. Description:
  174. Gets the current rotation for the given arrow.
  175. Param(s):
  176. arrowid - The arrowid returned by "CreateArrow" function.
  177. x, y, z - Variables to store the rotation of the arrow, passed by reference.
  178. Returns:
  179. Value returned by GetObjectRot or GetDynamicObjectRot
  180.  
  181. */
  182. stock GetArrowRot(arrowid, &Float: rx, &Float: ry, &Float: rz)
  183. {
  184. if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
  185. {
  186. #if !defined ARROW_NO_STREAMER
  187. return GetDynamicObjectRot( gArrowObjectID[arrowid], rx, ry, rz );
  188. #else
  189. return GetObjectRot( gArrowObjectID[arrowid], rx, ry, rz );
  190. #endif
  191. }
  192.  
  193. printf("Error: Arrow.inc::GetArrowRot()::Tried access invalid arrow Arrowid: %i", arrowid);
  194. return INVALID_ARROW_ID;
  195. }
  196.  
  197. /*
  198. Function:
  199. SetArrowColor
  200. Description:
  201. Sets a new color for the arrow
  202. Param(s):
  203. arrowid - The arrowid returned by "CreateArrow" function.
  204. argb_color - New color for the arrow, NOTE: ARGB format not RGBA
  205. Returns:
  206. Value returned by SetObjectMaterial or SetDynamicObjectMaterial
  207.  
  208. */
  209. stock SetArrowColor(arrowid, argb_color)
  210. {
  211. if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
  212. {
  213. #if !defined ARROW_NO_STREAMER
  214. return SetDynamicObjectMaterial(gArrowObjectID[arrowid], 0, -1, "none", "none", argb_color);
  215. #else
  216. return SetObjectMaterial(gArrowObjectID[arrowid], 0, -1, "none", "none", argb_color);
  217. #endif
  218. }
  219.  
  220. printf("Error: Arrow.inc::SetArrowColor()::Tried access invalid arrow Arrowid: %i", arrowid);
  221. return INVALID_ARROW_ID;
  222. }
  223.  
  224. /*
  225. Function:
  226. PointArrowAtPlayer
  227. Description:
  228. Points the given arrow at the given playerid
  229. Param(s):
  230. arrowid - The arrowid returned by "CreateArrow" function.
  231. playerid - ID of the player to point at.
  232. Returns:
  233. 1 if playerid is connected.
  234. 0 otherwise.
  235.  
  236. */
  237. stock PointArrowAtPlayer(arrowid, playerid)
  238. {
  239. if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
  240. {
  241. new
  242. Float: fTargetX, Float: fTargetY, Float: fTargetZ
  243. ;
  244.  
  245. if( GetPlayerPos(playerid, fTargetX, fTargetY, fTargetZ) )
  246. {
  247. PointArrowAtPoint(gArrowObjectID[arrowid], fTargetX, fTargetY);
  248. return 1;
  249. }
  250. return 0;
  251. }
  252. printf("Error: Arrow.inc::PointArrowAtPlayer()::Tried access invalid arrow Arrowid: %i", arrowid);
  253. return INVALID_ARROW_ID;
  254. }
  255.  
  256. /*
  257. Function:
  258. PointArrowAtVehicle
  259. Description:
  260. Points the given arrow at the given vehicle
  261. Param(s):
  262. arrowid - The arrowid returned by "CreateArrow" function.
  263. vehicleid - ID of the vehicle to point at.
  264. Returns:
  265. 1 if vehicleid is found.
  266. 0 otherwise.
  267.  
  268. */
  269. stock PointArrowAtVehicle(arrowid, vehicleid)
  270. {
  271. if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
  272. {
  273. new
  274. Float: fTargetX, Float: fTargetY, Float: fTargetZ
  275. ;
  276.  
  277. if( GetVehiclePos(vehicleid, fTargetX, fTargetY, fTargetZ) )
  278. {
  279. PointArrowAtPoint(gArrowObjectID[arrowid], fTargetX, fTargetY);
  280. return 1;
  281. }
  282. return 0;
  283. }
  284.  
  285. printf("Error: Arrow.inc::PointArrowAtVehicle()::Tried access invalid arrow Arrowid: %i", arrowid);
  286. return INVALID_ARROW_ID;
  287. }
  288.  
  289. /*
  290. Function:
  291. PointArrowAtObject
  292. Description:
  293. Points the given arrow at the given object
  294. Param(s):
  295. arrowid - The arrowid returned by "CreateArrow" function.
  296. objectid - ID of the object to point at.
  297. Returns:
  298. 1 if objectid is found.
  299. 0 otherwise.
  300.  
  301. */
  302. stock PointArrowAtObject(arrowid, objectid)
  303. {
  304. if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
  305. {
  306. new
  307. Float: fTargetX, Float: fTargetY, Float: fTargetZ
  308. ;
  309.  
  310. #if !defined ARROW_NO_STREAMER
  311. if( GetDynamicObjectPos(objectid, fTargetX, fTargetY, fTargetZ) )
  312. {
  313. PointArrowAtPoint(gArrowObjectID[arrowid], fTargetX, fTargetY);
  314. return 1;
  315. }
  316. #else
  317. if( GetObjectPos(objectid, fTargetX, fTargetY, fTargetZ) )
  318. {
  319. PointArrowAtPoint(gArrowObjectID[arrowid], fTargetX, fTargetY);
  320. return 1;
  321. }
  322. #endif
  323. return 0;
  324. }
  325. printf("Error: Arrow.inc::PointArrowAtObject()::Tried access invalid arrow Arrowid: %i", arrowid);
  326. return INVALID_ARROW_ID;
  327. }
  328.  
  329. /*
  330. Function:
  331. PointArrowAtPoint
  332. Description:
  333. Points the given arrow at the given point
  334. Param(s):
  335. arrowid - The arrowid returned by "CreateArrow" function.
  336. x, y - The point, to point the arrow at
  337. Returns:
  338. This function does not return a value
  339.  
  340. */
  341. stock PointArrowAtPoint(arrowid, Float: x, Float: y)
  342. {
  343. if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
  344. {
  345. new Float: fArrX, Float: fArrY, Float: fArrZ;
  346.  
  347. #if !defined ARROW_NO_STREAMER
  348. GetDynamicObjectPos(gArrowObjectID[arrowid], fArrX, fArrY, fArrZ);
  349. return SetDynamicObjectRot(gArrowObjectID[arrowid], 0.0, -90.00000, arw_PointToPoint(fArrX, fArrY, x, y)+ARW_Z_ROT_OFFSET);
  350. #else
  351. GetObjectPos(gArrowObjectID[arrowid], fArrX, fArrY, fArrZ);
  352. return SetObjectRot(gArrowObjectID[arrowid], 0.0, -90.00000, arw_PointToPoint(fArrX, fArrY, x, y)+ARW_Z_ROT_OFFSET);
  353. #endif
  354. }
  355.  
  356. printf("Error: Arrow.inc::PointArrowAtPoint()::Tried access invalid arrow Arrowid: %i", arrowid);
  357. return INVALID_ARROW_ID;
  358. }
  359.  
  360. stock Float:arw_PointToPoint(Float:X, Float:Y, Float:PointX, Float:PointY)
  361. {
  362. new Float:fAngle;
  363. if(X > PointX && Y > PointY)
  364. fAngle = floatabs(atan2(floatsub(PointX, X), floatsub(PointY, Y)));
  365. if(X > PointX && Y <= PointY)
  366. fAngle = floatadd(floatabs(atan2(floatsub(Y, PointY), floatsub(PointX, X))), 270.0);
  367. if(X <= PointX && Y > PointY)
  368. fAngle = floatadd(floatabs(atan2(floatsub(PointY, Y), floatsub(X, PointX))), 90.0);
  369. if(X <= PointX && Y <= PointY)
  370. fAngle = floatadd(floatabs(atan2(floatsub(X, PointX), floatsub(Y, PointY))), 180.0);
  371.  
  372. return fAngle >= 360.0 ? floatsub(fAngle, 360.0) : fAngle;
  373. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement