print ("Hello, World!") local ESX, micmuted, voicelevel = nil, false, 0 Citizen.CreateThread(function() while ESX == nil do TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) Citizen.Wait(0) end TriggerEvent('esx:setMoneyDisplay', 0.0) ESX.UI.HUD.SetDisplay(0.0) while ESX.GetPlayerData() == nil do Citizen.Wait(50) end ESX.PlayerData = ESX.GetPlayerData() local data = ESX.GetPlayerData() local accounts = data.accounts for _, account in pairs(accounts) do if account.name == "black_money" then if account.money > 0 then SendNUIMessage({ action = "setBlackMoney", money = account.money, playerId = GetPlayerServerId(PlayerId()) }) end end end SendNUIMessage({action = "setVoiceLevel", level = 1}) SendNUIMessage({action = "setMoney", money = data.money, playerId = GetPlayerServerId(PlayerId())}) end) RegisterNetEvent("nlc_notify") AddEventHandler("nlc_notify", function(type, title, message) if title ~= nil and title ~= "" and message ~= nil and message ~= "" and type ~= nil and type ~= "" and isStringValid(type) and isStringValid(title) and isStringValid(message) then SendNUIMessage({ action = "notify", type = type, title = title, message = message }) PlaySoundFrontend(-1, "ATM_WINDOW", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1) end end) RegisterCommand('announce2', function(source, args, rawCommand) end,fals) RegisterNetEvent("nlc_announce") AddEventHandler("nlc_announce", function(title, message) if title ~= nil and title ~= "" and message ~= nil and message ~= "" and isStringValid(title) and isStringValid(message) then SendNUIMessage({ action = "announce", title = title, message = message }) PlaySoundFrontend(-1, "OTHER_TEXT", "HUD_AWARDS", 1) end end) Citizen.CreateThread(function() while true do Citizen.Wait(500) local data = exports.saltychat:GetRadioChannel(true) if data == nil or data == '' then SendNUIMessage({ action = "setFunkState", active = false }) else SendNUIMessage({ action = "setFunkState", active = true }) end end end) AddEventHandler('SaltyChat_RadioChannelChanged', function(radioName, isPrimary) if radioName ~= nil then SendNUIMessage({ action = "setFunkState", active = true }) else SendNUIMessage({ action = "setFunkState", active = false }) end end) local loadedAmmo = false local toggledArm = false Citizen.CreateThread(function() while true do Citizen.Wait(500) if IsPedArmed(PlayerPedId(), 6) and not toggledArm then toggledArm = true loadedAmmo = true local ped = PlayerPedId() local _, weapon = GetCurrentPedWeapon(ped) local _, clipAmmo = GetAmmoInClip(ped, weapon) SendNUIMessage({ action = "setAmmo", state = true, ammo = GetAmmoInPedWeapon(ped, weapon), clip = clipAmmo }) elseif not IsPedArmed(PlayerPedId(), 6) and toggledArm then toggledArm = false if loadedAmmo then loadedAmmo = false SendNUIMessage({ action = "setAmmo", state = false }) end Citizen.Wait(500) end end end) AddEventHandler('CEventGunShot', function(entities, eventEntity, args) if eventEntity == PlayerPedId() then local ped = PlayerPedId() local _, weapon = GetCurrentPedWeapon(ped) local _, clipAmmo = GetAmmoInClip(ped, weapon) SendNUIMessage({ action = "setAmmo", state = true, ammo = GetAmmoInPedWeapon(ped, weapon), clip = clipAmmo }) end end) Citizen.CreateThread(function() while true do local ped = PlayerPedId() if IsPedInAnyVehicle(ped) then local vehicle = GetVehiclePedIsIn(ped, false) if vehicle and GetPedInVehicleSeat(vehicle, -1) == ped then local carSpeed = math.ceil(GetEntitySpeed(vehicle) * 3.6) local carRPM = GetVehicleCurrentRpm(vehicle) local fuel = ESX.Math.Round(GetVehicleFuelLevel(vehicle), 1) SendNUIMessage({ action = "carHud", state = true, speed = carSpeed, fuel = fuel, RPM = carRPM }) SendNUIMessage({ action = "carEngine", state = GetIsVehicleEngineRunning(vehicle) }) if GetVehicleDoorLockStatus(vehicle) == 1 then SendNUIMessage({ action = "carLock", state = true }) else SendNUIMessage({ action = "carLock", state = false }) end if GetEntitySpeed(vehicle) <= 10 then Citizen.Wait(350) elseif GetEntitySpeed(vehicle) <= 5 then Citizen.Wait(750) end Citizen.Wait(1) else SendNUIMessage({ action = "carHud", state = false }) Citizen.Wait(1000) end else SendNUIMessage({ action = "carHud", state = false }) Citizen.Wait(1000) end Citizen.Wait(0) end end) RegisterNetEvent('esx:playerLoaded') AddEventHandler('esx:playerLoaded', function(xPlayer) local data = xPlayer local accounts = data.accounts for _, account in pairs(accounts) do if account.name == "black_money" then if account.money > 0 then SendNUIMessage({ action = "setBlackMoney", money = account.money, playerId = GetPlayerServerId(PlayerId()) }) end end end SendNUIMessage({action = "setVoiceLevel", level = 1}) SendNUIMessage({action = "setMoney", money = data.money, playerId = GetPlayerServerId(PlayerId())}) end) RegisterNetEvent('SaltyChat_MicStateChanged') AddEventHandler('SaltyChat_MicStateChanged', function(isMicrophoneMuted) SendNUIMessage({ action = "setMicrophoneState", state = isMicrophoneMuted }) end) AddEventHandler('SaltyChat_TalkStateChanged', function(talking) SendNUIMessage({ action = "setMicrophoneState", state = not talking }) end) RegisterNetEvent('esx:setAccountMoney') AddEventHandler('esx:setAccountMoney', function(account) if account.name == "money" then SendNUIMessage({ action = "setMoney", money = account.money, playerId = GetPlayerServerId(PlayerId()) }) elseif account.name == "black_money" then SendNUIMessage({ action = "setBlackMoney", money = account.money, playerId = GetPlayerServerId(PlayerId()) }) end end) AddEventHandler('SaltyChat_MicStateChanged', function(isMicrophoneMuted) micmuted = isMicrophoneMuted if micmuted == false then SendNUIMessage({ action = "setVoiceLevel", level = voicelevel }) end end) RegisterNetEvent('SaltyChat_VoiceRangeChanged') AddEventHandler('SaltyChat_VoiceRangeChanged', function(voiceRange, index, availableVoiceRanges) if index == 0 then TriggerEvent('grv_notify', 'orange', "SaltyChat", 'Sprachreichweite: 3M') elseif index == 1 then TriggerEvent('grv_notify', 'orange', "SaltyChat", 'Sprachreichweite: 8M') elseif index == 2 then TriggerEvent('grv_notify', 'orange', "SaltyChat", 'Sprachreichweite: 16M') end SendNUIMessage({action = "setVoiceLevel", level = index + 1}) end) RegisterNetEvent('esx:activateMoney') AddEventHandler('esx:activateMoney', function(e) SendNUIMessage({ action = "setMoney", money = e, playerId = GetPlayerServerId(PlayerId()) }) end) Citizen.CreateThread(function() while true do Citizen.Wait(0) HideHudComponentThisFrame(3) -- CASH HideHudComponentThisFrame(4) -- MP CASH HideHudComponentThisFrame(2) -- weapon icon HideHudComponentThisFrame(9) -- STREET NAME HideHudComponentThisFrame(7) -- Area NAME HideHudComponentThisFrame(8) -- Vehicle Class HideHudComponentThisFrame(6) -- Vehicle Name end end) function isStringValid(string) for _, bString in pairs(blacklistedStrings) do if string.find(string.lower(string), string.lower(bString)) then return false end end return true end blacklistedStrings = { "<", ">", "script", "img", "video", "iframe", "audio", "mp3", "mp4", "ogg", "webm" }
Write, Run & Share Lua code online using OneCompiler's Lua online compiler for free. It's one of the robust, feature-rich online compilers for Lua language, running the latest Lua version 5.4. Getting started with the OneCompiler's Lua editor is easy and fast. The editor shows sample boilerplate code when you choose language as Lua and start coding.
OneCompiler's Lua online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Lua program which takes name as input and prints hello message with your name.
name = io.read("*a")
print ("Hello ", name)
Lua is a light weight embeddable scripting language which is built on top of C. It is used in almost all kind of applications like games, web applications, mobile applications, image processing etc. It's a very powerful, fast, easy to learn, open-source scripting language.
-- global variables
a = 10
-- local variables
local x = 30
Value Type | Description |
---|---|
number | Represents numbers |
string | Represents text |
nil | Differentiates values whether it has data or not |
boolean | Value can be either true or false |
function | Represents a sub-routine |
userdata | Represents arbitary C data |
thread | Represents independent threads of execution. |
table | Can hold any value except nil |
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition)
do
--code
end
Repeat-Until is also used to iterate a set of statements based on a condition. It is very similar to Do-While, it is mostly used when you need to execute the statements atleast once.
repeat
--code
until( condition )
For loop is used to iterate a set of statements based on a condition.
for init,max/min value, increment
do
--code
end
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increase re-usuability and modularity.
optional_function_scope function function_name( argument1, argument2, argument3........, argumentn)
--code
return params with comma seperated
end