Jump to content

Cursor not spawning


Remco1337

Recommended Posts

Server side:
 

mp.events.addCommand('createfaction', (player) => {
    if (player.data.adminLevel < 3) return gm.functions.returnUnauthorizedAdmin(player);
    player.call('openCreateFaction');
});

 

Clientside:

// Factions
var createFactionBrowser = null;

mp.gui.cursor.show(true, true);

mp.events.add("openCreateFaction", () => {
    mp.gui.chat.push("Opened faction creation!");
    createFactionBrowser = mp.browsers.new("package://factions/create.html");
    mp.gui.chat.activate(false);
    mp.gui.cursor.show(true, true);
});

It shows the message and opens the browser but the controls won't be frozen and the cursor won't show.

Edited by Remco1337
Link to comment
Share on other sites

This happens because of these lines 

mp.gui.chat.activate(false);
mp.gui.cursor.show(true, true);

If they are next to each other, your cursor will not appear. 

We need a solution!

Edit:

@MrPancakers  told me to use a timeout/timer and it WORKS!

 

TL;DR: Use a timeout of 1ms to show the cursor after deactivating chat input

Edited by xForcer
Link to comment
Share on other sites

  • 2 weeks later...
В 08.02.2020 в 02:45, xForcer сказал:

This happens because of these lines 

mp.gui.chat.activate(false);
mp.gui.cursor.show(true, true);

If they are next to each other, your cursor will not appear. 

We need a solution!

Edit:

@MrPancakers  told me to use a timeout/timer and it WORKS!

 

TL;DR: Use a timeout of 1ms to show the cursor after deactivating chat input

Timeout xD ? Maybe better using render event like this ?

 

let stateCursor = true;

    mp.events.add(RageEnums.EventKey.RENDER, () => {
       if (mp.keys.isDown(0x12)) {
           if (!stateCursor) {
               mp.gui.cursor.show(true, true);
               stateCursor = true;
           }
       } else {
           if (stateCursor) {
               mp.gui.cursor.show(false, false);
               stateCursor = false;
           }
       }
    });

 

and u don't need to disable chat to show cursor 

Link to comment
Share on other sites

8 minutes ago, Vernetti said:

Timeout xD ? Maybe better using render event like this ?

 


let stateCursor = true;

    mp.events.add(RageEnums.EventKey.RENDER, () => {
       if (mp.keys.isDown(0x12)) {
           if (!stateCursor) {
               mp.gui.cursor.show(true, true);
               stateCursor = true;
           }
       } else {
           if (stateCursor) {
               mp.gui.cursor.show(false, false);
               stateCursor = false;
           }
       }
    });

 

and u don't need to disable chat to show cursor 

The author asked for chatInput to be disabled and cursor shown when he has the browser opened.
The solution I provided works perfectly for his use case, I myself am using it.

You want him to press ALT key manually just to show the cursor after disabling the chatInput? Really? :D 

Link to comment
Share on other sites

1 час назад, xForcer сказал:

The author asked for chatInput to be disabled and cursor shown when he has the browser opened.
The solution I provided works perfectly for his use case, I myself am using it.

You want him to press ALT key manually just to show the cursor after disabling the chatInput? Really? :D 

xD

anyway render event is more effective here instead of timer

 

export default new class Cursor {
  constructor() {
    this.state = false;
    
    mp.events.add("render", () => {
       if (this.state === true) {
         mp.gui.cursor.show(true, true);
         mp.gui.chat.show(false);
       } else {
         mp.gui.cursor.show(false, false);
         mp.gui.chat.show(true);
       }
    });
  }
  show() {
    !this.state ? this.state = true : null;
  }
  hide() {
    this.state ? this.state = false : null;
  }
}

 

Edited by Vernetti
Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...