Main/resources/[standalone]/utility_lib/server/native_min.lua
2025-06-07 08:51:21 +02:00

1 line
No EOL
13 KiB
Lua

StartESX=function(a)ESX=exports["es_extended"]:getSharedObject()end;StartQB=function(a)QBCore=exports['qb-core']:GetCoreObject()end;ShowNotification=function(b,c,type)if GetResourceState("qb-core")=="started"then TriggerClientEvent('QBCore:Notify',b,c,type)elseif GetResourceState("es_extended")=="started"then TriggerClientEvent('esx:showNotification',b,c)end end;CreateLoop=function(d,e)Citizen.CreateThread(function()local f=true;_break=function()f=false end;while f do d()Citizen.Wait(e or 5)end end)end;AddItem=function(b,...)if ESX then xPlayer=ESX.GetPlayerFromId(b)xPlayer.addInventoryItem(...)else xPlayer=QBCore.Functions.GetPlayer(b)xPlayer.Functions.AddItem(...)end end;RemoveItem=function(b,...)if ESX then xPlayer=ESX.GetPlayerFromId(b)xPlayer.removeInventoryItem(...)else xPlayer=QBCore.Functions.GetPlayer(b)xPlayer.Functions.RemoveItem(...)end end;GetItem=function(b,...)if ESX then xPlayer=ESX.GetPlayerFromId(b)return xPlayer.getInventoryItem(...)else xPlayer=QBCore.Functions.GetPlayer(b)return xPlayer.Functions.GetItemByName(...)end end;HaveItem=function(b,...)if ESX then return GetItem(b,...).count>0 else return GetItem(b,...).amount>0 end end;HaveItemQuantity=function(b,g,h)if ESX then return GetItem(b,g).count>h else return GetItem(b,g).amount>h end end;AddMoney=function(b,type,...)if ESX then xPlayer=ESX.GetPlayerFromId(b)if type=="cash"then xPlayer.addMoney(...)else xPlayer.addAccountMoney(type,...)end else xPlayer=QBCore.Functions.GetPlayer(b)xPlayer.Functions.AddMoney(type,...)end end;RemoveMoney=function(b,type,...)if ESX then xPlayer=ESX.GetPlayerFromId(b)if type=="cash"then xPlayer.removeMoney(...)else xPlayer.removeAccountMoney(type,...)end else xPlayer=QBCore.Functions.GetPlayer(b)xPlayer.Functions.RemoveMoney(type,...)end end;HaveMoney=function(b,type,i)if ESX then xPlayer=ESX.GetPlayerFromId(b)if type=="cash"then return xPlayer.getMoney(type)>=i else return xPlayer.getAccount(type).money>=i end else xPlayer=QBCore.Functions.GetPlayer(b)return xPlayer.Functions.GetMoney(type)>=i end end;StartMySQL=function()MySQL={Async={},Sync={}}local function j(k)if nil==k then return{['']=''}end;assert(type(k)=="table","A table is expected")if next(k)==nil then return{['']=''}end;return k end;function MySQL.Sync.execute(l,k)assert(type(l)=="string"or type(l)=="number","The SQL Query must be a string")local m=0;local n=false;exports['mysql-async']:mysql_execute(l,j(k),function(o)m=o;n=true end)repeat Citizen.Wait(0)until n==true;return m end;function MySQL.Sync.fetchAll(l,k)assert(type(l)=="string"or type(l)=="number","The SQL Query must be a string")local m={}local n=false;exports['mysql-async']:mysql_fetch_all(l,j(k),function(o)m=o;n=true end)repeat Citizen.Wait(0)until n==true;return m end;function MySQL.Sync.fetchScalar(l,k)assert(type(l)=="string"or type(l)=="number","The SQL Query must be a string")local m=''local n=false;exports['mysql-async']:mysql_fetch_scalar(l,j(k),function(o)m=o;n=true end)repeat Citizen.Wait(0)until n==true;return m end;function MySQL.Sync.insert(l,k)assert(type(l)=="string"or type(l)=="number","The SQL Query must be a string")local m=0;local n=false;exports['mysql-async']:mysql_insert(l,j(k),function(o)m=o;n=true end)repeat Citizen.Wait(0)until n==true;return m end;function MySQL.Sync.store(l)assert(type(l)=="string","The SQL Query must be a string")local m=-1;local n=false;exports['mysql-async']:mysql_store(l,function(o)m=o;n=true end)repeat Citizen.Wait(0)until n==true;return m end;function MySQL.Sync.transaction(p,k)local m=0;local n=false;exports['mysql-async']:mysql_transaction(p,k,function(o)m=o;n=true end)repeat Citizen.Wait(0)until n==true;return m end;function MySQL.Async.execute(l,k,q)assert(type(l)=="string"or type(l)=="number","The SQL Query must be a string")exports['mysql-async']:mysql_execute(l,j(k),q)end;function MySQL.Async.fetchAll(l,k,q)assert(type(l)=="string"or type(l)=="number","The SQL Query must be a string")exports['mysql-async']:mysql_fetch_all(l,j(k),q)end;function MySQL.Async.fetchScalar(l,k,q)assert(type(l)=="string"or type(l)=="number","The SQL Query must be a string")exports['mysql-async']:mysql_fetch_scalar(l,j(k),q)end;function MySQL.Async.insert(l,k,q)assert(type(l)=="string"or type(l)=="number","The SQL Query must be a string")exports['mysql-async']:mysql_insert(l,j(k),q)end;function MySQL.Async.store(l,q)assert(type(l)=="string","The SQL Query must be a string")exports['mysql-async']:mysql_store(l,q)end;function MySQL.Async.transaction(p,k,q)return exports['mysql-async']:mysql_transaction(p,k,q)end;function MySQL.ready(r)Citizen.CreateThread(function()while GetResourceState('mysql-async')~='started'do Citizen.Wait(0)end;while not exports['mysql-async']:is_ready()do Citizen.Wait(0)end;r()end)end end;ExecuteSql=function(l,k)if MySQL==nil then StartMySQL()end;if string.find(l,"SELECT")then return MySQL.Sync.fetchAll(l,k)elseif string.find(l,"INSERT")or string.find(l,"UPDATE")then MySQL.Sync.execute(l,k)end end;SocietyAddItem=function(s,g,i)if not string.find(s,"society_")then s="society_"..s end;TriggerEvent('esx_addoninventory:getSharedInventory',s,function(t)t.addItem(g,i)end)end;SocietyRemoveItem=function(s,g,i)if not string.find(s,"society_")then s="society_"..s end;TriggerEvent('esx_addoninventory:getSharedInventory',s,function(t)t.removeItem(g,i)end)end;SocietyGetItem=function(s,g)if not string.find(s,"society_")then s="society_"..s end;local u=nil;TriggerEvent('esx_addoninventory:getSharedInventory',s,function(t)u=t.getItem(g)end)while u==nil do Citizen.Wait(1)end;return u end;SocietyHaveItem=function(s,g)if not string.find(s,"society_")then s="society_"..s end;local u=nil;TriggerEvent('esx_addoninventory:getSharedInventory',s,function(t)local v=t.getItem(g).count;u=v>0 end)while u==nil do Citizen.Wait(1)end;return u end;SocietyHaveItemQuantity=function(s,g,h)if not string.find(s,"society_")then s="society_"..s end;local u=nil;TriggerEvent('esx_addoninventory:getSharedInventory',s,function(t)local v=t.getItem(g).count;u=v>h end)while u==nil do Citizen.Wait(1)end;return u end;SocietyAddMoney=function(s,i)if not string.find(s,"society_")then s="society_"..s end;TriggerEvent('esx_addonaccount:getSharedAccount',s,function(w)w.addMoney(i)end)end;SocietyRemoveMoney=function(s,i)if not string.find(s,"society_")then s="society_"..s end;TriggerEvent('esx_addonaccount:getSharedAccount',s,function(w)w.removeMoney(i)end)end;SocietyHaveMoney=function(s,i)if not string.find(s,"society_")then s="society_"..s end;local x=nil;TriggerEvent('esx_addonaccount:getSharedAccount',s,function(w)x=w.money>=i end)while x==nil do Citizen.Wait(1)end;return x end;printd=function(y,z)if z then local A={}local function B(C,D)if A[tostring(C)]then print(D.."*"..tostring(C))else A[tostring(C)]=true;if type(C)=="table"then for E,F in pairs(C)do if type(F)=="table"then print(D.."["..E.."] => "..tostring(C).." {")B(F,D..string.rep(" ",string.len(E)+8))print(D..string.rep(" ",string.len(E)+6).."}")elseif type(F)=="string"then print(D.."["..E.."] => \""..F.."\"")else print(D.."["..E.."] => "..tostring(F))end end else print(D..tostring(C))end end end;if type(y)=="table"then print(tostring(y).." {")B(y," ")print("}")else developer("^1Error^0","error dumping table "..y.." why isnt a table","")end else if type(y)=="table"then print(json.encode(y,{indent=true}))else developer("^1Error^0","error dumping table "..y.." why isnt a table","")end end end;local G=string.gsub;string.multigsub=function(string,table,H)if type(table)then for I=1,#table do string=G(string,table[I],H[I])end else for I=1,#table do string=G(string,table[I],H)end end;return string end;table.fexist=function(y,J)return y[J]~=nil end;local K=table.remove;table.remove=function(y,L,M)if type(L)=="number"then return K(y,L)elseif type(L)=="string"then for N,O in pairs(y)do if N==L then y[N]=nil;if M then return N end end end end end;table.empty=function(C)return next(C)==nil end;local P=function(C,N,O)if type(N)=="number"then table.insert(C,O)else C[N]=O end end;table.merge=function(Q,R)local o=table.clone(Q)for N,O in pairs(R)do P(o,N,O)end;return o end;table.includes=function(C,S)if type(S)=="function"then for T,O in pairs(C)do if S(O)then return true end end else for T,O in pairs(C)do if S==O then return true end end end;return false end;table.filter=function(C,U)local o={}if type(U)=="function"then for N,O in pairs(C)do if U(N,O)then P(o,N,O)end end elseif type(U)=="table"then for N,O in pairs(C)do if table.includes(U,O)then P(o,N,O)end end end;return o end;table.find=function(C,S)if type(S)=="function"then for N,O in pairs(C)do if S(O)then return N,O end end else for N,O in pairs(C)do if S==O then return N,O end end end end;table.keys=function(C)local V={}for N,T in pairs(C)do table.insert(V,N)end;return V end;table.values=function(C)local W={}for T,O in pairs(C)do table.insert(W,O)end;return W end;math.round=function(X,Y)local T=10^Y;return math.floor(X*T+0.5)/T end;math.lerp=function(Z,_,a0)return Z+(_-Z)*a0 end;math.invlerp=function(Z,_,S)return(S-Z)/(_-Z)end;GetDataForJob=function(a1)return exports["utility_lib"]:GetDataForJob(a1)end;quat2euler=function(a2)local a3=2*(a2.w*a2.x+a2.y*a2.z)local a4=1-2*(a2.x*a2.x+a2.y*a2.y)local a5=math.atan2(a3,a4)local a6=math.sqrt(1+2*(a2.w*a2.y-a2.x*a2.z))local a7=math.sqrt(1-2*(a2.w*a2.y-a2.x*a2.z))local a8=2*math.atan2(a6,a7)-math.pi/2;local a9=2*(a2.w*a2.z+a2.x*a2.y)local aa=1-2*(a2.y*a2.y+a2.z*a2.z)local ab=math.atan2(a9,aa)return vec3(math.deg(a5),math.deg(a8),math.deg(ab))end;GenerateMatrix=function(E,ac)local ad,ae,af=math.rad(ac.x),math.rad(ac.y),math.rad(ac.z)local ag,ah=math.cos(ad),math.sin(ad)local ai,aj=math.cos(ae),math.sin(ae)local ak,al=math.cos(af),math.sin(af)local am=mat3(vec3(1,0,0),vec3(0,ag,-ah),vec3(0,ah,ag))local an=mat3(vec3(ai,0,aj),vec3(0,1,0),vec3(-aj,0,ai))local ao=mat3(vec3(ak,-al,0),vec3(al,ak,0),vec3(0,0,1))local ap=am*an*ao;local aq=mat4(vec4(ap[1].x,ap[2].x,ap[3].x,0),vec4(ap[1].y,ap[2].y,ap[3].y,0),vec4(ap[1].z,ap[2].z,ap[3].z,0),vec4(E.x,E.y,E.z,1))return aq end;GetOffsetFromPositionInWorldCoords=function(E,ac,ar)local as=GenerateMatrix(E,ac)return as*ar end;local at=100.0;local au=8100;local av=au/at;function GetSliceColRowFromCoords(aw)local ax=math.floor(aw.x/at)local ay=math.floor(aw.y/at)return ay,ax end;function GetWorldCoordsFromSlice(az)local ay=math.floor(az/av)local ax=az%av;return vec3(ax*at,ay*at,0.0)end;function GetSliceIdFromColRow(ay,ax)return math.floor(ay*av+ax)end;function GetSliceFromCoords(E)local ay,ax=GetSliceColRowFromCoords(E)return GetSliceIdFromColRow(ay,ax)end;function GetSurroundingSlices(az)local aA=az-av;local aB=az+av;local aC=az-1;local aD=az+1;local aE=az-av-1;local aF=az-av+1;local aG=az+av-1;local aH=az+av+1;return{aA,aB,aD,aC,aE,aF,aG,aH}end;local aI={}UtilityNet={}UtilityNet.CreateEntity=function(aJ,aw,aK)local aL=exports["utility_lib"]:CreateEntity(aJ,aw,aK)table.insert(aI,aL)return aL end;UtilityNet.DeleteEntity=function(aM)for N,O in pairs(aI)do if O==aM then table.remove(aI,N)break end end;return exports["utility_lib"]:DeleteEntity(aM)end;UtilityNet.DoesUNetIdExist=function(aM)for N,O in pairs(GlobalState.Entities)do if O.id==aM then return true end end;return false end;UtilityNet.GetEntityCoords=function(aM)for N,O in pairs(GlobalState.Entities)do if O.id==aM then return O.coords end end end;UtilityNet.GetEntityModel=function(aM)for N,O in pairs(GlobalState.Entities)do if O.id==aM then return O.model end end end;UtilityNet.SetModelRenderDistance=function(aJ,aN)return exports["utility_lib"]:SetModelRenderDistance(aJ,aN)end;UtilityNet.SetEntityCoords=function(aM,aO)return exports["utility_lib"]:SetEntityCoords(aM,aO)end;UtilityNet.SetEntityRotation=function(aM,aP)return exports["utility_lib"]:SetEntityRotation(aM,aP)end;local aQ=nil;aQ=function(aL,aR,aS)aS=aS or{}local aT=function()local aU=exports["utility_lib"]:GetEntityStateValue(aL,aR)for N,O in pairs(aS)do aU=aU[O]end;return aU end;return setmetatable({raw=function(self)return aT()end},{__pairs=function(self)return pairs(aT())end,__ipairs=function(self)return ipairs(aT())end,__len=function(self)return#aT()end,__index=function(T,N)local aV=aT()if type(aV[N])=="table"then local aW=table.clone(aS)table.insert(aW,N)return aQ(aL,aR,aW)else return aV[N]end end,__newindex=function(T,N,O)local aU=exports["utility_lib"]:GetEntityStateValue(aL,aR)local aV=aU;for N,O in pairs(aS)do aV=aV[O]end;aV[N]=O;exports["utility_lib"]:SetEntityStateValue(aL,aR,aU)end})end;UtilityNet.State=function(aL)local aX=setmetatable({},{__index=function(T,N)local S=exports["utility_lib"]:GetEntityStateValue(aL,N)if type(S)=="table"then return aQ(aL,N,{})else return S end end,__newindex=function(T,N,O)exports["utility_lib"]:SetEntityStateValue(aL,N,O)end})return aX end;AddEventHandler("onResourceStop",function(aY)if aY==GetCurrentResourceName()then for N,O in pairs(aI)do exports["utility_lib"]:DeleteEntity(O)end end end)