HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. A plugin magyarositasat sNaiL vegezte
  3. Latogasd meg: http://psgamers.net
  4. */
  5.  
  6.  
  7. #include <amxmodx>
  8. #include <fakemeta>
  9. #include <fakemeta_stocks>
  10.  
  11. #define PLUGIN "Tetris ASCII newmenus.inc"
  12. #define AUTHOR "Albernaz o Carniceiro Demoniaco"
  13. #define VERSION "1.2"
  14.  
  15. new const DICTIONARY[] = "tetris.txt";
  16.  
  17. const MAX_PLAYERS = 33
  18.  
  19. enum ML_DEFINITION
  20. {
  21. TETRIS_TITLE,
  22. TETRIS_GAME_OVER,
  23. TETRIS_PLAY_AGAIN,
  24. TETRIS_EXIT,
  25. TETRIS_MUSIC_ON,
  26. TETRIS_MUSIC_OFF,
  27. TETRIS_DIFFICULTY_LEVEL,
  28. TETRIS_START_GAME,
  29. TETRIS_DIFFICULTY
  30. }
  31.  
  32. const TETRIS_TITLE_LEN = 20
  33. const TETRIS_GAME_OVER_LEN = 15
  34. const TETRIS_PLAY_AGAIN_LEN = 20
  35. const TETRIS_EXIT_LEN = 15
  36. const TETRIS_MUSIC_LEN = 20
  37. const TETRIS_DIFFICULTY_LEVEL_LEN = 20
  38. const TETRIS_START_GAME_LEN = 15
  39. const TETRIS_DIFFICULTY_LEN = 15
  40.  
  41. new ML_DefinitionsString[ML_DEFINITION][] = {"TETRIS_TITLE","TETRIS_GAME_OVER","TETRIS_PLAY_AGAIN","TETRIS_EXIT","TETRIS_MUSIC_ON","TETRIS_MUSIC_OFF","TETRIS_DIFFICULTY_LEVEL","TETRIS_START_GAME","TETRIS_DIFFICULTY"}
  42.  
  43. enum GAME_STATE
  44. {
  45. START,
  46. IN_GAME,
  47. GAME_OVER
  48. }
  49.  
  50. enum POSITION
  51. {
  52. ROW,
  53. COL
  54. }
  55.  
  56. enum PIECE_NAME
  57. {
  58. I,
  59. J,
  60. L,
  61. O,
  62. S,
  63. T,
  64. Z
  65. }
  66.  
  67. enum TABLE_DIM
  68. {
  69. ROWS,
  70. COLS
  71. }
  72.  
  73. enum CELL_COLOR
  74. {
  75. INACTIVE,
  76. ACTIVE
  77. }
  78.  
  79. enum SOUND
  80. {
  81. SELECTION,
  82. LINE,
  83. FALL,
  84. GAMEOVER
  85. }
  86.  
  87. new Sounds[SOUND][] = { "tetris/selection.wav", "tetris/line.wav" , "tetris/fall.wav", "tetris/gameover.wav"}
  88.  
  89. enum MUSIC
  90. {
  91. MUSIC1,
  92. MUSIC2,
  93. MUSIC3
  94. }
  95.  
  96. new Musics[MUSIC][] = { "tetris/music1.mp3","tetris/music2.mp3","tetris/music3.mp3"}
  97.  
  98. enum DIFFICULTY_LEVEL
  99. {
  100. EASY,
  101. NORMAL,
  102. HARD
  103. }
  104.  
  105. enum CVAR
  106. {
  107. AMBIENT_SOUND
  108. }
  109. new Cvars[CVAR]
  110.  
  111. new Float:difficultyLevelsTaskDelay[DIFFICULTY_LEVEL] = {_:0.3,_:0.25,_:0.2}
  112. new DIFFICULTY_LEVEL:playersDifficultyLevel[MAX_PLAYERS];
  113.  
  114. new cellChar[] = {"O"}
  115. new cellCharColors[CELL_COLOR][] = {"\d","\r"}
  116.  
  117. const PieceSquareMaxWidth = 4;
  118. new const PiecesSquareWidth[PIECE_NAME] = {4,3,3,2,3,3,3}
  119. new Array:PiecesData[PIECE_NAME]
  120.  
  121. const TableRows = 14
  122. const TableCols = 10
  123. new Array:PlayersTables[MAX_PLAYERS]
  124.  
  125. new GAME_STATE:PlayersGameState[MAX_PLAYERS]
  126.  
  127. new GameStatesMenusIDs[GAME_STATE]
  128.  
  129. new Array:PlayersCurrentPieceData[MAX_PLAYERS]
  130. new PIECE_NAME:PlayersCurrentPieceName[MAX_PLAYERS]
  131. new PlayersCurrentPiecePosition[MAX_PLAYERS][POSITION]
  132.  
  133. new Array:PlayersNextPieceData[MAX_PLAYERS]
  134. new PIECE_NAME:PlayersNextPieceName[MAX_PLAYERS]
  135. new PlayersNextPiecePosition[MAX_PLAYERS][POSITION]
  136.  
  137. new bool:PlayersTableCellActive[MAX_PLAYERS]
  138.  
  139. new PlayersTaskID[MAX_PLAYERS]
  140. new Float:PlayersTaskDelay[MAX_PLAYERS]
  141. new PlayersMenuInGame[MAX_PLAYERS]
  142.  
  143. new PlayersButtons = IN_MOVELEFT | IN_MOVERIGHT | IN_FORWARD | IN_BACK;
  144.  
  145. new PlayersPreviousPressedButton[MAX_PLAYERS];
  146. new PlayersIsPlaying[MAX_PLAYERS];
  147.  
  148. new Float:PlayersPreviousMaxspeed[MAX_PLAYERS]
  149.  
  150. new ForwardPlayerPostThink;
  151.  
  152. new playersPlaying
  153.  
  154. new bool:playersMusic[MAX_PLAYERS]
  155.  
  156. public plugin_precache()
  157. {
  158. for(new SOUND:i=SOUND:0;i<SOUND;i++)
  159. precache_sound(Sounds[i])
  160.  
  161. for(new MUSIC:i=MUSIC:0;i<MUSIC;i++)
  162. precache_sound(Musics[i])
  163. }
  164.  
  165. playSound(id,sound[])
  166. {
  167. if(get_pcvar_num(Cvars[AMBIENT_SOUND]))
  168. {
  169. new Float:origin[3]
  170. pev(id,pev_origin,origin)
  171.  
  172. EF_EmitAmbientSound(0,origin,sound,1.0,ATTN_NORM,0,PITCH_NORM);
  173. }
  174. else
  175. {
  176. client_cmd(id,"spk %s",sound);
  177. }
  178. }
  179.  
  180. public plugin_cfg()
  181. {
  182. Cvars[AMBIENT_SOUND] = register_cvar("tetris_ambient_sound", "0");
  183.  
  184. for(new PIECE_NAME:i=I;i<PIECE_NAME;i++)
  185. {
  186. new pieceSquareWidth = PiecesSquareWidth[i];
  187. PiecesData[i] = createBiArray(pieceSquareWidth,pieceSquareWidth);
  188. }
  189.  
  190. setBiArrayCell(Array:PiecesData[I],0,1,true) // O
  191. setBiArrayCell(Array:PiecesData[I],1,1,true) // O
  192. setBiArrayCell(Array:PiecesData[I],2,1,true) // O
  193. setBiArrayCell(Array:PiecesData[I],3,1,true) // O
  194.  
  195. setBiArrayCell(Array:PiecesData[J],0,0,true) // O
  196. setBiArrayCell(Array:PiecesData[J],1,0,true) // OOO
  197. setBiArrayCell(Array:PiecesData[J],1,1,true)
  198. setBiArrayCell(Array:PiecesData[J],1,2,true)
  199.  
  200. setBiArrayCell(Array:PiecesData[J],0,0,true) // O
  201. setBiArrayCell(Array:PiecesData[J],1,0,true) // OOO
  202. setBiArrayCell(Array:PiecesData[J],1,1,true)
  203. setBiArrayCell(Array:PiecesData[J],1,2,true)
  204.  
  205. setBiArrayCell(Array:PiecesData[L],0,2,true) // O
  206. setBiArrayCell(Array:PiecesData[L],1,0,true) // OOO
  207. setBiArrayCell(Array:PiecesData[L],1,1,true)
  208. setBiArrayCell(Array:PiecesData[L],1,2,true)
  209.  
  210. setBiArrayCell(Array:PiecesData[O],0,0,true) // OO
  211. setBiArrayCell(Array:PiecesData[O],0,1,true) // OO
  212. setBiArrayCell(Array:PiecesData[O],1,0,true)
  213. setBiArrayCell(Array:PiecesData[O],1,1,true)
  214.  
  215. setBiArrayCell(Array:PiecesData[S],0,1,true) // OO
  216. setBiArrayCell(Array:PiecesData[S],0,2,true) // OO
  217. setBiArrayCell(Array:PiecesData[S],1,0,true)
  218. setBiArrayCell(Array:PiecesData[S],1,1,true)
  219.  
  220. setBiArrayCell(Array:PiecesData[T],0,1,true) // O
  221. setBiArrayCell(Array:PiecesData[T],1,0,true) // OOO
  222. setBiArrayCell(Array:PiecesData[T],1,1,true)
  223. setBiArrayCell(Array:PiecesData[T],1,2,true)
  224.  
  225. setBiArrayCell(Array:PiecesData[Z],0,0,true) // OO
  226. setBiArrayCell(Array:PiecesData[Z],0,1,true) // OO
  227. setBiArrayCell(Array:PiecesData[Z],1,1,true)
  228. setBiArrayCell(Array:PiecesData[Z],1,2,true)
  229.  
  230. GameStatesMenusIDs[START] = funcidx("menuTetrisStart");
  231. GameStatesMenusIDs[IN_GAME] = funcidx("menuTetrisInGamePre");
  232. GameStatesMenusIDs[GAME_OVER] = funcidx("menuTetrisGameOver");
  233. }
  234.  
  235. public plugin_init()
  236. {
  237. register_plugin(PLUGIN, VERSION, AUTHOR)
  238. register_clcmd("tetris","menuTetris");
  239. register_clcmd("say tetris","menuTetris");
  240. register_cvar("tetrisASCIIVersion",VERSION,FCVAR_SERVER);
  241. register_dictionary(DICTIONARY);
  242. }
  243.  
  244. public playerPostThink(id)
  245. {
  246. if(PlayersIsPlaying[id])
  247. {
  248. new Float:maxspeed
  249.  
  250. pev(id,pev_maxspeed,maxspeed);
  251.  
  252. if((maxspeed != 1.0) && (maxspeed != PlayersPreviousMaxspeed[id]))
  253. {
  254. PlayersPreviousMaxspeed[id] = maxspeed;
  255. }
  256.  
  257. set_pev(id,pev_maxspeed,1.0)
  258.  
  259. new button = pev(id, pev_button)
  260.  
  261. new myButton = button & PlayersButtons;
  262.  
  263. if(myButton)
  264. {
  265. new buttonUnique = myButton & ~PlayersPreviousPressedButton[id]
  266.  
  267. if(buttonUnique)
  268. {
  269. new piecePosition[POSITION]
  270. new PIECE_NAME:pieceName = PlayersCurrentPieceName[id]
  271.  
  272. new pieceSquareWidth = PiecesSquareWidth[pieceName]
  273. new Array:pieceData = createBiArray(pieceSquareWidth,pieceSquareWidth)
  274.  
  275. clonePiece(PlayersCurrentPieceData[id],pieceData,PlayersCurrentPiecePosition[id],piecePosition,pieceName);
  276.  
  277. switch(buttonUnique)
  278. {
  279. case IN_MOVELEFT:
  280. {
  281. piecePosition[COL]--;
  282. }
  283. case IN_MOVERIGHT:
  284. {
  285. piecePosition[COL]++;
  286. }
  287. case IN_FORWARD:
  288. {
  289. rotatePiece(pieceData,pieceName)
  290. }
  291. case IN_BACK:
  292. {
  293. piecePosition[ROW]++;
  294. }
  295. }
  296.  
  297. if(isValidPieceInTable(id,pieceData,piecePosition,pieceName))
  298. {
  299. PlayersCurrentPiecePosition[id] = piecePosition;
  300. PlayersCurrentPieceData[id] = pieceData;
  301. }
  302.  
  303. menuTetrisInGame(id)
  304. }
  305. }
  306.  
  307. PlayersPreviousPressedButton[id] = button;
  308. }
  309. }
  310.  
  311. public client_connect(id)
  312. {
  313. PlayersGameState[id] = START
  314. playersDifficultyLevel[id] = DIFFICULTY_LEVEL:0;
  315. playersMusic[id] = true
  316. }
  317.  
  318. public client_disconnect(id)
  319. {
  320. if(PlayersIsPlaying[id])
  321. playerQuitingGame(id);
  322. }
  323.  
  324. newTask(id,&taskID,&Float:taskDelay)
  325. {
  326. taskDelay = difficultyLevelsTaskDelay[playersDifficultyLevel[id]]
  327.  
  328. do
  329. {
  330. taskID = random(999999);
  331. }
  332. while(task_exists(taskID));
  333. }
  334.  
  335. Array:createBiArray(rows,cols)
  336. {
  337. new Array:array = ArrayCreate(rows)
  338.  
  339. for(new i=0;i<rows;i++)
  340. {
  341. new Array:line = ArrayCreate(cols)
  342.  
  343. for(new i=0;i<cols;i++)
  344. ArrayPushCell(line,false)
  345.  
  346. ArrayPushCell(array,line)
  347. }
  348.  
  349. return array;
  350. }
  351. destroyBiArray(Array:array,rows)
  352. {
  353. if(array)
  354. {
  355. for(new i=0;i<rows;i++)
  356. {
  357. new Array:line = ArrayGetCell(array,i)
  358. ArrayDestroy(line)
  359. }
  360.  
  361. ArrayDestroy(array)
  362. }
  363. }
  364.  
  365. rotatePiece(&Array:pieceData,PIECE_NAME:pieceName)
  366. {
  367. new pieceSquareWidth = PiecesSquareWidth[pieceName]
  368. new biggerIndex = pieceSquareWidth - 1;
  369.  
  370. new Array:newPieceData = createBiArray(pieceSquareWidth,pieceSquareWidth)
  371.  
  372. for(new i=0;i<pieceSquareWidth;i++)
  373. for(new j=0;j<pieceSquareWidth;j++)
  374. setBiArrayCell(newPieceData,i,j,getBiArrayCell(pieceData,biggerIndex - j,i))
  375.  
  376. destroyBiArray(pieceData,pieceSquareWidth);
  377.  
  378. pieceData = newPieceData;
  379. }
  380.  
  381. clonePiece(Array:piece1Data,Array:piece2Data,piece1Position[POSITION],piece2Position[POSITION],PIECE_NAME:pieceName)
  382. {
  383. new pieceSquareWidth = PiecesSquareWidth[pieceName]
  384.  
  385. for(new i = 0 ; i< pieceSquareWidth ; i++)
  386. for(new j = 0 ; j< pieceSquareWidth ; j++)
  387. setBiArrayCell(piece2Data,i,j,getBiArrayCell(piece1Data,i,j))
  388.  
  389. for(new POSITION:pos = ROW; pos < POSITION;pos++)
  390. piece2Position[pos] = piece1Position[pos];
  391. }
  392.  
  393. getRandomPiece(&Array:pieceData,piecePosition[POSITION],&PIECE_NAME:pieceName)
  394. {
  395. pieceName = PIECE_NAME:random(_:PIECE_NAME);
  396. new pieceSquareWidth = PiecesSquareWidth[pieceName]
  397.  
  398. pieceData = createBiArray(pieceSquareWidth,pieceSquareWidth)
  399.  
  400. clonePiece(PiecesData[pieceName],pieceData,piecePosition,piecePosition,pieceName);
  401.  
  402. initPiecePosition(piecePosition,pieceName);
  403. }
  404.  
  405. initPiecePosition(piecePosition[POSITION],PIECE_NAME:pieceName)
  406. {
  407. new pieceSquareWidth = PiecesSquareWidth[pieceName];
  408.  
  409. piecePosition[ROW] = -1
  410. piecePosition[COL] = (TableCols / 2 + TableCols % 2) - (pieceSquareWidth / 2)
  411. }
  412.  
  413. initTable(id)
  414. {
  415. PlayersTables[id] = createBiArray(TableRows,TableCols)
  416. }
  417.  
  418. initPlayerGame(id)
  419. {
  420. PlayersGameState[id] = IN_GAME;
  421.  
  422. initTable(id)
  423.  
  424. getRandomPiece(PlayersCurrentPieceData[id],PlayersCurrentPiecePosition[id],PlayersCurrentPieceName[id])
  425. getRandomPiece(PlayersNextPieceData[id],PlayersNextPiecePosition[id],PlayersNextPieceName[id])
  426.  
  427. new params[1]
  428. params[0] = id
  429.  
  430. playerEnteringGame(id,true);
  431.  
  432. newTask(id,PlayersTaskID[id],PlayersTaskDelay[id])
  433. }
  434.  
  435. playerEnteringGame(id,bool:starting = false)
  436. {
  437. pev(id,pev_maxspeed,PlayersPreviousMaxspeed[id])
  438.  
  439. new Float:delay = PlayersTaskDelay[id]
  440.  
  441. if(!starting)
  442. delay /= 2.0
  443.  
  444. new params[1]
  445. params[0] = id;
  446. set_task(delay,"movePieceDownTask",PlayersTaskID[id],params,1,"a",1)
  447.  
  448. if(playersMusic[id])
  449. client_cmd(id,"mp3 loop sound/%s",Musics[MUSIC:random(_:MUSIC)] );
  450.  
  451. PlayersIsPlaying[id] = true;
  452.  
  453. if(!playersPlaying++)
  454. ForwardPlayerPostThink = register_forward(FM_PlayerPostThink,"playerPostThink");
  455. }
  456. playerQuitingGame(id)
  457. {
  458. PlayersIsPlaying[id] = false;
  459.  
  460. new taskID = PlayersTaskID[id]
  461.  
  462. if(task_exists(taskID))
  463. remove_task(taskID);
  464.  
  465. set_pev(id,pev_maxspeed,PlayersPreviousMaxspeed[id])
  466.  
  467. client_cmd(id,"mp3 stop")
  468.  
  469. if(!--playersPlaying)
  470. unregister_forward(FM_PlayerPostThink,ForwardPlayerPostThink);
  471. }
  472.  
  473. bool:getBiArrayCell(Array:table,row,col)
  474. {
  475. return bool:ArrayGetCell(Array:ArrayGetCell(table,row),col)
  476. }
  477. setBiArrayCell(Array:table,row,col,value)
  478. {
  479. ArraySetCell(Array:ArrayGetCell(table,row),col,value)
  480. }
  481.  
  482. public menuTetris(id)
  483. {
  484. callfunc_begin_i(GameStatesMenusIDs[PlayersGameState[id]])
  485. callfunc_push_int(id);
  486. callfunc_end();
  487.  
  488. return PLUGIN_CONTINUE;
  489. }
  490.  
  491. public menuTetrisStart(id)
  492. {
  493. new menu = menu_create("","handleMenuTetrisStart");
  494.  
  495. new TetrisTitle[TETRIS_TITLE_LEN+1]
  496. formatex(TetrisTitle,TETRIS_TITLE_LEN,"%L",LANG_PLAYER,ML_DefinitionsString[TETRIS_TITLE])
  497.  
  498. new TetrisExit[TETRIS_EXIT_LEN+1]
  499. formatex(TetrisExit,TETRIS_EXIT_LEN,"%L",LANG_PLAYER,ML_DefinitionsString[TETRIS_EXIT])
  500.  
  501. new TetrisStartGame[TETRIS_START_GAME_LEN+1]
  502. formatex(TetrisStartGame,TETRIS_START_GAME_LEN,"%L",LANG_PLAYER,ML_DefinitionsString[TETRIS_START_GAME])
  503.  
  504. menu_setprop(menu,MPROP_TITLE,TetrisTitle);
  505. menu_setprop(menu,MPROP_EXITNAME,TetrisExit);
  506.  
  507. menu_additem(menu,TetrisStartGame,"1");
  508.  
  509. const ML_DifficultyLevelLen = 23 + 1
  510. new ML_DifficultyLevel[ML_DifficultyLevelLen + 1]
  511.  
  512. formatex(ML_DifficultyLevel,ML_DifficultyLevelLen,"%s%d",ML_DefinitionsString[TETRIS_DIFFICULTY_LEVEL],_:playersDifficultyLevel[id])
  513.  
  514. new difficultyLevelFormat[] = "%L: ^"\r%L\w^"";
  515.  
  516. const difficultyLevelLen = sizeof difficultyLevelFormat + TETRIS_DIFFICULTY_LEN + TETRIS_DIFFICULTY_LEVEL_LEN;
  517. new difficultyLevel[difficultyLevelLen + 1]
  518.  
  519. formatex(difficultyLevel,difficultyLevelLen,difficultyLevelFormat,LANG_PLAYER,ML_DefinitionsString[TETRIS_DIFFICULTY],LANG_PLAYER,ML_DifficultyLevel)
  520.  
  521. menu_additem(menu,difficultyLevel,"2");
  522.  
  523. menu_display(id,menu,0);
  524. }
  525.  
  526. public handleMenuTetrisStart(id,menu,item)
  527. {
  528. if(item >= 0)
  529. {
  530. new access, callback;
  531.  
  532. new actionString[2];
  533. menu_item_getinfo(menu,item,access, actionString,1,_,_, callback);
  534. new action = str_to_num(actionString);
  535.  
  536. switch(action)
  537. {
  538. case 1:
  539. {
  540. initPlayerGame(id)
  541. menuTetrisInGame(id);
  542. }
  543. case 2:
  544. {
  545. if(++playersDifficultyLevel[id] == DIFFICULTY_LEVEL)
  546. playersDifficultyLevel[id] = DIFFICULTY_LEVEL:0
  547.  
  548. playSound(id,Sounds[SELECTION]);
  549.  
  550. menuTetrisStart(id);
  551. }
  552. }
  553. }
  554.  
  555. menu_destroy(menu);
  556.  
  557. return PLUGIN_HANDLED;
  558. }
  559.  
  560. canMovePieceDown(id)
  561. {
  562. new piecePosition[POSITION]
  563. new PIECE_NAME:pieceName = PlayersCurrentPieceName[id]
  564.  
  565. new pieceSquareWidth = PiecesSquareWidth[pieceName]
  566. new Array:pieceData = createBiArray(pieceSquareWidth,pieceSquareWidth)
  567.  
  568. clonePiece(PlayersCurrentPieceData[id],pieceData,PlayersCurrentPiecePosition[id],piecePosition,pieceName);
  569.  
  570. piecePosition[ROW]++;
  571.  
  572. return isValidPieceInTable(id,pieceData,piecePosition,pieceName)
  573. }
  574. isValidPieceInTable(id,Array:pieceData,piecePosition[POSITION],PIECE_NAME:pieceName)
  575. {
  576. new pieceSquareWidth = PiecesSquareWidth[pieceName];
  577.  
  578. new positionInPiece[POSITION]
  579. new positionInTable[POSITION]
  580.  
  581. for(new i=0;i<pieceSquareWidth;i++)
  582. {
  583. positionInPiece[COL] = i
  584. positionInTable[COL] = piecePosition[COL] + positionInPiece[COL]
  585.  
  586. for(new j=0;j<pieceSquareWidth;j++)
  587. {
  588. positionInPiece[ROW] = (pieceSquareWidth - 1) - j;
  589. positionInTable[ROW] = piecePosition[ROW] - j
  590.  
  591. if(0 <= positionInTable[COL] < TableCols)
  592. {
  593. if(getBiArrayCell(pieceData,positionInPiece[ROW],positionInPiece[COL]) && positionInTable[ROW] >= 0)
  594. {
  595. if(positionInTable[ROW] < TableRows)
  596. {
  597. if(getBiArrayCell(PlayersTables[id],positionInTable[ROW],positionInTable[COL]))
  598. {
  599. return false;
  600. }
  601. }
  602. else
  603. {
  604. return false;
  605. }
  606. }
  607. }
  608. else
  609. {
  610. if(getBiArrayCell(pieceData,positionInPiece[ROW],positionInPiece[COL]))
  611. {
  612. return false;
  613. }
  614. }
  615. }
  616. }
  617.  
  618. return true;
  619. }
  620. putPieceInTable(id)
  621. {
  622. new pieceSquareWidth = PiecesSquareWidth[PlayersCurrentPieceName[id]];
  623.  
  624. new positionInPiece[POSITION]
  625. new positionInTable[POSITION]
  626.  
  627. for(new i=0;i<pieceSquareWidth;i++)
  628. {
  629. positionInPiece[COL] = i
  630. positionInTable[COL] = PlayersCurrentPiecePosition[id][COL] + i
  631.  
  632. for(new j=0;j<pieceSquareWidth;j++)
  633. {
  634. positionInPiece[ROW] = (pieceSquareWidth - 1) - j;
  635. positionInTable[ROW] = PlayersCurrentPiecePosition[id][ROW] - j;
  636.  
  637. if(positionInTable[ROW] < 0)
  638. {
  639. return false
  640. }
  641. else
  642. {
  643. if(getBiArrayCell(PlayersCurrentPieceData[id],positionInPiece[ROW],positionInPiece[COL]))
  644. {
  645. setBiArrayCell(PlayersTables[id],positionInTable[ROW],positionInTable[COL],true)
  646. }
  647. }
  648. }
  649. }
  650.  
  651. return true;
  652. }
  653.  
  654. cleanRow(id)
  655. {
  656. for(new row=0;row<TableRows;row++)
  657. {
  658. new bool:fullRow = true;
  659.  
  660. for(new col=0;col<TableCols;col++)
  661. {
  662. if(!getBiArrayCell(PlayersTables[id],row,col))
  663. {
  664. fullRow = false;
  665. break;
  666. }
  667. }
  668.  
  669. if(fullRow)
  670. {
  671.  
  672. for(new col=0;col<TableCols;col++)
  673. {
  674. setBiArrayCell(PlayersTables[id],row,col,false)
  675. }
  676.  
  677. return row;
  678. }
  679. }
  680.  
  681. return -1;
  682. }
  683.  
  684. handleGravityEffect(id,cleanedRow)
  685. {
  686. for(new col=0;col<TableCols;col++)
  687. {
  688. new lowerCleanRow = cleanedRow
  689.  
  690. for(new row= cleanedRow + 1; row < TableRows ; row++)
  691. {
  692. if(!getBiArrayCell(PlayersTables[id],row,col))
  693. {
  694. lowerCleanRow = row;
  695. }
  696. else
  697. {
  698. break;
  699. }
  700. }
  701.  
  702. for(new row = lowerCleanRow - 1; row >= 0; row--)
  703. {
  704. if(getBiArrayCell(PlayersTables[id],row,col))
  705. {
  706. setBiArrayCell(PlayersTables[id],row,col,false)
  707. setBiArrayCell(PlayersTables[id],lowerCleanRow,col,true)
  708. }
  709.  
  710. lowerCleanRow--
  711. }
  712. }
  713. }
  714.  
  715. public movePieceDownTask(params[])
  716. {
  717. new id = params[0]
  718.  
  719. if(PlayersIsPlaying[id])
  720. {
  721. new bool:createTask
  722.  
  723. if(canMovePieceDown(id))
  724. {
  725. PlayersCurrentPiecePosition[id][ROW]++
  726. createTask = true;
  727. }
  728. else
  729. {
  730. if(putPieceInTable(id))
  731. {
  732. playSound(id,Sounds[FALL]);
  733.  
  734. new row
  735.  
  736. do
  737. {
  738. row = cleanRow(id)
  739.  
  740. if(row != -1)
  741. {
  742. playSound(id,Sounds[LINE]);
  743.  
  744. handleGravityEffect(id,row)
  745. }
  746. }
  747. while(row != -1);
  748.  
  749. new PIECE_NAME:pieceName = PlayersNextPieceName[id]
  750.  
  751. PlayersCurrentPieceData[id] = PlayersNextPieceData[id];
  752. PlayersCurrentPieceName[id] = pieceName;
  753. initPiecePosition(PlayersCurrentPiecePosition[id],pieceName);
  754.  
  755. getRandomPiece(PlayersNextPieceData[id],PlayersNextPiecePosition[id],PlayersNextPieceName[id])
  756.  
  757. createTask = true;
  758. }
  759. else
  760. {
  761. playSound(id,Sounds[GAMEOVER]);
  762. PlayersGameState[id] = GAME_OVER;
  763.  
  764. destroyBiArray(PlayersTables[id],TableRows)
  765.  
  766. playerQuitingGame(id);
  767.  
  768. menuTetris(id);
  769.  
  770. return
  771. }
  772. }
  773.  
  774. new menu,newmenu
  775.  
  776. player_menu_info(id,menu,newmenu);
  777.  
  778. if(newmenu == PlayersMenuInGame[id])
  779. {
  780. if(createTask)
  781. {
  782. set_task(PlayersTaskDelay[id],"movePieceDownTask",PlayersTaskID[id],params,1,"a",1)
  783. menuTetris(id);
  784. }
  785. }
  786. else
  787. {
  788. playerQuitingGame(id);
  789. }
  790. }
  791. }
  792.  
  793. public menuTetrisInGamePre(id)
  794. {
  795. if(!PlayersIsPlaying[id])
  796. {
  797. playerEnteringGame(id);
  798. }
  799.  
  800. menuTetrisInGame(id);
  801. }
  802. public menuTetrisInGame(id)
  803. {
  804. new menu = menu_create("","handleMenuTetrisInGame");
  805.  
  806. PlayersMenuInGame[id] = menu;
  807.  
  808. new TetrisMusic[TETRIS_MUSIC_LEN+1]
  809. formatex(TetrisMusic,TETRIS_MUSIC_LEN,"%L",LANG_PLAYER, playersMusic[id] ? ML_DefinitionsString[TETRIS_MUSIC_ON] : ML_DefinitionsString[TETRIS_MUSIC_OFF])
  810.  
  811. new TetrisExit[TETRIS_EXIT_LEN+1]
  812. formatex(TetrisExit,TETRIS_EXIT_LEN,"%L",LANG_PLAYER,ML_DefinitionsString[TETRIS_EXIT])
  813.  
  814. menu_additem(menu,TetrisMusic,"1");
  815. menu_additem(menu,TetrisExit,"2");
  816.  
  817. menu_addblank(menu,0)
  818.  
  819. const rowStringLen = 3 * TableCols + 1;
  820.  
  821. new currentPieceSquareWidth = PiecesSquareWidth[PlayersCurrentPieceName[id]];
  822.  
  823. new currentPieceEndRow = PlayersCurrentPiecePosition[id][ROW]
  824.  
  825. new currentPieceStartRow = currentPieceEndRow - currentPieceSquareWidth + 1
  826.  
  827. new currentPieceStartCol = PlayersCurrentPiecePosition[id][COL]
  828. new currentPieceEndCol = currentPieceStartCol + currentPieceSquareWidth - 1;
  829.  
  830. for(new row=0; row < currentPieceStartRow; row++)
  831. {
  832. PlayersTableCellActive[id] = false;
  833.  
  834. new rowString[rowStringLen];
  835. format(rowString,2,cellCharColors[INACTIVE]);
  836.  
  837. for(new col = 0;col < TableCols; col++)
  838. {
  839. new bool:active = getBiArrayCell(PlayersTables[id],row,col)
  840.  
  841. if(active != PlayersTableCellActive[id])
  842. {
  843. PlayersTableCellActive[id] = active;
  844. format(rowString,rowStringLen-1,"%s%s",rowString,cellCharColors[CELL_COLOR:active]);
  845. }
  846.  
  847. format(rowString,rowStringLen-1,"%s%s",rowString,cellChar);
  848. }
  849.  
  850. menu_addtext(menu,rowString,0);
  851. }
  852.  
  853. if(0 <= currentPieceEndRow)
  854. {
  855. if(currentPieceEndRow >= TableRows)
  856. currentPieceEndRow = TableRows - 1;
  857.  
  858. for(new row = currentPieceStartRow; row <= currentPieceEndRow; row++)
  859. {
  860. if(row >= 0)
  861. {
  862. PlayersTableCellActive[id] = false;
  863.  
  864. new rowString[rowStringLen];
  865. format(rowString,2,cellCharColors[INACTIVE]);
  866.  
  867. for(new col=0;col<currentPieceStartCol;col++)
  868. {
  869. new bool:active = getBiArrayCell(PlayersTables[id],row,col)
  870.  
  871. if(active != PlayersTableCellActive[id])
  872. {
  873. PlayersTableCellActive[id] = active;
  874. format(rowString,rowStringLen-1,"%s%s",rowString,cellCharColors[CELL_COLOR:active]);
  875. }
  876.  
  877. format(rowString,rowStringLen-1,"%s%s",rowString,cellChar);
  878. }
  879.  
  880. new positionInPiece[POSITION]
  881.  
  882. if(currentPieceEndCol >= TableCols)
  883. currentPieceEndCol = TableCols - 1;
  884.  
  885. positionInPiece[ROW] = row - currentPieceStartRow;
  886.  
  887.  
  888. for(new col=currentPieceStartCol;col<=currentPieceEndCol;col++)
  889. {
  890. if(col >= 0)
  891. {
  892. positionInPiece[COL] = col - currentPieceStartCol;
  893.  
  894. new bool:active = getBiArrayCell(PlayersCurrentPieceData[id],positionInPiece[ROW],positionInPiece[COL]) || getBiArrayCell(PlayersTables[id],row,col)
  895.  
  896. if(active != PlayersTableCellActive[id])
  897. {
  898. PlayersTableCellActive[id] = active;
  899. format(rowString,rowStringLen-1,"%s%s",rowString,cellCharColors[CELL_COLOR:active]);
  900. }
  901.  
  902. format(rowString,rowStringLen-1,"%s%s",rowString,cellChar);
  903. }
  904. }
  905.  
  906. for(new col=currentPieceEndCol+1;col< TableCols;col++)
  907. {
  908. new bool:active = getBiArrayCell(PlayersTables[id],row,col)
  909.  
  910. if(active != PlayersTableCellActive[id])
  911. {
  912. PlayersTableCellActive[id] = active;
  913. format(rowString,rowStringLen-1,"%s%s",rowString,cellCharColors[CELL_COLOR:active]);
  914. }
  915.  
  916. format(rowString,rowStringLen-1,"%s%s",rowString,cellChar);
  917. }
  918.  
  919. menu_addtext(menu,rowString,0);
  920. }
  921. }
  922. }
  923.  
  924. for(new row=currentPieceEndRow+1; row < TableRows; row++)
  925. {
  926. PlayersTableCellActive[id] = false;
  927.  
  928. new rowString[rowStringLen];
  929. format(rowString,2,cellCharColors[INACTIVE]);
  930.  
  931. for(new col = 0;col < TableCols; col++)
  932. {
  933. new bool:active = getBiArrayCell(PlayersTables[id],row,col)
  934.  
  935. if(active != PlayersTableCellActive[id])
  936. {
  937. PlayersTableCellActive[id] = active;
  938. format(rowString,rowStringLen-1,"%s%s",rowString,cellCharColors[CELL_COLOR:active]);
  939. }
  940.  
  941. format(rowString,rowStringLen-1,"%s%s",rowString,cellChar);
  942. }
  943.  
  944. menu_addtext(menu,rowString,0);
  945. }
  946.  
  947. new TetrisTitle[TETRIS_TITLE_LEN+1]
  948. formatex(TetrisTitle,TETRIS_TITLE_LEN,"%L",LANG_PLAYER,ML_DefinitionsString[TETRIS_TITLE])
  949.  
  950. menu_setprop(menu,MPROP_TITLE,TetrisTitle);
  951. menu_setprop(menu,MPROP_EXITNAME,TetrisExit);
  952.  
  953. for(new i=3;i<=7;i++)
  954. menu_addtext(menu,"",1)
  955.  
  956. menu_display(id,menu,0);
  957.  
  958. }
  959.  
  960. public handleMenuTetrisInGame(id,menu,item)
  961. {
  962. if(item >= 0)
  963. {
  964. new access, callback;
  965.  
  966. new actionString[2];
  967. menu_item_getinfo(menu,item,access, actionString,1,_,_, callback);
  968. new action = str_to_num(actionString);
  969.  
  970. switch(action)
  971. {
  972. case 0:
  973. {
  974. playerQuitingGame(id);
  975. }
  976. case 1:
  977. {
  978. client_cmd(id,"mp3 stop")
  979.  
  980. playersMusic[id] = !playersMusic[id]
  981.  
  982. if(playersMusic[id])
  983. client_cmd(id,"mp3 loop sound/%s",Musics[MUSIC:random(_:MUSIC)] );
  984.  
  985. menuTetrisInGame(id)
  986. }
  987. }
  988. }
  989.  
  990. menu_destroy(menu);
  991.  
  992. return PLUGIN_HANDLED;
  993. }
  994.  
  995. public menuTetrisGameOver(id)
  996. {
  997. client_cmd(id,"mp3 stop")
  998.  
  999. new menu = menu_create("","handleMenuTetrisGameOver");
  1000.  
  1001. new tetrisExit[TETRIS_EXIT_LEN+1]
  1002. formatex(tetrisExit,TETRIS_EXIT_LEN,"%L",LANG_PLAYER,ML_DefinitionsString[TETRIS_EXIT])
  1003.  
  1004. new tetrisPlayAgain[TETRIS_PLAY_AGAIN_LEN+1]
  1005. formatex(tetrisPlayAgain,TETRIS_PLAY_AGAIN_LEN,"%L",LANG_PLAYER,ML_DefinitionsString[TETRIS_PLAY_AGAIN])
  1006.  
  1007. new tetrisTitleFormat[] = "%L^n^n%L"
  1008. const tetrisTitleLen = sizeof tetrisTitleFormat + TETRIS_TITLE_LEN + TETRIS_GAME_OVER_LEN
  1009. new tetrisTitle[tetrisTitleLen+1]
  1010.  
  1011. formatex(tetrisTitle,tetrisTitleLen,tetrisTitleFormat,LANG_PLAYER,ML_DefinitionsString[TETRIS_TITLE],LANG_PLAYER,ML_DefinitionsString[TETRIS_GAME_OVER])
  1012.  
  1013. menu_setprop(menu,MPROP_TITLE,tetrisTitle);
  1014. menu_setprop(menu,MPROP_EXITNAME,tetrisExit);
  1015.  
  1016. menu_additem(menu,tetrisPlayAgain,"1");
  1017.  
  1018. menu_display(id,menu,0);
  1019. }
  1020.  
  1021. public handleMenuTetrisGameOver(id,menu,item)
  1022. {
  1023. if(item >= 0)
  1024. {
  1025. new access, callback;
  1026.  
  1027. new actionString[2];
  1028. menu_item_getinfo(menu,item,access, actionString,1,_,_, callback);
  1029. new action = str_to_num(actionString);
  1030.  
  1031. switch(action)
  1032. {
  1033. case 1:
  1034. {
  1035. PlayersGameState[id] = START
  1036. menuTetris(id);
  1037. }
  1038. }
  1039. }
  1040.  
  1041. menu_destroy(menu);
  1042.  
  1043. return PLUGIN_HANDLED;
  1044. }
  1045. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  1046. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1038\\ f0\\ fs16 \n\\ par }
  1047. */
  1048.