Author Topic: Custom Menu System v1.0  (Read 10763 times)

0 Members and 1 Guest are viewing this topic.

Offline sseebbyy

  • VC:MP Veteran
  • *****
  • Posts: 774
  • Immortal VC:MP Player
    • View Profile
    • Zombie Invasion => Server Forum [DEAD PROJECT]
Custom Menu System v1.0
« on: September 17, 2014, 07:36:19 pm »
Custom Menu System v1.0



Since we are able to use textdraws, sprites, custom objects, weapons etc, it's time to create great and useful things, that will make us, and our players, enjoy the game very very much !!
It's our purpose to make our servers better and better !!

I am happy to present you the first Menu System ever made for Vice City Multiplayer !

It supports one submenu for every option shown in the main menu !

Here is the whole code you need:



I have made an example of menu, with submenus:

Add this to onScriptLoad
Code: [Select]
CreateMenu("Menu System","Option1","Option2","Option3","Option4","Option5","Option6","Option7","Option8");
menu[0].AddSubMenu(1,"Suboption1-nr1","Suboption1-nr2");
menu[0].AddSubMenu(2,"Suboption2-nr1","Suboption2-nr2","Suboption2-nr3");
menu[0].AddSubMenu(3,"Suboption3-nr1","Suboption3-nr2","Suboption3-nr3","Suboption3-nr4");
menu[0].AddSubMenu(4,"Suboption4-nr1","Suboption4-nr2","Suboption4-nr3","Suboption4-nr4","Suboption4-nr5");
menu[0].AddSubMenu(5,"Suboption5-nr1","Suboption5-nr2","Suboption5-nr3","Suboption5-nr4","Suboption5-nr5","Suboption5-nr6");
menu[0].AddSubMenu(6,"Suboption6-nr1","Suboption6-nr2","Suboption6-nr3","Suboption6-nr4","Suboption6-nr5","Suboption6-nr6","Suboption6-nr7");
menu[0].AddSubMenu(7,"Suboption7-nr1","Suboption7-nr2","Suboption7-nr3","Suboption7-nr4","Suboption7-nr5","Suboption&-nr6","Suboption7-nr7","Suboption7-nr8");
menu[0].AddSubMenu(8,"You","cannot","add","just","one","option !","The reason","is very logic.");

Then you create a command like this, to show you the menu:
Code: [Select]
if(cmd == "showfirstmenu")
{
          menu[0].ShowForPlayer(player);
}



I strongly suggest you to create menus and submenus onServerStart/onScriptLoad !!
Why ? Because you need to keep the evidence of the id of the menu you want to use, so you will not damage any other menu.

You can walk between options using UP and DOWN ARROWS, and when you choosed one, press SPACEBAR ! (just like in San Andreas)
When you think you don't need the custom menu anymore, press BACKSPACE, and it will be hidden again.
;)



Details
Every textdraw and sprite that is created by functions like CreateMenu and menu[menuid].AddSubMenu, is actually permanently on server, and them are shown just when needs to be.
That's why I suggest you to use it only in onServerStart/onScriptLoad.

other note: There are two events that are called when you select an option or a suboption.
(the events were added in the pastebin, but just forgot to give details about it)

This is called when a player choose an option from the main menu, that has no submenu:
Code: [Select]
onPlayerMenu(player, menuid, option)
{
}
menuid - the ID of the main menu. (the first menu created has ID 0)
option - option ID choosed by the player. (the first option from the menu has ID 1)

This is called when a player choose an option from a submenu of an option choosed in the main menu:
Code: [Select]
onPlayerSubMenu(player, submenuid, option)
{
}
submenuid - submenu ID - the option choosed in the main menu
option - ID of the option choosed in the submenu

Here is an example for every event:
http://pastebin.com/QSBJLhrF

And from here, you can download a .nut file with all you need to run the menu system, + the sprite you need:
http://www.solidfiles.com/d/c349cb0c34/Menu_System_by_Seby.rar
http://www.solidfiles.com/d/6cc4f83f60/menubackground.png



Credits
Scripter: Seby
Special thanks goes to those guys because I learnt important squirrel stuff from them:
heekz - he teached me how to create class
Knucis - told me about vargv, and how to use them
Gudio - for supporting me in this whole time (he knows what I mean :D), finding the problem when I thought there is no fix for it and teaching me squirrel important stuff.
« Last Edit: September 23, 2014, 03:54:38 pm by sseebbyy »

Quote
Painful/Noob scripters acts like: I Am The Best Scripter Because I Announce My Releases With Big Font Size Without Giving Too Much Info' In The Hope They All Will Download And Check It. I Ignore Bad Replies, Replies That I Could Learn From, And Replies With So Much Text.



