Guest User

Untitled

a guest
Sep 25th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.65 KB | None | 0 0
  1. /*
  2. * =============================================================================================== *
  3. * =============================================================================================== *
  4. * =============================================================================================== *
  5. * =============================================================================================== *
  6. * ================================ Codectile's ================================ *
  7. * ================================ Objectometry ================================ *
  8. * ================================ -Library- ================================ *
  9. * ================================ -Version 1.0- ================================ *
  10. * ================================ ================================ *
  11. * =============================================================================================== *
  12. * =============================================================================================== *
  13. * =============================================================================================== *
  14. */
  15.  
  16. /*
  17. Introduction: This include helps in creating objects in different types of circular paths/tracks.This include is still under development.
  18. The functions below will not work unless streamer plugin is included in your script.
  19. There are total 6 different types of functions -
  20.  
  21. CreateDynamicObjectCircle(playerid,modelid,Float:posx,Float:posy,Float:posz, Float:rx, Float:ry, Float:rz,Float:radius,Float:sep,bool:facecenter=false)
  22. CreateDynamicObjectSpiral(playerid,modelid,Float:posx,Float:posy,Float:posz, Float:rx, Float:ry, Float:rz,Float:radius,Float:hsep,Float:vsep,bool:facecenter=false)
  23. CreateDynamicObjectCylinder(playerid,modelid,Float:posx,Float:posy,Float:posz, Float:rx, Float:ry, Float:rz,Float:radius,Float:hsep,Float:vsep,parts,bool:facecenter=false)
  24. CreateDynamicObjectWhirl(playerid,modelid,Float:posx,Float:posy,Float:posz,Float:rx,Float:ry,Float:rz,Float:radius,Float:sep,bool:facecenter=false)
  25. CreateDynamicCircleIn(playerid,modelid,Float:posx,Float:posy,Float:posz,Float:rx,Float:ry,Float:rz,Float:radius,Float:sep,parts,bool:facecenter=false)
  26. CreateDynamicCircleOut(playerid,modelid,Float:posx,Float:posy,Float:posz,Float:rx,Float:ry,Float:rz,Float:radius,Float:sep,parts,bool:facecenter=false)
  27.  
  28.  
  29. Dependencies: Streamer Plugin (Incognito)
  30.  
  31. Bugs: None yet.
  32.  
  33. Source Code: www.github.com/codectile
  34. Credits: Incognito
  35.  
  36. Note: This include has been modified and integrated for use in Texture Studio
  37. */
  38.  
  39.  
  40.  
  41. /* The following codes are too much fragile, please "do not edit them". */
  42.  
  43. /* Creates object in a circular path */
  44.  
  45. #include <YSI\y_hooks>
  46. #define MAX_OBM 1000
  47.  
  48. enum OBMINFO
  49. {
  50. OMBID,
  51. OMBModel,
  52. Float:OBMX,
  53. Float:OBMY,
  54. Float:OBMZ,
  55. Float:OBMRX,
  56. Float:OBMRY,
  57. Float:OBMRZ,
  58. }
  59.  
  60. static OBMStack[MAX_PLAYERS][MAX_OBM][OBMINFO];
  61.  
  62. hook OnFilterScriptInit()
  63. {
  64. for(new i = 0; i < MAX_PLAYERS; i++)
  65. {
  66. for(new j = 0; j < MAX_OBM; j++) OBMStack[i][j][OMBID] = -1;
  67. }
  68. return 1;
  69. }
  70.  
  71. hook OnFilterScriptExit()
  72. {
  73. foreach(new i : Player) ClearOBMStack(i);
  74. return 1;
  75. }
  76.  
  77. hook OnPlayerDisconnect(playerid, reason)
  78. {
  79. ClearOBMStack(playerid);
  80. return 1;
  81. }
  82.  
  83. ClearOBMStack(playerid)
  84. {
  85. for(new i = 0; i < MAX_OBM; i++)
  86. {
  87. if(OBMStack[playerid][i][OMBID] != -1)
  88. {
  89. DestroyDynamicObject(OBMStack[playerid][i][OMBID]);
  90. OBMStack[playerid][i][OMBID] = -1;
  91. }
  92. }
  93. return 1;
  94. }
  95.  
  96. ApplyOBM(playerid)
  97. {
  98. ClearGroup(playerid);
  99. new index;
  100. for(new i = 0; i < MAX_OBM; i++)
  101. {
  102. if(OBMStack[playerid][i][OMBID] != -1)
  103. {
  104. index = AddDynamicObject(OBMStack[playerid][i][OMBModel],
  105. OBMStack[playerid][i][OBMX], OBMStack[playerid][i][OBMY], OBMStack[playerid][i][OBMZ],
  106. OBMStack[playerid][i][OBMRX], OBMStack[playerid][i][OBMRY], OBMStack[playerid][i][OBMRZ]
  107. );
  108. GroupedObjects[playerid][index] = true;
  109. UpdateObject3DText(index, true);
  110. OnUpdateGroup3DText(index);
  111. }
  112. }
  113. return 1;
  114. }
  115.  
  116. static AddOBMObject(playerid,modelid,Float:x,Float:y,Float:z,Float:rx,Float:ry,Float:rz)
  117. {
  118. for(new i = 0; i < MAX_OBM; i++)
  119. {
  120. if(OBMStack[playerid][i][OMBID] == -1)
  121. {
  122. OBMStack[playerid][i][OMBID] = CreateDynamicObject(modelid, x, y, z, rx, ry, rz, -1, -1, -1, 300.0, 300.0);
  123. OBMStack[playerid][i][OMBModel] = modelid;
  124. OBMStack[playerid][i][OBMX] = x;
  125. OBMStack[playerid][i][OBMY] = y;
  126. OBMStack[playerid][i][OBMZ] = z;
  127. OBMStack[playerid][i][OBMRX] = rx;
  128. OBMStack[playerid][i][OBMRY] = ry;
  129. OBMStack[playerid][i][OBMRZ] = rz;
  130. return i;
  131. }
  132. }
  133. return 1;
  134. }
  135.  
  136. CreateDynamicObjectCircle(playerid,modelid,deg,Float:posx,Float:posy,Float:posz, Float:rx, Float:ry, Float:rz, Float:orx, Float:ory, Float:radius,Float:sep,bool:facecenter=false)
  137. {
  138. if(facecenter == false)
  139. {
  140. new Float:angle = 0.0,Float:x = 0.0,Float:y = 0.0;
  141. for(new i = 0;i < deg;i += 1)
  142. {
  143. if(angle <= float(deg))
  144. {
  145. x = posx+radius*floatcos(angle,degrees);
  146. y = posy+radius*floatsin(angle,degrees);
  147. AddOBMObject(playerid,modelid, x, y, posz,rx,ry,rz);
  148. angle = angle+sep;
  149. }
  150. else break;
  151. }
  152. }
  153. else
  154. {
  155. new Float:angle = 0.0,Float:x = 0.0,Float:y = 0.0,Float:z,Float:detrx,Float:detry,Float:detrz;
  156. for(new i = 0;i < float(deg);i += 1)
  157. {
  158. if(angle <= deg)
  159. {
  160. x=posx+radius*floatcos(angle,degrees);
  161. y=posy+radius*floatsin(angle,degrees);
  162.  
  163. // Translate to rotation
  164. AttachPoint(x, y, posz,
  165. orx, ory, angle-180.0,
  166. posx, posy, posz, rx, ry, rz,
  167. x, y, z,
  168. detrx, detry, detrz
  169. );
  170. AddOBMObject(playerid,modelid, x, y, z, detrx, detry, detrz);
  171. angle = angle+sep;
  172. }
  173. else break;
  174. }
  175. }
  176. Streamer_Update(playerid);
  177. return 1;
  178. }
  179.  
  180. /* Creates objects in a Helical path */
  181. CreateDynamicObjectSpiral(playerid,modelid,deg,Float:posx,Float:posy,Float:posz, Float:rx, Float:ry, Float:rz, Float:orx, Float:ory, Float:radius,Float:hsep,Float:vsep,bool:facecenter=false)
  182. {
  183. if(facecenter == false)
  184. {
  185. new Float:angle = 0.0,Float:x = 0.0,Float:y = 0.0,Float:c = 0.0;
  186. for(new i = 0;i < deg;i += 1)
  187. {
  188. if(angle <= float(deg))
  189. {
  190. x=posx+radius*floatcos(angle,degrees);
  191. y=posy+radius*floatsin(angle,degrees);
  192. AddOBMObject(playerid,modelid, x, y, posz+c,rx,ry,rz);
  193. c = c+vsep;
  194. angle = angle+hsep;
  195. }
  196. else break;
  197. }
  198. }
  199. else
  200. {
  201. new Float:angle = 0.0,Float:x = 0.0,Float:y = 0.0,Float:z, Float:c = 0.0, Float:detrx,Float:detry,Float:detrz;
  202. for(new i = 0;i < deg;i += 1)
  203. {
  204. if(angle <= float(deg))
  205. {
  206. x=posx+radius*floatcos(angle,degrees);
  207. y=posy+radius*floatsin(angle,degrees);
  208.  
  209.  
  210. // Translate to rotation
  211. AttachPoint(x, y, posz+c,
  212. orx, ory, angle+180.0,
  213. posx, posy, posz, rx, ry, rz,
  214. x, y, z,
  215. detrx, detry, detrz
  216. );
  217. AddOBMObject(playerid,modelid, x, y, z, detrx, detry, detrz);
  218.  
  219. c=c+vsep;
  220. angle = angle+hsep;
  221. }
  222. else break;
  223. }
  224. }
  225. Streamer_Update(playerid);
  226. return 1;
  227. }
  228.  
  229. /* Creates objects in a Cylinderical path */
  230. CreateDynamicObjectCylinder(playerid,modelid,deg,Float:posx,Float:posy,Float:posz, Float:rx, Float:ry, Float:rz, Float:orx, Float:ory, Float:radius,Float:hsep,Float:vsep,parts,bool:facecenter=false)
  231. {
  232. if(facecenter == false)
  233. {
  234. new Float:angle=0.0,Float:x=0.0,Float:y=0.0,Float:c=0.0;
  235. for(new j=0;j<parts;j++)
  236. {
  237. angle = 0.0,x = 0.0,y = 0.0;
  238. for(new i=0;i<deg;i+=1)
  239. {
  240. if(angle <= float(deg))
  241. {
  242. x=posx+radius*floatcos(angle,degrees);
  243. y=posy+radius*floatsin(angle,degrees);
  244. AddOBMObject(playerid,modelid, x, y, posz+c,rx,ry,rz);
  245. angle=angle+hsep;
  246. }
  247. else break;
  248. }
  249. c=c+vsep;
  250. }
  251. }
  252. else
  253. {
  254. new Float:angle = 0.0,Float:x = 0.0,Float:y = 0.0,Float:z, Float:c = 0.0, Float:detrx,Float:detry,Float:detrz;
  255. for(new j=0;j<parts;j++)
  256. {
  257. angle = 0.0,x = 0.0,y = 0.0;
  258. for(new i=0;i<deg;i+=1)
  259. {
  260. if(angle <= float(deg))
  261. {
  262. x=posx+radius*floatcos(angle,degrees);
  263. y=posy+radius*floatsin(angle,degrees);
  264.  
  265. // Translate to rotation
  266. AttachPoint(x, y, posz+c,
  267. orx, ory, angle+180.0,
  268. posx, posy, posz, rx, ry, rz,
  269. x, y, z,
  270. detrx, detry, detrz
  271. );
  272. AddOBMObject(playerid,modelid, x, y, z, detrx, detry, detrz);
  273. angle=angle+hsep;
  274. }
  275. else break;
  276. }
  277. c=c+vsep;
  278. }
  279. }
  280. Streamer_Update(playerid);
  281. return 1;
  282. }
  283.  
  284.  
  285. /* Creates objects in a reversed "6" type of path */
  286. CreateDynamicObjectWhirl(playerid,modelid,deg,Float:posx,Float:posy,Float:posz,Float:rx,Float:ry,Float:rz, Float:orx, Float:ory, Float:radius,Float:sep,bool:facecenter=false)
  287. {
  288. if(facecenter == false)
  289. {
  290. new Float:angle=0.0,Float:x=0.0,Float:y=0.0;
  291. for(new i=0;i<deg;i+=1)
  292. {
  293. if(angle <= float(deg))
  294. {
  295. x=posx+(radius-i)*floatcos(angle,degrees);
  296. y=posy+(radius-i)*floatsin(angle,degrees);
  297. AddOBMObject(playerid,modelid, x, y, posz,rx,ry,rz);
  298. angle=angle+sep;
  299. }
  300. else break;
  301. }
  302. }
  303. else
  304. {
  305. new Float:angle = 0.0,Float:x = 0.0,Float:y = 0.0,Float:z,Float:detrx,Float:detry,Float:detrz;
  306. for(new i = 0;i < deg;i += 1)
  307. {
  308. if(angle <= float(deg))
  309. {
  310. x=posx+(radius-i)*floatcos(angle,degrees);
  311. y=posy+(radius-i)*floatsin(angle,degrees);
  312.  
  313. // Translate to rotation
  314. AttachPoint(x, y, posz,
  315. orx, ory, angle+180.0,
  316. posx, posy, posz, rx, ry, rz,
  317. x, y, z,
  318. detrx, detry, detrz
  319. );
  320. AddOBMObject(playerid,modelid, x, y, z, detrx, detry, detrz);
  321. angle=angle+sep;
  322. }
  323. else break;
  324. }
  325. }
  326.  
  327. Streamer_Update(playerid);
  328. return 1;
  329. }
  330.  
  331. /* Creates objects in a circular path within a circular pathed object */
  332. CreateDynamicCircleIn(playerid,modelid,deg,Float:posx,Float:posy,Float:posz,Float:rx,Float:ry,Float:rz, Float:orx, Float:ory, Float:radius,Float:sep,parts,bool:facecenter=false)
  333. {
  334. if(facecenter == false)
  335. {
  336. new Float:angle=0.0,Float:x=0.0,Float:y=0.0;
  337. for(new j=0;j<parts;j++)
  338. {
  339. angle=0.0,x=0.0,y=0.0;
  340. for(new i=0;i<deg;i+=1)
  341. {
  342. if(angle <= float(deg))
  343. {
  344. x=posx+(radius)*floatcos(angle,degrees);
  345. y=posy+(radius)*floatsin(angle,degrees);
  346. AddOBMObject(playerid,modelid, x, y, posz,rx,ry,rz);
  347. angle=angle+sep;
  348. }
  349. else break;
  350. }
  351. radius-=2.5;
  352. }
  353. }
  354. else
  355. {
  356. new Float:angle = 0.0,Float:x = 0.0,Float:y = 0.0,Float:z,Float:detrx,Float:detry,Float:detrz;
  357. for(new j=0;j<parts;j++)
  358. {
  359. angle=0.0,x=0.0,y=0.0;
  360. for(new i=0;i<deg;i+=1)
  361. {
  362. if(angle <= float(deg))
  363. {
  364. x=posx+(radius)*floatcos(angle,degrees);
  365. y=posy+(radius)*floatsin(angle,degrees);
  366.  
  367. // Translate to rotation
  368. AttachPoint(x, y, posz,
  369. orx, ory, angle+180.0,
  370. posx, posy, posz, rx, ry, rz,
  371. x, y, z,
  372. detrx, detry, detrz
  373. );
  374. AddOBMObject(playerid,modelid, x, y, z, detrx, detry, detrz);
  375. angle=angle+sep;
  376. }
  377. else break;
  378. }
  379. radius-=2.5;
  380. }
  381. }
  382. Streamer_Update(playerid);
  383. return 1;
  384. }
  385.  
  386. /* Creates objects in a circular path outside a circular pathed object */
  387. CreateDynamicCircleOut(playerid,modelid,deg,Float:posx,Float:posy,Float:posz,Float:rx,Float:ry,Float:rz, Float:orx, Float:ory, Float:radius,Float:sep,parts,bool:facecenter=false)
  388. {
  389. if(facecenter == false)
  390. {
  391. new Float:angle=0.0,Float:x=0.0,Float:y=0.0;
  392. for(new j=0;j<parts;j++)
  393. {
  394. angle=0.0,x=0.0,y=0.0;
  395. for(new i=0;i<deg;i+=1)
  396. {
  397. if(angle <= float(deg))
  398. {
  399. x=posx+(radius)*floatcos(angle,degrees);
  400. y=posy+(radius)*floatsin(angle,degrees);
  401. AddOBMObject(playerid,modelid, x, y, posz,rx,ry,rz);
  402. angle=angle+sep;
  403. }
  404. else break;
  405. }
  406. radius+=2.5;
  407. }
  408. }
  409. else
  410. {
  411. new Float:angle = 0.0,Float:x = 0.0,Float:y = 0.0,Float:z,Float:detrx,Float:detry,Float:detrz;
  412. for(new j=0;j<parts;j++)
  413. {
  414. angle=0.0,x=0.0,y=0.0;
  415. for(new i=0;i<deg;i+=1)
  416. {
  417. if(angle <= float(deg))
  418. {
  419. x=posx+(radius)*floatcos(angle,degrees);
  420. y=posy+(radius)*floatsin(angle,degrees);
  421. // Translate to rotation
  422. AttachPoint(x, y, posz,
  423. orx, ory, angle+180.0,
  424. posx, posy, posz, rx, ry, rz,
  425. x, y, z,
  426. detrx, detry, detrz
  427. );
  428. AddOBMObject(playerid,modelid, x, y, z, detrx, detry, detrz);
  429. angle=angle+sep;
  430. }
  431. else break;
  432. }
  433. radius+=2.5;
  434. }
  435. }
  436.  
  437. Streamer_Update(playerid);
  438. return 1;
  439. }
  440.  
  441. //==========================================================================================
  442.  
  443.  
  444. stock AttachPoint(Float:offx, Float:offy, Float:offz, Float:offrx, Float:offry, Float:offrz, Float:px, Float:py, Float:pz, Float:prx, Float:pry, Float:prz, &Float:RetX, &Float:RetY, &Float:RetZ, &Float:RetRX, &Float:RetRY, &Float:RetRZ, sync_rotation = 1)
  445. {
  446. new
  447. Float:g_sin[3],
  448. Float:g_cos[3],
  449. Float:off_x,
  450. Float:off_y,
  451. Float:off_z;
  452.  
  453. EDIT_FloatEulerFix(prx, pry, prz);
  454.  
  455. off_x = offx - px; // static offset
  456. off_y = offy - py; // static offset
  457. off_z = offz - pz; // static offset
  458.  
  459. // Calculate the new position
  460. EDIT_FloatConvertValue(prx, pry, prz, g_sin, g_cos);
  461. RetX = px + off_x * g_cos[1] * g_cos[2] - off_x * g_sin[0] * g_sin[1] * g_sin[2] - off_y * g_cos[0] * g_sin[2] + off_z * g_sin[1] * g_cos[2] + off_z * g_sin[0] * g_cos[1] * g_sin[2];
  462. RetY = py + off_x * g_cos[1] * g_sin[2] + off_x * g_sin[0] * g_sin[1] * g_cos[2] + off_y * g_cos[0] * g_cos[2] + off_z * g_sin[1] * g_sin[2] - off_z * g_sin[0] * g_cos[1] * g_cos[2];
  463. RetZ = pz - off_x * g_cos[0] * g_sin[1] + off_y * g_sin[0] + off_z * g_cos[0] * g_cos[1];
  464.  
  465. if (sync_rotation)
  466. {
  467. // Calculate the new rotation
  468. EDIT_FloatConvertValue(asin(g_cos[0] * g_cos[1]), atan2(g_sin[0], g_cos[0] * g_sin[1]) + offrz, atan2(g_cos[1] * g_cos[2] * g_sin[0] - g_sin[1] * g_sin[2], g_cos[2] * g_sin[1] - g_cos[1] * g_sin[0] * -g_sin[2]), g_sin, g_cos);
  469. EDIT_FloatConvertValue(asin(g_cos[0] * g_sin[1]), atan2(g_cos[0] * g_cos[1], g_sin[0]), atan2(g_cos[2] * g_sin[0] * g_sin[1] - g_cos[1] * g_sin[2], g_cos[1] * g_cos[2] + g_sin[0] * g_sin[1] * g_sin[2]), g_sin, g_cos);
  470. EDIT_FloatConvertValue(atan2(g_sin[0], g_cos[0] * g_cos[1]) + offrx, asin(g_cos[0] * g_sin[1]), atan2(g_cos[2] * g_sin[0] * g_sin[1] + g_cos[1] * g_sin[2], g_cos[1] * g_cos[2] - g_sin[0] * g_sin[1] * g_sin[2]), g_sin, g_cos);
  471.  
  472. RetRX = asin(g_cos[1] * g_sin[0]);
  473. RetRY = atan2(g_sin[1], g_cos[0] * g_cos[1]) + offry;
  474. RetRZ = atan2(g_cos[0] * g_sin[2] - g_cos[2] * g_sin[0] * g_sin[1], g_cos[0] * g_cos[2] + g_sin[0] * g_sin[1] * g_sin[2]);
  475. }
  476. }
  477.  
  478.  
  479.  
  480.  
  481.  
  482. stock EDIT_FloatConvertValue(Float:rot_x, Float:rot_y, Float:rot_z, Float:sin[3], Float:cos[3])
  483. {
  484. sin[0] = floatsin(rot_x, degrees);
  485. sin[1] = floatsin(rot_y, degrees);
  486. sin[2] = floatsin(rot_z, degrees);
  487. cos[0] = floatcos(rot_x, degrees);
  488. cos[1] = floatcos(rot_y, degrees);
  489. cos[2] = floatcos(rot_z, degrees);
  490. return 1;
  491. }
  492.  
  493. /*
  494. * Fixes a bug that causes objects to not rotate
  495. * correctly when rotating on the Z axis only.
  496. */
  497. stock EDIT_FloatEulerFix(&Float:rot_x, &Float:rot_y, &Float:rot_z)
  498. {
  499. EDIT_FloatGetRemainder(rot_x, rot_y, rot_z);
  500. if((!floatcmp(rot_x, 0.0) || !floatcmp(rot_x, 360.0))
  501. && (!floatcmp(rot_y, 0.0) || !floatcmp(rot_y, 360.0)))
  502. {
  503. rot_y = 0.00000002;
  504. }
  505. return 1;
  506. }
  507.  
  508. stock EDIT_FloatGetRemainder(&Float:rot_x, &Float:rot_y, &Float:rot_z)
  509. {
  510. EDIT_FloatRemainder(rot_x, 360.0);
  511. EDIT_FloatRemainder(rot_y, 360.0);
  512. EDIT_FloatRemainder(rot_z, 360.0);
  513. return 1;
  514. }
  515.  
  516. stock EDIT_FloatRemainder(&Float:remainder, Float:value)
  517. {
  518. if(remainder >= value)
  519. {
  520. while(remainder >= value)
  521. {
  522. remainder = remainder - value;
  523. }
  524. }
  525. else if(remainder < 0.0)
  526. {
  527. while(remainder < 0.0)
  528. {
  529. remainder = remainder + value;
  530. }
  531. }
  532. return 1;
  533. }
Advertisement
Add Comment
Please, Sign In to add comment