Kernell 44 Posted February 18, 2012 LoveFist, а чем плох toJSON и fromJSON? Как я вижу делает тоже самое. Share this post Link to post
MX_Master 8 Posted February 18, 2012 У него функция сериализации, которая сохраняет все как Lua код. toJSON сохраняет как JSON код. Строковым Lua кодом легче потом манипулировать. Хоть в БД, хоть скрипт создавай, хоть loadstring() Share this post Link to post
Kenix 55 Posted February 19, 2012 Добавил ещё одну очень полезную функцию. Share this post Link to post
MX_Master 8 Posted February 20, 2012 Добавил ещё одну очень полезную функцию. Ну а теперь ты функции группируй и под спойлер разные группы (: Share this post Link to post
Kenix 55 Posted February 20, 2012 Изменил оформление и теперь всё по группам. Share this post Link to post
MX_Master 8 Posted February 20, 2012 Все-таки некоторые группы слишком большие. Даже под спойлером оно сморится как салатик из овощей и фруктов одним слоем. А мой вариант не подошел, где под спойлером были коды? Share this post Link to post
MX_Master 8 Posted February 20, 2012 Отлично. Теперь я наконец увидел какие функции есть (: а то листать весь длинный пост просто не хватало сил. Share this post Link to post
Kenix 55 Posted February 20, 2012 Сейчас есть проблема. Очень нужна функция , которая бы перебирала ВСЮ таблицу. Например. local t = { a = '1'; b = { '2'; c = { '3'; ['4'] = { '5' } } } } Share this post Link to post
Kenix 55 Posted February 20, 2012 В том то и дело , что нет. Если в таблице есть таблицы то они их не перебирает. t = { a = { 'a'; ['c'] = { 'b' } } } for _,v in pairs( t ) do print( v ) end -- table: 0x2538600 Нужно вообще всё перебрать. Ладно если индекс числовой , а вот если нет? Share this post Link to post
Kernell 44 Posted February 20, 2012 Ну так это логично. function table.print( array ) -- может переполниться стек при очень больших таблицах for _, value in pairs( array ) do if type( value ) == 'table' then table.print( value ); else print( value ); end end end Ладно если индекс числовой , а вот если нет? Ну и что? ipairs перебирает таблицу как массив. pairs перебирает весь хэш Share this post Link to post
Kenix 55 Posted February 20, 2012 Нужно результат вернуть весь. Именно из функции. Т.е к примеру вызывал функцию в аргументе таблица. Ну и на выходе уже выходила таблица 1 дименсионная, а не 2,3,4 и т.д. P.S Плохо умею объяснять .. Share this post Link to post
Kernell 44 Posted February 20, 2012 Не понимаю что ты хочешь.. function table.x3( array ) local result = {}; for _, value in pairs( array ) do if type( value ) == 'table' then for _, v in pairs( table.x3( value ) ) do table.insert( result, v ); end else table.insert( result, value ); end end return result; end таблица 1 дименсионная Это что за таблица такая? Share this post Link to post
Kenix 55 Posted February 20, 2012 Спасибо большое, что-то ступил я.. Это что за таблица такая? 1. t = { [1] = '1'; [2] = '2'; [3] = '3'; } 2. t = { } t[1] = { } t[1][1] = '1'; t[1][2] = '2'; t[1][3] = '3'; Share this post Link to post
TwiX! 0 Posted March 20, 2012 function guiCreateColoredLabel(x1, y1, x2, y2, txt, relative, parent) TextWithOld = 0 TablicaJednegoWersu = {} local teksty = getColors(txt) for i=1,#teksty do TablicaJednegoWersu[i] = guiCreateLabel ( x1+TextWithOld, y1, x2, y2, teksty[i][1], relative, parent ) guiLabelSetColor(TablicaJednegoWersu[i],teksty[i][2],teksty[i][3],teksty[i][4]) guiSetFont ( TablicaJednegoWersu[i], "default-bold-small") -- меняйте шрифт тут TextWithOld = guiLabelGetTextExtent(TablicaJednegoWersu[i]) + TextWithOld end return TablicaJednegoWersu end function getColors(text) local CzesciTekstu = {} local ColorCode = "#(%x%x%x%x%x%x)" if string.find(text,ColorCode,1) then Ilosc = 0 p,k = string.find(text,ColorCode,1) if p ~= 1 then Ilosc = Ilosc + 1 CzesciTekstu[Ilosc] = {string.sub(text,0,p-1),255,255,255} text = string.sub(text,p) end while string.find(text,ColorCode) do Ilosc = Ilosc + 1 local p2,k2 = string.find(text,ColorCode,7) if p2 then CzesciTekstu[Ilosc] = {string.sub(text,8,p2-1),hexToRGB(string.sub(text,0,8))} text = string.sub(text,p2) else CzesciTekstu[Ilosc] = {string.sub(text,8),hexToRGB(string.sub(text,0,8))} text = "" end end return CzesciTekstu else CzesciTekstu[1] = {text,255,255,255} return CzesciTekstu end end function hexToRGB ( hex ) hex = hex:gsub("#","") return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6)) end Example guiCreateColoredLabel(387,3,78,23,"#00ff00Asd",false,TAB)-- или window или image Или local name = getPlayerName(source) guiCreateColoredLabel(387,3,78,23,"Welcome "..name ,false,TAB)-- или window или image Будет работать с цветом Конечно guiSetText не будет работать.. нужно destroyElement и опять создавать лабел Share this post Link to post
TheNormalnij 29 Posted March 12, 2013 elementRotationToPoint, можно проще, видел в зомби скрипте. function elementRotationToPoint( el, px, py, pz ) x, y, z, = getElementPosition ( el ) rotalion = ( 360 - math.deg ( math.atan2 ( ( x - px ), ( y - py ) ) ) ) % 360 setPedRotation( el, 0, 0, rotalion ) end Share this post Link to post
TheNormalnij 29 Posted March 17, 2013 Получает html цвет формата #FF53e3 и возвращает цвета rgb из неё. function html_to_rgb( html ) if html then html = string.upper ( html ) t = { } for i=1,6 do b = string.byte( html, i + 1 ) if b >= 44 and b <= 57 then t[i] = b - 48 end if b >= 65 and b <= 70 then t[i] = b - 55 end if not t[i] then return false end end red = (t[1] * 16) + ( t[2] ) green = (t[3] * 16) + ( t[4] ) blue = (t[5] * 16) + ( t[6] ) return red, green, blue end return false end Share this post Link to post
Kenix 55 Posted March 17, 2013 Ваша последняя функция бесполезна ибо уже есть getColorFromString и она делает тоже самое Share this post Link to post
TheNormalnij 29 Posted March 17, 2013 Ваша последняя функция бесполезна ибо уже есть getColorFromString и она делает тоже самое Спасибо. Что-то я не мог ее найти. Зато было интересное времяпровождение Share this post Link to post
TheNormalnij 29 Posted August 17, 2013 Сортирует индексы таблицы не меня порядок значений. function table.sortIndex( tab ) if type( tab ) ~= 'table' then return false; end local max = 1 for i, n in pairs( tab ) do if type( i ) == 'number' and max < i then max = i end end for i = max, 1, -1 do if tab[i] == nil then for k = i, max do tab[k] = tab[k+1] end end end return true end Пример: local t = { [2] = 3; [5] = 2; [7] = 1; [10] = 16; [9] = false; } table.sortIndex( t ) for i, n in ipairs( t ) do print( i, n ) end --[[ 1 3 2 2 3 1 4 false 5 16 --]] Share this post Link to post
N1kS 10 Posted October 23, 2013 Необходимо было написать функцию динамической телепортации по маркерам, возможно кому то пригодиться. --[[ Описание: Функция возращает маркер, на который будет необходимо телепортироваться. markers[n][1] - позиция X markers[n][2] - позиция Y markers[n][3] - позиция Z markers[n][4] - Указатель, на какой маркер нам предстоит телепортация. ]] markers = {} markers[1] = {739.255859375,-1430.580078125,13.5234375, 2}; markers[2] = {725.0029296875,-1436.09375,13.5390625, 1}; function detectOfMarker(hitElement) local x, y, z, currentMarker, hitedMarker; local index; if(getElementType(hitElement) == "player" and isPedInVehicle(hitElement) == false) then x, y, z = getElementPosition(hitElement); currentMarker = getDistanceBetweenPoints3D(x, y, z, markers[1][1], markers[1][2], markers[1][3]); for i, v in pairs(markers) do hitedMarker = getDistanceBetweenPoints3D(x, y, z, v[1], v[2], v[3]); if(hitedMarker < currentMarker) then index = i; else index = 1; end end return markers[index][4]; end end addEventHandler("onMarkerHit", root, detectOfMarker); Share this post Link to post
Kenix 55 Posted March 29, 2014 Добавлена новая, очень полезная функция math.rating. + Добавлена функция от TheNormalnij Share this post Link to post