Смена скина - Samp 0.3x

Уроки по скриптингу

Moderator: SJplayer

Avatar
Topic author
Дим M
Администратор
Администратор
Posts: 1319
With us: 7 years 5 months

Смена скина - Samp 0.3x

Post #1by Дим » 6 May 2013, 11:44

Смена скина - Samp 0.3x

Image


Ко всем include нужно добавить:

Code: Select all

#include <gl_common>   


Ко всем define нужно добавить:

Code: Select all

#define TOTAL_ITEMS         300
#define SELECTION_ITEMS     21
#define ITEMS_PER_LINE      7

#define HEADER_TEXT "Skins"
#define NEXT_TEXT   "Next"
#define PREV_TEXT   "Prev"

#define DIALOG_BASE_X       75.0
#define DIALOG_BASE_Y       130.0
#define DIALOG_WIDTH        550.0
#define DIALOG_HEIGHT       180.0
#define SPRITE_DIM_X        60.0
#define SPRITE_DIM_Y        70.0   


Ко всем new нужно добавить:

Code: Select all

new gTotalItems TOTAL_ITEMS;
new 
PlayerText:gCurrentPageTextDrawId[MAX_PLAYERS];
new 
PlayerText:gHeaderTextDrawId[MAX_PLAYERS];
new 
PlayerText:gBackgroundTextDrawId[MAX_PLAYERS];
new 
PlayerText:gNextButtonTextDrawId[MAX_PLAYERS];
new 
PlayerText:gPrevButtonTextDrawId[MAX_PLAYERS];
new 
PlayerText:gSelectionItems[MAX_PLAYERS][SELECTION_ITEMS];
new 
gSelectionItemsTag[MAX_PLAYERS][SELECTION_ITEMS];
new 
gItemAt[MAX_PLAYERS];

new 
gItemList[TOTAL_ITEMS] = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,
50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,
97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,
132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,
167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,
202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,
237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,
272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299
};  


Добавим функции, в любое место:

Code: Select all

GetNumberOfPages()
{
    if((
gTotalItems >= SELECTION_ITEMS) && (gTotalItems SELECTION_ITEMS) == 0)
    {
        return (
gTotalItems SELECTION_ITEMS);
    }
    else return (
gTotalItems SELECTION_ITEMS) + 1;
}

PlayerText:CreateCurrentPageTextDraw(playeridFloat:XposFloat:Ypos)
{
    new 
PlayerText:txtInit;
       
txtInit CreatePlayerTextDraw(playeridXposYpos"0/0");
       
PlayerTextDrawUseBox(playeridtxtInit0);
    
PlayerTextDrawLetterSize(playeridtxtInit0.41.1);
    
PlayerTextDrawFont(playeridtxtInit1);
    
PlayerTextDrawSetShadow(playeridtxtInit0);
    
PlayerTextDrawSetOutline(playeridtxtInit1);
    
PlayerTextDrawColor(playeridtxtInit0xACCBF1FF);
    
PlayerTextDrawShow(playeridtxtInit);
    return 
txtInit;
}

PlayerText:CreatePlayerDialogButton(playeridFloat:XposFloat:YposFloat:WidthFloat:Heightbutton_text[])
{
     new 
PlayerText:txtInit;
       
txtInit CreatePlayerTextDraw(playeridXposYposbutton_text);
       
PlayerTextDrawUseBox(playeridtxtInit1);
       
PlayerTextDrawBoxColor(playeridtxtInit0x000000FF);
       
PlayerTextDrawBackgroundColor(playeridtxtInit0x000000FF);
    
PlayerTextDrawLetterSize(playeridtxtInit0.41.1);
    
PlayerTextDrawFont(playeridtxtInit1);
    
PlayerTextDrawSetShadow(playeridtxtInit0); // no shadow
    
PlayerTextDrawSetOutline(playeridtxtInit0);
    
PlayerTextDrawColor(playeridtxtInit0x4A5A6BFF);
    
PlayerTextDrawSetSelectable(playeridtxtInit1);
    
PlayerTextDrawAlignment(playeridtxtInit2);
    
PlayerTextDrawTextSize(playeridtxtInitHeightWidth); // The width and height are reversed for centering.. something the game does <g>
    
PlayerTextDrawShow(playeridtxtInit);
    return 
txtInit;
}

PlayerText:CreatePlayerHeaderTextDraw(playeridFloat:XposFloat:Yposheader_text[])
{
    new 
PlayerText:txtInit;
       
txtInit CreatePlayerTextDraw(playeridXposYposheader_text);
       
PlayerTextDrawUseBox(playeridtxtInit0);
    
PlayerTextDrawLetterSize(playeridtxtInit1.253.0);
    
PlayerTextDrawFont(playeridtxtInit0);
    
PlayerTextDrawSetShadow(playeridtxtInit0);
    
PlayerTextDrawSetOutline(playeridtxtInit1);
    
PlayerTextDrawColor(playeridtxtInit0xACCBF1FF);
    
PlayerTextDrawShow(playeridtxtInit);
    return 
txtInit;
}

