Log in to reply
 

Cant figure out how to loop in NativeUI (ScripthookvDotnet



  • I have been trying to write a money drop function in single player using scripthookVdotnet and NativeUI. I cant for the life of me figure this out. I have tried rewriting it in multiple ways. The problem is if i don't use a loop it only drops once. When i do loop, it doesn't stop dropping and I cant open the menu again for some reason. So what i'm really trying to do is open the menu while its dropping so i could possibly stop it.

    void DropMoney()
            {
                var moneyDrop = new UIMenuCheckboxItem("Money Drop", ketchup, "This took wayy too long.");
                moneyMenu.AddItem(moneyDrop);
                moneyMenu.OnCheckboxChange += (sender, item, checked_) =>
                {
                    if (item == moneyDrop)
                    {
                        DropFunction(true);
                    }
                };
            }
    
    public void DropFunction(bool dropTrue)
            {
    
                while (dropTrue)
                {
                    UI.ShowSubtitle("Dropped money");
                    int money_bag = Function.Call<int>(Hash.GET_HASH_KEY, "prop_money_bag_01");
                    int pickup_title = Function.Call<int>(Hash.GET_HASH_KEY, "PICKUP_MONEY_CASE");
                    Vector3 dropPos = Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0f, 0f, 2f));
                    Function.Call(Hash.CREATE_AMBIENT_PICKUP, pickup_title, dropPos.X, dropPos.Y, dropPos.Z, 0, 200000, money_bag, false, true);
                    Function.Call(Hash.CREATE_AMBIENT_PICKUP, pickup_title, dropPos.X, dropPos.Y, dropPos.Z, 0, 200000, money_bag, false, true);
                    Function.Call(Hash.CREATE_AMBIENT_PICKUP, pickup_title, dropPos.X, dropPos.Y, dropPos.Z, 0, 200000, money_bag, false, true);
                    Function.Call(Hash.CREATE_AMBIENT_PICKUP, pickup_title, dropPos.X, dropPos.Y, dropPos.Z, 0, 200000, money_bag, false, true);
                    Function.Call(Hash.CREATE_AMBIENT_PICKUP, pickup_title, dropPos.X, dropPos.Y, dropPos.Z, 0, 200000, money_bag, false, true);
                    Function.Call(Hash.CREATE_AMBIENT_PICKUP, pickup_title, dropPos.X, dropPos.Y, dropPos.Z, 0, 200000, money_bag, false, true);
                    Function.Call(Hash.CREATE_AMBIENT_PICKUP, pickup_title, dropPos.X, dropPos.Y, dropPos.Z, 0, 200000, money_bag, false, true);
                    Function.Call(Hash.CREATE_AMBIENT_PICKUP, pickup_title, dropPos.X, dropPos.Y, dropPos.Z, 0, 200000, money_bag, false, true);
                    Function.Call(Hash.CREATE_AMBIENT_PICKUP, pickup_title, dropPos.X, dropPos.Y, dropPos.Z, 0, 200000, money_bag, false, true);
    
                    Wait(200);
    
                }
            }
    


  • Fixed your code block. Tip: do the following:

    ```cs
    // code
    ```

    First you need to specify what you want to achieve: Do you want to continuously drop money or drop money on a key press?

    In the first case, you want to run the DropFunction in a loop. In ScriptHookVDotNet, the Tick handler does this for you, and you just need to put all functions you want to be looped in the Tick handler, which is usually called OnTick in examples. For keeping state, you could keep a boolean and toggle, and use that boolean in the OnTick function.

    If you want to drop money on a key press, you don't need to do anything additionally.

    In both these situations you do not want to have another while(bool). If you have a while(bool) you need to make sure you let the script sleep in between loops, and have an exit condition (that steps out of the while loop).


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.