[ACS] Simple Shop Menu

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
AqwerfNet
New User
Posts: 15
Joined: Sat Aug 27, 2016 10:23 pm
Location: Japan

[ACS] Simple Shop Menu

#1

Post by AqwerfNet » Sat Nov 26, 2016 5:36 pm

Hello,

I'm trying to make a shop menu with acs, but i don't know where to begin; Of course i made some search and have ideas of how it works...
But my main problems are:

-I can't make it: By this i mean i have the idea but i can't make it concrete...

-Multiplayer support : How i do ? And what informations server care ?
Last edited by AqwerfNet on Sun Nov 27, 2016 5:39 pm, edited 1 time in total.

User avatar
Fused
Contributor
Posts: 663
Joined: Sat Nov 09, 2013 9:47 am
Location: Netherlands
Contact:

[ACS] Re: Simple Shop Menu

#2

Post by Fused » Sat Nov 26, 2016 5:59 pm

I don't have alot of time to type this, so excuse my rush in explanation.
Be sure you have a very good understanding on ACS, because otherwise you really can't have a decent menu without running into problems every time.

I am assuming with "problems with creating a shop" you mean the general selection of options, so I guess I'll try and cover that.

There are two ways you could do this, a shop controlled by keyboard and by mouse.
Funnily enough, the mouse one would be the easiest probably.

mouse:
Firstly you will need a script for displaying a mouse through ACS. The best mouse around is from the library ACSutils.
The way you have a mouse react to anything at all is by checking where your cursor is using the coordinates it draws to. You should save the coordinates of your button inside an array.

Here's a small example from Zombie Horde. The buttons and its content are drawn from an array, and a different array holds the top left and bottom right edge coordinates so we know where the button exists.

Code: Select all

// Submenu coordinates and slots.
// 3 submenus.
// x amount of clickable / writeable items (max is 2 as this is the highest).
// 4 positions, being top left x y and bottom right x y.

#DEFINE SUB1_SIZE 2
#DEFINE SUB2_SIZE 2
#DEFINE SUB3_SIZE 2

int SubMenuCoords [3][2][4] = {
    // submenu 1
    {
        {231.0, 200.0, 424.0, 211.0}, // submenu identifier
        {241.0, 438.0, 291.0, 450.0}, // return
    },
   
    // submenu 2
    {
        {231.0, 200.0, 424.0, 211.0}, // submenu identifier
        {241.0, 438.0, 291.0, 450.0}, // return
    },
   
    // submenu 3
    {
        {231.0, 200.0, 424.0, 211.0}, // submenu identifier
        {241.0, 438.0, 291.0, 450.0}, // return
    }
};

int SubMenuSlots [3][2][4] = {
    // submenu 1
    {
        {"This is submenu 1", -90.0, -60.0},
		{"return", -150.0, 180.0}
    },
   
    // submenu 2
    {
        {"This is submenu 2", -90.0, -60.0},
		{"return", -150.0, 180.0}
    },
   
    // submenu 3
    {
        {"This is submenu 3", -90.0, -60.0},
		{"return", -150.0, 180.0}
    }
};
To check input, just check for firing or altfiring.
Now what I did, and I think is most clean and efficient, is to check the coordinates with your mouse and match any in the array. If there's a match, get the index of it and give it as an item.

The button should be constantly redrawn with a loop, and each time you check for the amount of said item in your inventory. And then you pretty much highlight the button accordingly. The same script drawing the buttons could do the action whatever the button does. And that should cover your most difficult problem.

keyboard:
Keyboard can be very difficult if you have multiple rows of buttons. Otherwise it's probably extremely easy. Keyboard can have a similar function from the mouse where you give items, but now rather than checking for coordinates, just check if the user presses up or down with GetPlayerInput. Say down gives one, where up retracts one. Be sure to check for limitations. The code below should properly handle 5 buttons, although my ACS is a little rusty.

Code: Select all

