Oblivion_UFF

SEF Pool Minigame

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