[FREE] [ESX] BeAware-Elevator

BeAware-Elevator

A highly configurable ESX elevator script based on NativeUI

Features:

  • Multiple Floors
  • Job whitelist
  • Item whitelist
  • Configurable Text

Config

Option Description Default
Config.MarkerDistance Disctance where markers get rendered 50
Config.Key Key to open elevator menu 38
Config.Description Header text (universal) “Elevator”
Config.TooFarAway Error text if you are too far away “Too far away”
Config.NoPermission Error text if you have insufficient permissions “insufficient permissions”
Config.ScreenFade Change if the Screen fades black true

Dependency

NativeUILua: Get it here!

Download

Download: Github

Help

Example

Casino = {
    {
        text = ("Press ~INPUT_PICKUP~ to use the Elevator"),
        label = ("Entrance"),
        description = ("Go to the Entrance"),
        marker = {type = 1, scale = 3.0, height = 0.5, r = 0, g = 255, b = 255, a = 200},
        coords = {x = 924.43, y = 46.87, z = 80.11, h = 60.01},
        
    },
    {
        text = ("Press ~INPUT_PICKUP~ to use the Elevator"),
        label = ("Roof"),
        description = ("Enter Roof"),
        marker = {type = 1, scale = 1.5, height = 0.5, r = 0, g = 255, b = 255, a = 200},
        coords = {x = 964.49, y = 58.76, z = 111.55, h = 55.63},
        jobs = {
	    ["police"] = 2,
	    ["ambulance"] = 1,
	},
        items = {
	    "bread",
	    "water",
	},
     },
    
},

Download: Github

2 Likes

Einbindung das man per Config auswählen kann zwischen dem neuen esx_textui oder dem klassischen helptext wäre stark.

[   2006469] [b2545_GTAProce]             MainThrd/ ^1SCRIPT ERROR: @BeAware-Elevator/client/client.lua:123: attempt to perform arithmetic on a nil value (local 'h')^7
[   2006469] [b2545_GTAProce]             MainThrd/ ^3> Teleport^7 (^[email protected]/client/client.lua^7:123)
[   2006469] [b2545_GTAProce]             MainThrd/ ^3> Activated^7 (^[email protected]/client/client.lua^7:78)
[   2006469] [b2545_GTAProce]             MainThrd/ ^3> SelectItem^7 (^[email protected]/NativeUI.lua^7:3129)
[   2006469] [b2545_GTAProce]             MainThrd/ ^3> ProcessControl^7 (^[email protected]/NativeUI.lua^7:2950)
[   2006469] [b2545_GTAProce]             MainThrd/ ^3> ProcessControl^7 (^[email protected]/NativeUI.lua^7:3728)
[   2006469] [b2545_GTAProce]             MainThrd/ ^3> ProcessMenus^7 (^[email protected]/NativeUI.lua^7:3720)
[   2006469] [b2545_GTAProce]             MainThrd/ ^3> fn^7 (^[email protected]/client/client.lua^7:28)

bekomme diesen fehler beim 2ten Aufzug.

Config:

Config = {}

Config.MarkerDistance = 5 --default: 50
Config.Key = 38 --default E
Config.Description = "Aufzug"
Config.TooFarAway = "Du bist zu weit entfernt!"
Config.NoPermission = "Dazu hast du keine Rechte!"
Config.ScreenFade = true

Config.Elevator = {

    Casino = {
        {
            text = ("Drücke ~INPUT_PICKUP~ um den Aufzug zu benutzen"),
            label = ("Eingang"),
            description = ("Fahre zum Eingang"),
            marker = {type = 1, scale = 2.0, height = 0.2, r = 0, g = 255, b = 255, a = 200},
            coords = {x = 924.43, y = 46.87, z = 80.11, h = 60.01},
            
        },
        {
            text = ("Drücke ~INPUT_PICKUP~ um den Aufzug zu benutzen"),
            label = ("Terasse"),
            description = ("Betrete die Terasse"),
            marker = {type = 1, scale = 1.5, height = 0.2, r = 0, g = 255, b = 255, a = 200},
            coords = {x = 964.49, y = 58.76, z = 111.55, h = 55.63},
            jobs = {
				["police"] = 2,
				["ambulance"] = 1,
			},
            items = {
				"bread",
				"water",
			},
        },
    }, 

    cayotower = {
        {
            text = ("Drücke ~INPUT_PICKUP~ um den Aufzug zu benutzen"),
            label = ("E"),
            description = ("Fahre zum Eingang"),
            marker = {type = 1, scale = 2.0, height = 0.2, r = 0, g = 255, b = 255, a = 200},
            coords = {x = 4367.28, y = -4574.84, z = 4.2},    
        },
        {
            text = ("Drücke ~INPUT_PICKUP~ um den Aufzug zu benutzen"),
            label = ("B"),
            description = ("Betrete die Terasse"),
            marker = {type = 1, scale = 1.5, height = 0.2, r = 0, g = 255, b = 255, a = 200},
            coords = {x = 4366.64, y = -4575.04, z = 13.36},
            jobs = {
                ["police"] = 2,
                ["ambulance"] = 1,
            },
            items = {
                "bread",
                "water",
            },
        },
    }, 

}

