Jump to content
Sign in to follow this  
Bonuspunkt

ShowKeys

Recommended Posts

NOTE: i did not stop fiddling with the code, and extracted functions to own modules so you need more than one file, and specific file locations etc etc etc.

if you want an up-to-date copy you can download the bundle here but this code should work anyway

 

fyi, since last update (0.33), you can access the movement + attack key(s) the player is pressing, so you can see the keys while specing

again ugly but working

require "base/internal/ui/reflexcore"

ShowKeys =
{
    canPosition = false,

    draw = function()

        -- no player => no crosshair
        local player = getPlayer();
        if player == nil then return end;

        -- editor => no crosshair
        if player.state == PLAYER_STATE_EDITOR then return; end

        nvgFillColor(Color(255,255,255));
        nvgFontSize(FONT_SIZE_DEFAULT);
        nvgFontFace(FONT_TEXT);
        nvgTextAlign(NVG_ALIGN_CENTER, NVG_ALIGN_MIDDLE);


        if player.buttons.forward then
            nvgText(0, -20, "^");
        end
        if player.buttons.back then
            nvgText(0, 20, "v");
        end
        if player.buttons.left then
            nvgText(-20, 0, "<");
        end
        if player.buttons.right then
            nvgText(20, 0, ">");
        end
        if player.buttons.jump then
            nvgText(-20, 40, "J");
        end
        if player.buttons.attack then
            nvgText(20, 40, "A");
        end

    end
};
registerWidget("ShowKeys");

update: changed font

update: removed canHide = false

Share this post


Link to post
Share on other sites

You might use * for attack instead of "A"... I wondered what it stood for, until I read the code.

 

The special thing about this code is that spectators can see the movement of other players? IIRC there was a console command that did it for the player, i.e. to us in videos.

Share this post


Link to post
Share on other sites

Is there any (automated) way to only show the keys when I'm spectating others, but hide them when I'm playing myself?

 

I guess it would be possible with a bind that alternates hiding and showing the widget, but maybe there is a more elegant way

Share this post


Link to post
Share on other sites

Sorry for being so noob, but i have issues with installation of any lua script.

I downloaded pack with all script and put them in "bonus" folder C:Program Files (x86)SteamsteamappscommonReflexbaseinternaluibonus

In main menu i have the list of all scripts but they don't work in game.

Share this post


Link to post
Share on other sites

What you need for them to show are entries in your Reflexgame.cfg file, add these lines at the end of the file:

ui_show_widget ShowKeys
ui_set_widget_scale ShowKeys 1.0000
ui_set_widget_anchor ShowKeys 0 0
ui_set_widget_offset ShowKeys 0.0000 0.0000

These show the widget and then place it at the centre of the HUD.

 

Update: It should read show and not hide.

Share this post


Link to post
Share on other sites

you have to write

ui_show_widget ShowKeys

in your console

ui_set_widget_scale ShowKeys 1.0000
ui_set_widget_anchor ShowKeys 0 0
ui_set_widget_offset ShowKeys 0.0000 0.0000

is optional and just for size an position

 

the list is there so you can see all the available widgets and yeah show/hide them with the console commands

 

soon as we can access the widget states we can build a nice ui for it

Share this post


Link to post
Share on other sites

The line in the widget code in the first post:

canPosition = false,

you will need to change to:

canPosition = true,

and save the .lua file. Repositioning should then work.

 

I am not quite certain myself but canPosition seems to be a special global variable that determines what can be done in the function code of widgets.

Share this post


Link to post
Share on other sites

I'd suggest adding

        -- menu => no crosshair
        if isInMenu() then return end;

after

draw = function()

so that you don't see the keypresses of the player you're speccing when you're in the menu.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×