Advertisement
Rei_Ayanami

[FS] 8 ball pool

Apr 27th, 2024
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.47 KB | None | 0 0
  1. #include <a_samp>
  2. #include <physics>
  3. #include <zcmd>
  4. #include <sscanf>
  5.  
  6. #define OBJ_SLOT_POOL (0)
  7.  
  8. enum poolBall
  9. {
  10. bObject,
  11. bExisting
  12. }
  13.  
  14. new
  15. PlayingPool[MAX_PLAYERS],
  16. PoolCamera[MAX_PLAYERS],
  17. UsingChalk[MAX_PLAYERS],
  18. PoolScore[MAX_PLAYERS],
  19. Float:AimAngle[MAX_PLAYERS][2],
  20. AimObject,
  21. PoolStarted,
  22. PoolAimer = -1,
  23. PoolLastShooter = -1,
  24. PoolLastScore,
  25. PoolBall[16][poolBall],
  26. Text:PoolTD[4],
  27. Float:PoolPower,
  28. PoolDir;
  29.  
  30. main() { }
  31.  
  32. public OnGameModeInit()
  33. {
  34. SetGameModeText("Objects Physics - Pool Demo");
  35. AddPlayerClass(0, 2442.1621,2059.5051,10.8203, 269.1425, 0, 0, 0, 0, 0, 0);
  36.  
  37. LoadPool();
  38.  
  39. return 1;
  40. }
  41.  
  42. public OnGameModeExit()
  43. {
  44. return 1;
  45. }
  46.  
  47. public OnPlayerRequestClass(playerid, classid)
  48. {
  49. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  50. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  51. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  52. return 1;
  53. }
  54.  
  55. command(play, playerid, params[])
  56. {
  57. if(!PlayingPool[playerid])
  58. {
  59. PlayingPool[playerid] = 1;
  60. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  61. GivePlayerWeapon(playerid, 7, 1);
  62. PoolScore[playerid] = 0;
  63. if(!PoolStarted)
  64. {
  65. PoolStarted = 1;
  66. RespawnPoolBalls(1);
  67. }
  68. }
  69. else
  70. {
  71. if(PoolAimer != playerid)
  72. {
  73. PlayingPool[playerid] = 0;
  74. new
  75. count = GetPoolPlayersCount();
  76. if(count <= 0)
  77. {
  78. PoolStarted = 0;
  79. RespawnPoolBalls();
  80. }
  81. }
  82. }
  83. return 1;
  84. }
  85.  
  86. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  87. {
  88. if(PoolStarted && PlayingPool[playerid])
  89. {
  90. if (IsKeyJustUp(KEY_SECONDARY_ATTACK, newkeys, oldkeys))
  91. {
  92. if(PlayingPool[playerid] && PoolAimer != playerid && !UsingChalk[playerid])
  93. {
  94. SetTimerEx("PlayPoolSound", 1400, 0, "d", 31807);
  95. SetPlayerArmedWeapon(playerid, 0);
  96. SetPlayerAttachedObject(playerid, OBJ_SLOT_POOL, 338, 6, 0, 0.07, -0.85, 0, 0, 0);
  97. ApplyAnimation(playerid, "POOL", "POOL_ChalkCue",3.0,0,0,0,0,0,1);
  98. UsingChalk[playerid] = 1;
  99. SetTimerEx("RestoreWeapon", 3500, 0, "d", playerid);
  100. }
  101. }
  102. if (IsKeyJustUp(KEY_JUMP, newkeys, oldkeys))
  103. {
  104. if(PoolAimer == playerid)
  105. {
  106. if(PoolCamera[playerid] < 2) PoolCamera[playerid]++;
  107. else PoolCamera[playerid] = 0;
  108. new
  109. Float:poolrot = AimAngle[playerid][0],
  110. Float:Xa,
  111. Float:Ya,
  112. Float:Za,
  113. Float:x,
  114. Float:y;
  115. GetObjectPos(PoolBall[0][bObject], Xa, Ya, Za);
  116. switch(PoolCamera[playerid])
  117. {
  118. case 0:
  119. {
  120. GetXYBehindObjectInAngle(PoolBall[0][bObject], poolrot, x, y, 0.675);
  121. SetPlayerCameraPos(playerid, x, y, 998.86785888672+0.28);
  122. SetPlayerCameraLookAt(playerid, Xa, Ya, Za+0.170);
  123. }
  124. case 1:
  125. {
  126. SetPlayerCameraPos(playerid, 511.84469604492, -84.831642150879, 1001.4904174805);
  127. SetPlayerCameraLookAt(playerid,510.11267089844, -84.831642150879, 998.86785888672);
  128. }
  129. case 2:
  130. {
  131. SetPlayerCameraPos(playerid, 508.7971496582, -84.831642150879, 1001.4904174805);
  132. SetPlayerCameraLookAt(playerid,510.11267089844, -84.831642150879, 998.86785888672);
  133. }
  134. }
  135. }
  136. }
  137. if (IsKeyJustUp(KEY_HANDBRAKE, newkeys, oldkeys))
  138. {
  139. if(AreAllBallsStopped())
  140. {
  141. if(PoolAimer != playerid)
  142. {
  143. if(!UsingChalk[playerid] && PoolAimer == -1 && PoolBall[0][bExisting])
  144. {
  145. new
  146. Float:poolrot,
  147. Float:X,
  148. Float:Y,
  149. Float:Z,
  150. Float:Xa,
  151. Float:Ya,
  152. Float:Za,
  153. Float:x,
  154. Float:y;
  155. GetPlayerPos(playerid, X, Y, Z);
  156. GetObjectPos(PoolBall[0][bObject], Xa, Ya, Za);
  157. if(Is2DPointInRangeOfPoint(X, Y, Xa, Ya, 1.5) && Z < 999.5)
  158. {
  159. TogglePlayerControllable(playerid, 0);
  160. GetAngleToXY(Xa, Ya, X, Y, poolrot);
  161. SetPlayerFacingAngle(playerid, poolrot);
  162. AimAngle[playerid][0] = poolrot;
  163. AimAngle[playerid][1] = poolrot;
  164. SetPlayerArmedWeapon(playerid, 0);
  165. GetXYInFrontOfPos(Xa, Ya, poolrot+180, x, y, 0.085);
  166. AimObject = CreateObject(3004, x, y, Za, 7.0, 0, poolrot+180);
  167. switch(PoolCamera[playerid])
  168. {
  169. case 0:
  170. {
  171. GetXYBehindObjectInAngle(PoolBall[0][bObject], poolrot, x, y, 0.675);
  172. SetPlayerCameraPos(playerid, x, y, 998.86785888672+0.28);
  173. SetPlayerCameraLookAt(playerid, Xa, Ya, Za+0.170);
  174. }
  175. case 1:
  176. {
  177. SetPlayerCameraPos(playerid, 511.84469604492, -84.831642150879, 1001.4904174805);
  178. SetPlayerCameraLookAt(playerid,510.11267089844, -84.831642150879, 998.86785888672);
  179. }
  180. case 2:
  181. {
  182. SetPlayerCameraPos(playerid, 508.7971496582, -84.831642150879, 1001.4904174805);
  183. SetPlayerCameraLookAt(playerid,510.11267089844, -84.831642150879, 998.86785888672);
  184. }
  185. }
  186. ApplyAnimation(playerid, "POOL", "POOL_Med_Start",50.0,0,0,0,1,1,1);
  187. PoolAimer = playerid;
  188. TextDrawShowForPlayer(playerid, PoolTD[0]);
  189. TextDrawShowForPlayer(playerid, PoolTD[1]);
  190. TextDrawTextSize(PoolTD[2], 501.0, 0.0);
  191. TextDrawShowForPlayer(playerid, PoolTD[2]);
  192. TextDrawShowForPlayer(playerid, PoolTD[3]);
  193. PoolPower = 1.0;
  194. PoolDir = 0;
  195. }
  196. }
  197. }
  198. else
  199. {
  200. TogglePlayerControllable(playerid, 1);
  201. GivePlayerWeapon(playerid, 7, 1);
  202. ApplyAnimation(playerid, "CARRY", "crry_prtial", 1.0, 0, 0, 0, 0, 0, 1);
  203. SetCameraBehindPlayer(playerid);
  204. PoolAimer = -1;
  205. DestroyObject(AimObject);
  206. TextDrawHideForPlayer(playerid, PoolTD[0]);
  207. TextDrawHideForPlayer(playerid, PoolTD[1]);
  208. TextDrawHideForPlayer(playerid, PoolTD[2]);
  209. TextDrawHideForPlayer(playerid, PoolTD[3]);
  210. }
  211. }
  212. }
  213. if (IsKeyJustUp(KEY_FIRE, newkeys, oldkeys))
  214. {
  215. if(PoolAimer == playerid)
  216. {
  217. new
  218. Float:speed;
  219. ApplyAnimation(playerid, "POOL", "POOL_Med_Shot",3.0,0,0,0,0,0,1);
  220. speed = 0.4 + (PoolPower * 2.0) / 100.0;
  221. PHY_SetObjectVelocity(PoolBall[0][bObject], speed * floatsin(-AimAngle[playerid][0], degrees), speed * floatcos(-AimAngle[playerid][0], degrees));
  222. if(PoolCamera[playerid] == 0)
  223. {
  224. switch(random(2))
  225. {
  226. case 0: SetPlayerCameraPos(playerid, 511.84469604492, -84.831642150879, 1001.4904174805);
  227. case 1: SetPlayerCameraPos(playerid, 508.7971496582, -84.831642150879, 1001.4904174805);
  228. }
  229. SetPlayerCameraLookAt(playerid,510.11267089844, -84.831642150879, 998.86785888672);
  230. }
  231. PlayPoolSound(31810);
  232. PoolAimer = -1;
  233. DestroyObject(AimObject);
  234. GivePlayerWeapon(playerid, 7, 1);
  235. PoolLastShooter = playerid;
  236. PoolLastScore = 0;
  237. TextDrawHideForPlayer(playerid, PoolTD[0]);
  238. TextDrawHideForPlayer(playerid, PoolTD[1]);
  239. TextDrawHideForPlayer(playerid, PoolTD[2]);
  240. TextDrawHideForPlayer(playerid, PoolTD[3]);
  241. }
  242. }
  243. }
  244. return 1;
  245. }
  246.  
  247. public PHY_OnObjectUpdate(objectid)
  248. {
  249. if(PoolStarted)
  250. {
  251. for(new i; i < sizeof PoolBall; i++)
  252. {
  253. if(objectid == PoolBall[i][bObject] && PHY_IsObjectMoving(PoolBall[i][bObject]))
  254. {
  255. new
  256. hole = IsBallInHole(i);
  257. if(hole)
  258. {
  259. new
  260. Float:speed,
  261. Float:vx, Float:vy, Float:vz;
  262. PHY_GetObjectVelocity(PoolBall[i][bObject], vx, vy, vz);
  263. speed = floatsqroot(vx * vx + vy * vy) + 0.2;
  264.  
  265. PoolBall[i][bExisting] = 0;
  266. PHY_DeleteObject(PoolBall[i][bObject]);
  267.  
  268. PlayPoolSound(31803 + random(3));
  269.  
  270. switch(hole)
  271. {
  272. case 1: MoveObject(PoolBall[i][bObject], 509.61123657,-85.79737091,998.86785889-0.25, speed);
  273. case 2: MoveObject(PoolBall[i][bObject], 510.67373657,-84.84423065,998.86785889-0.25, speed);
  274. case 3: MoveObject(PoolBall[i][bObject], 510.61914062,-83.88769531,998.86785889-0.25, speed);
  275. case 4: MoveObject(PoolBall[i][bObject], 509.61077881,-83.89227295,998.86785889-0.25, speed);
  276. case 5: MoveObject(PoolBall[i][bObject], 510.61825562,-85.80107880,998.86785889-0.25, speed);
  277. case 6: MoveObject(PoolBall[i][bObject], 509.55642700,-84.84602356,998.86785889-0.25, speed);
  278. }
  279. if(i)
  280. {
  281. PoolScore[PoolLastShooter] ++;
  282. PoolLastScore ++;
  283. new string[128];
  284. if(PoolLastScore > 0) format(string, 128, "~g~~h~+%d", PoolLastScore);
  285. else format(string, 128, "~r~~h~%d", PoolLastScore);
  286. GameTextForPlayer(PoolLastShooter, string, 100000, 4);
  287. PlayerPlaySound(PoolLastShooter, 1250, 0.0, 0.0, 0.0);
  288. }
  289. else
  290. {
  291. PoolScore[PoolLastShooter] --;
  292. PoolLastScore --;
  293. new string[128];
  294. if(PoolLastScore > 0) format(string, 128, "~g~~h~+~r~~h~%d", PoolLastScore);
  295. else format(string, 128, "~r~~h~%d", PoolLastScore);
  296. GameTextForPlayer(PoolLastShooter, string, 100000, 4);
  297. PlayerPlaySound(PoolLastShooter, 1250, 0.0, 0.0, 0.0);
  298. }
  299. if(GetPoolBallsCount() <= 1)
  300. {
  301. PoolStarted = 0;
  302. PoolAimer = -1;
  303. new
  304. winscore = GetMaxPoolScore(),
  305. name[MAX_PLAYER_NAME];
  306. RespawnPoolBalls();
  307. RestoreCamera(PoolLastShooter);
  308. PoolLastShooter = -1;
  309. foreach (new p : Player)
  310. {
  311. if(PlayingPool[p] && PoolScore[p] == winscore)
  312. {
  313. new
  314. string[128];
  315. GetPlayerName(p, name, sizeof name);
  316. format(string, 128, "{FFFF45}The winner is: {EBEBEB}%s {FFFF45}with {EBEBEB}%d {FFFF45}points.", name, winscore);
  317. SendPoolPlayersMessage(string);
  318. }
  319. }
  320. foreach (new p : Player)
  321. {
  322. if(PlayingPool[p])
  323. {
  324. PlayingPool[p] = 0;
  325. }
  326. }
  327. }
  328. else if(AreAllBallsStopped())
  329. {
  330. SetTimerEx("RestoreCamera", 800, 0, "d", PoolLastShooter);
  331. PoolLastShooter = -1;
  332. }
  333. }
  334. return 1;
  335. }
  336. }
  337. }
  338. return 1;
  339. }
  340.  
  341. public PHY_OnObjectCollideWithObject(object1, object2)
  342. {
  343. if(PoolStarted)
  344. {
  345. for(new i; i < sizeof PoolBall; i++)
  346. {
  347. if(object1 == PoolBall[i][bObject])
  348. {
  349. PlayPoolSound(31800 + random(3));
  350. return 1;
  351. }
  352. }
  353. }
  354. return 1;
  355. }
  356.  
  357. public PHY_OnObjectCollideWithWall(objectid, wallid)
  358. {
  359. if(PoolStarted)
  360. {
  361. for(new i; i < sizeof PoolBall; i++)
  362. {
  363. if(objectid == PoolBall[i][bObject])
  364. {
  365. PlayPoolSound(31808);
  366. return 1;
  367. }
  368. }
  369. }
  370. return 1;
  371. }
  372.  
  373. public OnPlayerDisconnect(playerid, reason)
  374. {
  375. if(PoolAimer == playerid)
  376. {
  377. PoolAimer = -1;
  378. TextDrawHideForPlayer(playerid, PoolTD[0]);
  379. TextDrawHideForPlayer(playerid, PoolTD[1]);
  380. TextDrawHideForPlayer(playerid, PoolTD[2]);
  381. TextDrawHideForPlayer(playerid, PoolTD[3]);
  382. DestroyObject(AimObject);
  383. }
  384. if(PlayingPool[playerid])
  385. {
  386. PlayingPool[playerid] = 0;
  387. new
  388. count = GetPoolPlayersCount();
  389. if(count <= 0)
  390. {
  391. PoolStarted = 0;
  392. RespawnPoolBalls();
  393. }
  394. }
  395. return 1;
  396. }
  397.  
  398. public OnPlayerDeath(playerid, killerid, reason)
  399. {
  400. if(PoolAimer == playerid)
  401. {
  402. PoolAimer = -1;
  403. TextDrawHideForPlayer(playerid, PoolTD[0]);
  404. TextDrawHideForPlayer(playerid, PoolTD[1]);
  405. TextDrawHideForPlayer(playerid, PoolTD[2]);
  406. TextDrawHideForPlayer(playerid, PoolTD[3]);
  407. DestroyObject(AimObject);
  408. }
  409. if(PlayingPool[playerid])
  410. {
  411. PlayingPool[playerid] = 0;
  412. new
  413. count = GetPoolPlayersCount();
  414. if(count <= 0)
  415. {
  416. PoolStarted = 0;
  417. RespawnPoolBalls();
  418. }
  419. }
  420. return 1;
  421. }
  422.  
  423. public OnPlayerSpawn(playerid)
  424. {
  425. PreloadAnimLib(playerid, "POOL");
  426.  
  427. if(PoolAimer == playerid)
  428. {
  429. PoolAimer = -1;
  430. TextDrawHideForPlayer(playerid, PoolTD[0]);
  431. TextDrawHideForPlayer(playerid, PoolTD[1]);
  432. TextDrawHideForPlayer(playerid, PoolTD[2]);
  433. TextDrawHideForPlayer(playerid, PoolTD[3]);
  434. DestroyObject(AimObject);
  435. }
  436. if(PlayingPool[playerid])
  437. {
  438. PlayingPool[playerid] = 0;
  439. new
  440. count = GetPoolPlayersCount();
  441. if(count <= 0)
  442. {
  443. PoolStarted = 0;
  444. RespawnPoolBalls();
  445. }
  446. }
  447. return 1;
  448. }
  449.  
  450. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  451. {
  452. if(PlayingPool[playerid])
  453. {
  454. PlayingPool[playerid] = 0;
  455. new
  456. count = GetPoolPlayersCount();
  457. if(count <= 0)
  458. {
  459. PoolStarted = 0;
  460. RespawnPoolBalls();
  461. }
  462. }
  463. return 1;
  464. }
  465.  
  466. Float:GetPointDistanceToPoint(Float:x1,Float:y1,Float:x2,Float:y2)
  467. {
  468. new Float:x, Float:y;
  469. x = x1-x2;
  470. y = y1-y2;
  471. return floatsqroot(x*x+y*y);
  472. }
  473.  
  474.  
  475. stock GetAngleToXY(Float:X, Float:Y, Float:CurrX, Float:CurrY, &Float:angle)
  476. {
  477. angle = atan2(Y-CurrY, X-CurrX);
  478. angle = floatsub(angle, 90.0);
  479. if(angle < 0.0) angle = floatadd(angle, 360.0);
  480. }
  481.  
  482.  
  483. stock GetXYInFrontOfPos(Float:xx,Float:yy,Float:a, &Float:x2, &Float:y2, Float:distance)
  484. {
  485. if(a>360)
  486. {
  487. a=a-360;
  488. }
  489. xx += (distance * floatsin(-a, degrees));
  490. yy += (distance * floatcos(-a, degrees));
  491. x2=xx;
  492. y2=yy;
  493. }
  494.  
  495. stock IsPointFacingPoint(Float:dOffset, Float:X, Float:Y, Float:pA, Float:pX, Float:pY)
  496. {
  497. new
  498. Float:ang;
  499.  
  500. if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
  501. else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
  502. else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
  503.  
  504. if(AngleInRangeOfAngle(-ang, pA, dOffset)) return true;
  505.  
  506. return false;
  507.  
  508. }
  509.  
  510. stock Is2DPointInRangeOfPoint(Float:x, Float:y, Float:x2, Float:y2, Float:range)
  511. {
  512. x2 -= x;
  513. y2 -= y;
  514. return ((x2 * x2) + (y2 * y2)) < (range * range);
  515. }
  516.  
  517. stock IsObjectInSphere(objectid,Float:x,Float:y,Float:z,Float:radius2)
  518. {
  519. new Float:x1,Float:y1,Float:z1,Float:tmpdis;
  520. GetObjectPos(objectid,x1,y1,z1);
  521. tmpdis = floatsqroot(floatpower(floatabs(floatsub(x,x1)),2)+ floatpower(floatabs(floatsub(y,y1)),2)+ floatpower(floatabs(floatsub(z,z1)),2));
  522. if(tmpdis < radius2) return 1;
  523. return 0;
  524. }
  525.  
  526. GetBallModel(i)
  527. {
  528. switch(i)
  529. {
  530. case 0: return 3003;
  531. case 1: return 3002;
  532. case 2: return 3001;
  533. case 3: return 2995;
  534. case 4: return 2996;
  535. case 5: return 3106;
  536. case 6: return 3105;
  537. case 7: return 3103;
  538. case 8: return 3001;
  539. case 9: return 3100;
  540. case 10: return 2997;
  541. case 11: return 3000;
  542. case 12: return 3102;
  543. case 13: return 2999;
  544. case 14: return 2998;
  545. case 15: return 3104;
  546. }
  547. return 0;
  548. }
  549.  
  550. stock GetPoolBallsCount()
  551. {
  552. new
  553. count;
  554. for(new i; i < 16; i++)
  555. {
  556. if(PoolBall[i][bExisting] || i == 0) count++;
  557. }
  558. return count;
  559. }
  560.  
  561.  
  562. stock GetMaxPoolScore()
  563. {
  564. new
  565. scoremax = -1;
  566. foreach (new i : Player)
  567. {
  568. if(PlayingPool[i])
  569. {
  570. if(PoolScore[i] > scoremax)
  571. {
  572. scoremax = PoolScore[i];
  573. }
  574. }
  575. }
  576. return scoremax;
  577. }
  578.  
  579. stock SendPoolPlayersMessage(string[])
  580. {
  581. foreach (new i : Player)
  582. {
  583. if(PlayingPool[i])
  584. {
  585. SendClientMessage(i, -1, string);
  586. }
  587. }
  588. }
  589.  
  590. stock AreAllBallsStopped()
  591. {
  592. new
  593. Float:x, Float:y, Float:z;
  594. for(new i; i < 16; i++)
  595. {
  596. if(PoolBall[i][bExisting])
  597. {
  598. PHY_GetObjectVelocity(PoolBall[i][bObject], x, y, z);
  599. if(x != 0.0 || y != 0.0)
  600. return 0;
  601. }
  602. }
  603. return 1;
  604. }
  605.  
  606. stock RespawnPoolBalls(init = 0)
  607. {
  608. for(new i; i < 16; i++)
  609. {
  610. /*PoolBall[i][bMoving] = 0;
  611. PoolBall[i][bSpeed] = 0;*/
  612. //StopObject(PoolBall[i][bObject]);
  613. DestroyObject(PoolBall[i][bObject]);
  614. if(PoolBall[i][bExisting])
  615. {
  616. PHY_DeleteObject(PoolBall[i][bObject]);
  617. PoolBall[i][bExisting] = 0;
  618. }
  619. }
  620.  
  621. if(PoolAimer != -1)
  622. {
  623. TogglePlayerControllable(PoolAimer, 1);
  624. ClearAnimations(PoolAimer);
  625. ApplyAnimation(PoolAimer, "CARRY", "crry_prtial", 1.0, 0, 0, 0, 0, 0);
  626. SetCameraBehindPlayer(PoolAimer);
  627. PoolAimer = -1;
  628. DestroyObject(AimObject);
  629. TextDrawHideForPlayer(PoolAimer, PoolTD[0]);
  630. TextDrawHideForPlayer(PoolAimer, PoolTD[1]);
  631. TextDrawHideForPlayer(PoolAimer, PoolTD[2]);
  632. TextDrawHideForPlayer(PoolAimer, PoolTD[3]);
  633. }
  634.  
  635. CreateBalls();
  636. if(init)
  637. {
  638. for(new i; i < sizeof PoolBall; i++)
  639. InitBall(i);
  640. }
  641. }
  642.  
  643. stock CreateBalls()
  644. {
  645. PoolBall[0][bObject] = CreateObject(3003, 510.11218261719, -84.40771484375, 998.86785888672, 0, 0, 0);
  646. PoolBall[1][bObject] = CreateObject(3002, 510.10882568359, -85.166389465332, 998.86749267578, 0, 0, 0);
  647. PoolBall[2][bObject] = CreateObject(3101, 510.14270019531, -85.232612609863, 998.86749267578, 0, 0, 0);
  648. PoolBall[3][bObject] = CreateObject(2995, 510.0676574707, -85.232200622559, 998.86749267578, 0, 0, 0);
  649. PoolBall[4][bObject] = CreateObject(2996, 510.18600463867, -85.295257568359, 998.86749267578, 0, 0, 0);
  650. PoolBall[5][bObject] = CreateObject(3106, 510.11242675781, -85.297294616699, 998.86749267578, 0, 0, 0);
  651. PoolBall[6][bObject] = CreateObject(3105, 510.03665161133, -85.299163818359, 998.86749267578, 0, 0, 0);
  652. PoolBall[7][bObject] = CreateObject(3103, 510.22308349609, -85.362342834473, 998.86749267578, 0, 0, 0);
  653. PoolBall[8][bObject] = CreateObject(3001, 510.14828491211, -85.365989685059, 998.86749267578, 0, 0, 0);
  654. PoolBall[9][bObject] = CreateObject(3100, 510.07455444336, -85.365234375, 998.86749267578, 0, 0, 0);
  655. PoolBall[10][bObject] = CreateObject(2997, 510.00054931641, -85.363563537598, 998.86749267578, 0, 0, 0);
  656. PoolBall[11][bObject] = CreateObject(3000, 510.25915527344, -85.431137084961, 998.86749267578, 0, 0, 0);
  657. PoolBall[12][bObject] = CreateObject(3102, 510.18399047852, -85.430549621582, 998.86749267578, 0, 0, 0);
  658. PoolBall[13][bObject] = CreateObject(2999, 510.10900878906, -85.43196105957, 998.86749267578, 0, 0, 0);
  659. PoolBall[14][bObject] = CreateObject(2998, 510.03570556641, -85.432624816895, 998.86749267578, 0, 0, 0);
  660. PoolBall[15][bObject] = CreateObject(3104, 509.96197509766, -85.427406311035, 998.86749267578, 0, 0, 0);
  661. }
  662.  
  663. stock InitBall(i)
  664. {
  665. PHY_InitObject(PoolBall[i][bObject], 3003, _, _, PHY_MODE_2D);
  666. PHY_SetObjectFriction(PoolBall[i][bObject], 0.40);
  667. PHY_RollObject(PoolBall[i][bObject], _, PHY_ROLLING_MODE_ADVANCED);
  668. PHY_SetObjectWorld(PoolBall[i][bObject], 3);
  669. PoolBall[i][bExisting] = 1;
  670. }
  671.  
  672. stock LoadPool()
  673. {
  674. CreateBalls();
  675.  
  676. SetTimer("PoolTimer", 21, 1);
  677.  
  678. PHY_SetWallWorld(PHY_CreateWall(509.627 - 0.038, -85.780 - 0.038, 510.598 + 0.038, -85.780 - 0.038), 3);
  679. PHY_SetWallWorld(PHY_CreateWall(510.598 + 0.038, -85.780 - 0.038, 510.598 + 0.038, -83.907 + 0.038), 3);
  680. PHY_SetWallWorld(PHY_CreateWall(510.598 + 0.038, -83.907 + 0.038, 509.627 - 0.038, -83.907 + 0.038), 3);
  681. PHY_SetWallWorld(PHY_CreateWall(509.627 - 0.038, -83.907 + 0.038, 509.627 - 0.038, -85.780 - 0.038), 3);
  682.  
  683.  
  684. PoolTD[0] = TextDrawCreate(505.000000, 260.000000, "~n~~n~");
  685. TextDrawBackgroundColor(PoolTD[0], 255);
  686. TextDrawFont(PoolTD[0], 1);
  687. TextDrawLetterSize(PoolTD[0], 0.500000, 0.439999);
  688. TextDrawColor(PoolTD[0], -1);
  689. TextDrawSetOutline(PoolTD[0], 0);
  690. TextDrawSetProportional(PoolTD[0], 1);
  691. TextDrawSetShadow(PoolTD[0], 1);
  692. TextDrawUseBox(PoolTD[0], 1);
  693. TextDrawBoxColor(PoolTD[0], 255);
  694. TextDrawTextSize(PoolTD[0], 569.000000, -10.000000);
  695.  
  696. PoolTD[1] = TextDrawCreate(506.000000, 261.000000, "~n~~n~");
  697. TextDrawBackgroundColor(PoolTD[1], 255);
  698. TextDrawFont(PoolTD[1], 1);
  699. TextDrawLetterSize(PoolTD[1], 0.500000, 0.300000);
  700. TextDrawColor(PoolTD[1], -1);
  701. TextDrawSetOutline(PoolTD[1], 0);
  702. TextDrawSetProportional(PoolTD[1], 1);
  703. TextDrawSetShadow(PoolTD[1], 1);
  704. TextDrawUseBox(PoolTD[1], 1);
  705. TextDrawBoxColor(PoolTD[1], 911303167);
  706. TextDrawTextSize(PoolTD[1], 568.000000, 0.000000);
  707.  
  708. PoolTD[2] = TextDrawCreate(506.000000, 261.000000, "~n~~n~");
  709. TextDrawBackgroundColor(PoolTD[2], 255);
  710. TextDrawFont(PoolTD[2], 1);
  711. TextDrawLetterSize(PoolTD[2], 0.500000, 0.300000);
  712. TextDrawColor(PoolTD[2], -1);
  713. TextDrawSetOutline(PoolTD[2], 0);
  714. TextDrawSetProportional(PoolTD[2], 1);
  715. TextDrawSetShadow(PoolTD[2], 1);
  716. TextDrawUseBox(PoolTD[2], 1);
  717. TextDrawBoxColor(PoolTD[2], -1949699841);
  718. TextDrawTextSize(PoolTD[2], 501.000000, 0.000000);
  719.  
  720. PoolTD[3] = TextDrawCreate(503.000000, 240.000000, "Power");
  721. TextDrawBackgroundColor(PoolTD[3], 255);
  722. TextDrawFont(PoolTD[3], 2);
  723. TextDrawLetterSize(PoolTD[3], 0.280000, 1.699999);
  724. TextDrawColor(PoolTD[3], -1);
  725. TextDrawSetOutline(PoolTD[3], 1);
  726. TextDrawSetProportional(PoolTD[3], 1);
  727. }
  728.  
  729. stock GetPoolPlayersCount()
  730. {
  731. new
  732. count;
  733. if(PoolStarted)
  734. {
  735. foreach (new i : Player)
  736. {
  737. if(PlayingPool[i])
  738. {
  739. count++;
  740. }
  741. }
  742. }
  743. return count;
  744. }
  745.  
  746. forward PoolTimer();
  747. public PoolTimer()
  748. {
  749. if(!PoolStarted) return 0;
  750. if(PoolAimer != -1)
  751. {
  752. new
  753. playerid = PoolAimer,
  754. keys,
  755. ud,
  756. lr;
  757. GetPlayerKeys(playerid, keys, ud, lr);
  758. if(!(keys & KEY_FIRE))
  759. {
  760. if(lr)
  761. {
  762. new
  763. Float:X,
  764. Float:Y,
  765. Float:Z,
  766. Float:Xa,
  767. Float:Ya,
  768. Float:Za,
  769. Float:x,
  770. Float:y,
  771. Float:newrot,
  772. Float:dist;
  773. GetPlayerPos(playerid, X, Y ,Z);
  774. GetObjectPos(PoolBall[0][bObject], Xa, Ya, Za);
  775. newrot = AimAngle[playerid][0] + (lr > 0 ? 0.9 : -0.9);
  776. dist = GetPointDistanceToPoint(X, Y, Xa, Ya);
  777. if(AngleInRangeOfAngle(AimAngle[playerid][1], newrot, 30.0))
  778. {
  779. AimAngle[playerid][0] = newrot;
  780. switch(PoolCamera[playerid])
  781. {
  782. case 0:
  783. {
  784. GetXYBehindObjectInAngle(PoolBall[0][bObject], newrot, x, y, 0.675);
  785. SetPlayerCameraPos(playerid, x, y, 998.86785888672+0.28);
  786. SetPlayerCameraLookAt(playerid, Xa, Ya, Za+0.170);
  787. }
  788. case 1:
  789. {
  790. SetPlayerCameraPos(playerid, 511.84469604492, -84.831642150879, 1001.4904174805);
  791. SetPlayerCameraLookAt(playerid,510.11267089844, -84.831642150879, 998.86785888672);
  792. }
  793. case 2:
  794. {
  795. SetPlayerCameraPos(playerid, 508.7971496582, -84.831642150879, 1001.4904174805);
  796. SetPlayerCameraLookAt(playerid,510.11267089844, -84.831642150879, 998.86785888672);
  797. }
  798. }
  799. GetXYInFrontOfPos(Xa, Ya, newrot+180, x, y, 0.085);
  800. SetObjectPos(AimObject, x, y, Za);
  801. SetObjectRot(AimObject, 7.0, 0, AimAngle[playerid][0]+180);
  802. GetXYInFrontOfPos(Xa, Ya, newrot+180, X, Y, dist);
  803. SetPlayerPos(playerid, X, Y, Z);
  804. SetPlayerFacingAngle(playerid, newrot);
  805. }
  806. }
  807. }
  808. else
  809. {
  810. if(PoolDir)
  811. PoolPower -= 2.0;
  812. else
  813. PoolPower += 2.0;
  814. if(PoolPower <= 0)
  815. {
  816. PoolDir = 0;
  817. PoolPower = 2.0;
  818. }
  819. else if(PoolPower > 100.0)
  820. {
  821. PoolDir = 1;
  822. PoolPower = 98.0;
  823. }
  824. TextDrawTextSize(PoolTD[2], 501.0 + ((67.0 * PoolPower)/100.0), 0.0);
  825. TextDrawShowForPlayer(playerid, PoolTD[2]);
  826. }
  827. }
  828.  
  829. if(PoolLastShooter != -1 && AreAllBallsStopped())
  830. {
  831. SetTimerEx("RestoreCamera", 800, 0, "d", PoolLastShooter);
  832. PoolLastShooter = -1;
  833. }
  834. return 1;
  835. }
  836.  
  837. forward RestoreCamera(playerid);
  838. public RestoreCamera(playerid)
  839. {
  840. if(!PoolBall[0][bExisting])
  841. {
  842. DestroyObject(PoolBall[0][bObject]);
  843. PoolBall[0][bObject] = CreateObject(GetBallModel(0) ,510.11218261719, -84.40771484375, 998.86785888672, 0, 0, 0);
  844. InitBall(0);
  845. }
  846. GameTextForPlayer(playerid, " ", 100000, 4);
  847. if(PoolAimer == playerid) return 0;
  848. TogglePlayerControllable(playerid, 1);
  849. return SetCameraBehindPlayer(playerid);
  850. }
  851.  
  852. forward RestoreWeapon(playerid);
  853. public RestoreWeapon(playerid)
  854. {
  855. RemovePlayerAttachedObject(playerid, OBJ_SLOT_POOL);
  856. UsingChalk[playerid] = 0;
  857. GivePlayerWeapon(playerid, 7, 1);
  858. ApplyAnimation(playerid, "CARRY", "crry_prtial", 1.0, 0, 0, 0, 0, 0, 1);
  859. return 1;
  860. }
  861.  
  862. stock IsBallInHole(i)
  863. {
  864. if(IsObjectInSphere(PoolBall[i][bObject],509.61123657,-85.79737091,998.86785889,0.0825)) return 1;
  865. else if(IsObjectInSphere(PoolBall[i][bObject],510.67373657,-84.84423065,998.86785889,0.0825)) return 2;
  866. else if(IsObjectInSphere(PoolBall[i][bObject],510.61914062,-83.88769531,998.86785889,0.0825)) return 3;
  867. else if(IsObjectInSphere(PoolBall[i][bObject],509.61077881,-83.89227295,998.86785889,0.0825)) return 4;
  868. else if(IsObjectInSphere(PoolBall[i][bObject],510.61825562,-85.80107880,998.86785889,0.0825)) return 5;
  869. else if(IsObjectInSphere(PoolBall[i][bObject],509.55642700,-84.84602356,998.86785889,0.0825)) return 6;
  870. else return 0;
  871. }
  872.  
  873. stock GetXYBehindObjectInAngle(objectid, Float:a, &Float:x2, &Float:y2, Float:distance)
  874. {
  875. new Float:z;
  876. GetObjectPos(objectid, x2, y2, z);
  877.  
  878. x2 += (distance * floatsin(-a+180, degrees));
  879. y2 += (distance * floatcos(-a+180, degrees));
  880. }
  881.  
  882. forward PlayPoolSound(soundid);
  883. public PlayPoolSound(soundid)
  884. {
  885. foreach(new i : Player)
  886. {
  887. if(PlayingPool[i])
  888. {
  889. PlayerPlaySound(i, soundid, 0, 0, 0);
  890. }
  891. }
  892. return 1;
  893. }
  894.  
  895. stock IsKeyJustDown(key, newkeys, oldkeys)
  896. {
  897. if((newkeys & key) && !(oldkeys & key)) return 1;
  898. return 0;
  899. }
  900.  
  901. stock IsKeyJustUp(key, newkeys, oldkeys)
  902. {
  903. if(!(newkeys & key) && (oldkeys & key)) return 1;
  904. return 0;
  905. }
  906.  
  907. stock PreloadAnimLib(playerid, animlib[])
  908. {
  909. ApplyAnimation(playerid,animlib,"null",0.0,0,0,0,0,0);
  910. }
  911.  
  912. stock AngleInRangeOfAngle(Float:a1, Float:a2, Float:range)
  913. {
  914. a1 -= a2;
  915. if((a1 < range) && (a1 > -range)) return true;
  916.  
  917. return false;
  918. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement