Cui button command

Discussion in 'Rust Development' started by eed, May 31, 2017.

  1. eed

    eed

    As when clicking on the button, call the command on behalf of the player?
    ex. backpack.open
     
  2. This is a part of one of my plugins. You pretty much just add Command = "", to the button
    Code:
                alarmbuttons.Add(new CuiButton{
                    Button ={Command = "rustalerts.close all",Color = "0 255 0 0"},
                    RectTransform ={AnchorMin = GetPercent(1449,210),AnchorMax = GetPercent(1481,178)},
                    Text ={Text = "",FontSize = 22,Align = TextAnchor.MiddleCenter}
                },"buttonoverlay");
    Rustcui.cs check this out
     
  3. eed

    eed

    backpack dont open. If you first open the inventory, and then click on the inventory button, the backpack opens.
    hook press inventory button dont work? Solved - Listening for key input? | Oxide
     
  4. Only these work now and what do you mean it doesnt open
    Code:
    FORWARD
    BACKWARD
    LEFT
    RIGHT
    JUMP
    DUCK
    SPRINT
    USE
    FIRE_PRIMARY
    FIRE_SECONDARY
    RELOAD
    FIRE_THIRD
    
     
  5. eed

    eed

     
  6. eed

    eed

    refresh or remove cui
    Superimposed on each other

    Code:
    private void tpCdShow(BasePlayer player)
            {
                timer.Once(1f, () => tpCdShow(player));
                string scd = NTeleportation?.CallHook("GetCooldownRemaining",player, "home").ToString();
                //Puts(NTeleportation?.CallHook("GetCooldownRemaining",player, "home").ToString());
                if(scd == null) return;
                //Puts("123");
                var elements = new CuiElementContainer();
                            elements.Add(new CuiLabel
                    {
                        Text =
                        {
                            Text = scd,
                            FontSize = 18,
                        },
                        RectTransform =
                        {
                            AnchorMin = "0 0",
                            AnchorMax = "1 1"
                        }
                    });
                //Puts(NTeleportation?.CallHook("GetCooldownRemaining",player, "home").ToString());
                CuiHelper.AddUi(player, elements);  
                CuiHelper.DestroyUi(player, "elements");
            }
     

    Attached Files:

  7. You have it backwards
    Code:
                CuiHelper.DestroyUi(player, "elements");
                CuiHelper.AddUi(player, elements);  
     
  8. eed

    eed

    dont work
    Screenshot
     
  9. Oh destroyui destroys it by name and you arent naming it so that work. Im not at my computer ill gove an example later
     
  10. eed

    eed

    ok thx,
    example cui+timer pls.
     
  11. Code:
                    var alarmdataui = new CuiElementContainer();
                    alarmdataui.Add(new CuiPanel{
                    Image ={Color = "0.1 0.1 0.1 0"},
                    RectTransform ={AnchorMin = "0 0",AnchorMax = "1 1"}
                    }, "Hud", "cuinameexample");
                    CuiHelper.DestroyUi(player,"cuinameexample");
                timer.Once(0.1f, () => {
                    if(AlarmGui.stage!=2){
                        CuiHelper.AddUi(player,alarmdataui);
                    }
                });
    you mean something like this?
     
  12. eed

    eed

    dont destroy
    Code:
    private void tpCdShow(BasePlayer player)
            {
                timer.Once(1f, () => tpCdShow(player));
                string scd = NTeleportation?.CallHook("GetCooldownRemaining", player, "home").ToString();
                if (scd == null) return;
                var teleportcd = new CuiElementContainer();
                teleportcd.Add(new CuiPanel{
                    Image ={Color = "0.1 0.1 0.1 0"},
                    RectTransform ={AnchorMin = "0 0",AnchorMax = "1 1"}
                    }, "Hud", "cuinameexample");
                teleportcd.Add(new CuiLabel
                {
                    Text =
                        {
                            Text = i.ToString(),
                            FontSize = 18,
                        },
                    RectTransform =
                        {
                            AnchorMin = "0 0",
                            AnchorMax = "1 1"
                        }
                });
                i++;
                CuiHelper.DestroyUi(player, "cuinameexample");
                CuiHelper.AddUi(player, teleportcd);        }
     
  13. You need to parent thelabel to cuinameexample
     
  14. eed

    eed

    Screenshot
    With this figured out, thank you. But does this affect FPS?
     
    Last edited by a moderator: Jun 3, 2017
  15. if its like "hud", "teleportcd" hud is the parent teleportcd is the name you don't need to put a name for everything, but it is good to put a parent. So all you have to do for the second one is just add }, "teleportcd" and don't have another part and then "teleportcd" would be the parent
    [DOUBLEPOST=1496472282][/DOUBLEPOST]Its better to reply then update an old post imo. Im on and off my computer right now, but you shouldn't have them both the same name if i recall
     
  16. eed

    eed

    Code:
        var mainName = elements.Add(new CuiPanel
                {
                    Image =
                    {
                        //Url = "http://gamestores.ru/img/plugin_new.png"
                        Color = "0.1 0.1 0.1 0.7"
                    },
                    RectTransform =
                    {
                        // слева  - длина
                        AnchorMin = "0.000 0.90",
                        // снизу - высота
                        AnchorMax = "0.077 0.925"
                    },
                    CursorEnabled = false
                }, "Hud", "mainName2");
                elements.Add(new CuiElement()
                {
                    Parent = "mainName2",
                    Name = "ui.store.buttonimage",
                    Components =
                        {
                            //vk
                            new CuiRawImageComponent
                            {
                                Sprite = "assets/content/textures/generic/fulltransparent.tga",
                                Url = "https://s8.hostingkartinok.com/uploads/images/2017/06/34b4d26b5f0cf6380692da0750aa9e6f.png"
                            },
                            new CuiRectTransformComponent()
                            {
                                AnchorMin = "0.02 0.14",
                                AnchorMax = "0.17 0.86"
                            }
                        }
                });
                elements.Add(new CuiLabel
                {
                    Text =
                    {
                        Text = "/athreemrustserver",
                        FontSize = 10,
                    },
                    RectTransform =
                    {
                        AnchorMin = "0.015 0.905",
                        AnchorMax = "0.097 0.920"
                    }
                }, "Hud", "mainName2");
    destroy only last label, why?
    Code:
    CuiHelper.DestroyUi(player, "mainName2");
     
  17. try this i'm not inigame yet to see what the problem is, but i think the problem was that you where namaing something twice
    Code:
    var mainName = elements.Add(new CuiPanel
                {
                    Image =
                    {
                        //Url = "http://gamestores.ru/img/plugin_new.png"
                        Color = "0.1 0.1 0.1 0.7"
                    },
                    RectTransform =
                    {
                        // слева  - длина
                        AnchorMin = "0.000 0.90",
                        // снизу - высота
                        AnchorMax = "0.077 0.925"
                    },
                    CursorEnabled = false
                }, "Hud", "mainName2");
                elements.Add(new CuiElement()
                {
                    Parent = "mainName2",
                    Name = "ui.store.buttonimage",
                    Components =
                        {
                            //vk
                            new CuiRawImageComponent
                            {
                                Sprite = "assets/content/textures/generic/fulltransparent.tga",
                                Url = "https://s8.hostingkartinok.com/uploads/images/2017/06/34b4d26b5f0cf6380692da0750aa9e6f.png"
                            },
                            new CuiRectTransformComponent()
                            {
                                AnchorMin = "0.02 0.14",
                                AnchorMax = "0.17 0.86"
                            }
                        }
                });
                elements.Add(new CuiLabel
                {
                    Text =
                    {
                        Text = "/athreemrustserver",
                        FontSize = 10,
                    },
                    RectTransform =
                    {
                        AnchorMin = "0.015 0.905",
                        AnchorMax = "0.097 0.920"
                    }
                },"mainName2");