[Include] [0.3X] mSelection 1.1 R3 - Create Model Preview Menus with a few lines of code
#1

mSelection(For SA-MP 0.3x and above)

(Translation: German translation/Deutsche Ьbersetzung
)

A include which adds the possibility to create Model Preview Menus with only a few lines of code.

Updates
- 1.1 R3
Fixes Bug with blocking OnPlayerClick(Player)TextDraw
The selection menu instantly closed in all earlier verions if used/shown in OnDialogResponse

- 1.1 R2
Fixes bug when pressing ESC

- 1.1
Fixes bug when pressing ESC
Adds dynamic per player menus
Adds "cancel" button to the menus

- 1.0 R3:
Fixes bug with using ShowModelSelectionMenu in OnPlayerModelSelection

- 1.0 R2:
Adds possibility to use ShowModelSelectionMenu in OnPlayerModelSelection

Overview

pawn Код:
// for both (static and per player lists)
HideModelSelectionMenu(playerid)
//static lists
LoadModelSelectionMenu(f_name[])
ShowModelSelectionMenu(playerid, ListID, header_text[], dialogBGcolor = 0x4A5A6BBB, previewBGcolor = 0x88888899 , tdSelectionColor = 0xFFFF00AA)

forward OnPlayerModelSelection(playerid, response, listid, modelid);
//dynamic per player lists
ShowModelSelectionMenuEx(playerid, items_array[], item_amount, header_text[], extraid, Float:Xrot = 0.0, Float:Yrot = 0.0, Float:Zrot = 0.0, Float:mZoom = 1.0, dialogBGcolor = 0x4A5A6BBB, previewBGcolor = 0x88888899 , tdSelectionColor = 0xFFFF00AA)

