Shopping Cart
How ToVideo Addons how to and converting to an addon

[ESX][JS][How-to] ESX With JavaScript! – Modding Tutorials

[ad_1]

FiveM Modding Tutorial

Not too long ago I’ve been writing all of my scripts in JS, with FiveM the principle economic system framework is ESX. Writing ESX capabilities inside JS may be very simple and right this moment Im going to point out you how one can do it!

Updated Version

Server-
Calling Shared Object.
JS:

let ESX = null;
emit("esx:getSharedObject", (obj) => ESX = obj);

LUA:

ESX = nil
TriggerEvent('esx:getSharedObject', perform(obj) ESX = obj finish)

Its fairly easy to transform Lua code to JS, for instance if you happen to needed to get a xPlayers cash you’d simply do

let xPlayer = ESX.GetPlayerFromId(supply);
let money = xPlayer.getMoney();
console.log(money);

Consumer-
JS:

let ESX = null;
emit("esx:getSharedObject", (obj) => ESX = obj);

LUA:

ESX = nil

Citizen.CreateThread(perform()
	whereas ESX == nil do
		TriggerEvent('esx:getSharedObject', perform(obj) ESX = obj finish)
		Citizen.Wait(0)
	finish
finish)

Right here you should utilize shopper capabilities like ESX.ShowNotification, which is similar for LUA and JS.

Hopefully this made you think about attempting JS, I began with FiveM scripts in LUA however got here from a primarily JS background. I like writing in JS extra since you #1 have entry to Node Modules and #2 Im extra fluent in JS. Although LUA nonetheless turns out to be useful typically.

[ad_2]

Authentic supply: https://discussion board.cfx.re/t/esx-js-how-to-esx-with-javascript/1604792

Leave a Reply
FiveM ESX Scripts

The best scripts and maps

Best support

Problems? We are there to help!

Wide range of products

We have a wide range of products

100% Secure Checkout

Stripe