Forum

> > CS2D > Scripts > Add tabs to the menu hc admin script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Add tabs to the menu hc admin script

6 replies
To the start Previous 1 Next To the start

old Add tabs to the menu hc admin script

cs2d_is_a_Gem
User Off Offline

Quote
Can someone give me a small tutorial on how to add tabs to the hc menu?

I'm trying to add this to f2 >


I managed to add this to f4 >


I tried to do this well before asking for help, but it was impossible for me at this time.
In advance thanks !

old Re: Add tabs to the menu hc admin script

Qb
User Off Offline

Quote
user cs2d_is_a_Gem has written
1
2
3
4
5
6
7
8
sc = "2" -- 0 = f2 , 1 = f3 , 2 = f4 --

addhook("serveraction","redirect")
function redirect(id,rd)
     if (rd == 3) then
     rsm(id)
     end
end

I think we should go through this code line by line.

sc = "2" -- 0 = f2 , 1 = f3 , 2 = f4 --

This is a pointless variable. By the looks of it it was intended to give information about which of the 3 hotkeys to bind to. But then again the value is a string which doesn't make any sense since cs2d lua hook serveraction hook passes a number(action) to signal the key that was pressed. Also the comment at the end is wrong. It should be F2=1, F3=2, F4=3

addhook("serveraction","redirect")

This binds the function
redirect
to the cs2d lua hook serveraction hook. This way whenever a server action is performed(a player presses either of F2-F4) it calls the function with 2 parameters: the player id and the server action key pressed F2=1, F3=2, F4=3

function redirect(id,rd)

This defines the redirect with 2 parameters id and rd. Because of the way the hook works the second parameter(rd) is the server action key.

if (rd == 3) then

Here is your problem. You check if rd(the server action key) is 3. But as I already wrote server action 3 is not F2 but F4 (F2=1, F3=2, F4=3). So if you want to only want you menu to open when F2 is pressed you have to check if the server action is 1.

1
2
3
4
5
6
addhook("serveraction","redirect")
function redirect(id,rd)
     if (rd == 1) then
     rsm(id)
     end
end
This should have it all fixed.

I went through the code step by step because I want you to also understand what is wrong and why I do the changes. I think it helps much better if I help you understand the code so you can also make changes to it on your own.

old Re: Add tabs to the menu hc admin script

cs2d_is_a_Gem
User Off Offline

Quote
@user Qb: I think your answer has nothing to do with my question anyways thank you for trying to help me.
This Code was quickly written as an example to add it to the code of administration of hc.
You corrected minor errors in the code. What I can do myself.
I already managed to add it to the menu f2 of hc.
Thanks to a private message sent to me by a player.
Thank you very much anyway.

old Re: Add tabs to the menu hc admin script

Qb
User Off Offline

Quote
Oh yes, I just realized. I didn't read your whole post but just the more-tags titles (probably because they are bold) and thought I knew what it was about. Sorry ^.^

Could you please post your solution anyway? This way other people searching for the same thing can also read how to do it and don't just find this thread which doesn't provide an answer. This way these people wouldn't need to open their own thread about it.

old Re: Add tabs to the menu hc admin script

Ajmin
User Off Offline

Quote
Add this to hc/modules/playerstats.lua

1
hc.add_menu_command("Other Servers", rsm, hc.SHOW_STATS_TO_ME_LEVEL, hc.COMMAND_MENU_KEY)

Also ensure all your functions,including menu hook are added to the script aswell.

Edit: Never mind,just figured out that you already got the solution.

old Re: Add tabs to the menu hc admin script

cs2d_is_a_Gem
User Off Offline

Quote
@user Qb: If I can share the code with you and everyone else,
But before, need to clarify that I had a problem with my previous post, press the `send` button due to an error.

Anyway this code was not written by me.
This person wrote the code @user Yunuu: And shared with us.

Code Full tested and worked. >
√
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview