Oblivion_UFF

Pool Minigame

Oct 13th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.84 KB | None | 0 0
  1. #include <a_samp>
  2. #include <physics>
  3. #include <zcmd>
  4.  
  5. #define MAX_POOL 100
  6.  
  7. new POOL_COUNT = 0;
  8. new InPOOL[MAX_PLAYERS];
  9. new PlayerPoolID[MAX_PLAYERS] = 0;
  10. enum POOL_MODEL
  11. {
  12. ID,
  13. TEXT[100],
  14. Float:POS[3],
  15. TABLE,
  16. Text3D:LABEL,
  17. BALLS[16],
  18. };
  19. new POOL[MAX_POOL][POOL_MODEL];
  20.  
  21.  
  22. public OnFilterScriptExit(){ return 1; }
  23. public OnFilterScriptInit(){
  24.  
  25. print("[Pool System by Victor, SEF]");
  26. return 1;
  27. }
  28. CMD:createpool(playerid) return cmd_pool(playerid);
  29. CMD:pool(playerid)
  30. {
  31. if(InPOOL[playerid] == 1) return SendClientMessage(playerid, -1, "[POOL]: You are already playing pool minigame!");
  32. createPoolTable(playerid);
  33. SendClientMessage(playerid, -1, "[POOL]: Successfully, Pool table created!");
  34. SendClientMessage(playerid, -1, "[POOL]: Use /ppool (/playpool), to play pool!");
  35. SendClientMessage(playerid, -1, "[POOL]: Use /dpool (/deletepool), to destroy pool!");
  36. return 1;
  37. }
  38.  
  39. CMD:playpool(playerid) return cmd_ppool(playerid);
  40. CMD:ppool(playerid)
  41. {
  42. if(InPOOL[playerid] == 0) return SendClientMessage(playerid, -1, "[POOL]: You are not playing pool minigame!");
  43. new
  44. speed = 3,
  45. Float: angle;
  46. for(new i = 0; i < POOL_COUNT; i++)
  47. {
  48. if(POOL[i][ID] == PlayerPoolID[playerid])
  49. {
  50. GetPlayerFacingAngle(playerid, angle);
  51.  
  52. PHY_SetObjectVelocity(POOL[i][BALLS][0], speed * floatsin( -angle, degrees), speed * floatcos( -angle, degrees));
  53. }
  54. }
  55. return 1;
  56. }
  57. CMD:deletepool(playerid) return cmd_dpool(playerid);
  58. CMD:dpool(playerid)
  59. {
  60. if(InPOOL[playerid] == 0) return SendClientMessage(playerid, -1, "[POOL]: You are not playing pool minigame!");
  61. for(new i = 0; i < POOL_COUNT; i++)
  62. {
  63. if(POOL[i][ID] == PlayerPoolID[playerid])
  64. {
  65. DestroyObject(POOL[i][BALLS][0]);
  66. DestroyObject(POOL[i][BALLS][1]);
  67. DestroyObject(POOL[i][BALLS][2]);
  68. DestroyObject(POOL[i][BALLS][3]);
  69. DestroyObject(POOL[i][BALLS][4]);
  70. DestroyObject(POOL[i][BALLS][5]);
  71. DestroyObject(POOL[i][BALLS][6]);
  72. DestroyObject(POOL[i][BALLS][7]);
  73. DestroyObject(POOL[i][BALLS][8]);
  74. DestroyObject(POOL[i][BALLS][9]);
  75. DestroyObject(POOL[i][BALLS][10]);
  76. DestroyObject(POOL[i][BALLS][11]);
  77. DestroyObject(POOL[i][BALLS][12]);
  78. DestroyObject(POOL[i][BALLS][13]);
  79. DestroyObject(POOL[i][BALLS][14]);
  80. DestroyObject(POOL[i][BALLS][15]);
  81. PHY_DeleteObject(POOL[i][BALLS][0]);
  82. PHY_DeleteObject(POOL[i][BALLS][1]);
  83. PHY_DeleteObject(POOL[i][BALLS][2]);
  84. PHY_DeleteObject(POOL[i][BALLS][3]);
  85. PHY_DeleteObject(POOL[i][BALLS][4]);
  86. PHY_DeleteObject(POOL[i][BALLS][5]);
  87. PHY_DeleteObject(POOL[i][BALLS][6]);
  88. PHY_DeleteObject(POOL[i][BALLS][7]);
  89. PHY_DeleteObject(POOL[i][BALLS][8]);
  90. PHY_DeleteObject(POOL[i][BALLS][9]);
  91. PHY_DeleteObject(POOL[i][BALLS][10]);
  92. PHY_DeleteObject(POOL[i][BALLS][11]);
  93. PHY_DeleteObject(POOL[i][BALLS][12]);
  94. PHY_DeleteObject(POOL[i][BALLS][13]);
  95. PHY_DeleteObject(POOL[i][BALLS][14]);
  96. PHY_DeleteObject(POOL[i][BALLS][15]);
  97. Delete3DTextLabel(POOL[i][LABEL]);
  98. DestroyObject(POOL[i][TABLE]);
  99. PHY_DeleteObject(POOL[i][TABLE]);
  100. InPOOL[playerid] = 0;
  101. PlayerPoolID[playerid] = 0;
  102. }
  103. }
  104. return 1;
  105.  
  106. }
  107. public OnPlayerConnect(playerid)
  108. {
  109. InPOOL[playerid] = 0;
  110. return 1;
  111. }
  112.  
  113.  
  114.  
  115. public PHY_OnObjectUpdate(objectid){
  116.  
  117. new
  118. poolid = 0; // setup pool table
  119.  
  120. for(new i = 0; i < GetMaxPlayers(); i++){
  121. if( IsInBall(objectid , POOL[poolid][POS][0] + 0.955, POOL[poolid][POS][1] + 0.510, POOL[poolid][POS][2] -0.045,0.10) ||
  122. IsInBall(objectid , POOL[poolid][POS][0] + 0.955, POOL[poolid][POS][1] - 0.510, POOL[poolid][POS][2] -0.045,0.10) ||
  123. IsInBall(objectid , POOL[poolid][POS][0] + 0.000, POOL[poolid][POS][1] + 0.550, POOL[poolid][POS][2] -0.045,0.10) ||
  124. IsInBall(objectid , POOL[poolid][POS][0] + 0.000, POOL[poolid][POS][1] - 0.550, POOL[poolid][POS][2] -0.045,0.10) ||
  125. IsInBall(objectid , POOL[poolid][POS][0] - 0.955, POOL[poolid][POS][1] + 0.510, POOL[poolid][POS][2] -0.045,0.10) ||
  126. IsInBall(objectid , POOL[poolid][POS][0] - 0.955, POOL[poolid][POS][1] - 0.510, POOL[poolid][POS][2] -0.045,0.10))
  127. {
  128. new
  129. str[50];
  130.  
  131. for(new j = 0; j < 16; j++)
  132. {
  133.  
  134. if(objectid == POOL[poolid][BALLS][j])
  135. {
  136.  
  137. new type[6];
  138.  
  139. if(POOL[poolid][BALLS][j] > 8) format(type ,sizeof(type), "stripe");
  140. else format(type ,sizeof(type), "solid");
  141.  
  142. format(str ,sizeof(str), "delete object id : number %d %s ball", POOL[poolid][BALLS][j], type);
  143. SendClientMessage(i, -1, str);
  144.  
  145. DestroyObject(POOL[poolid][BALLS][j]);
  146. PHY_DeleteObject(POOL[poolid][BALLS][j]);
  147. }
  148.  
  149. }
  150.  
  151. }
  152.  
  153. }
  154.  
  155. return 1;
  156. }
  157.  
  158.  
  159.  
  160. stock createPoolTable(playerid){
  161.  
  162. new Float:pos[3];
  163.  
  164. // table id
  165. POOL[POOL_COUNT][ID] = ( POOL_COUNT + 1);
  166. PlayerPoolID[playerid] = POOL[POOL_COUNT][ID];
  167.  
  168.  
  169. // table position
  170. GetPlayerFrontPos(playerid, pos[0], pos[1], pos[2] , 1.5);
  171. POOL[POOL_COUNT][POS] = pos;
  172.  
  173.  
  174. // balls object array
  175. POOL[POOL_COUNT][BALLS][0] = CreateObject(3003, pos[0] + 0.5, pos[1], pos[2] -0.045 , 0, 0, 0);
  176. POOL[POOL_COUNT][BALLS][1] = CreateObject(3002, pos[0] - 0.3, pos[1], pos[2] -0.045 , 0, 0, 0);
  177. POOL[POOL_COUNT][BALLS][2] = CreateObject(3100, pos[0] - 0.525, pos[1] - 0.040, pos[2] -0.045 , 0, 0, 0);
  178. POOL[POOL_COUNT][BALLS][3] = CreateObject(3101, pos[0] - 0.375, pos[1] + 0.044, pos[2] -0.045 , 0, 0, 0);
  179. POOL[POOL_COUNT][BALLS][4] = CreateObject(3102, pos[0] - 0.600, pos[1] + 0.079, pos[2] -0.045 , 0, 0, 0);
  180. POOL[POOL_COUNT][BALLS][5] = CreateObject(3103, pos[0] - 0.525, pos[1] + 0.118, pos[2] -0.045 , 0, 0, 0);
  181. POOL[POOL_COUNT][BALLS][6] = CreateObject(3104, pos[0] - 0.600, pos[1] - 0.157, pos[2] -0.045 , 0, 0, 0);
  182. POOL[POOL_COUNT][BALLS][7] = CreateObject(3105, pos[0] - 0.450, pos[1] - 0.079, pos[2] -0.045 , 0, 0, 0);
  183. POOL[POOL_COUNT][BALLS][8] = CreateObject(3106, pos[0] - 0.450, pos[1], pos[2] -0.045 , 0, 0, 0);
  184. POOL[POOL_COUNT][BALLS][9] = CreateObject(2995, pos[0] - 0.375, pos[1] - 0.044, pos[2] -0.045 , 0, 0, 0);
  185. POOL[POOL_COUNT][BALLS][10] = CreateObject(2996, pos[0] - 0.450, pos[1] + 0.079, pos[2] -0.045 , 0, 0, 0);
  186. POOL[POOL_COUNT][BALLS][11] = CreateObject(2997, pos[0] - 0.525, pos[1] - 0.118, pos[2] -0.045 , 0, 0, 0);
  187. POOL[POOL_COUNT][BALLS][12] = CreateObject(2998, pos[0] - 0.600, pos[1] - 0.079, pos[2] -0.045 , 0, 0, 0);
  188. POOL[POOL_COUNT][BALLS][13] = CreateObject(2999, pos[0] - 0.600, pos[1], pos[2] -0.045 , 0, 0, 0);
  189. POOL[POOL_COUNT][BALLS][14] = CreateObject(3000, pos[0] - 0.600, pos[1] + 0.157, pos[2] -0.045 , 0, 0, 0);
  190. POOL[POOL_COUNT][BALLS][15] = CreateObject(3001, pos[0] - 0.525, pos[1] + 0.040, pos[2] -0.045 , 0, 0, 0);
  191.  
  192.  
  193. // table object
  194. POOL[POOL_COUNT][TABLE] = CreateObject(2964, pos[0], pos[1], pos[2] -1 , 0, 0, 0);
  195.  
  196.  
  197. // 3d label object
  198. format(POOL[POOL_COUNT][TEXT], 100, "[SEF] POOL TABLE (ID: %d)", PlayerPoolID[playerid]);
  199. POOL[POOL_COUNT][LABEL] = Create3DTextLabel(POOL[POOL_COUNT][TEXT], -1, POOL[POOL_COUNT][POS][0], POOL[POOL_COUNT][POS][1], POOL[POOL_COUNT][POS][2], 10.0, 0, 0);
  200.  
  201.  
  202. // setup physics boundary
  203. PHY_CreateArea( pos[0] - 1.000, pos[1] - 0.500, pos[0] + 1.000, pos[1] + 0.500,0.6,FLOAT_NEG_INFINITY);
  204.  
  205. for(new i = 0; i < 16; i++){
  206.  
  207. // setup physics balls
  208.  
  209. PHY_InitObject( POOL[POOL_COUNT][BALLS][i] , 3003, _, _, PHY_MODE_2D);
  210. PHY_SetObjectFriction( POOL[POOL_COUNT][BALLS][i] , 0.08);
  211. PHY_RollObject( POOL[POOL_COUNT][BALLS][i] ,1);
  212. }
  213.  
  214. // counting table
  215. POOL_COUNT ++;
  216. InPOOL[playerid] =1;
  217. }
  218.  
  219.  
  220.  
  221. stock GetPlayerFrontPos(playerid,&Float:x,&Float:y,&Float:z,Float:distance=0.0){
  222.  
  223. new
  224. Float:px,
  225. Float:py,
  226. Float:pz,
  227. Float:pa;
  228.  
  229. GetPlayerPos(playerid,px,py,pz);
  230. GetPlayerFacingAngle(playerid,pa);
  231.  
  232. x = px+(floatsin(-pa, degrees)*distance);
  233. y = py+(floatcos(-pa, degrees)*distance);
  234.  
  235. z = pz;
  236.  
  237. }
  238.  
  239.  
  240. stock IsInBall(objectid,Float:x,Float:y,Float:z,Float:radius){
  241.  
  242. new
  243. Float:pos[3],
  244. Float:dis;
  245.  
  246. GetObjectPos(objectid, pos[0], pos[1], pos[2]);
  247.  
  248. dis = floatsqroot(floatpower(floatabs(floatsub(x, pos[0] )), 2)+ floatpower(floatabs(floatsub(y, pos[1] )), 2)+ floatpower(floatabs(floatsub(z, pos[2] )), 2));
  249.  
  250. if(dis < radius) return 1;
  251. return 0;
  252. }
Add Comment
Please, Sign In to add comment