PlayerText:CreatePlayerBackgroundTextDraw(playeridFloat:XposFloat:YposFloat:WidthFloat:Height)
{
    new 
PlayerText:txtBackground CreatePlayerTextDraw(playeridXposYpos,
    
"                                            ~n~"); // enough space for everyone
    
PlayerTextDrawUseBox(playeridtxtBackground1);
    
PlayerTextDrawBoxColor(playeridtxtBackground0x4A5A6BBB);
    
PlayerTextDrawLetterSize(playeridtxtBackground5.05.0);
    
PlayerTextDrawFont(playeridtxtBackground0);
    
PlayerTextDrawSetShadow(playeridtxtBackground0);
    
PlayerTextDrawSetOutline(playeridtxtBackground0);
    
PlayerTextDrawColor(playeridtxtBackground,0x000000FF);
    
PlayerTextDrawTextSize(playeridtxtBackgroundWidthHeight);
       
PlayerTextDrawBackgroundColor(playeridtxtBackground0x4A5A6BBB);
    
PlayerTextDrawShow(playeridtxtBackground);
    return 
txtBackground;
}

PlayerText:CreateModelPreviewTextDraw(playeridmodelindexFloat:XposFloat:YposFloat:widthFloat:height)
{
    new 
PlayerText:txtPlayerSprite CreatePlayerTextDraw(playeridXposYpos""); // it has to be set with SetText later
    
PlayerTextDrawFont(playeridtxtPlayerSpriteTEXT_DRAW_FONT_MODEL_PREVIEW);
    
PlayerTextDrawColor(playeridtxtPlayerSprite0xFFFFFFFF);
    
PlayerTextDrawBackgroundColor(playeridtxtPlayerSprite0x88888899);
    
PlayerTextDrawTextSize(playeridtxtPlayerSpritewidthheight); // Text size is the Width:Height
    
PlayerTextDrawSetPreviewModel(playeridtxtPlayerSpritemodelindex);
    
PlayerTextDrawSetSelectable(playeridtxtPlayerSprite1);
    
PlayerTextDrawShow(playerid,txtPlayerSprite);
    return 
txtPlayerSprite;
}

DestroyPlayerModelPreviews(playerid)
{
    new 
x=0;
    while(
!= SELECTION_ITEMS) {
        if(
gSelectionItems[playerid][x] != PlayerText:INVALID_TEXT_DRAW) {
            
PlayerTextDrawDestroy(playeridgSelectionItems[playerid][x]);
            
gSelectionItems[playerid][x] = PlayerText:INVALID_TEXT_DRAW;
        }
        
x++;
    }
}