forward OnPlayerModelSelectionEx(playerid, response, extraid, modelid);
  • LoadModelSlectionMenu(f_name[])
    Loads the menu content from a file and returns the listid.
    1. f_name[]: Filename of the list in your scriptfiles folder
    2. returns: ID of the list
    File:
    Every line looks like: modelID xRot yRot zRot Zoom (The red ones are optional and don't have to be added)

    Example Infernus ID 411:
    Код:
    411
    411 180.0
    411 0.0 180.0
    411 0.0 0.0 180.0
    411 0.0 0.0 0.0 1.0
    All 4 examples are possible and will show an Infernus with different rotations set.

    Example all planes: planes.txt
    Код:
    460 16.0 0.0 -55.0
    476 16.0 0.0 -55.0
    511 16.0 0.0 -55.0
    512 16.0 0.0 -55.0
    513 16.0 0.0 -55.0
    519 16.0 0.0 -55.0
    520 16.0 0.0 -55.0
    553 16.0 0.0 -55.0
    577 16.0 0.0 -55.0
    592 16.0 0.0 -55.0
    593 16.0 0.0 -55.0
    Note:
    If more models use the same rotation/zoom information then the information will only be saved once to save memory.(For example 100 vehicles with the same rotation will only need one rotation to be saved)

  • HideModelSelectionMenu(playerid)
    Hide menu for player.
    1. playerid: playerid
    2. returns: nothing

  • ShowModelSelectionMenu(playerid, ListID, header_text[], dialogBGcolor = 0x4A5A6BBB, previewBGcolor = 0x88888899 , tdSelectionColor = 0xFFFF00AA)
    Show menu for player.
    1. playerid: playerid
    2. ListID: The ID of the list/menu to be shown
    3. header_test[]: heading of the list/menu
    4. dialogBGcolor(optional): Look at the picture below for the color (*1)
    5. previewBGcolor(optional): Look at the picture below for the color (*2)
    6. tdSelectionColor(optional): Look at the picture below for the color (*3)
    7. returns: 1 success, 0 failed


  • OnPlayerModelSelection(playerid, response, listid, modelid)
    Called when a player selects a model or pressing esc
    1. playerid: playerid
    2. response: 1 = Model selected, 0 = canceled (esc)
    3. listid: The ID of the list
    4. modelid: selected model

  • ShowModelSelectionMenuEx(playerid, items_array[], item_amount, header_text[], extraid, Float:Xrot = 0.0, Float:Yrot = 0.0, Float:Zrot = 0.0, Float:mZoom = 1.0, dialogBGcolor = 0x4A5A6BBB, previewBGcolor = 0x88888899 , tdSelectionColor = 0xFFFF00AA)
    Show menu for player.
    1. playerid: playerid
    2. items_array[]: Array of items to be shown
    3. item_amount: Amount of items in items_array[] (For example: item_amount = 3 would show items_array[0-2])
    4. header_test[]: heading of the list/menu
    5. extraid: extraid which gets passed to OnPlayerModelSelectionEx after selection
    6. Xrot: X rotation for the previews
    7. Yrot: Y rotation for the previews
    8. Zrot: Z rotation for the previews
    9. mZoom: Zoom for the previews
    10. dialogBGcolor(optional): Look at the picture below for the color (*1)
    11. previewBGcolor(optional): Look at the picture below for the color (*2)
    12. tdSelectionColor(optional): Look at the picture below for the color (*3)
    13. returns: 1 success, 0 failed


  • OnPlayerModelSelectionEx(playerid, response, extraid, modelid)
    Called when a player selects a model or pressing esc
    1. playerid: playerid
    2. response: 1 = Model selected, 0 = canceled (esc)
    3. extraid: The extraid used in ShowModelSelectionMenuEx
    4. modelid: selected model
Example Script

Example #1 Static Lists
Scriptfiles: planes.txt - skins.txt
pawn Код:
#include <a_samp>
#include <mSelection>

new planelist = mS_INVALID_LISTID;
new skinlist = mS_INVALID_LISTID;
public OnFilterScriptInit()
{
    planelist = LoadModelSelectionMenu("planes.txt");
    skinlist = LoadModelSelectionMenu("skins.txt");
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/plane", true) == 0)
    {
        ShowModelSelectionMenu(playerid, planelist, "->Planes<-");
        return 1;
    }
    if(strcmp(cmdtext, "/changeskin", true) == 0)
    {
        ShowModelSelectionMenu(playerid, skinlist, "Select Skin");
        return 1;
    }
    return 0;
}

public OnPlayerModelSelection(playerid, response, listid, modelid)
{
    if(listid == planelist)
    {
        if(response)
        {
            SendClientMessage(playerid, 0xFF0000FF, "Plane Spawned");
            new Float:pos[3]; GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            CreateVehicle(modelid, pos[0] + 2.5, pos[1], pos[2] + 2.5, 0.0, random(128), random(128), -1);
        }
        else SendClientMessage(playerid, 0xFF0000FF, "Canceled plane selection");
        return 1;
    }
    if(listid == skinlist)
    {
        if(response)
        {
            SendClientMessage(playerid, 0xFF0000FF, "Skin Changed");
            SetPlayerSkin(playerid, modelid);
        }
        else SendClientMessage(playerid, 0xFF0000FF, "Canceled skin selection");
        return 1;
    }
    return 1;
}
Example #2 Dynamic per player lists
pawn Код:
#include <a_samp>
#include <mSelection>

#define CUSTOM_TRAILER_MENU 1

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/selectVehicleTrailer", true) == 0)
    {
        new cars[15];
        cars[0] = 435;
        cars[1] = 450;
        cars[2] = 569;
        cars[3] = 570;
        cars[4] = 584;
        cars[5] = 590;
        cars[6] = 591;
        cars[7] = 606;
        cars[8] = 607;
        cars[9] = 608;
        cars[10] = 610;
        cars[11] = 611;
        ShowModelSelectionMenuEx(playerid, cars, 12, "Select trailer", CUSTOM_TRAILER_MENU, 16.0, 0.0, -55.0);
        return 1;
    }
    return 0;
}

