Advertisement
Phanto90

PBlock v1.0

Sep 7th, 2011
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.92 KB | None | 0 0
  1. /*
  2. ================================================================================
  3.                                                  
  4.                         =====[Phanto's Script]=====
  5.                         |         PBlock minigame |
  6.                         |            Version: 1.0 |
  7.                         |           Type: Include |
  8.                         ===========================
  9.  
  10. Please, don't remove credits.
  11. ================================================================================
  12. */
  13.  
  14.  
  15. #if defined PBlock_Included
  16.   #endinput
  17. #endif
  18. #define PBlock_Included
  19.  
  20. #include a_samp
  21.  
  22. //=============================DIALOGS
  23. #define DIALOG_PBLOCK  1030
  24. //=============================MACRO
  25. #define PRESSED(%0) \
  26.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  27. //=============================CHECKPLAYERPLAYING
  28. new bool:pblock_isplaying[MAX_PLAYERS];
  29. new bool:just_pressed_key[MAX_PLAYERS];
  30. new player_scores[MAX_PLAYERS];
  31. //=============================TABLEBLOCKINFO
  32. new block_table[MAX_PLAYERS][5][10];
  33. //=============================COORDINATESFORMOVINGBLOCK
  34. new moving_block[MAX_PLAYERS][2];
  35. //=============================BLOCKSCOLOR
  36. enum
  37.     {
  38.     NO_BLOCK,
  39.     RED_BLOCK,
  40.     BLUE_BLOCK,
  41.     LIGHTBLUE_BLOCK,
  42.     YELLOW_BLOCK,
  43.     PURPLE_BLOCK,
  44.     GREEN_BLOCK,
  45.     LIGHTGREEN_BLOCK,
  46.     WHITE_BLOCK
  47.     }
  48. //=============================TIMER
  49. new pblock_timer[MAX_PLAYERS];
  50. //=============================TEXTDRAWS
  51. new Text:pblock_background,Text:pblock_background2,Text:pblock_title,
  52.     Text:pblock_score,Text:pblock_table;
  53.  
  54. //================================================================ONGAMEMODEINIT
  55. public OnGameModeInit()
  56. {
  57.     pblock_background = TextDrawCreate(228.000000, 44.000000, "_");
  58.     TextDrawBackgroundColor(pblock_background, 255);
  59.     TextDrawFont(pblock_background, 1);
  60.     TextDrawLetterSize(pblock_background, 0.500000, 39.199996);
  61.     TextDrawColor(pblock_background, -1);
  62.     TextDrawSetOutline(pblock_background, 0);
  63.     TextDrawSetProportional(pblock_background, 1);
  64.     TextDrawSetShadow(pblock_background, 1);
  65.     TextDrawUseBox(pblock_background, 1);
  66.     TextDrawBoxColor(pblock_background, 858993493);
  67.     TextDrawTextSize(pblock_background, 421.000000, 0.000000);
  68.  
  69.     pblock_title = TextDrawCreate(228.000000, 19.000000, "P~b~~h~~h~Block~w~ - v1.0      (~r~x~w~)");
  70.     TextDrawBackgroundColor(pblock_title, 255);
  71.     TextDrawFont(pblock_title, 2);
  72.     TextDrawLetterSize(pblock_title, 0.439999, 2.099999);
  73.     TextDrawColor(pblock_title, -1);
  74.     TextDrawSetOutline(pblock_title, 1);
  75.     TextDrawSetProportional(pblock_title, 1);
  76.     TextDrawUseBox(pblock_title, 1);
  77.     TextDrawBoxColor(pblock_title, 87875741);
  78.     TextDrawTextSize(pblock_title, 421.000000, 0.000000);
  79.  
  80.     pblock_score = TextDrawCreate(419.000000, 379.000000, "SCORE: 1003");
  81.     TextDrawAlignment(pblock_score, 3);
  82.     TextDrawBackgroundColor(pblock_score, 255);
  83.     TextDrawFont(pblock_score, 2);
  84.     TextDrawLetterSize(pblock_score, 0.370000, 1.900001);
  85.     TextDrawColor(pblock_score, -1);
  86.     TextDrawSetOutline(pblock_score, 1);
  87.     TextDrawSetProportional(pblock_score, 1);
  88.  
  89.     pblock_background2 = TextDrawCreate(244.000000, 44.000000, "_");
  90.     TextDrawBackgroundColor(pblock_background2, 255);
  91.     TextDrawFont(pblock_background2, 1);
  92.     TextDrawLetterSize(pblock_background2, 0.500000, 36.999984);
  93.     TextDrawColor(pblock_background2, -1);
  94.     TextDrawSetOutline(pblock_background2, 0);
  95.     TextDrawSetProportional(pblock_background2, 1);
  96.     TextDrawSetShadow(pblock_background2, 1);
  97.     TextDrawUseBox(pblock_background2, 1);
  98.     TextDrawBoxColor(pblock_background2, 673720575);
  99.     TextDrawTextSize(pblock_background2, 404.000000, 0.000000);
  100.  
  101.     pblock_table = TextDrawCreate(251.000000, 44.000000, "~w~O~b~~h~~h~O~y~O~r~O~p~O~n~OOOOO~n~OOOOO~n~OOOOO~n~OOOOO~n~OO OO~n~OOOOO~n~OOOOO~n~OOOOO~n~OOOOO");
  102.     TextDrawBackgroundColor(pblock_table, 255);
  103.     TextDrawFont(pblock_table, 2);
  104.     TextDrawLetterSize(pblock_table, 1.049998, 3.699997);
  105.     TextDrawColor(pblock_table, -1);
  106.     TextDrawSetOutline(pblock_table, 1);
  107.     TextDrawSetProportional(pblock_table, 0);
  108.     if (funcidx("PBlock_OnGameModeInit") != -1)
  109.     {
  110.         return CallLocalFunction("PBlock_OnGameModeInit", "");
  111.     }
  112.     return 1;
  113. }
  114.  
  115. #if defined _ALS_OnGameModeInit
  116.   #undef OnGameModeInit
  117. #else
  118.   #define _ALS_OnGameModeInit
  119. #endif
  120. #define OnGameModeInit PBlock_OnGameModeInit
  121. forward PBlock_OnGameModeInit();
  122. //============================================================ONPLAYERDISCONNECT
  123. public OnPlayerDisconnect(playerid)
  124. {
  125.     PBlock_ExitGame(playerid);
  126.     if (funcidx("PBlock_OnGameModeInit") != -1)
  127.     {
  128.         return CallLocalFunction("PBlock_OnPlayerDisconnect", "d", playerid);
  129.     }
  130.     return 1;
  131. }
  132.  
  133. #if defined _ALS_OnPlayerDisconnect
  134.   #undef OnPlayerDisconnect
  135. #else
  136.   #define _ALS_OnPlayerDisconnect
  137. #endif
  138. #define OnPlayerDisconnect PBlock_OnPlayerDisconnect
  139. forward PBlock_OnPlayerDisconnect(playerid);
  140. //================================================================CREATENEWBLOCK
  141. stock PBlock_Create_NewBlock(playerid)
  142. {
  143.     if(block_table[playerid][2][9] != NO_BLOCK)
  144.         {
  145.         PBlock_GameOver(playerid);
  146.         return 0;
  147.         }
  148.     moving_block[playerid] = {2, 9};
  149.     block_table[playerid][2][9] = random(WHITE_BLOCK)+1;
  150.     PBlock_Refresh_Textdraw(playerid);
  151.     return 1;
  152. }
  153. //===============================================================PBLOCKSTARTGAME
  154. stock PBlock_StartGame(playerid)
  155. {
  156.     PB_PlaySound(playerid, 1076);
  157.     TogglePlayerControllable(playerid, 0);
  158.     player_scores[playerid] = 0;
  159.     TextDrawSetString(pblock_score, "Score: 0");
  160.     TextDrawShowForPlayer(playerid, pblock_background);
  161.     TextDrawShowForPlayer(playerid, pblock_background2);
  162.     TextDrawShowForPlayer(playerid, pblock_title);
  163.     TextDrawShowForPlayer(playerid, pblock_score);
  164.     TextDrawSetString(pblock_table, ""); //Resetting table.
  165.     TextDrawShowForPlayer(playerid, pblock_table);
  166.     ShowPlayerDialog(playerid, DIALOG_PBLOCK, 0, "{157FFF}P{FFCA16}Block {C1C1C1}- v1.0", "   {C1C1C1}Welcome to {157FFF}PBlock Minigame\n\n{C1C1C1}In what does it consist?\nYou will have to reach the maximum points setting in a column \n 3 squares of the same color.\nHave fun!\n-{157FFF}Phanto","Play!", "Exit");
  167.     return 1;
  168. }
  169. //=================================================================PBLOCKEXITGAME
  170. stock PBlock_ExitGame(playerid)
  171. {
  172.     PB_PlaySound(playerid, 1077);
  173.     TextDrawHideForPlayer(playerid, pblock_background);
  174.     TextDrawHideForPlayer(playerid, pblock_background2);
  175.     TextDrawHideForPlayer(playerid, pblock_title);
  176.     TextDrawHideForPlayer(playerid, pblock_score);
  177.     TextDrawSetString(pblock_table, ""); //Resetting table.
  178.     TextDrawHideForPlayer(playerid, pblock_table);
  179.     KillTimer(pblock_timer[playerid]);
  180.     pblock_isplaying[playerid] = false;
  181.     TogglePlayerControllable(playerid, 1);
  182.     return 1;
  183. }
  184. //===============================================================PBLOCKSTARTGAME
  185. stock PBlock_GameStart(playerid)
  186. {
  187.     for(new i; i<5; i++)
  188.     {
  189.         for(new j; j<10; j++)
  190.             {
  191.             block_table[playerid][i][j] = NO_BLOCK; //Resetting block info
  192.             }
  193.     }
  194.     GameTextForPlayer(playerid, "~g~~h~~h~GAME STARTS!", 3000, 1);
  195.     PBlock_Create_NewBlock(playerid);
  196.     pblock_isplaying[playerid] = true;
  197.     pblock_timer[playerid] = SetTimerEx("PBlock_Fall", 1000, true, "d", playerid);
  198.     return 1;
  199. }
  200. //================================================================PBLOCKGAMEOVER
  201. stock PBlock_GameOver(playerid)
  202. {
  203.     pblock_isplaying[playerid] = false;
  204.     GameTextForPlayer(playerid, "~r~GAME OVER", 3000, 1);
  205.     KillTimer(pblock_timer[playerid]);
  206.     ShowPlayerDialog(playerid, DIALOG_PBLOCK, 0, "{157FFF}P{FFCA16}Block {C1C1C1}- v1.0", "   {157FFF}PBlock Minigame\n\n{EA3E13}You Lost{C1C1C1}!","Retry!", "Exit");
  207.     return 1;
  208. }
  209. //====================================================================PBLOCKFALL
  210. forward PBlock_Fall(playerid);
  211. public PBlock_Fall(playerid)
  212. {
  213.     if(!moving_block[playerid][1] || block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]-1] != NO_BLOCK)
  214.         {
  215.         PBlock_Create_NewBlock(playerid);
  216.         PBlock_Deleting_Block(playerid);
  217.         return 1;
  218.         }
  219.     PB_PlaySound(playerid, 1131);
  220.     block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]-1] = block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]];
  221.     block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]] = NO_BLOCK;
  222.     moving_block[playerid][1]--;
  223.     PBlock_Refresh_Textdraw(playerid);
  224.     return 1;
  225. }
  226. //=========================================================PBLOCKREFRESHTEXTDRAW
  227. stock PBlock_Refresh_Textdraw(playerid)
  228. {
  229.     new text_string[580];
  230.     for(new p_y = 9; p_y >= 0; p_y--)
  231.         {
  232.         for(new p_x; p_x < 5; p_x++)
  233.             {
  234.             switch(block_table[playerid][p_x][p_y])
  235.                 {
  236.                 case NO_BLOCK: strins(text_string, " ", strlen(text_string), 580);
  237.                 case RED_BLOCK: strins(text_string, "~r~~h~O", strlen(text_string), 580);
  238.                 case BLUE_BLOCK: strins(text_string, "~b~~h~O", strlen(text_string), 580);
  239.                 case LIGHTBLUE_BLOCK: strins(text_string, "~b~~h~~h~O", strlen(text_string), 580);
  240.                 case YELLOW_BLOCK: strins(text_string, "~y~O", strlen(text_string), 580);
  241.                 case PURPLE_BLOCK: strins(text_string, "~p~O", strlen(text_string), 580);
  242.                 case GREEN_BLOCK: strins(text_string, "~g~O", strlen(text_string), 580);
  243.                 case LIGHTGREEN_BLOCK: strins(text_string, "~g~~h~~h~O", strlen(text_string), 580);
  244.                 case WHITE_BLOCK: strins(text_string, "~w~O", strlen(text_string), 580);
  245.                 }
  246.             if(p_x == 4)
  247.                 {
  248.                 strins(text_string, "~n~", strlen(text_string), 580);
  249.                 }
  250.             }
  251.         }
  252.     TextDrawSetString(pblock_table, text_string);
  253.     TextDrawShowForPlayer(playerid,pblock_table);
  254.     return 1;
  255. }
  256. //============================================================CHECKBLOCKTODELETE
  257. stock PBlock_Deleting_Block(playerid)
  258. {
  259.     enum info_check {last_block_type, amount};
  260.     new pblock_check[info_check];
  261.     new score_string[50];
  262.     for(new p_x; p_x < 5; p_x++)
  263.         {
  264.         for(new p_y; p_y < 10; p_y++)
  265.             {
  266.             if(!p_y)
  267.                 {
  268.                 pblock_check[last_block_type] = block_table[playerid][p_x][p_y];
  269.                 pblock_check[amount] = 1;
  270.                 continue;
  271.                 }
  272.             if(block_table[playerid][p_x][p_y] == pblock_check[last_block_type])
  273.                 {
  274.                 pblock_check[amount]++;
  275.                 continue;
  276.                 }
  277.             else
  278.                 {
  279.                 if(pblock_check[amount] >= 3 && pblock_check[last_block_type]!= NO_BLOCK) // Why >= 3? Because I'm developing another version where it will check also rows (not only column as now). For now checking if it is >3 is useless.
  280.                     {
  281.                     player_scores[playerid]++;
  282.                     format(score_string, sizeof(score_string), "Score: %d", player_scores[playerid]);
  283.                     TextDrawSetString(pblock_score, score_string);
  284.                     TextDrawShowForPlayer(playerid, pblock_score);
  285.                     PB_PlaySound(playerid, 1057);
  286.                     for(new pb_del = p_y - pblock_check[amount]; pb_del < p_y; pb_del++)
  287.                         {
  288.                         block_table[playerid][p_x][pb_del] = NO_BLOCK;
  289.                         }
  290.                     }
  291.                 pblock_check[amount] = 1;
  292.                 pblock_check[last_block_type] = block_table[playerid][p_x][p_y];
  293.                 }
  294.             }
  295.         }
  296.     PBlock_Refresh_Textdraw(playerid);
  297.     return 1;
  298. }
  299. //==============================================================ONDIALOGRESPONSE
  300. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  301. {
  302.     if(dialogid == DIALOG_PBLOCK)
  303.         {
  304.         if(!response)
  305.             {
  306.             PBlock_ExitGame(playerid);
  307.             return 1;
  308.             }
  309.         PBlock_GameStart(playerid);
  310.         return 1;
  311.         }
  312.     if (funcidx("PBlock_OnDialogResponse") != -1)
  313.     {
  314.         return CallLocalFunction("PBlock_OnDialogResponse", "dddds", playerid, dialogid, response, listitem, inputtext);
  315.     }
  316.     return 1;
  317. }
  318.  
  319. #if defined _ALS_OnDialogResponse
  320.   #undef OnDialogResponse
  321. #else
  322.   #define _ALS_OnDialogResponse
  323. #endif
  324. #define OnDialogResponse PBlock_OnDialogResponse
  325. forward PBlock_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  326. //================================================================ONPLAYERUPDATE
  327. public OnPlayerUpdate(playerid)
  328. {
  329.     new pb_keys, pb_updown, pb_leftright;
  330.     GetPlayerKeys(playerid, pb_keys, pb_updown, pb_leftright);
  331.     if(pb_leftright == 128 || pb_leftright == -128)
  332.         {
  333.         OnPlayerKeyStateChange(playerid, pb_leftright, 0); //Left & Right keys doesn't recall OnPlayerKeyStateChange, so we need to recall ourself
  334.         }
  335.     if (funcidx("PBlock_OnPlayerUpdate") != -1)
  336.     {
  337.         return CallLocalFunction("PBlock_OnPlayerUpdate", "d", playerid);
  338.     }
  339.     return 1;
  340. }
  341.  
  342. #if defined _ALS_OnPlayerUpdate
  343.   #undef OnPlayerUpdate
  344. #else
  345.   #define _ALS_OnPlayerUpdate
  346. #endif
  347. #define OnPlayerUpdate PBlock_OnPlayerUpdate
  348. forward PBlock_OnPlayerUpdate(playerid);
  349. //========================================================ONPLAYERKEYSTATECHANGE
  350. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  351. {
  352.     if(just_pressed_key[playerid]) return 1; //To prevent "double movement" of the moving block
  353.     if(pblock_isplaying[playerid])
  354.         {
  355.         if(PRESSED(KEY_LEFT))
  356.             {
  357.             if(!moving_block[playerid][0] || block_table[playerid][moving_block[playerid][0]-1][moving_block[playerid][1]] != NO_BLOCK) return 1;
  358.             PB_PlaySound(playerid, 1131);
  359.             block_table[playerid][moving_block[playerid][0]-1][moving_block[playerid][1]] = block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]];
  360.             block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]] = NO_BLOCK;
  361.             moving_block[playerid][0]--;
  362.             PBlock_Refresh_Textdraw(playerid);
  363.             just_pressed_key[playerid] = true;
  364.             SetTimerEx("Remove_JustPressed", 300, false, "d", playerid);
  365.             return 1;
  366.             }
  367.         if(PRESSED(KEY_RIGHT))
  368.             {
  369.             if(moving_block[playerid][0] == 4 || block_table[playerid][moving_block[playerid][0]+1][moving_block[playerid][1]] != NO_BLOCK) return 1;
  370.             PB_PlaySound(playerid, 1131);
  371.             block_table[playerid][moving_block[playerid][0]+1][moving_block[playerid][1]] = block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]];
  372.             block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]] = NO_BLOCK;
  373.             moving_block[playerid][0]++;
  374.             PBlock_Refresh_Textdraw(playerid);
  375.             just_pressed_key[playerid] = true;
  376.             SetTimerEx("Remove_JustPressed", 300, false, "d", playerid);
  377.             return 1;
  378.             }
  379.         }
  380.     if (funcidx("PBlock_OnPlayerKeyStateChange") != -1)
  381.     {
  382.         return CallLocalFunction("PBlock_OnPlayerKeyStateChange", "ddd", playerid, newkeys, oldkeys);
  383.     }
  384.     return 1;
  385. }
  386.  
  387. #if defined _ALS_OnPlayerKeyStateChange
  388.   #undef OnPlayerKeyStateChange
  389. #else
  390.   #define _ALS_OnPlayerKeyStateChange
  391. #endif
  392. #define OnPlayerKeyStateChange PBlock_OnPlayerKeyStateChange
  393. forward PBlock_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  394. //=============================================================REMOVEJUSTPRESSED
  395. forward Remove_JustPressed(playerid);
  396. public Remove_JustPressed(playerid)
  397. {
  398.     just_pressed_key[playerid] = false;
  399.     return 1;
  400. }
  401. //===================================================================PBPLAYSOUND
  402. stock PB_PlaySound(playerid, soundid)
  403. {
  404.     new Float:pb_xpos, Float:pb_ypos, Float:pb_zpos;
  405.     GetPlayerPos(playerid, pb_xpos, pb_ypos, pb_zpos);
  406.     PlayerPlaySound(playerid, soundid, pb_xpos, pb_ypos, pb_zpos);
  407.     return 1;
  408. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement