ESX = nil local directions = { [0] = 'N', [45] = 'NW', [90] = 'W', [135] = 'SW', [180] = 'S', [225] = 'SE', [270] = 'E', [315] = 'NE', [360] = 'N', } Citizen.CreateThread(function() local minimap = RequestScaleformMovie("minimap") SetRadarBigmapEnabled(true, false) Wait(0) SetRadarBigmapEnabled(false, true) SetRadarZoom(1200) while true do Wait(0) BeginScaleformMovieMethod(minimap, "SETUP_HEALTH_ARMOUR") SetRadarBigmapEnabled(false, true) SetRadarZoom(1200) ScaleformMovieMethodAddParamInt(3) EndScaleformMovieMethod() end end) CreateThread(function() while true do Wait(400) local state = NetworkIsPlayerTalking(PlayerId()) local mode = Player(GetPlayerServerId(PlayerId())).state.proximity.mode SendNUIMessage({ type = 'UPDATE_VOICE', isTalking = state, mode = mode }) end end) CreateThread(function() while true do Wait(100) if IsPedInAnyVehicle(PlayerPedId()) and not IsPauseMenuActive() then Wait(100) local PedCar = GetVehiclePedIsUsing(PlayerPedId(), false) Speed = math.floor(GetEntitySpeed(PedCar) * 3.6 + 0.5) MaxSpeed = math.ceil(GetVehicleEstimatedMaxSpeed(PedCar) * 3.6 + 0.5) SpeedPercent = Speed / MaxSpeed * 100 rpm = GetVehicleCurrentRpm(PedCar) * 100 SendNUIMessage({ speedometer = true, speed = Speed, percent = SpeedPercent, rpmx = rpm, }) else Citizen.Wait(1000) end end end) CreateThread(function() while true do Wait(450) if IsPedInAnyVehicle(PlayerPedId()) and not IsPauseMenuActive() then DisplayRadar(true) local PedCar = GetVehiclePedIsUsing(PlayerPedId(), false) local coords = GetEntityCoords(PlayerPedId()) local fuel = tostring(math.ceil(GetVehicleFuelLevel(PedCar))) local _,lightsOn,highbeamsOn = GetVehicleLightsState(PedCar) local lightMode = 1 if lightsOn == 1 then lightMode = lightMode + 1 end if highbeamsOn == 1 then lightMode = lightMode + 1 end SetMapZoomDataLevel(0, 0.96, 0.9, 0.08, 0.0, 0.0) -- Level 0 SetMapZoomDataLevel(1, 1.6, 0.9, 0.08, 0.0, 0.0) -- Level 1 SetMapZoomDataLevel(2, 8.6, 0.9, 0.08, 0.0, 0.0) -- Level 2 SetMapZoomDataLevel(3, 12.3, 0.9, 0.08, 0.0, 0.0) -- Level 3 SetMapZoomDataLevel(4, 22.3, 0.9, 0.08, 0.0, 0.0) -- Level 4 SendNUIMessage({ showhud = true, lights = lightMode, paliwo = fuel, }) SendNUIMessage({ type = 'UPDATE_SEATBELT', belt = exports['Atlanta_blackout']:pasyState() }) else SendNUIMessage({ showhud = false }) if exports["gcphone"]:getMenuIsOpen() then DisplayRadar(true) else DisplayRadar(false) end Wait(2000) end end end) local hash1, hash2; CreateThread(function() while true do Wait(500) local ped, direction = PlayerPedId(), nil for k, v in pairs(directions) do direction = GetEntityHeading(ped) if math.abs(direction - k) < 22.5 then direction = v break end end local coords = GetEntityCoords(ped, true) local zone = GetNameOfZone(coords.x, coords.y, coords.z) local zoneLabel = GetLabelText(zone) local var1, var2 = GetStreetNameAtCoord(coords.x, coords.y, coords.z, Citizen.ResultAsInteger(), Citizen.ResultAsInteger()) hash1 = GetStreetNameFromHashKey(var1); hash2 = GetStreetNameFromHashKey(var2); local street2; if (hash2 == '') then street2 = zoneLabel; else street2 = hash2..', '..zoneLabel; end --[[local blip = GetFirstBlipInfoId(8) local distance = 0 local ghahahah = 0 if (blip ~= 0) then local coord = GetBlipCoords(blip) ghahahah = CalculateTravelDistanceBetweenPoints(GetEntityCoords(Citizen.InvokeNative(0x43A66C31C68491C0,-1)), coord) if blip ~= 0 then if ghahahah ~= 0 then distance = ghahahah else distance = 0 end end end]] SendNUIMessage({ street = street2, direction = (direction or 'N'), direction2 = direction .. ' | ' .. street2, --waypoint = distance, }) end end) CreateThread(function() while true do Wait(1000) TriggerEvent('esx_status:getStatus', 'hunger', function(status) hunger = status.getPercent() end) TriggerEvent('esx_status:getStatus', 'thirst', function(status) thirst = status.getPercent() end) local armor = GetPedArmour(PlayerPedId()) local hp = GetEntityHealth(PlayerPedId()) - 100 local nurkowanie = GetPlayerUnderwaterTimeRemaining(PlayerId()) * 10 --local inwater = IsPedSwimmingUnderWater(PlayerPedId()), SendNUIMessage({ type = 'UPDATE_HUD', hunger = hunger, thirst = thirst, armor = armor, nurkowanie = nurkowanie, --inwater = inwater, zycie = hp, isdead = hp <= 0 }) end end) CreateThread(function() while true do Wait(180000) TriggerEvent('esx_status:getStatus', 'hunger', function(status) hunger = status.getPercent() end) TriggerEvent('esx_status:getStatus', 'thirst', function(status) thirst = status.getPercent() end) if hunger < 20 and thirst < 20 then --ESX.ShowNotification("~r~Zostało Ci poniżej 20% jedzenia i picia!") exports.dopeNotify:SendNotification({ text = '<b><i class="fas fa-bell"></i> POWIADOMIENIE</span></b></br>Zostało Ci poniżej <span style="color: #FF0000;"><b>20%</b> <span style="color: #ffe100;">jedzenia i picia!', type = "info", timeout = 3000, layout = "topRight" }) elseif hunger < 20 then --ESX.ShowNotification("~r~Zostało Ci poniżej 20% jedzenia!") exports.dopeNotify:SendNotification({ text = '<b><i class="fas fa-bell"></i> POWIADOMIENIE</span></b></br>Zostało Ci poniżej <span style="color: #FF0000;"><b>20%</b> <span style="color: #ffe100;">jedzenia!', type = "info", timeout = 3000, layout = "topRight" }) elseif thirst < 20 then --ESX.ShowNotification("~r~Zostało Ci poniżej 20% picia!") exports.dopeNotify:SendNotification({ text = '<b><i class="fas fa-bell"></i> POWIADOMIENIE</span></b></br>Zostało Ci poniżej <span style="color: #FF0000;"><b>20%</b> <span style="color: #ffe100;">picia!', type = "info", timeout = 3000, layout = "topRight" }) end end end) CreateThread(function() while true do Wait(2000) local data = exports['rp-radio']:GetRadioData() if tostring(data[3]) == "0" then SendNUIMessage({ hideradio = true }) else SendNUIMessage({ showradio = true }) end SendNUIMessage({ radionumber = data[2], radiocount = data[3], }) end end) CreateThread(function() while true do Wait(5000) local idpedala = GetPlayerServerId(PlayerId()) SendNUIMessage({ type = 'UPDATE_ID', id = idpedala }) end end) RegisterNetEvent("hud:Speedo", function(b) SendNUIMessage({ type = "HIDE_SPEDDO", bool = b }) end) RegisterNetEvent('esx:playerLoaded') AddEventHandler('esx:playerLoaded', function(playerData) for k,v in pairs(ESX.PlayerData.slots) do local found = false for k2,v2 in pairs(ESX.PlayerData.loadout) do if k == v2.id then found = true if v.slot then count = v.count and 'x' .. v.count SendNUIMessage({ action = 'updateSlot', item = v.name, count = count, slot = v.slot }) end end end for k3,v3 in pairs(ESX.PlayerData.inventory) do if v3.count > 0 then if k == v3.name then found = true if v.slot then count = v.count and 'x' .. v.count SendNUIMessage({ action = 'updateSlot', item = v.name, count = count, slot = v.slot }) end end end end if not found then ESX.SetSlot(k, nil, true) end end end) RegisterNetEvent('hud:updateSlot') AddEventHandler('hud:updateSlot', function(slot, count, item) count = count and 'x' .. count SendNUIMessage({ action = 'updateSlot', item = item, count = count, slot = slot }) end) function ToggleSlots() if not ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then SendNUIMessage({action = 'toggleslots'}) end end RegisterCommand("+toggleslots", ToggleSlots) RegisterKeyMapping("+toggleslots", "Przełączanie widoczności slotów", "keyboard", "TAB") RegisterCommand("off", function(source, args, raw) ESX.DisplaySlots(false) end) RegisterCommand("hud", function(source, args, raw) SendNUIMessage({ action = 'show_hud' }) SetNuiFocus(true, true) cameraLocked = true -- wyjebac end) RegisterNUICallback("stopedit", function() SetNuiFocus(false, false) cameraLocked = false -- wyjebac end) -- wyjebac -- Citizen.CreateThread(function() while true do Citizen.Wait(1) if cameraLocked == true then DisableControlAction(0, 1, true) DisableControlAction(0, 2, true) end end end)
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