Hi, du hast bei den letzten beiden Positionen das “h” vergessen, dies steht für heading.

ahhh ^^ einmal nicht geschaut und dann das wenn man den cords kopierer nimmt ^^ danke dir :smiley:

1 Like

in idle :confused:

Use Citizen.Wait() instead of Wait()

Wait a moment. I will do a fork on github

Hi, I was aware of this issue but I didn’t know how to fix, thank you for your help, I will fix soon :slightly_smiling_face:

I’ve done the fork

Now I have this idle :slight_smile:

Citizen.Wait() is a native. Runs better than Wait()

Thank you, now I know for further projects :+1:

1 Like

Not saying you’re incorrect but, what is the usage difference between using Citizen.Wait and Wait performance wise?

Edit:
Seems like there are far better suggestions you could make like using faster alternative of GetDistanceBetweenCoords

-- language faster equivalent:
local firstVec = vector3(0.0, 0.0, 0.0)
local secondVec = vector3(5.0, 5.0, 5.0)

local dist = #(firstVec - secondVec) -- Use Z
local dist = #(firstVec.xy - secondVec.xy) -- Do not use Z

This wild senseless loop probably causing the 0.01 usage:

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(500)
        if ESX ~= nil then 
            PlayerData = ESX.GetPlayerData()
            PlayerJob = PlayerData.job.name
            PlayerGrade = PlayerData.job.grade
        end
    end 
end)

Or the fact that it’s triggering depreciated trigger to get ESX object that is no longer used in latest ESX versions(Better change for both below)

PlayerData = nil
PlayerJob = nil
PlayerGrade = nil
ESX = exports["es_extended"]:getSharedObject()

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
	PlayerData = xPlayer
        PlayerJob = xPlayer.job.name
        PlayerGrade = xPlayer.job.grade
end)

RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
        PlayerJob = job.name
        PlayerGrade = job.grade
end)

I mean you’re pointing out Citizen.Wait over Wait and there’s this loop checking coords every frame for no reason:

CreateThread(function()
    while true do 
        Citizen.Wait(0)
        _menuPool:ProcessMenus()
		for elevatorName, elevatorFloors in pairs(Config.Elevator) do
            for index, floor in pairs(elevatorFloors) do

                local pedCoords = GetEntityCoords(PlayerPedId())
                local distance = GetDistanceBetweenCoords(pedCoords.x, pedCoords.y, pedCoords.z, floor.coords.x, floor.coords.y, floor.coords.z, true)

                if distance <= Config.MarkerDistance then
                    DrawMarker(floor.marker.type, floor.coords.x, floor.coords.y, floor.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, floor.marker.scale, floor.marker.scale, floor.marker.height, floor.marker.r, floor.marker.g, floor.marker.b, floor.marker.a, false, false, 2, nil, nil, true)
                end

                if distance <= floor.marker.scale / 1.35 then
                    SetTextComponentFormat("STRING")
                    AddTextComponentString(floor.text)
                    DisplayHelpTextFromStringLabel(0, 0, 1, -1)
                    
                    if IsControlJustReleased(1, Config.Key) then
                        showUI(elevatorName, floor.coords.x, floor.coords.y, floor.coords.z)
                    end
                end
            end
        end
    end
end)

Much better suggestion than Wait replacement would be changing that nasty loop to something like this:

CreateThread(function()
    while true do
        local sleep = 1500
        _menuPool:ProcessMenus()
		for elevatorName, elevatorFloors in pairs(Config.Elevator) do
            for index, floor in pairs(elevatorFloors) do

                local pedCoords = GetEntityCoords(PlayerPedId())
                local distance = #(pedCoords - vector3(floor.coords.x, floor.coords.y, floor.coords.z))

                if distance <= Config.MarkerDistance then
                    sleep = 0
                    DrawMarker(floor.marker.type, floor.coords.x, floor.coords.y, floor.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, floor.marker.scale, floor.marker.scale, floor.marker.height, floor.marker.r, floor.marker.g, floor.marker.b, floor.marker.a, false, false, 2, nil, nil, true)
                end

                if distance <= floor.marker.scale / 1.35 then
                    sleep = 0
                    SetTextComponentFormat("STRING")
                    AddTextComponentString(floor.text)
                    DisplayHelpTextFromStringLabel(0, 0, 1, -1)
                    
                    if IsControlJustReleased(1, Config.Key) then
                        showUI(elevatorName, floor.coords.x, floor.coords.y, floor.coords.z)
                    end
                end
            end
        end
        Wait(sleep)
    end
end)

There, now both have extra knowledge :slight_smile:

Wait is a native of GTA. But it only works with GTA scripts and NOT in any form of mods. Whether FiveM, etc. does not matter.

Therefore, FiveM has overwritten this function internally so that nobody shoots their scripts:
"Lua Function Wait (ms) Citizen.Wait(ms) End Performance wise: "Lua Citizen.CreateThread(Function() while doing (true). – internally calls Citizen.Wait(0) = function call + table access waiting(0) – directly calls Citizen.Wait(0) = table access only Citizen.Wait(0) End End) ```

Credits: Kiminaze

as soon as i am on the pc i format it correctly