SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 12/01/2013, 02:42 PM   #1
d0
Beta Tester
 
d0's Avatar
 
Join Date: Oct 2007
Location: Germany
Posts: 434
Reputation: 135
Post [0.3X] mSelection 1.1 R3 - Create Model Preview Menus with a few lines of code

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 Code:
// 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:
    Code:
    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
    Code:
    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 Code:
#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 Code:
#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
Attached Files
File Type: zip mSelection1.1R3.zip (7.9 KB, 20188 views)
__________________
<3

Last edited by d0; 01/02/2013 at 09:34 PM.
d0 is offline   Reply With Quote
Old 12/01/2013, 02:48 PM   #2
pasha97
Gangsta
 
pasha97's Avatar
 
Join Date: Feb 2012
Location: Voronezh,Russia
Posts: 651
Reputation: 60
Default Re: [0.3X] mSelection 1.0 - Create Model Preview Menus with a few lines of code

omg, i even can't express all my feelings!! This is awesome dude! THank you a lot!
__________________
pasha97 is offline   Reply With Quote
Old 12/01/2013, 02:53 PM   #3
Black Wolf
Gangsta
 
Join Date: Mar 2009
Location: On the bed with your sister.
Posts: 505
Reputation: 166
Default Re: [0.3X] mSelection 1.0 - Create Model Preview Menus with a few lines of code

Cool man thanks for it
You've maded it alot easier.
__________________
<not allowed>
Black Wolf is offline   Reply With Quote
Old 12/01/2013, 03:16 PM   #4
oOFotherOo
Gangsta
 
oOFotherOo's Avatar
 
Join Date: May 2012
Location: Tokyo
Posts: 639
Reputation: 49
Default Respuesta: [0.3X] mSelection 1.0 - Create Model Preview Menus with a few lines of code

Nice ! Thanks you.
oOFotherOo is offline   Reply With Quote
Old 12/01/2013, 03:47 PM   #5
Mean
High-roller
 
Join Date: Jul 2010
Location: 14th annual lemon party
Posts: 2,726
Reputation: 229
Default Re: [0.3X] mSelection 1.0 - Create Model Preview Menus with a few lines of code

Nice work, will definitely come useful.
Mean is offline   Reply With Quote
Old 12/01/2013, 04:09 PM   #6
pasha97
Gangsta
 
pasha97's Avatar
 
Join Date: Feb 2012
Location: Voronezh,Russia
Posts: 651
Reputation: 60
Default Re: [0.3X] mSelection 1.0 - Create Model Preview Menus with a few lines of code

Can you help me, i dont undestand why this doesn't work
pawn Code:
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
__________________
pasha97 is offline   Reply With Quote
Old 12/01/2013, 04:31 PM   #7
d0
Beta Tester
 
d0's Avatar
 
Join Date: Oct 2007
Location: Germany
Posts: 434
Reputation: 135
Default Re: [0.3X] mSelection 1.0 - Create Model Preview Menus with a few lines of code

Quote:
Originally Posted by pasha97 View Post
Can you help me, i dont undestand why this doesn't work
pawn Code:
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
__________________
<3
d0 is offline   Reply With Quote
Old 12/01/2013, 04:37 PM   #8
pasha97
Gangsta
 
pasha97's Avatar
 
Join Date: Feb 2012
Location: Voronezh,Russia
Posts: 651
Reputation: 60
Default Re: [0.3X] mSelection 1.0 - Create Model Preview Menus with a few lines of code

Quote:
Originally Posted by D0erfler View Post
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.
__________________
pasha97 is offline   Reply With Quote
Old 12/01/2013, 04:56 PM   #9
d0
Beta Tester
 
d0's Avatar
 
Join Date: Oct 2007
Location: Germany
Posts: 434
Reputation: 135
Default Re: [0.3X] mSelection 1.0 - Create Model Preview Menus with a few lines of code

Quote:
Originally Posted by pasha97 View Post
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
__________________
<3
d0 is offline   Reply With Quote
Old 12/01/2013, 05:29 PM   #10
Baboon
Banned
 
Join Date: Nov 2010
Location: The Netherlands
Posts: 918
Reputation: 348
Default Re: [0.3X] mSelection 1.0 R2 - Create Model Preview Menus with a few lines of code

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.
Baboon is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IS there any way to hide black box around the model preview? pasha97 Scripting Help 2 09/01/2013 11:26 AM
How to create new lines Torran Help Archive 3 06/03/2010 04:58 PM
how to create menus? sandisk125 Help Archive 2 08/10/2009 08:45 PM
how to create an menus? sandisk125 Help Archive 2 10/08/2009 03:36 PM


All times are GMT. The time now is 03:22 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.