Strix Posted November 5, 2014 Share Posted November 5, 2014 Возвращает угол и направление заноса транспортного средства float getVehicleDriftAngle ( element theVehicle ) function getVehicleDriftAngle(theVehicle) if getElementType(theVehicle) ~= "vehicle" then return false end local vX, vY = getElementVelocity(theVehicle) if (vX == 0.0 and vY == 0.0) then return 0.0 end local rotX, rotY, rotZ = getElementRotation(theVehicle) local moveDirection = math.deg(-math.atan2(vX, vY)) if rotZ > 180 then rotZ = rotZ - 360 end local driftAngle = moveDirection - rotZ; if driftAngle < -180.0 then driftAngle = driftAngle + 360.0 elseif driftAngle > 180.0 then driftAngle = driftAngle - 360.0 end return driftAngle end http://pastebin.com/T8xzNcDD Link to comment
N1kS Posted November 11, 2014 Share Posted November 11, 2014 Создаем таблички с помощью Lua. С примером, кто знает, что и как работает - измените сами. Возможно кому то интересно будет. -- Ваше подключение в БД, не забудьте изменить, пожалуйста! local pDBConnection = dbConnect ( "mysql", "dbname=dbName;host=127.0.0.1", "username", "password", "share=0" ) local aTables = { ["tunning"] = { { name="id", type="INT", length=11, unsigned=true, allowNull=false, default="AI", primaryKey=true }, { name="vehicleID", type="TINYINT", length=3, unsigned=true, allowNull=false, default=false, primaryKey=false }, { name="loginName", type="VARCHAR", length=64, allowNull=false, default=false }, { name="JSON", type="VARCHAR", length=1024, allowNull=false, default=false }, } } addEventHandler ( "onResourceStart", resourceRoot, function() for tableName, tableInfo in pairs ( aTables ) do -- Размер таблицы local iSize = table.size ( tableInfo ) -- Индекс PRIMARY KEY local iPrimaryKeyIndex = 0 -- Сам запрос local sQuery = "CREATE TABLE IF NOT EXISTS `"..tableName.."` (\n" for i = 1, iSize do sQuery = sQuery.."`"..tableInfo[i].name.."` " sQuery = sQuery..tableInfo[i].type if tableInfo[i].length then sQuery = sQuery.."("..tableInfo[i].length..") " else sQuery = sQuery.." " end if tableInfo[i].unsigned then sQuery = sQuery.."UNSIGNED " end if not tableInfo[i].allowNull then sQuery = sQuery.."NOT NULL " else sQuery = sQuery.."NULL " end if tableInfo[i].default then if tableInfo[i].default == "AI" then sQuery = sQuery.."AUTO_INCREMENT " else sQuery = sQuery.."DEFAULT '"..tableInfo[i].default.."' " end end if tableInfo[i].primaryKey then iPrimaryKeyIndex = i end local iLen = string.len ( sQuery ) sQuery = string.sub ( sQuery, 1, iLen - 1 ) sQuery = sQuery..", \n" if i == iSize then sQuery = sQuery.."PRIMARY KEY (`"..tableInfo[iPrimaryKeyIndex].name.."`)\n)" end end dbExec ( pDBConnection , sQuery ) end end ) Link to comment
Kernell Posted November 11, 2014 Share Posted November 11, 2014 https://github.com/mabako/mta-paradise/ ... ut.lua#L60 Link to comment
N1kS Posted November 12, 2014 Share Posted November 12, 2014 https://github.com/mabako/mta-paradise/blob/master/resources/sql/layout.lua#L60 Эта даже столбики отсутствующие создает. Спасибо! Правда она на плагине... Link to comment
Kenix Posted September 26, 2015 Author Share Posted September 26, 2015 Недавно мне понадобилась функция для разделения массива на несколько кусков (рандомно). Может кому понадобится. local function size( a ) local i = 0; for _ in pairs( a ) do i = i + 1; end return i; end function table.slice( t ) if size( t ) > 0 then local New = {}; local iRand = math.random( 1, size( t ) ); local iCount = 0; for i, v in pairs( t ) do if iCount < iRand then table.insert( New, v ); t[ i ] = nil; else break; end iCount = iCount + 1; end return New; end return false; end Пример использования: local a = {}; for i = 1, 20 do table.insert( a, i ); end while true do local take = table.slice( a ); if not take then break; end print( unpack( take ) ); end --[[ Результат 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ]] Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now