Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C# Help. UI Ignoring Logic?

Featured Replies

So apologies if my script here seems super messy or just plane wrong, I am super new to coding in C#. I've been having issues with the UI for a couple hours and I finally kinda got it working. The script right now is supposed to open up a menu whenever a player gets close enough to a Vector3 location. (Left out that part of the script so it wouldn't be too much)

 

So I can get the menu to activate perfectly fine. That part pretty much works as intended. But for some reason the "else if " line wants to fire too, even when the logic is wrong.

 

Pretty sure this is user error but I'm honestly at a loss.  Any help would be awesome! Code can be found below.

 

https://pastebin.com/jRXPFrrp

Talking a whole lot of nonsense - since 1999

  • Management Team

You are checking the position of all 8 hotel locations. That means you are very likely to be away from at least one of these positions at all times, hence your code is firing constantly. You could add a boolean and only show your "warning" when you are not close to any hotel. Like this:

 

while (true)
{
    GameFiber.Yield();
    bool isCloseToAnyHotel = false;
    for (int index = 0; index < 8; index++) 
    {
        if (Vector3.Distance2D(hotelLocation[index], Game.LocalPlayer.Character.AbovePosition) < 20 ) // Only activate if the player is close enough.
        {                      
            isCloseToAnyHotel = true; 
            Game.DisplayHelp("Menu Should Be activated");
            if (activeMenu == !true)
            {
                mainMenu.Visible = true;
                activeMenu = true;
                GameFiber.StartNew(delegate
                {
                    while (true)
                    {
                        GameFiber.Yield();
                        _menuPool.ProcessMenus();
                        
                    }
                });
                
            }        
        }
    }

    if (!isCloseToAnyHotel)
    {
        // Now only fired when you are not close to any hotel.
        Game.DisplayNotification("You are away from a hotel.");
    }
}

 

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

  • Author
8 hours ago, LMS said:

You are checking the position of all 8 hotel locations. That means you are very likely to be away from at least one of these positions at all times, hence your code is firing constantly. You could add a boolean and only show your "warning" when you are not close to any hotel. Like this:

 

Dude, you are awesome! Thanks a bunch. I hadn't thought of it like that when I was typing the code. A thousand times, thank you.

 

Talking a whole lot of nonsense - since 1999

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.