06.04.2015, 06:34
(
Last edited by Gammix; 14/10/2019 at 08:28 PM.
)
PreviewModelDialog.inc
Version: 4.7.2 || Last Updated: 14 October, 2019
This include introduces you to a new dialog style: "DIALOG_STYLE_PREVIEW_MODEL". A SA-MP looking like dialog with both standard buttons but with preview models in a list form!Version: 4.7.2 || Last Updated: 14 October, 2019
For preview of dialogs, skip down to examples for photos.
Functionality:
- No size limits
Because of Pawn-Memory, all listitems are allocated dynamically, that means you can have as many listitems a you want!
- No pre-allocation of memory
The memory for storing player dialog's listitems data is done during run-time, no pre-allocated memory at all! So no big .amx sizes!
- Big enough preview
A fairly large and intractable preview model listitem textdraw/button allowing you to clearly view models!
- Rotation and Zoom buttons
You can rotate Z-angle of each listitem while you are viewing the dialog, this is an in-game feature accessed by the player viewing the dialog.
Similarly, you have another couple buttons for increasing/decreasing model's zoom.
Preview:
- A perfect scroll bar
Scrollbar is made of Sprite (LD_SPAC:WHITE) allowing a perfect measurement of length according to page size!
- GameText codes in listitems
Since the dialog is made with pure textdraws, you can use label codes (e.g. ~n~ - switch line or ~r~ - red color) in preview model's labeltext.
- Hooked ShowPlayerDialog
Support samp dialog function "ShowPlayerDialog" and you can handle response under "OnDialogResponse". Check the examples for how to use.
- Adding custom rotation/color
You can set each model rotation using a simple string pattern while making the dialog's list.
Example:
We will make a list of 3 cars each set to rotation(0.0, 0.0, -50.0, 1.0).
Notice: The highlighted bracketed string, that's how you set rotation.
Code:400(0.0, 0.0, -50.0, 1.0)\tLandstalker\n\ 401(0.0, 0.0, -50.0, 1.0)\tBravura\n\ 402(0.0, 0.0, -50.0, 1.0)\tBuffalo
Here we will only modify the first car with rotation(0.0, 0.0, 0.0, 0.75) and also colors(0, 6).
Notice: The rest models will have default values for rotation(0.0, 0.0, -45.0, 1.0) and colors(-1, -1).
Code:522(0.0, 0.0, 0.0, 0.75, 0, 6)\tNRG-500\n\ 523\tHPV1000\n\ 521\tFCR-900
So basically this is the pattern for making listitems:
Code:modelid(ROTX, ROTY, ROTZ, ZOOM, COLOR1, COLOR2)\tTEXT
A simple skin selection dialog with all samp skins as listitems.
Source:
PHP Code:
CMD:skins(playerid) {
const MAX_SKINS = 312;
new subString[16];
static string[MAX_SKINS * sizeof(subString)];
if (string[0] == EOS) {
for (new i; i < MAX_SKINS; i++) {
format(subString, sizeof(subString), "%i\tID: %i\n", i, i);
strcat(string, subString);
}
}
return ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PREVIEW_MODEL, "Skin Selection Dialog", string, "Select", "Cancel");
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
if (dialogid == 0) {
if (response) {
SetPlayerSkin(playerid, listitem);
GameTextForPlayer(playerid, "~g~Skin Changed!", 3000, 3);
}
}
return 1;
}
A simple weapon shop dialog, you can modify the array, add/delete weapons from it and the dialog shape itself!
You can also see i used custom rotations for each listitem in this dialog.
Source:
PHP Code:
enum E_WEAPON_SHOP_DATA {
WEAPON_MODELID,
WEAPON_NAME[35],
WEAPON_PRICE,
WEAPON_AMMO,
WEAPON_ID
};
new const WEAPON_SHOP[][E_WEAPON_SHOP_DATA] = {
{335, "Knife", 0, 1, WEAPON_KNIFE},
{341, "Chainsaw", 1500, 1, WEAPON_CHAINSAW},
{342, "Grenade", 1545, 1, WEAPON_GRENADE},
{343, "Moltove", 1745, 1, WEAPON_MOLTOV},
{347, "Silenced 9mm", 1500, 150, WEAPON_SILENCED},
{348, "Desert Eagle", 3199, 150, WEAPON_DEAGLE},
{350, "Sawed Off Shotgun", 4999, 100, WEAPON_SAWEDOFF},
{351, "Spas12 Shotgun", 3870, 100, WEAPON_SHOTGSPA},
{352, "Micro-UZI", 3500, 300, WEAPON_UZI},
{353, "MP5", 2999, 200, WEAPON_MP5},
{372, "Tec-9", 3500, 300, WEAPON_TEC9},
{358, "Sniper Rifle", 4999, 50, WEAPON_SNIPER},
{355, "Ak47", 2999, 200, WEAPON_AK47},
{356, "M4", 3155, 200, WEAPON_M4},
{359, "RPG", 1999, 1, WEAPON_ROCKETLAUNCHER},
{361, "Flamethrower", 3500, 350, WEAPON_FLAMETHROWER},
{362, "Minigun", 10000, 350, WEAPON_MINIGUN},
{363, "Satchel Charge", 1999, 2, WEAPON_SATCHEL},
{365, "Spray Can", 800, 200, WEAPON_SPRAYCAN},
{366, "Fire Extinguisher", 855, 200, WEAPON_FIREEXTINGUISHER}
};
CMD:weapons(playerid) {
new subString[64];
static string[sizeof(WEAPON_SHOP) * sizeof(subString)];
if (string[0] == EOS) {
for (new i; i < sizeof(WEAPON_SHOP); i++) {
format(subString, sizeof(subString), "%i(0.0, 0.0, -50.0, 1.5)\t%s~n~~g~~h~$%i\n", WEAPON_SHOP[i][WEAPON_MODELID], WEAPON_SHOP[i][WEAPON_NAME], WEAPON_SHOP[i][WEAPON_PRICE]);
strcat(string, subString);
}
}
return ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PREVIEW_MODEL, "Weapon Shop Dialog", string, "Purchase", "Cancel");
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
if (dialogid == 1) {
if (response) {
if (GetPlayerMoney(playerid) < WEAPON_SHOP[listitem][WEAPON_PRICE]) {
SendClientMessage(playerid, 0xAA0000FF, "Not enough money to purchase this gun!");
return cmd_weapons(playerid);
}
GivePlayerMoney(playerid, -WEAPON_SHOP[listitem][WEAPON_PRICE]);
GivePlayerWeapon(playerid, WEAPON_SHOP[listitem][WEAPON_ID], WEAPON_SHOP[listitem][WEAPON_AMMO]);
GameTextForPlayer(playerid, "~g~Gun Purchased!", 3000, 3);
}
}
return 1;
}
PreviewModelDialog.inc: https://github.com/Agneese-Saini/SA-...ginVersion.inc
PreviewModelDialog.inc (plugin-free-version): https://github.com/Agneese-Saini/SA-...reeVersion.inc
If you are using the recommended version i.e. memory plugin version, you'll need to download and install Pawn-Memory plugin, link below.
pawn-memory.dll/.so: https://sampforum.blast.hk/showthread.php?tid=645166