public OnPlayerModelSelectionEx(playerid, response, extraid, modelid)
{
    if(extraid == CUSTOM_TRAILER_MENU)
    {
        if(response)
        {
            SendClientMessage(playerid, 0xFF0000FF, "Trailer Spawned");
            new Float:pos[3]; GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            CreateVehicle(modelid, pos[0] + 2.5, pos[1], pos[2] + 2.5, 0.0, random(128), random(128), -1);
        }
        else SendClientMessage(playerid, 0xFF0000FF, "Canceled trailer selection");
    }
    return 1;
}
Thanks to:
Kye: for creating vspawner.pwn


Downloads:
Include+Example Script+Scriptfiles: View attachments
Reply
#2

omg, i even can't express all my feelings!! This is awesome dude! THank you a lot!
Reply
#3

Cool man thanks for it
You've maded it alot easier.
Reply
#4

Nice ! Thanks you.
Reply
#5

Nice work, will definitely come useful.
Reply
#6

Can you help me, i dont undestand why this doesn't work
pawn Код:
if(listid == mainvlist)
    {

        if(response)
        {

            if(modelid==519)
            {
     
            ShowModelSelectionMenu(playerid, planelist, "Planes");
            }
            if(modelid==487)
            {
            ShowModelSelectionMenu(playerid, helicopterslist, "Helicopters");
            }
            if(modelid==522)
            {
            ShowModelSelectionMenu(playerid, bikeslist, "Bikes");
            }
            if(modelid==560)
            {
            ShowModelSelectionMenu(playerid, carslist, "Cars");
            }
            if(modelid==452)
            {
            ShowModelSelectionMenu(playerid, boatslist, "Boats");
            }
            if(modelid==19336)
            {
            ShowModelSelectionMenu(playerid, specialslist, "Specials");
            }
            if(modelid==501)
            {
            ShowModelSelectionMenu(playerid, rclist, "RC vehicles");
            }
        }
        return 1;
    }
every thing is ok, there are all required files in script files, and i used LoadModelSelectionMenu in OnGameModeINnit
Reply
#7

Quote:
Originally Posted by pasha97
Посмотреть сообщение
Can you help me, i dont undestand why this doesn't work
pawn Код:
if(listid == mainvlist)
    {

        if(response)
        {

            if(modelid==519)
            {
     
            ShowModelSelectionMenu(playerid, planelist, "Planes");
            }
            if(modelid==487)
            {
            ShowModelSelectionMenu(playerid, helicopterslist, "Helicopters");
            }
            if(modelid==522)
            {
            ShowModelSelectionMenu(playerid, bikeslist, "Bikes");
            }
            if(modelid==560)
            {
            ShowModelSelectionMenu(playerid, carslist, "Cars");
            }
            if(modelid==452)
            {
            ShowModelSelectionMenu(playerid, boatslist, "Boats");
            }
            if(modelid==19336)
            {
            ShowModelSelectionMenu(playerid, specialslist, "Specials");
            }
            if(modelid==501)
            {
            ShowModelSelectionMenu(playerid, rclist, "RC vehicles");
            }
        }
        return 1;
    }
every thing is ok, there are all required files in script files, and i used LoadModelSelectionMenu in OnGameModeINnit
A bug with using ShowModelSelectionMenu inside of OnPlayerModelSelection

Download R2 from the first post to be able to use ShowModelSelectionMenu in OnPlayerModelSelection
Reply
#8

Quote:
Originally Posted by D0erfler
Посмотреть сообщение
A bug with using ShowModelSelectionMenu inside of OnPlayerModelSelection

Download R2 from the first post to be able to use ShowModelSelectionMenu in OnPlayerModelSelection
thank you! but it doesn't work The next selection meny appears for fiew moments and then dissapears again. It sounds like when i click the selection, the next selection menu autimatically cancels.
Reply
#9

Quote:
Originally Posted by pasha97
Посмотреть сообщение
thank you! but it doesn't work The next selection meny appears for fiew moments and then dissapears again.
Show the whole script please

