Hi all, for work I’m a software developer, but new to this lua/js scripting stuff. I’m hoping to get some help regarding events, handling them, and more. Here is the situation.

Currently, I’ve added some custom stuff to the ps-inventory js file that added a separate section of slots, and it works fine. The issue comes in when I want to add the logic. Basically when someone dies, I want a slot to go away, and only when they go to EMS and get healed will they get them back. So, if we JUST focus on the death part here is my situation.

I’ve figured out how to listen to the event in client lua with the baseevents:onPlayerDied, and have it triggering properly. Issue I’m running into is when that event is run, how to let the js file know so it can update the inventory number from 5 to 4. I’ve looked into just listening for the event in the client js file, but haven’t had any luck, so basically the way I see it, when the AddEventHandler("baseevents:onPlayerDied is triggered, I’d like it to call a function in javascript. How do I achieve this? Or, is there a best way to do this whole process?

Thank you ahead of time for any help/answers and for the time you’re taking to read this, I’ve been searching through all kinds of docs, boards, etc and can’t seem to figure out what to do.

When discussing .js scripting within FiveM an important distinction to make is if the .js is running as an HTML source “file”, or if it is running directly on the client as a “script”.
With you speaking of an inventory, and you having added slots, I will assume the .js file is running as an HTML source, and is using some logic such as

window.addEventListener('message', function(event) {

and this is how HTML .js files listen for data from the client .lua scripts, you can find more detailed information here Fullscreen NUI - Cfx.re Docs

.js scripts that are running directly on the client will use emit and onNet, you will have to look further into how to properly use .js scripts here Creating your first script in JavaScript - Cfx.re Docs

2 Likes

Jiminy,

Thank you for that!

You were correct that I was referring to the .js being HTML source, the way you broke it down helped immensely and I was able to get it to work, thank you so much!!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.