itschip / react-fivem-lua-boilerplate

A React boilerplate for FiveM, with Lua to easily set up a React project with Typescript.
8 stars 15 forks source link

Command isn't working #4

Closed alecdiaz1 closed 3 years ago

alecdiaz1 commented 3 years ago

I think I've installed it correctly, if I remove the style={ visibility ? { visibility: 'visible' } : { visibility: 'hidden' }} from the div in App.tsx the content shows up on the screen. But doing /show:nui doesn't seem to toggle the nui visibility. I can confirm that the command is being triggered as I can send a message to chat when I run the command. It's just the visibility doesn't seem to toggle.

itschip commented 3 years ago

Are you sure that you built it correctly? Using the build:resources comand

alecdiaz1 commented 3 years ago

Yeah, I'm running build:resources and my changes appear (just leaving the app always visible). This is also my first time making a FiveM resource so maybe there's something simple that I'm missing?

I also tried logging when useNuiEvent receives an event but I haven't been able to see any event being received when I run /show:nui. But the message show:nui run! appears in chat.

cl_main.lua

RegisterCommand('show:nui', function(source, args, rawCommand)
  SendNuiMessage({
    app = "REACTNUI",
    method = "setVisibility",
    data = true,
  })
  SendNuiMessage({
    app = "newspaper",
    method = "testFunc",
    data = 'test message',
  })
  TriggerEvent('chat:addMessage', {
    args = { 'show:nui run!' }
  })
end, false)

useCoreService.ts

import { useSetRecoilState } from 'recoil'
import { useVisibility } from './useVisibility'
import { coreState } from './state'
import { useNuiEvent } from 'fivem-nui-react-lib'

export const useCoreService = () => {
  const setShowHide = useSetRecoilState(coreState.visibility)
  // You can change these strings to whatever you wish :)
  useNuiEvent<boolean>('REACTNUI', 'setVisibility', setShowHide)
  useNuiEvent('newspaper', 'testFunc', (msg) => console.log(`${msg} ---- msg`))
  return useVisibility()
}
itschip commented 3 years ago

@alecdiaz1 Thanks for the issue. I'll look into this today, to see if I can replicate.

EDIT: Can you open your nui_devtools in-game, and then if if the html body as been populated?

itschip commented 3 years ago

@alecdiaz1 This might be my fault...

Check if the resource prop on the NuiProvider, in the index.tsx file is the same to whatever your resource is called :D

alecdiaz1 commented 3 years ago

@itschip I can confirm that the html body is populated, removing the div that controls visibility, the UI pops up in game (but automatically on starting resource, not through command). The resource prop is also set to the name of my resource.

Here's the commit I'm working off of. Commits after that I removed the core hooks and handled the Nui messages on my own though.

itschip commented 3 years ago

Oh fuck me.... its SendNUIMessage, not SendNuiMessage. Try that

Edit: check the natives documentation for this :P

alecdiaz1 commented 3 years ago

@itschip 🤦‍♂️ Haha yep it was the SendNuiMessage being that instead of the correct SendNUIMessage. I believe cl_main.lua needs to be updated to fix that then?

itschip commented 3 years ago

Yup, it needs an update indeed :)

itschip commented 3 years ago

@alecdiaz1 Fixed now!