Offline UkRs

  • Street Thug
  • *
  • Posts: 5
  • I am a NewBie Scripter and Banned From LU Forum :P
    • View Profile
Re: Dialog System v1.0
« Reply #1 on: September 17, 2014, 08:05:18 pm »
:O man u r making VC:MP in to SA:MP or even IV:MP :P

Offline Franklin

  • Wiseguy
  • **
  • Posts: 76
  • WiSeGuY
    • View Profile
Re: Dialog System v1.0
« Reply #2 on: September 17, 2014, 08:13:44 pm »
amazing  :)

Offline S.L.C

  • Street Thug
  • *
  • Posts: 42
  • Sorry if you weren't impressed!
    • View Profile
Re: Dialog System v1.0
« Reply #3 on: September 17, 2014, 08:25:22 pm »
Haha, I was working on a similar system for a mod I was playing with. The concept is similar to the menus in CS 1.6. Although I suggest that you make the dialogs saveable in XML, JSON or any structured format and then load them your self at server startup. This gives you the ability to introduce individual styling and keep the code clean. One more suggestion is to allow users to bind their own functions when a client interacts with a menu item. The function binding process shouldn't be too hard to implement in Squirrel.

Good job  ;)

PS:

This is a menu system and not a  dialog system. A dialog is a simple window that asks you something or requests some simple input. This is a dialog (actually a modal window) and this is a menu. Menu definition: "A menu is a collection of elements showing related user actions"
« Last Edit: September 17, 2014, 08:45:35 pm by S.L.C »

Offline sseebbyy

  • VC:MP Veteran
  • *****
  • Posts: 774
  • Immortal VC:MP Player
    • View Profile
    • Zombie Invasion => Server Forum [DEAD PROJECT]
Re: Dialog System v1.0
« Reply #4 on: September 17, 2014, 09:54:05 pm »
One more suggestion is to allow users to bind their own functions when a client interacts with a menu item.

Damn... forgot to give details about it.
It is already implemented...

There are two events, onPlayerDialog (when a player choose an option that has no submenu) and onPlayerSubDialog (when a player choose an option from the submenu of a main option)

I will add more info in the first post.

EDIT: The first post was updated.

Although I suggest that you make the dialogs saveable in XML, JSON or any structured format and then load them your self at server startup.
I will not do that. Anyone can edit it, but keep the original credits !
« Last Edit: September 17, 2014, 10:27:45 pm by sseebbyy »

Quote
Painful/Noob scripters acts like: I Am The Best Scripter Because I Announce My Releases With Big Font Size Without Giving Too Much Info' In The Hope They All Will Download And Check It. I Ignore Bad Replies, Replies That I Could Learn From, And Replies With So Much Text.



Offline George

  • Street Thug
  • *
  • Posts: 32
    • View Profile
Re: Dialog System v1.0
« Reply #5 on: September 18, 2014, 12:25:37 am »
Splendorous! :)
Nice job!

It's a great job, I had to say once again. But I think VCMP should give us a proper dialog system based on CEGUI library that I think it uses. Like LU does. ( i guess :P )
(LBR)George, XE Head Scripter, Xs Developer, LBR's founder, playing VCMP since 2009

Offline stormeus

  • VC:MP Developer
  • VC:MP Veteran
  • *
  • Posts: 1122
    • View Profile
Re: Dialog System v1.0
« Reply #6 on: September 18, 2014, 04:49:15 am »
I think VCMP should give us a proper dialog system based on CEGUI library that I think it uses

We plan on adding a GUI system in the future. We don't plan on using CEGUI for performance reasons.
Do not PM me for support.




Offline George

  • Street Thug
  • *
  • Posts: 32
    • View Profile
Re: Dialog System v1.0
« Reply #7 on: September 18, 2014, 06:17:31 am »
I think VCMP should give us a proper dialog system based on CEGUI library that I think it uses

We plan on adding a GUI system in the future. We don't plan on using CEGUI for performance reasons.
LU uses a GUI system, I don't know what library is that but seems be pretty good on performance, should you use it, or do you have another thing in mind?

And sorry for the off topic, but I'm really curious about that. :P
(LBR)George, XE Head Scripter, Xs Developer, LBR's founder, playing VCMP since 2009

Offline NE.Restricted

  • Wiseguy
  • **
  • Posts: 97
    • View Profile
Re: Dialog System v1.0
« Reply #8 on: September 18, 2014, 09:56:23 am »
The very most useful script I ever found! Thanks for releasing it.
I am NE.CrystalBlue!!!
Quote
i cant able to understand

