commit cfb82c2d4b6a55366f22de84c871df85456abe0e Author: rubin Date: Sun Jan 1 22:46:02 2023 +0300 add file diff --git a/corn-hud.lua b/corn-hud.lua new file mode 100644 index 0000000..e62c940 --- /dev/null +++ b/corn-hud.lua @@ -0,0 +1,305 @@ +script_name('ProdHUD') +script_author("Serhiy_Rubin") +script_version("22/09/2019") +require 'lib.sampfuncs' +require 'lib.moonloader' +local sampev, inicfg = require 'lib.samp.events', require 'inicfg' +local render, antiflood = false, 0 +local zerno, urojai, narko, priceZerno, priceUrojai, priceNarko, finfoCheck = 0, 0, 0, 0, 0, 0, 0 +local coord = { + ['Farm 0'] = {x = -379.220367, y = -1425.855591, z = 25.862316 }, + ['Farm 1'] = {x = -116.514381, y = 2.906076, z = 3.227722 }, + ['Farm 2'] = {x = -1055.663330, y = -1203.198486, z = 129.136978 }, + ['Farm 3'] = {x = -0.693013, y = 74.493423, z = 3.231136 }, + ['Farm 4'] = {x = 1912.754150, y = 176.559540, z = 37.375542 }, + ['Narko'] = {x = 2182.483887, y = -1657.505615, z = 15.201279 }, + ['Zerno'] = {x = 2206.272949, y = -2245.668457, z = 13.661810 }, + ['Urojai'] = {x = 1622.458374, y = 2327.077881, z = 10.934480 } +} + +function main() + if not isSampLoaded() or not isSampfuncsLoaded() then return end + while not isSampAvailable() do wait(0) end + repeat + wait(100) + local res, id = sampGetPlayerIdByCharHandle(PLAYER_PED) + nickname = sampGetPlayerNickname(id) + if res then score = sampGetPlayerScore(id) end + until score > 0 + local magicChar = { ":", "|" } + local hostName = sampGetCurrentServerName() + for i = 1, #magicChar do hostName = hostName:gsub(magicChar[i], '') end + if string.find(hostName, "Legacy") then serverName = "Legacy" end + if string.find(hostName, "Reborn") then serverName = "Reborn" end + if string.find(hostName, "Revolution") then serverName = "Revolution" end + if hostName == "Samp-Rp.Ru Server 02 Client 0.3.7" then serverName = "Two" end + if serverName == nil then thisScript():unload() end + iniName = string.format("ProdHUD-%s", serverName) + ini = inicfg.load({ + ['Farm 0'] = { + corn = 0, + cornPrice = 0, + product = 0, + productPrice = 0, + prodName = '', + bank = 0 + }, + ['Farm 1'] = { + corn = 0, + cornPrice = 0, + product = 0, + productPrice = 0, + prodName = '', + bank = 0 + }, + ['Farm 2'] = { + corn = 0, + cornPrice = 0, + product = 0, + productPrice = 0, + prodName = '', + bank = 0 + }, + ['Farm 3'] = { + corn = 0, + cornPrice = 0, + product = 0, + productPrice = 0, + prodName = '', + bank = 0 + }, + ['Farm 4'] = { + corn = 0, + cornPrice = 0, + product = 0, + productPrice = 0, + prodName = '', + bank = 0 + }, + price = { + zerno = 0, + urojai = 0, + narko = 0 + }, + Render = { + FontName='Segoe UI', + FontSize=10, + FontFlag=15, + Color1='2f72f7', + Color2='FFFFFF' + }, + Settings = { + Key1='VK_RBUTTON', + Key2='VK_C', + X=0, + Y=0 + }, + }, iniName) + inicfg.save(ini, iniName) + sampfuncsLog(' {FFFFFF}ProdHUD by Serhiy_Rubin loaded. CMD: /prod | /prod hud. | Key combo: '..ini.Settings.Key1:gsub("VK_", '')..' + '..ini.Settings.Key2:gsub("VK_", '')) + font = renderCreateFont(ini.Render.FontName, ini.Render.FontSize, ini.Render.FontFlag) + sampRegisterChatCommand('prod', function(param) + if param:lower():find('pos') then + SetPos() + else + render = not render + end + end) + while true do + wait(0) + points = '' + for k,v in pairs(coord) do + local dist = math.floor(getDistanceBetweenCoords3d(v.x, v.y, v.z, getCharCoordinates(playerPed))) + if dist <= 30 then + points = k + end + end + if finfoCheck == 1 then + if points:find('Farm') then + if math.ceil(os.clock() * 1000 - antiflood) > 999 then + finfoCheck = 2 + sampSendChat('/finfo') + end + else + finfoCheck = 0 + end + end + if render then + renderText = { + [1] = '{00D900}Цена покупки зерна: '..ini.price.zerno..'$', + [2] = '{00D900}Цена продажи урожая: '..ini.price.urojai..'$', + [3] = '{00D900}Цена продажи наркотиков: '..ini.price.narko..'$', + [4] = '{00D900} ', + [5] = string.format('{00D900}Ферма №0 | Баланс: %d$ | Зерно: %d [%d$] | %s: %d [%d$]', ini['Farm 0'].bank, ini['Farm 0'].corn, ini['Farm 0'].cornPrice, ini['Farm 0'].prodName, ini['Farm 0'].product, ini['Farm 0'].productPrice), + [6] = string.format('{00D900}Ферма №1 | Баланс: %d$ | Зерно: %s [%s$] | %s: %s [%s$]', ini['Farm 1'].bank, ini['Farm 1'].corn, ini['Farm 1'].cornPrice, ini['Farm 1'].prodName, ini['Farm 1'].product, ini['Farm 1'].productPrice), + [7] = string.format('{00D900}Ферма №2 | Баланс: %d$ | Зерно: %s [%s$] | %s: %s [%s$]', ini['Farm 2'].bank, ini['Farm 2'].corn, ini['Farm 2'].cornPrice, ini['Farm 2'].prodName, ini['Farm 2'].product, ini['Farm 2'].productPrice), + [8] = string.format('{00D900}Ферма №3 | Баланс: %d$ | Зерно: %s [%s$] | %s: %s [%s$]', ini['Farm 3'].bank, ini['Farm 3'].corn, ini['Farm 3'].cornPrice, ini['Farm 3'].prodName, ini['Farm 3'].product, ini['Farm 3'].productPrice), + [9] = string.format('{00D900}Ферма №4 | Баланс: %d$ | Зерно: %s [%s$] | %s: %s [%s$]', ini['Farm 4'].bank, ini['Farm 4'].corn, ini['Farm 4'].cornPrice, ini['Farm 4'].prodName, ini['Farm 4'].product, ini['Farm 4'].productPrice), + } + local X, Y = ini.Settings.X, ini.Settings.Y + for i = 1, #renderText do + renderFontDrawText(font, renderText[i], X, Y, -1) + if i ~= 4 then + Y = Y + (renderGetFontDrawHeight(font) - (renderGetFontDrawHeight(font) / 5)) + else + Y = Y + (renderGetFontDrawHeight(font) / 5) + end + end + end + if isKeyDown(VK_RBUTTON) and (isCharInModel(PLAYER_PED, 440) or isKeyDown(VK_C)) then + sampSetCursorMode(3) + mouse = 1 + local posX, posY = getScreenResolution() + local plus = (renderGetFontDrawHeight(font) + (renderGetFontDrawHeight(font) / 10)) + posX = posX / 2 + posY = ((posY / 2.2) - (renderGetFontDrawHeight(font) * 3)) + renderText = { + [1] = (render and 'ProdHUD: ON' or 'ProdHUD: OFF'), + [2] = 'Загрузить', + [3] = 'Разгрузить', + [4] = 'Информация о ферме', + } + for i = 1, #renderText do + renderFontDrawText(font, renderText[i], posX - (renderGetFontDrawTextLength(font, renderText[i]) / 2), posY, 0xFF00D900) + local textLenght = renderGetFontDrawTextLength(font, renderText[i]) + local textHeight = renderGetFontDrawHeight(font) + local curX, curY = getCursorPos() + if curX >= posX and curX <= posX + textLenght and curY >= posY and curY <= posY + textHeight then + renderFontDrawText(font, renderText[i], posX - (renderGetFontDrawTextLength(font, renderText[i]) / 2), posY, -1) + if isKeyJustPressed(1) then + if i == 1 then + render = not render + end + if i == 2 then + if points ~= '' then + if points:find('Farm') then + local wareprod = (ini[points].prodName == 'Картофель' and urojai or narko ) + local prod = ( (1000 - wareprod) < tonumber(ini[points].product) and (1000 - wareprod) or tonumber(ini[points].product) ) + sampAddChatMessage(prod, -1 ) + sampSendChat('/cornmenu 2 '..prod) + finfoCheck = 1 + end + if points:find('Zerno') then + sampSendChat('/cornmenu 0 '..(1000 - zerno)) + end + end + end + if i == 3 then + if points ~= '' then + if points:find('Farm') then + sampSendChat('/cornmenu 1 '..zerno) + finfoCheck = 1 + end + if points:find('Narko') then + sampSendChat('/cornmenu 3 '..narko) + end + if points:find('Urojai') then + sampSendChat('/cornmenu 3 '..urojai) + end + end + end + if i == 4 then + sampSendChat('/finfo') + end + end + end + posY = posY + plus + end + else + if mouse ~= nil and mouse == 1 then + sampSetCursorMode(0) + mouse = nil + end + end + end +end + +function sampev.onServerMessage(color, message) + if message:find(' Зерно: (%d+) / 1000') then + zerno = message:match(' Зерно: (%d+) / 1000') + end + if message:find(' Урожай: (%d+) / 1000') then + urojai = message:match(' Урожай: (%d+) / 1000') + end + if message:find(' Наркотики: (%d+) / 1000') then + narko = message:match(' Наркотики: (%d+) / 1000') + end +end + +function sampev.onCreate3DText(id, color, position, distance, testLOS, attachedPlayerId, attachedVehicleId, text) + if text:find('{FF8000}Разгрузка наркотиков.*Стоимость наркотиков (%d+) вирт') then + ini.price.narko = text:match('{FF8000}Разгрузка наркотиков.*Стоимость наркотиков (%d+) вирт') + inicfg.save(ini, iniName) + end + if text:find('{FF8000}Загрузка зерна.*Стоимость зерна (%d+) вирт.+') then + ini.price.zerno = text:match('{FF8000}Загрузка зерна.*Стоимость зерна (%d+) вирт.+') + inicfg.save(ini, iniName) + end + if text:find('{FF8000}Разгрузка урожая.*Стоимость урожая (%d+) вирт') then + ini.price.urojai = text:match('{FF8000}Разгрузка урожая.*Стоимость урожая (%d+) вирт') + inicfg.save(ini, iniName) + end +end + +function sampev.onShowDialog(dialogId, style, title, button1, button2, text) + if text:find('.+Цена зерна: (%d+).*Зерна закуплено: (%d+) / 10000.*.+продукт: (.+).+на складе: (%d+) / 10000.*Цена продукта: (%d+)') then + local S0 = CheckCoord() + if S0 ~= '' then + ini[S0].bank, ini[S0].cornPrice, ini[S0].corn, ini[S0].prodName, ini[S0].product, ini[S0].productPrice = text:match('.+Баланс банка: (%d+).+Цена зерна: (%d+).*Зерна закуплено: (%d+) / 10000.*.+продукт: (%W+)..*Количество на складе: (%d+) / 10000.*Цена продукта: (%d+)') + inicfg.save(ini, iniName) + if finfoCheck ~= 0 then + finfoCheck = 0 + return false + end + end + end + if text:find('{FFFFFF}Зерна куплено: {0289CC}(%d+).*{FFFFFF}Цена: {0289CC}%d+ вирт.*{FFFFFF}Скидка: {0289CC}%d+ вирт') then + zerno = zerno + tonumber(text:match('{FFFFFF}Зерна куплено: {0289CC}(%d+).*{FFFFFF}Цена: {0289CC}%d+ вирт.*{FFFFFF}Скидка: {0289CC}%d+ вирт')) + end + if text:find('{FFFFFF}Зерна продано: {0289CC}(%d+).*{FFFFFF}Цена: {0289CC}%d+ вирт.*{FFFFFF}Добавлено к ЗП: {0289CC}%d+ вирт') then + zerno = zerno - tonumber(text:match('{FFFFFF}Зерна продано: {0289CC}(%d+).*{FFFFFF}Цена: {0289CC}%d+ вирт.*{FFFFFF}Добавлено к ЗП: {0289CC}%d+ вирт')) + end + if text:find('{FFFFFF}Урожая куплено: {0289CC}(%d+).*{FFFFFF}Цена: {0289CC}%d+ вирт') then + urojai = urojai + tonumber(text:match('{FFFFFF}Урожая куплено: {0289CC}(%d+).*{FFFFFF}Цена: {0289CC}%d+ вирт')) + end + if text:find('Урожая продано: {0289CC}(%d+).*{FFFFFF}Цена: {0289CC}%d+ вирт') then + urojai = urojai - tonumber(text:match('Урожая продано: {0289CC}(%d+).*{FFFFFF}Цена: {0289CC}%d+ вирт')) + end + if text:find('{FFFFFF}Наркотиков куплено: {0289CC}(%d+).*{FFFFFF}Цена: {0289CC}%d+ вирт') then + narko = narko + tonumber(text:match('{FFFFFF}Наркотиков куплено: {0289CC}(%d+).*{FFFFFF}Цена: {0289CC}%d+ вирт')) + end + if text:find('Наркотиков продано: {0289CC}(%d+)') then + narko = narko - tonumber(text:match('Наркотиков продано: {0289CC}(%d+)')) + end +end + +function sampev.onSendChat(message) antiflood = os.clock() * 1000 end +function sampev.onSendCommand(cmd) antiflood = os.clock() * 1000 end + +function CheckCoord() + for k,v in pairs(coord) do + local dist = math.floor(getDistanceBetweenCoords3d(v.x, v.y, v.z, getCharCoordinates(playerPed))) + if dist <= 30 then + return k + end + end + return '' +end + +function SetPos() + lua_thread.create(function() + wait(100) + repeat + wait(0) + pos = true + sampSetCursorMode(3) + local X, Y = getCursorPos() + ini.Settings.X = X + ini.Settings.Y = Y + inicfg.save(ini, iniName) + until isKeyJustPressed(1) + sampSetCursorMode(0) + wait(100) + pos = false + end) +end \ No newline at end of file