Phanto90

PBlock v1.0

Sep 6th, 2011
275
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 if(block_table[playerid][p_x][p_y] != pblock_check[last_block_type])
  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.                 }
  293.             }
  294.         }
  295.     PBlock_Refresh_Textdraw(playerid);
  296.     return 1;
  297. }
  298. //==============================================================ONDIALOGRESPONSE
  299. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  300. {
  301.     if(dialogid == DIALOG_PBLOCK)
  302.         {
  303.         if(!response)
  304.             {
  305.             PBlock_ExitGame(playerid);
  306.             return 1;
  307.             }
  308.         PBlock_GameStart(playerid);
  309.         return 1;
  310.         }
  311.     if (funcidx("PBlock_OnDialogResponse") != -1)
  312.     {
  313.         return CallLocalFunction("PBlock_OnDialogResponse", "dddds", playerid, dialogid, response, listitem, inputtext);
  314.     }
  315.     return 1;
  316. }
  317.  
  318. #if defined _ALS_OnDialogResponse
  319.   #undef OnDialogResponse
  320. #else
  321.   #define _ALS_OnDialogResponse
  322. #endif
  323. #define OnDialogResponse PBlock_OnDialogResponse
  324. forward PBlock_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  325. //================================================================ONPLAYERUPDATE
  326. public OnPlayerUpdate(playerid)
  327. {
  328.     new pb_keys, pb_updown, pb_leftright;
  329.     GetPlayerKeys(playerid, pb_keys, pb_updown, pb_leftright);
  330.     if(pb_leftright == 128 || pb_leftright == -128)
  331.         {
  332.         OnPlayerKeyStateChange(playerid, pb_leftright, 0); //Left & Right keys doesn't recall OnPlayerKeyStateChange, so we need to recall ourself
  333.         }
  334.     if (funcidx("PBlock_OnPlayerUpdate") != -1)
  335.     {
  336.         return CallLocalFunction("PBlock_OnPlayerUpdate", "d", playerid);
  337.     }
  338.     return 1;
  339. }
  340.  
  341. #if defined _ALS_OnPlayerUpdate
  342.   #undef OnPlayerUpdate
  343. #else
  344.   #define _ALS_OnPlayerUpdate
  345. #endif
  346. #define OnPlayerUpdate PBlock_OnPlayerUpdate
  347. forward PBlock_OnPlayerUpdate(playerid);
  348. //========================================================ONPLAYERKEYSTATECHANGE
  349. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  350. {
  351.     if(just_pressed_key[playerid]) return 1; //To prevent "double movement" of the moving block
  352.     if(pblock_isplaying[playerid])
  353.         {
  354.         if(PRESSED(KEY_LEFT))
  355.             {
  356.             if(!moving_block[playerid][0] || block_table[playerid][moving_block[playerid][0]-1][moving_block[playerid][1]] != NO_BLOCK) return 1;
  357.             PB_PlaySound(playerid, 1131);
  358.             block_table[playerid][moving_block[playerid][0]-1][moving_block[playerid][1]] = block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]];
  359.             block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]] = NO_BLOCK;
  360.             moving_block[playerid][0]--;
  361.             PBlock_Refresh_Textdraw(playerid);
  362.             just_pressed_key[playerid] = true;
  363.             SetTimerEx("Remove_JustPressed", 300, false, "d", playerid);
  364.             return 1;
  365.             }
  366.         if(PRESSED(KEY_RIGHT))
  367.             {
  368.             if(moving_block[playerid][0] == 4 || block_table[playerid][moving_block[playerid][0]+1][moving_block[playerid][1]] != NO_BLOCK) return 1;
  369.             PB_PlaySound(playerid, 1131);
  370.             block_table[playerid][moving_block[playerid][0]+1][moving_block[playerid][1]] = block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]];
  371.             block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]] = NO_BLOCK;
  372.             moving_block[playerid][0]++;
  373.             PBlock_Refresh_Textdraw(playerid);
  374.             just_pressed_key[playerid] = true;
  375.             SetTimerEx("Remove_JustPressed", 300, false, "d", playerid);
  376.             return 1;
  377.             }
  378.         }
  379.     if (funcidx("PBlock_OnPlayerKeyStateChange") != -1)
  380.     {
  381.         return CallLocalFunction("PBlock_OnPlayerKeyStateChange", "ddd", playerid, newkeys, oldkeys);
  382.     }
  383.     return 1;
  384. }
  385.  
  386. #if defined _ALS_OnPlayerKeyStateChange
  387.   #undef OnPlayerKeyStateChange
  388. #else
  389.   #define _ALS_OnPlayerKeyStateChange
  390. #endif
  391. #define OnPlayerKeyStateChange PBlock_OnPlayerKeyStateChange
  392. forward PBlock_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  393. //=============================================================REMOVEJUSTPRESSED
  394. forward Remove_JustPressed(playerid);
  395. public Remove_JustPressed(playerid)
  396. {
  397.     just_pressed_key[playerid] = false;
  398.     return 1;
  399. }
  400. //===================================================================PBPLAYSOUND
  401. stock PB_PlaySound(playerid, soundid)
  402. {
  403.     new Float:pb_xpos, Float:pb_ypos, Float:pb_zpos;
  404.     GetPlayerPos(playerid, pb_xpos, pb_ypos, pb_zpos);
  405.     PlayerPlaySound(playerid, soundid, pb_xpos, pb_ypos, pb_zpos);
  406.     return 1;
  407. }
Advertisement
Add Comment
Please, Sign In to add comment