...
if (GetPlayerInput(-1, INPUT_BUTTONS) & BT_FORWARD)
{
	item++;
	item %= 5;
}
else if (GetPlayerInput(-1, INPUT_BUTTONS) & BT_BACK)
{
	if(Radio_index == 0) item = 5;
	item--;
}
...
And just update the button whenever someone presses something for performance sakes (although you wont notice a difference)
The more difficult part comes when buttons are next to eachother. I can't really explain what to do as this obviously varies, but if you for example have a row of 5 buttons and the next one has 3, you could add 5 times the item so it acts like you move a spot to the right. If you have even more rows You could probably check how much you have of said amount to determine the row you currently have selected.

- Don't worry about multiplayer support too much. A shop should be fully clientside. For any serverside action like giving items, use RequestScriptPuke

And yeah if you want to combine the two you will have to find a way to do that and keep it clean. I wasn't able to in Zombie Horde as the two can really create bad user experience, so I wouln't if I were you.

So here's lots of text on how to cover buttons. I probably missed alot as I am in a rush like I said, but I hope this covers your most difficult problem. If there's other stuff that's a problem, or this wasn't the problem at all, feel free to ask.
My mods
Image Image

My socials
Image Image

User avatar
AqwerfNet
New User
Posts: 15
Joined: Sat Aug 27, 2016 10:23 pm
Location: Japan

[ACS] Re: Simple Shop Menu

#3

Post by AqwerfNet » Sat Nov 26, 2016 9:46 pm

ok Thank you,

Now I worked a bit on it and that what i made : https://github.com/thenaonao/DoomSpaceO ... ter/menu.c
But i dont know why , but it seem my Y integer is equal to 1 instead of 0 and it display the wrong hud...
Someone found a bug in it?

EDIT: Missed a break...

kodi
New User
Posts: 14
Joined: Wed Dec 30, 2015 2:57 pm

[ACS] Re: Simple Shop Menu

#4

Post by kodi » Sun Nov 27, 2016 10:16 am

I like to define available buttons like this:
HBC[2][0]=/*name*/ "mfd_screen_left"; //left mfd screen
HBC[2][1]=/*Xleft*/ fixeddiv((fixeddiv(scaled_hudx,2.0) - mfdoffset - 5.0 - mfdscreenwidth),scaled_hudx);
HBC[2][2]=/*XRight*/fixeddiv((fixeddiv(scaled_hudx,2.0) - mfdoffset - 5.0),scaled_hudx);
HBC[2][3]=/*YTop*/ fixeddiv(scaled_hudy - mfdheight + 5.0,scaled_hudy);
HBC[2][4]=/*Ybot*/ fixeddiv(scaled_hudy - mfdheight + 5.0 + mfdscreenheight,scaled_hudy);
HBC[2][5]= /*xmid/*/ hbc[2][2] - ((hbc[2][2]-hbc[2][1])/2);
HBC[2][6]= /*ymid/*/ hbc[2][4] - ((hbc[2][4]-hbc[2][3])/2);
Then it's a simple matter to compare normalized mouse coordinates with any entry in the button array(s).

User avatar
AqwerfNet
New User
Posts: 15
Joined: Sat Aug 27, 2016 10:23 pm
Location: Japan

[ACS] Re: Simple Shop Menu

#5

Post by AqwerfNet » Sun Nov 27, 2016 1:28 pm

Fused wrote: - Don't worry about multiplayer support too much. A shop should be fully clientside. For any serverside action like giving items, use RequestScriptPuke
Well my menu don't work in Multiplayer, I have no idea why??
edit: by don't work, I mean moving with buttons don't work...
Here is my code : https://github.com/thenaonao/DoomSpaceO ... ter/menu.c

User avatar
Fused
Contributor
Posts: 663
Joined: Sat Nov 09, 2013 9:47 am
Location: Netherlands
Contact:

[ACS] Re: Simple Shop Menu

#6

Post by Fused » Sun Nov 27, 2016 4:26 pm

You should clientside most of that input script. Right now the server still draws alot of the menu that only the client needs really. Either that or try setting Compat_ClientsSendFullButtonInfo TRUE in your server to fix it.
My mods
Image Image

My socials
Image Image

User avatar
AqwerfNet
New User
Posts: 15
Joined: Sat Aug 27, 2016 10:23 pm
Location: Japan

[ACS] Re: Simple Shop Menu

#7

Post by AqwerfNet » Sun Nov 27, 2016 5:39 pm

Oh! Thank you !

And yea i put most of them clienside only!

Post Reply