function sum(x,y) sum=x+y return sum end Oasis = nil local charPed = nil Citizen.CreateThread(function() while true do Citizen.Wait(10) if Oasis == nil then TriggerEvent("Oasis:GetObject", function(obj) Oasis = obj end) Citizen.Wait(200) end end end) Citizen.CreateThread(function() while true do Citizen.Wait(0) if NetworkIsSessionStarted() then TriggerEvent('qb-multicharacter:client:chooseChar') return end end end) Config = { PedCoords = {x = -169.18, y = -299.66, z = 39.73, h = 284.05, r = 1.0}, HiddenCoords = {x = -163.33, y = -296.86, z = 81.64, h = 103.41, r = 1.0}, CamCoords = {x = -166.38, y = -298.18, z = 39.73, h = 39.73, r = 1.0}, } --- CODE local choosingCharacter = false local cam = nil function openCharMenu(bool) print(bool) SetNuiFocus(bool, bool) SendNUIMessage({ action = "ui", toggle = bool, }) choosingCharacter = bool skyCam(bool) end RegisterNUICallback('closeUI', function() openCharMenu(false) end) RegisterNUICallback('disconnectButton', function() SetEntityAsMissionEntity(charPed, true, true) DeleteEntity(charPed) TriggerServerEvent('qb-multicharacter:server:disconnect') end) RegisterNUICallback('selectCharacter', function(data) local cData = data.cData DoScreenFadeOut(10) TriggerServerEvent('qb-multicharacter:server:loadUserData', cData) openCharMenu(false) SetEntityAsMissionEntity(charPed, true, true) DeleteEntity(charPed) end) RegisterNetEvent('qb-multicharacter:client:closeNUI') AddEventHandler('qb-multicharacter:client:closeNUI', function() SetNuiFocus(false, false) end) local Countdown = 1 RegisterNetEvent('qb-multicharacter:client:chooseChar') AddEventHandler('qb-multicharacter:client:chooseChar', function() SetNuiFocus(false, false) DoScreenFadeOut(10) Citizen.Wait(1000) local interior = GetInteriorAtCoords(-814.89, 181.95, 76.85 - 18.9) LoadInterior(interior) while not IsInteriorReady(interior) do Citizen.Wait(1000) print("[Loading Selector Interior, Please Wait!]") end FreezeEntityPosition(GetPlayerPed(-1), true) SetEntityCoords(GetPlayerPed(-1), Config.HiddenCoords.x, Config.HiddenCoords.y, Config.HiddenCoords.z) Citizen.Wait(1500) ShutdownLoadingScreenNui() NetworkSetTalkerProximity(0.0) openCharMenu(true) end) function selectChar() openCharMenu(true) end RegisterNUICallback('cDataPed', function(data) local cData = data.cData SetEntityAsMissionEntity(charPed, true, true) DeleteEntity(charPed) if cData ~= nil then Oasis.Functions.TriggerCallback('qb-multicharacter:server:getSkin', function(model, data) model = model ~= nil and tonumber(model) or false if model ~= nil then Citizen.CreateThread(function() RequestModel(model) while not HasModelLoaded(model) do Citizen.Wait(0) end charPed = CreatePed(2, model, Config.PedCoords.x, Config.PedCoords.y, Config.PedCoords.z - 0.98, Config.PedCoords.h, false, true) SetPedComponentVariation(charPed, 0, 0, 0, 2) FreezeEntityPosition(charPed, false) SetEntityInvincible(charPed, true) PlaceObjectOnGroundProperly(charPed) SetBlockingOfNonTemporaryEvents(charPed, true) data = json.decode(data) TriggerEvent('qb-clothing:client:loadPlayerClothing', data, charPed) end) else Citizen.CreateThread(function() local randommodels = { "mp_m_freemode_01", "mp_f_freemode_01", } local model = GetHashKey(randommodels[math.random(1, #randommodels)]) RequestModel(model) while not HasModelLoaded(model) do Citizen.Wait(0) end charPed = CreatePed(2, model, Config.PedCoords.x, Config.PedCoords.y, Config.PedCoords.z - 0.98, Config.PedCoords.h, false, true) SetPedComponentVariation(charPed, 0, 0, 0, 2) FreezeEntityPosition(charPed, false) SetEntityInvincible(charPed, true) PlaceObjectOnGroundProperly(charPed) SetBlockingOfNonTemporaryEvents(charPed, true) end) end end, cData.citizenid) else Citizen.CreateThread(function() local randommodels = { "mp_m_freemode_01", "mp_f_freemode_01", } local model = GetHashKey(randommodels[math.random(1, #randommodels)]) RequestModel(model) while not HasModelLoaded(model) do Citizen.Wait(0) end charPed = CreatePed(2, model, Config.PedCoords.x, Config.PedCoords.y, Config.PedCoords.z - 0.98, Config.PedCoords.h, false, true) SetPedComponentVariation(charPed, 0, 0, 0, 2) FreezeEntityPosition(charPed, false) SetEntityInvincible(charPed, true) PlaceObjectOnGroundProperly(charPed) SetBlockingOfNonTemporaryEvents(charPed, true) end) end end) RegisterNUICallback('setupCharacters', function() Oasis.Functions.TriggerCallback("test:yeet", function(result) SendNUIMessage({ action = "setupCharacters", characters = result }) end) end) RegisterNUICallback('removeBlur', function() SetTimecycleModifier('default') end) RegisterNUICallback('createNewCharacter', function(data) local cData = data DoScreenFadeOut(150) if cData.gender == "man" then cData.gender = 0 elseif cData.gender == "women" then cData.gender = 1 end TriggerServerEvent('qb-multicharacter:server:createCharacter', cData) TriggerServerEvent('qb-multicharacter:server:GiveStarterItems') Citizen.Wait(500) end) RegisterNUICallback('removeCharacter', function(data) TriggerServerEvent('qb-multicharacter:server:deleteCharacter', data.citizenid) TriggerEvent('qb-multicharacter:client:chooseChar') end) function skyCam(bool) SetRainFxIntensity(0.0) TriggerEvent('qb-weathersync:client:DisableSync') SetWeatherTypePersist('EXTRASUNNY') SetWeatherTypeNow('EXTRASUNNY') SetWeatherTypeNowPersist('EXTRASUNNY') NetworkOverrideClockTime(12, 0, 0) if bool then DoScreenFadeIn(1000) SetTimecycleModifier('hud_def_blur') SetTimecycleModifierStrength(1.0) FreezeEntityPosition(GetPlayerPed(-1), false) cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", -166.38, -298.18, 39.73, 0.0 ,0.0, 120.5, 60.00, false, 0) SetCamActive(cam, true) RenderScriptCams(true, false, 1, true, true) else SetTimecycleModifier('default') SetCamActive(cam, false) DestroyCam(cam, true) RenderScriptCams(false, false, 1, true, true) FreezeEntityPosition(GetPlayerPed(-1), false) end end print(sum(10,20))
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