08.02.2018, 21:07
posY - this will store your textdraw Y position
height - this will be your textdraw height (TextSize)
startY - put in your default position of scrollbar (where the scroll bar starts from)
maxHeight - maximum height the scollbar can have, expand your scrollbar to max and note the TextSize of Y
totalItems - how many items are there in your list
pageSize - how many items a page can display
currentPage - by default your scrollbar will start from 0, you can set this to whatever page you wish to start from
Note: Use font type 4 for making scrollbar textdraw, the algorithm works perfectly for it. Recommended to use "LD_SPAC:WHITE" or "LD_SPAC:BLACK" sprites.
Example usage: (why not)
height - this will be your textdraw height (TextSize)
startY - put in your default position of scrollbar (where the scroll bar starts from)
maxHeight - maximum height the scollbar can have, expand your scrollbar to max and note the TextSize of Y
totalItems - how many items are there in your list
pageSize - how many items a page can display
currentPage - by default your scrollbar will start from 0, you can set this to whatever page you wish to start from
PHP код:
stock ScrollBar(&Float:posY, &Float:height, Float:startY, Float:maxHeight, totalItems, pageSize, currentPage = 0) {
// calculate how many pages can be possible
new pages = (totalItems / pageSize) + ((totalItems % pageSize) ? 1 : 0);
// scrollbar height (Y-axis)
height = (maxHeight / pages);
// scrollbar position (Y-axis)
// the position adjust with the page number you set in "currentPage" (0 = startY)
posY = startY;
posY += (height * currentPage);
}
Example usage: (why not)
PHP код:
new PlayerText:scrollPTD[MAX_PLAYERS];
public OnPlayerConnect(playerid) {
new Float:y, Float:height;
ScrollBar(y, height, 166.5, 108.0, 100, 10); // 100 items and each page handles 10 items
scrollPTD[playerid] = CreatePlayerTextDraw(playerid, 489.0000, y, "LD_SPAC:WHITE");
PlayerTextDrawFont(playerid, scrollPTD[playerid], 4);
PlayerTextDrawLetterSize(playerid, scrollPTD[playerid], 0.0000, 18.2000);
PlayerTextDrawColor(playerid, scrollPTD[playerid], -16776961);
PlayerTextDrawSetShadow(playerid, scrollPTD[playerid], 0);
PlayerTextDrawSetOutline(playerid, scrollPTD[playerid], 0);
PlayerTextDrawBackgroundColor(playerid, scrollPTD[playerid], 255);
PlayerTextDrawSetProportional(playerid, scrollPTD[playerid], 1);
PlayerTextDrawUseBox(playerid, scrollPTD[playerid], 1);
PlayerTextDrawBoxColor(playerid, scrollPTD[playerid], 150);
PlayerTextDrawTextSize(playerid, scrollPTD[playerid], 7.5000, height);
PlayerTextDrawShow(playerid, scrollPTD[playerid]);
}