English Add tabs to the menu hc admin script

6 replies
Goto Page
To the start Previous 1 Next To the start
Up
M3_Quick
User
Offline Off
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 !
IMG:https://i.imgur.com/DCz9Dko.png
14.08.17 11:44:26 pm
Up
TheNecro
User
Offline Off
user M3_Quick has written:
Code:
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.

Code:
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

Code:
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

Code:
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.

Code:
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.

Code:
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.
15.08.17 03:44:51 am
Up
M3_Quick
User
Offline Off
@user TheNecro: 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.
IMG:https://i.imgur.com/DCz9Dko.png
15.08.17 10:47:35 am
Up
TheNecro
User
Offline Off
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.
16.08.17 04:57:17 am
Up
M3_Quick
User
Offline Off
@user TheNecro: yes, este codigo fue creado por @
IMG:https://i.imgur.com/DCz9Dko.png
16.08.17 11:17:55 am
Up
JeeewNazi
User
Offline Off
Add this to hc/modules/playerstats.lua

Code:
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.
21.08.17 04:35:38 am
Up
M3_Quick
User
Offline Off
@user TheNecro: 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 -Yunus: And shared with us.

Code Full tested and worked. >
√
IMG:https://i.imgur.com/DCz9Dko.png
To the start Previous 1 Next To the start