Edit: I see the problem, CancelSelectTextDraw is called after the first selection and the client takes a while to respond to that function which causes the new menu to get hidden as soon the sa-mp client responses to CancelSelectTextDraw.
Will add something like a minimum time of having the menu open(~1 second) to fix it.

Check back in a few moments and download R3

Edit: It's fixed and tested now, download R3
and thanks for reporting the problem
Reply
#10

This looks pretty neat ,
but could you perhaps modify the menu so we are able to do the same as CreateMenu? So we can use AddMenuItem?
This would be super usefull whenever people want to script inventories.
Reply
#11

Quote:
Originally Posted by D0erfler
Посмотреть сообщение
Show the whole script please

Edit: I see the problem, CancelSelectTextDraw is called after the first selection and the client takes a while to respond to that function which causes the new menu to get hidden as soon the sa-mp client responses to CancelSelectTextDraw.
Will add something like a minimum time of having the menu open(~1 second) to fix it.

Check back in a few moments and download R3

Edit: It's fixed and tested now, download R3
and thanks for reporting the problem
Thank you a lot, i will try the R3 version tomorrow!
Reply
#12

Thank you for this very useful include,
It was annoying to edit the vspawner.pwn file accordingly to your needs, and this makes it much easier, I'll be using it now, but it is still static and can't use dynamic options, like with dialogs or menus. I'll not discard this include.
Reply
#13

Quote:
Originally Posted by admantis
Посмотреть сообщение
Thank you for this very useful include,
It was annoying to edit the vspawner.pwn file accordingly to your needs, and this makes it much easier, I'll be using it now, but it is still static and can't use dynamic options, like with dialogs or menus. I'll not discard this include.
I already added dynamic lists/menus for the next version, should be ready for tomorrow.
Reply
#14

Awesome, nice one
Reply
#15

Do you think you could add a version with a button to close it instead of choosing something?
Reply
#16

Quote:
Originally Posted by Memoryz
Посмотреть сообщение
Do you think you could add a version with a button to close it instead of choosing something?
You can press escape to close the menu, or you could create another button that will hide the selection textdraws.
Reply
#17

I think it would be awesome, if we could write titles for each item. Perhaps, we could write a title for an item in the file. SO, every line would look like that:

modelID Title xRot yRot zRot Zoom

For example,

445 Saloon 0.0 0.0 45.0 1.0
Reply
#18

pawn Код:
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(178) : error 017: undefined symbol "TEXT_DRAW_FONT_MODEL_PREVIEW"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(182) : error 017: undefined symbol "PlayerTextDrawSetPreviewModel"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(183) : error 017: undefined symbol "PlayerTextDrawSetPreviewRot"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(175) : warning 203: symbol is never used: "mZoom"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(175) : warning 203: symbol is never used: "Zrot"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(175) : warning 203: symbol is never used: "Yrot"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(175) : warning 203: symbol is never used: "Xrot"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(175) : warning 203: symbol is never used: "modelindex"
Any help?!
Reply
#19

Lol, thanks a lot I will use this!
Reply
#20

Quote:
Originally Posted by Kevin FOx
Посмотреть сообщение
pawn Код:
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(178) : error 017: undefined symbol "TEXT_DRAW_FONT_MODEL_PREVIEW"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(182) : error 017: undefined symbol "PlayerTextDrawSetPreviewModel"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(183) : error 017: undefined symbol "PlayerTextDrawSetPreviewRot"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(175) : warning 203: symbol is never used: "mZoom"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(175) : warning 203: symbol is never used: "Zrot"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(175) : warning 203: symbol is never used: "Yrot"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(175) : warning 203: symbol is never used: "Xrot"
C:\Users\sawab center\Desktop\samp03x_svr_RC1_win32\pawno\include\mSelection.inc(175) : warning 203: symbol is never used: "modelindex"
Any help?!
update your samp includes to 0.3x!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)