ShowPlayerModelPreviews(playerid)
{
    new 
x=0;
    new 
Float:BaseX DIALOG_BASE_X;
    new 
Float:BaseY DIALOG_BASE_Y - (SPRITE_DIM_Y 0.33); // down a bit
    
new linetracker 0;
    
    new 
itemat GetPVarInt(playerid"skinc_page") * SELECTION_ITEMS;
    
    
// Destroy any previous ones created
    
DestroyPlayerModelPreviews(playerid);

    while(
!= SELECTION_ITEMS && itemat gTotalItems) {
        if(
linetracker == 0) {
            
BaseX DIALOG_BASE_X 25.0// in a bit from the box
            
BaseY += SPRITE_DIM_Y 1.0// move on the Y for the next line
        
}
          
gSelectionItems[playerid][x] = CreateModelPreviewTextDraw(playeridgItemList[itemat], BaseXBaseYSPRITE_DIM_XSPRITE_DIM_Y);
          
gSelectionItemsTag[playerid][x] = gItemList[itemat];
        
BaseX += SPRITE_DIM_X 1.0// move on the X for the next sprite
        
linetracker++;
        if(
linetracker == ITEMS_PER_LINElinetracker 0;
        
itemat++;
        
x++;
    }
}


UpdatePageTextDraw(playerid)
{
    new 
PageText[64+1];
    
format(PageText64"%d/%d"GetPVarInt(playerid,"skinc_page") + 1GetNumberOfPages());
    
PlayerTextDrawSetString(playeridgCurrentPageTextDrawId[playerid], PageText);
}


CreateSelectionMenu(playerid)
{
    
gBackgroundTextDrawId[playerid] = CreatePlayerBackgroundTextDraw(playeridDIALOG_BASE_XDIALOG_BASE_Y 20.0DIALOG_WIDTHDIALOG_HEIGHT);
    
gHeaderTextDrawId[playerid] = CreatePlayerHeaderTextDraw(playeridDIALOG_BASE_XDIALOG_BASE_YHEADER_TEXT);
    
gCurrentPageTextDrawId[playerid] = CreateCurrentPageTextDraw(playeridDIALOG_WIDTH 30.0DIALOG_BASE_Y 15.0);
    
gNextButtonTextDrawId[playerid] = CreatePlayerDialogButton(playeridDIALOG_WIDTH 30.0DIALOG_BASE_Y+DIALOG_HEIGHT+100.050.016.0NEXT_TEXT);
    
gPrevButtonTextDrawId[playerid] = CreatePlayerDialogButton(playeridDIALOG_WIDTH 90.0DIALOG_BASE_Y+DIALOG_HEIGHT+100.050.016.0PREV_TEXT);

    
ShowPlayerModelPreviews(playerid);
    
UpdatePageTextDraw(playerid);
}

DestroySelectionMenu(playerid)
{
    
DestroyPlayerModelPreviews(playerid);

    
PlayerTextDrawDestroy(playeridgHeaderTextDrawId[playerid]);
    
PlayerTextDrawDestroy(playeridgBackgroundTextDrawId[playerid]);
    
PlayerTextDrawDestroy(playeridgCurrentPageTextDrawId[playerid]);
    
PlayerTextDrawDestroy(playeridgNextButtonTextDrawId[playerid]);
    
PlayerTextDrawDestroy(playeridgPrevButtonTextDrawId[playerid]);

    
gHeaderTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
    
gBackgroundTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
    
gCurrentPageTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
    
gNextButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
    
gPrevButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
}

HandlePlayerItemSelection(playeridselecteditem)
{
    
// In this case we change the player's skin
      
if(gSelectionItemsTag[playerid][selecteditem] >= && gSelectionItemsTag[playerid][selecteditem] < 300) {
        
SetPlayerSkin(playeridgSelectionItemsTag[playerid][selecteditem]);
        return;
    }
}   


в public OnPlayerConnect(playerid) добавим:

Code: Select all

gHeaderTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
gBackgroundTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
gCurrentPageTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
gNextButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
gPrevButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
for(new 
x=0SELECTION_ITEMSx++) {
gSelectionItems[playerid][x] = PlayerText:INVALID_TEXT_DRAW;
}
gItemAt[playerid] = 0;
return 
1;   


Добавить в любой место:

Code: Select all

public OnPlayerClickPlayerTextDraw(playeridPlayerText:playertextid)
{
    if(
GetPVarInt(playerid"skinc_active") == 0) return 0;
    new 
curpage GetPVarInt(playerid"skinc_page");
    if(
playertextid == gNextButtonTextDrawId[playerid]) {
        if(
curpage < (GetNumberOfPages() - 1)) {
            
SetPVarInt(playerid"skinc_page"curpage 1);
            
ShowPlayerModelPreviews(playerid);
             
UpdatePageTextDraw(playerid);
             
PlayerPlaySound(playerid10830.00.00.0);
        } else {
            
PlayerPlaySound(playerid10850.00.00.0);
        }
        return 
1;
    }
    if(
playertextid == gPrevButtonTextDrawId[playerid]) {
        if(
curpage 0) {
            
SetPVarInt(playerid"skinc_page"curpage 1);
            
ShowPlayerModelPreviews(playerid);
            
UpdatePageTextDraw(playerid);
            
PlayerPlaySound(playerid10840.00.00.0);
        } else {
            
PlayerPlaySound(playerid10850.00.00.0);
        }
        return 
1;
    }
    new 
x=0;
    while(
!= SELECTION_ITEMS) {
        if(
playertextid == gSelectionItems[playerid][x]) {
            
HandlePlayerItemSelection(playeridx);
            
PlayerPlaySound(playerid10830.00.00.0);
            
DestroySelectionMenu(playerid);
            
CancelSelectTextDraw(playerid);
            
SetPVarInt(playerid"skinc_active"0);
            return 
1;
        }
        
x++;
    }
    return 
0;

 


Теперь надо создать команду в OnPlayerCommandText(playerid, cmdtext[])

Code: Select all

        if(strcmp("/skinchange"cmdtrue) == 0)
    {
        
DestroySelectionMenu(playerid);
        
SetPVarInt(playerid"skinc_active"1);
        
CreateSelectionMenu(playerid);
        
SelectTextDraw(playerid0xACCBF1FF);
        return 
1;
    }   
i love you mxIni Mysql

! ! !


  • Similar Topics
    Replies
    Views
    Last post

Return to “Уроки”

Who is online

Users browsing this forum: 1 guest
Bots: Google [Bot]