Offline thijn

  • LU testers
  • VC:MP Veteran
  • *
  • Posts: 667
  • Im proud to be pro.
    • View Profile
    • Vice Underdogs
Re: Dialog System v1.0
« Reply #9 on: September 18, 2014, 12:01:26 pm »
While the system looks nice, the script could've been a lot better. If you'd use arrays as parameters instead of using vargv you would be able to take out a lot of switches and a lot of duplicate code.

And I think what S.L.C. means is you can add your own custom function to an item. Something like this should give you an idea on how to do this:

When you create an item in the dialog, you specify a function as a string:
Code: [Select]
AddSubDialog(1,"Test 1","onDialogTest");

Then in your addsubdialog you save that function string like so:
Code: [Select]
if( getroottable().rawin( callbackFunction ) )
{
local pPointer = getroottable().rawget( callbackFunction );
if( pPointer )
{
subCallback[option] = pPointer;
}
}

When the player selects that you call that function like so:
Code: [Select]
subCallback[option](player, otherParameters);



Offtopic:
I think VCMP should give us a proper dialog system based on CEGUI library that I think it uses

We plan on adding a GUI system in the future. We don't plan on using CEGUI for performance reasons.
LU uses a GUI system, I don't know what library is that but seems be pretty good on performance, should you use it, or do you have another thing in mind?

And sorry for the off topic, but I'm really curious about that. :P
The LU GUI system was written from scratch by the Liberty Unleashed team. Since they joined forces, I would think VCMP would just use that.

Offline sseebbyy

  • VC:MP Veteran
  • *****
  • Posts: 774
  • Immortal VC:MP Player
    • View Profile
    • Zombie Invasion => Server Forum [DEAD PROJECT]
Re: Dialog System v1.0
« Reply #10 on: September 18, 2014, 12:51:19 pm »
And I think what S.L.C. means is you can add your own custom function to an item.

After I have seen your example of code, I understood the idea.
It is a real good idea/suggestion. It would do the usage of this system easier, but I should script it like that from start, and not to edit it now.
The way I scripted it it's good too, and you can get used to it fast.



While the system looks nice, the script could've been a lot better.

I know it, but it was a real challenge for me too. I was pretty sure, from start, that I will not handle it good.
But I'm very satisfied by the result. (it's what&how I wanted)

I used to dissappoint myself, sometimes, thinking like this:
"I'm working on it for days while you and other pro scripters could finish it in one day"
(while I was working on the first first version of the system)

No one wants to know how was the first (first) version of the system, but after I learnt the main idea, I rewritten it.
This one is made in like one day, under 1000 lines... just like I wanted.
« Last Edit: September 18, 2014, 12:53:44 pm by sseebbyy »

Quote
Painful/Noob scripters acts like: I Am The Best Scripter Because I Announce My Releases With Big Font Size Without Giving Too Much Info' In The Hope They All Will Download And Check It. I Ignore Bad Replies, Replies That I Could Learn From, And Replies With So Much Text.



Offline Honey.

  • Made Man
  • ***
  • Posts: 111
    • View Profile
Re: Dialog System v1.0
« Reply #11 on: September 18, 2014, 06:53:46 pm »
Oh so this was your secret, Very Well Done!  ;)

Offline NeskWriter

  • Crime Boss
  • ****
  • Posts: 355
    • View Profile
Re: Dialog System v1.0
« Reply #12 on: September 18, 2014, 07:01:32 pm »
Once I saw the screens I asked mysef: "How's this possible?". Damn, that's brilliant


-Funniest quotes-

Quote from: asad3man
i cant able to understand

Offline sseebbyy

  • VC:MP Veteran
  • *****
  • Posts: 774
  • Immortal VC:MP Player
    • View Profile
    • Zombie Invasion => Server Forum [DEAD PROJECT]
Re: Dialog System v1.0
« Reply #13 on: September 18, 2014, 09:03:14 pm »
Oh so this was your secret, Very Well Done!  ;)

Ahahaha, yes... this was my secret. :D



Thanks to all for the good replies !  :-*

Quote
Painful/Noob scripters acts like: I Am The Best Scripter Because I Announce My Releases With Big Font Size Without Giving Too Much Info' In The Hope They All Will Download And Check It. I Ignore Bad Replies, Replies That I Could Learn From, And Replies With So Much Text.



Offline Mariu22S

  • Wiseguy
  • **
  • Posts: 78
  • VC-MP Maniac
    • View Profile
Re: Dialog System v1.0
« Reply #14 on: September 18, 2014, 09:08:36 pm »
Nice. Good Job :)