Vice City Multiplayer

VC:MP 0.4 (Beta) => Script Discussion => Script Releases => Topic started by: sseebbyy on September 17, 2014, 07:36:19 pm

Title: Custom Menu System v1.0
Post by: sseebbyy 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 !
Picture 1 (https://imagizer.imageshack.us/v2/706x397q90/673/J8XuDB.png) - Picture 2 (https://imagizer.imageshack.us/v2/706x397q90/905/pKxwSM.png)

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

Here is the whole code you need:
http://pastebin.com/Ph2XA4hc



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.
Title: Re: Dialog System v1.0
Post by: UkRs on September 17, 2014, 08:05:18 pm
:O man u r making VC:MP in to SA:MP or even IV:MP :P
Title: Re: Dialog System v1.0
Post by: Franklin on September 17, 2014, 08:13:44 pm
amazing  :)
Title: Re: Dialog System v1.0
Post by: S.L.C 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 (http://semantic-ui.com/modules/modal.html#/examples) (actually a modal window) and this is a menu (http://semantic-ui.com/collections/menu.html). Menu definition: "A menu is a collection of elements showing related user actions"
Title: Re: Dialog System v1.0
Post by: sseebbyy 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 !
Title: Re: Dialog System v1.0
Post by: George 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 )
Title: Re: Dialog System v1.0
Post by: stormeus 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.
Title: Re: Dialog System v1.0
Post by: George 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
Title: Re: Dialog System v1.0
Post by: NE.Restricted on September 18, 2014, 09:56:23 am
The very most useful script I ever found! Thanks for releasing it.
Title: Re: Dialog System v1.0
Post by: thijn 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.
Title: Re: Dialog System v1.0
Post by: sseebbyy 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.
Title: Re: Dialog System v1.0
Post by: Honey. on September 18, 2014, 06:53:46 pm
Oh so this was your secret, Very Well Done!  ;)
Title: Re: Dialog System v1.0
Post by: NeskWriter on September 18, 2014, 07:01:32 pm
Once I saw the screens I asked mysef: "How's this possible?". Damn, that's brilliant
Title: Re: Dialog System v1.0
Post by: sseebbyy 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 !  :-*
Title: Re: Dialog System v1.0
Post by: Mariu22S on September 18, 2014, 09:08:36 pm
Nice. Good Job :)
Title: Re: Dialog System v1.0
Post by: NE.Restricted on September 19, 2014, 09:56:34 am
Help!!!
Quote from: VCMPServer.exe
AN ERROR HAS OCCURED [arith op + on between null and integer]

CALLSTACK
*FUNCTION [KeyBindDialog()]
*FUNCTION [onKeyDown()]

LOCALS
...(nothing is null here...)
Title: Re: Dialog System v1.0
Post by: tђยภ๔єгรt๏г๓ on September 19, 2014, 11:54:04 am
:O nice job seby :)
Title: Re: Dialog System v1.0
Post by: Franklin on September 19, 2014, 06:04:22 pm
we need a board for squirrel scripts releases ;v
Title: Re: Dialog System v1.0
Post by: sseebbyy on September 22, 2014, 04:42:37 pm
Help!!!
Quote from: VCMPServer.exe
AN ERROR HAS OCCURED [arith op + on between null and integer]

CALLSTACK
*FUNCTION [KeyBindDialog()]
*FUNCTION [onKeyDown()]

LOCALS
...(nothing is null here...)

Can you tell me what have you done ?
Title: Re: Dialog System v1.0
Post by: NE.Restricted on September 22, 2014, 05:01:05 pm
Help!!!
Quote from: VCMPServer.exe
AN ERROR HAS OCCURED [arith op + on between null and integer]

CALLSTACK
*FUNCTION [KeyBindDialog()]
*FUNCTION [onKeyDown()]

LOCALS
...(nothing is null here...)

Can you tell me what have you done ?
The exception happened on a line of your code. But dont worry ill make my own (better) dialog system that supports images.
Title: Re: Dialog System v1.0
Post by: Honey. on September 22, 2014, 05:08:28 pm
Help!!!
Quote from: VCMPServer.exe
AN ERROR HAS OCCURED [arith op + on between null and integer]

CALLSTACK
*FUNCTION [KeyBindDialog()]
*FUNCTION [onKeyDown()]

LOCALS
...(nothing is null here...)

Can you tell me what have you done ?
The exception happened on a line of your code. But dont worry ill make my own (better) dialog system that supports images.

Hello NE.Arrogant,

I didn't have any errors with this script so blame yourself.
Title: Re: Dialog System v1.0
Post by: sseebbyy on September 22, 2014, 05:15:39 pm
The exception happened on a line of your code. But dont worry ill make my own (better) dialog system that supports images.

I just tested the whole script again, and I get no error.
If you implemented my system in your script, then I suggest you to check it again, because you may miss something.
Title: Re: Dialog System v1.0
Post by: NeskWriter on September 22, 2014, 05:30:33 pm
Quote from: NE.Restricted
ill make my own (better) dialog system that supports images.

Hey dude don't call your work better than anyone's until you finish it. Anyways hope to see something perfect
Title: Re: Dialog System v1.0
Post by: stormeus on September 22, 2014, 11:00:26 pm
Help!!!
Quote from: VCMPServer.exe
AN ERROR HAS OCCURED [arith op + on between null and integer]

CALLSTACK
*FUNCTION [KeyBindDialog()]
*FUNCTION [onKeyDown()]

LOCALS
...(nothing is null here...)

Add at the top of KeyBindDialog:

Code: [Select]
function KeyBindDialog(player, bind)
{
if (dialogoptionchoosen[player.ID] == null || subdialogoptionchoosen[player.ID] == null)
return;
Title: Re: Dialog System v1.0
Post by: NE.Restricted on September 23, 2014, 08:51:50 am
Quote from: NE.Restricted
ill make my own (better) dialog system that supports images.

Hey dude don't call your work better than anyone's until you finish it. Anyways hope to see something perfect
I mean that I will include more features, like if the choice Football stadium is selected, I can specify an image to be shown on the top-center-right.
Title: Re: Custom Menu System v1.0
Post by: sseebbyy on September 23, 2014, 04:00:17 pm
Update

I have corrected the script. Like S.L.C. said, it is a Menu, and not a Dialog !
Every function and event is now using "Menu" instead of "Dialog".
If you used the system, I suggest you to update it. :)

Thanks !