Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ================================================================================
- =====[Phanto's Script]=====
- | PBlock minigame |
- | Version: 1.1 |
- | Type: Include |
- ===========================
- Please, don't remove credits.
- ================================================================================
- */
- #if defined PBlock_Included
- #endinput
- #endif
- #define PBlock_Included
- #include a_samp
- //=============================DIALOGS
- #define DIALOG_PBLOCK 1030
- //=============================MACRO
- #define PRESSED(%0) \
- (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
- //=============================CHECKPLAYERPLAYING
- new bool:pblock_isplaying[MAX_PLAYERS];
- new bool:just_pressed_key[MAX_PLAYERS];
- new player_scores[MAX_PLAYERS];
- //=============================TABLEBLOCKINFO
- new block_table[MAX_PLAYERS][5][10];
- //=============================COORDINATESFORMOVINGBLOCK
- new moving_block[MAX_PLAYERS][2];
- //=============================BLOCKSCOLOR
- enum
- {
- NO_BLOCK,
- RED_BLOCK,
- BLUE_BLOCK,
- LIGHTBLUE_BLOCK,
- YELLOW_BLOCK,
- PURPLE_BLOCK,
- GREEN_BLOCK,
- LIGHTGREEN_BLOCK,
- WHITE_BLOCK
- }
- //=============================TIMER
- new pblock_timer[MAX_PLAYERS];
- //=============================TEXTDRAWS
- new Text:pblock_background,Text:pblock_background2,Text:pblock_title,
- Text:pblock_score,Text:pblock_table;
- //================================================================ONGAMEMODEINIT
- public OnGameModeInit()
- {
- pblock_background = TextDrawCreate(228.000000, 44.000000, "_");
- TextDrawBackgroundColor(pblock_background, 255);
- TextDrawFont(pblock_background, 1);
- TextDrawLetterSize(pblock_background, 0.500000, 39.199996);
- TextDrawColor(pblock_background, -1);
- TextDrawSetOutline(pblock_background, 0);
- TextDrawSetProportional(pblock_background, 1);
- TextDrawSetShadow(pblock_background, 1);
- TextDrawUseBox(pblock_background, 1);
- TextDrawBoxColor(pblock_background, 858993493);
- TextDrawTextSize(pblock_background, 421.000000, 0.000000);
- pblock_title = TextDrawCreate(228.000000, 19.000000, "P~b~~h~~h~Block~w~ - v1.1 (~r~x~w~)");
- TextDrawBackgroundColor(pblock_title, 255);
- TextDrawFont(pblock_title, 2);
- TextDrawLetterSize(pblock_title, 0.439999, 2.099999);
- TextDrawColor(pblock_title, -1);
- TextDrawSetOutline(pblock_title, 1);
- TextDrawSetProportional(pblock_title, 1);
- TextDrawUseBox(pblock_title, 1);
- TextDrawBoxColor(pblock_title, 87875741);
- TextDrawTextSize(pblock_title, 421.000000, 0.000000);
- pblock_score = TextDrawCreate(419.000000, 379.000000, "SCORE: 1003");
- TextDrawAlignment(pblock_score, 3);
- TextDrawBackgroundColor(pblock_score, 255);
- TextDrawFont(pblock_score, 2);
- TextDrawLetterSize(pblock_score, 0.370000, 1.900001);
- TextDrawColor(pblock_score, -1);
- TextDrawSetOutline(pblock_score, 1);
- TextDrawSetProportional(pblock_score, 1);
- pblock_background2 = TextDrawCreate(244.000000, 44.000000, "_");
- TextDrawBackgroundColor(pblock_background2, 255);
- TextDrawFont(pblock_background2, 1);
- TextDrawLetterSize(pblock_background2, 0.500000, 36.999984);
- TextDrawColor(pblock_background2, -1);
- TextDrawSetOutline(pblock_background2, 0);
- TextDrawSetProportional(pblock_background2, 1);
- TextDrawSetShadow(pblock_background2, 1);
- TextDrawUseBox(pblock_background2, 1);
- TextDrawBoxColor(pblock_background2, 673720575);
- TextDrawTextSize(pblock_background2, 404.000000, 0.000000);
- 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");
- TextDrawBackgroundColor(pblock_table, 255);
- TextDrawFont(pblock_table, 2);
- TextDrawLetterSize(pblock_table, 1.049998, 3.699997);
- TextDrawColor(pblock_table, -1);
- TextDrawSetOutline(pblock_table, 1);
- TextDrawSetProportional(pblock_table, 0);
- if (funcidx("PBlock_OnGameModeInit") != -1)
- {
- return CallLocalFunction("PBlock_OnGameModeInit", "");
- }
- return 1;
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit PBlock_OnGameModeInit
- forward PBlock_OnGameModeInit();
- //============================================================ONPLAYERDISCONNECT
- public OnPlayerDisconnect(playerid, reason)
- {
- PBlock_ExitGame(playerid);
- if (funcidx("PBlock_OnPlayerDisconnect") != -1)
- {
- return CallLocalFunction("PBlock_OnPlayerDisconnect", "dd", playerid, reason);
- }
- return 1;
- }
- #if defined _ALS_OnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define _ALS_OnPlayerDisconnect
- #endif
- #define OnPlayerDisconnect PBlock_OnPlayerDisconnect
- forward PBlock_OnPlayerDisconnect(playerid, reason);
- //================================================================CREATENEWBLOCK
- stock PBlock_Create_NewBlock(playerid)
- {
- if(block_table[playerid][2][9] != NO_BLOCK)
- {
- PBlock_GameOver(playerid);
- return 0;
- }
- moving_block[playerid] = {2, 9};
- block_table[playerid][2][9] = random(WHITE_BLOCK)+1;
- PBlock_Refresh_Textdraw(playerid);
- return 1;
- }
- //===============================================================PBLOCKSTARTGAME
- stock PBlock_StartGame(playerid)
- {
- PB_PlaySound(playerid, 1076);
- TogglePlayerControllable(playerid, 0);
- player_scores[playerid] = 0;
- TextDrawSetString(pblock_score, "Score: 0");
- TextDrawShowForPlayer(playerid, pblock_background);
- TextDrawShowForPlayer(playerid, pblock_background2);
- TextDrawShowForPlayer(playerid, pblock_title);
- TextDrawShowForPlayer(playerid, pblock_score);
- TextDrawSetString(pblock_table, ""); //Resetting table.
- TextDrawShowForPlayer(playerid, pblock_table);
- ShowPlayerDialog(playerid, DIALOG_PBLOCK, 0, "{157FFF}P{FFCA16}Block {C1C1C1}- v1.1", " {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 or a row \n 3 or more squares of the same color.\nHave fun!\n-{157FFF}Phanto","Play!", "Exit");
- return 1;
- }
- //=================================================================PBLOCKEXITGAME
- stock PBlock_ExitGame(playerid)
- {
- PB_PlaySound(playerid, 1077);
- TextDrawHideForPlayer(playerid, pblock_background);
- TextDrawHideForPlayer(playerid, pblock_background2);
- TextDrawHideForPlayer(playerid, pblock_title);
- TextDrawHideForPlayer(playerid, pblock_score);
- TextDrawSetString(pblock_table, ""); //Resetting table.
- TextDrawHideForPlayer(playerid, pblock_table);
- KillTimer(pblock_timer[playerid]);
- pblock_isplaying[playerid] = false;
- TogglePlayerControllable(playerid, 1);
- return 1;
- }
- //===============================================================PBLOCKSTARTGAME
- stock PBlock_GameStart(playerid)
- {
- for(new i; i<5; i++)
- {
- for(new j; j<10; j++)
- {
- block_table[playerid][i][j] = NO_BLOCK; //Resetting block info
- }
- }
- GameTextForPlayer(playerid, "~g~~h~~h~GAME STARTS!", 3000, 1);
- PBlock_Create_NewBlock(playerid);
- pblock_isplaying[playerid] = true;
- pblock_timer[playerid] = SetTimerEx("PBlock_Fall", 1000, true, "d", playerid);
- return 1;
- }
- //================================================================PBLOCKGAMEOVER
- stock PBlock_GameOver(playerid)
- {
- pblock_isplaying[playerid] = false;
- GameTextForPlayer(playerid, "~r~GAME OVER", 3000, 1);
- KillTimer(pblock_timer[playerid]);
- ShowPlayerDialog(playerid, DIALOG_PBLOCK, 0, "{157FFF}P{FFCA16}Block {C1C1C1}- v1.1", " {157FFF}PBlock Minigame\n\n{EA3E13}You Lost{C1C1C1}!","Retry!", "Exit");
- return 1;
- }
- //====================================================================PBLOCKFALL
- forward PBlock_Fall(playerid);
- public PBlock_Fall(playerid)
- {
- if(!moving_block[playerid][1] || block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]-1] != NO_BLOCK)
- {
- new bool: all_blocks_deleted = false;
- while(!all_blocks_deleted)
- {
- if(!PBlock_Deleting_Block(playerid))
- all_blocks_deleted = true;
- }
- PBlock_Create_NewBlock(playerid);
- return 1;
- }
- PB_PlaySound(playerid, 1131);
- block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]-1] = block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]];
- block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]] = NO_BLOCK;
- moving_block[playerid][1]--;
- PBlock_Refresh_Textdraw(playerid);
- return 1;
- }
- //=========================================================PBLOCKREFRESHTEXTDRAW
- stock PBlock_Refresh_Textdraw(playerid)
- {
- new text_string[580];
- for(new p_y = 9; p_y >= 0; p_y--)
- {
- for(new p_x; p_x < 5; p_x++)
- {
- switch(block_table[playerid][p_x][p_y])
- {
- case NO_BLOCK: strins(text_string, " ", strlen(text_string), 580);
- case RED_BLOCK: strins(text_string, "~r~~h~O", strlen(text_string), 580);
- case BLUE_BLOCK: strins(text_string, "~b~~h~O", strlen(text_string), 580);
- case LIGHTBLUE_BLOCK: strins(text_string, "~b~~h~~h~O", strlen(text_string), 580);
- case YELLOW_BLOCK: strins(text_string, "~y~O", strlen(text_string), 580);
- case PURPLE_BLOCK: strins(text_string, "~p~O", strlen(text_string), 580);
- case GREEN_BLOCK: strins(text_string, "~g~O", strlen(text_string), 580);
- case LIGHTGREEN_BLOCK: strins(text_string, "~g~~h~~h~O", strlen(text_string), 580);
- case WHITE_BLOCK: strins(text_string, "~w~O", strlen(text_string), 580);
- }
- if(p_x == 4)
- {
- strins(text_string, "~n~", strlen(text_string), 580);
- }
- }
- }
- TextDrawSetString(pblock_table, text_string);
- TextDrawShowForPlayer(playerid,pblock_table);
- return 1;
- }
- //============================================================CHECKBLOCKTODELETE
- stock PBlock_Deleting_Block(playerid)
- {
- enum info_check {last_block_type, amount};
- new pblock_check[info_check];
- new score_string[50];
- for(new p_x; p_x < 5; p_x++) //Checking columns
- {
- for(new p_y; p_y < 10; p_y++)
- {
- if(!p_y)
- {
- pblock_check[last_block_type] = block_table[playerid][p_x][p_y];
- pblock_check[amount] = 1;
- continue;
- }
- if(block_table[playerid][p_x][p_y] == pblock_check[last_block_type])
- {
- pblock_check[amount]++;
- continue;
- }
- else if(block_table[playerid][p_x][p_y] != pblock_check[last_block_type] || p_y == 5)
- {
- if(pblock_check[amount] >= 3 && pblock_check[last_block_type]!= NO_BLOCK)
- {
- player_scores[playerid]++;
- format(score_string, sizeof(score_string), "Score: %d", player_scores[playerid]);
- TextDrawSetString(pblock_score, score_string);
- TextDrawShowForPlayer(playerid, pblock_score);
- PB_PlaySound(playerid, 1057);
- for(new pb_del = p_y - pblock_check[amount]; pb_del < p_y; pb_del++)
- {
- block_table[playerid][p_x][pb_del] = NO_BLOCK;
- }
- }
- pblock_check[amount] = 1;
- pblock_check[last_block_type] = block_table[playerid][p_x][p_y];
- }
- }
- }
- pblock_check[amount] = 0;
- pblock_check[last_block_type] = NO_BLOCK;
- for(new p_y; p_y < 10; p_y++) //Checking rows
- {
- for(new p_x; p_x < 5; p_x++)
- {
- if(!p_x)
- {
- pblock_check[last_block_type] = block_table[playerid][p_x][p_y];
- pblock_check[amount] = 1;
- continue;
- }
- if(block_table[playerid][p_x][p_y] == pblock_check[last_block_type])
- {
- pblock_check[amount]++;
- continue;
- }
- else if(block_table[playerid][p_x][p_y] != pblock_check[last_block_type] || p_x == 5)
- {
- if(pblock_check[amount] >= 3 && pblock_check[last_block_type]!= NO_BLOCK)
- {
- player_scores[playerid]++;
- format(score_string, sizeof(score_string), "Score: %d", player_scores[playerid]);
- TextDrawSetString(pblock_score, score_string);
- TextDrawShowForPlayer(playerid, pblock_score);
- PB_PlaySound(playerid, 1057);
- for(new pb_del = p_x - pblock_check[amount]; pb_del < p_x; pb_del++)
- {
- block_table[playerid][pb_del][p_y] = NO_BLOCK;
- PBlock_OrderColumn(playerid, pb_del);
- }
- return 1;
- }
- pblock_check[amount] = 1;
- pblock_check[last_block_type] = block_table[playerid][p_x][p_y];
- }
- }
- }
- PBlock_Refresh_Textdraw(playerid);
- return 0;
- }
- //=============================================================PBLOCKORDERCOLUMN
- stock PBlock_OrderColumn(playerid, p_x)
- {
- new bool:all_blocks_ordered = false;
- while(!all_blocks_ordered)
- {
- for(new p_y = 1; p_y < 10; p_y++)
- {
- if(block_table[playerid][p_x][p_y - 1] == NO_BLOCK)
- {
- block_table[playerid][p_x][p_y - 1] = block_table[playerid][p_x][p_y];
- block_table[playerid][p_x][p_y] = NO_BLOCK;
- }
- }
- if(PBlock_IsColumnOrdered(playerid, p_x))
- all_blocks_ordered = true;
- }
- return 1;
- }
- //=========================================================PBLOCKISCOLUMNORDERED
- PBlock_IsColumnOrdered(playerid, p_x)
- {
- new empty_block_coord = -1;
- for(new p_y; p_y < 10; p_y++)
- {
- if(block_table[playerid][p_x][p_y] == NO_BLOCK)
- empty_block_coord = p_y;
- if(block_table[playerid][p_x][p_y] != NO_BLOCK && empty_block_coord != -1)
- return 0;
- }
- return 1;
- }
- //==============================================================ONDIALOGRESPONSE
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DIALOG_PBLOCK)
- {
- if(!response)
- {
- PBlock_ExitGame(playerid);
- return 1;
- }
- PBlock_GameStart(playerid);
- return 1;
- }
- if (funcidx("PBlock_OnDialogResponse") != -1)
- {
- return CallLocalFunction("PBlock_OnDialogResponse", "dddds", playerid, dialogid, response, listitem, inputtext);
- }
- return 1;
- }
- #if defined _ALS_OnDialogResponse
- #undef OnDialogResponse
- #else
- #define _ALS_OnDialogResponse
- #endif
- #define OnDialogResponse PBlock_OnDialogResponse
- forward PBlock_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
- //================================================================ONPLAYERUPDATE
- public OnPlayerUpdate(playerid)
- {
- new pb_keys, pb_updown, pb_leftright;
- GetPlayerKeys(playerid, pb_keys, pb_updown, pb_leftright);
- if(pb_leftright == 128 || pb_leftright == -128)
- {
- OnPlayerKeyStateChange(playerid, pb_leftright, 0); //Left & Right keys doesn't recall OnPlayerKeyStateChange, so we need to recall ourself
- }
- if (funcidx("PBlock_OnPlayerUpdate") != -1)
- {
- return CallLocalFunction("PBlock_OnPlayerUpdate", "d", playerid);
- }
- return 1;
- }
- #if defined _ALS_OnPlayerUpdate
- #undef OnPlayerUpdate
- #else
- #define _ALS_OnPlayerUpdate
- #endif
- #define OnPlayerUpdate PBlock_OnPlayerUpdate
- forward PBlock_OnPlayerUpdate(playerid);
- //========================================================ONPLAYERKEYSTATECHANGE
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(just_pressed_key[playerid]) return 1; //To prevent "double movement" of the moving block
- if(pblock_isplaying[playerid])
- {
- if(PRESSED(KEY_LEFT))
- {
- if(!moving_block[playerid][0] || block_table[playerid][moving_block[playerid][0]-1][moving_block[playerid][1]] != NO_BLOCK) return 1;
- PB_PlaySound(playerid, 1131);
- block_table[playerid][moving_block[playerid][0]-1][moving_block[playerid][1]] = block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]];
- block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]] = NO_BLOCK;
- moving_block[playerid][0]--;
- PBlock_Refresh_Textdraw(playerid);
- just_pressed_key[playerid] = true;
- SetTimerEx("Remove_JustPressed", 300, false, "d", playerid);
- return 1;
- }
- if(PRESSED(KEY_RIGHT))
- {
- if(moving_block[playerid][0] == 4 || block_table[playerid][moving_block[playerid][0]+1][moving_block[playerid][1]] != NO_BLOCK) return 1;
- PB_PlaySound(playerid, 1131);
- block_table[playerid][moving_block[playerid][0]+1][moving_block[playerid][1]] = block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]];
- block_table[playerid][moving_block[playerid][0]][moving_block[playerid][1]] = NO_BLOCK;
- moving_block[playerid][0]++;
- PBlock_Refresh_Textdraw(playerid);
- just_pressed_key[playerid] = true;
- SetTimerEx("Remove_JustPressed", 300, false, "d", playerid);
- return 1;
- }
- }
- if (funcidx("PBlock_OnPlayerKeyStateChange") != -1)
- {
- return CallLocalFunction("PBlock_OnPlayerKeyStateChange", "ddd", playerid, newkeys, oldkeys);
- }
- return 1;
- }
- #if defined _ALS_OnPlayerKeyStateChange
- #undef OnPlayerKeyStateChange
- #else
- #define _ALS_OnPlayerKeyStateChange
- #endif
- #define OnPlayerKeyStateChange PBlock_OnPlayerKeyStateChange
- forward PBlock_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
- //=============================================================REMOVEJUSTPRESSED
- forward Remove_JustPressed(playerid);
- public Remove_JustPressed(playerid)
- {
- just_pressed_key[playerid] = false;
- return 1;
- }
- //===================================================================PBPLAYSOUND
- stock PB_PlaySound(playerid, soundid)
- {
- new Float:pb_xpos, Float:pb_ypos, Float:pb_zpos;
- GetPlayerPos(playerid, pb_xpos, pb_ypos, pb_zpos);
- PlayerPlaySound(playerid, soundid, pb_xpos, pb_ypos, pb_zpos);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement