script_name('ProdHUD') script_authors("RuBin") local samp = require 'samp.events' local inicfg = require 'inicfg' function main() if not isSampLoaded() or not isSampfuncsLoaded() then return end while not isSampAvailable() do wait(100) end iniLoad() font = renderCreateFont(ini.settings.font_name, ini.settings.font_size, ini.settings.font_flag) while true do wait(0) doRenderMenu() doBuyMode() doSendDialog() doCheckMonMode() end end function samp.onServerMessage(color, message) if message:find("Вы должны находиться на складе, с выбранным вами типом бизнеса") or message:find("Неверно указано количество") or message:find("В фургоне нет места") or message:find("У вас нет продуктов") or message:find("Нужно находиться рядом с бизнесом, которому хотите продать") or message:find("У вас недостаточно денег") or (isCar() and message:find("Вы заработали %d+ вирт, из которых %d+ вирт будет добавлено к вашей зарплате")) then if buyMode ~= nil then scip = true end buyMode = nil if checkMon ~= nil then return false end end if string.find(message, " Еда: (%d+) / (%d+)") then prod.food, prod_count = string.match(message, " Еда: (%d+) / (%d+)") if prod_count == prod.food and buyMode then scip = true end if prod.food == "0" and buyMode then scip = true end buyMode = nil end if string.find(message, " Бензин: (%d+) / (%d+)") then prod.benz, prod_count = string.match(message, " Бензин: (%d+) / (%d+)") if prod_count == prod.benz and buyMode then scip = true end if prod.benz == "0" and buyMode then scip = true end buyMode = nil end if string.find(message, " Товары: (%d+) / (%d+)") then prod.products, prod_count = string.match(message, " Товары: (%d+) / (%d+)") if prod_count == prod.products and buyMode then scip = true end if prod.products == "0" and buyMode then scip = true end buyMode = nil end if string.find(message, " Алкоголь: (%d+) / (%d+)") then prod.alcohol, prod_count = string.match(message, " Алкоголь: (%d+) / (%d+)") if prod_count == prod.alcohol and buyMode then scip = true end if prod.alcohol == "0" and buyMode then scip = true end buyMode = nil end end function samp.onShowDialog(DdialogId, Dstyle, Dtitle, Dbutton1, Dbutton2, Dtext) dialogActiveTime = os.clock() * 1000 if buyMode ~= nil or (buyMode == nil and scip ~= nil) then if Dtitle:find("Развозчик продуктов") then if scip == nil then send_dialog = { time = os.clock() * 1000, id = DdialogId, button = 1, listitem = (sell and 1 or 0), input = "" } end return false end if Dtext:find("Бары и клубы") and Dtext:find("Заправки") then if scip == nil then local list = { alcohol = 0, benz = 1, products = 3, food = 2 } send_dialog = { time = os.clock() * 1000, id = DdialogId, button = 1, listitem = list[buyMode], input = "" } end return false end if Dtitle:find("Ввод параметра") and Dtext:find("Введите количество продуктов от %d+ до (%d+)") then if scip == nil then local count = tonumber(Dtext:match("Введите количество продуктов от %d+ до (%d+)")) - prod[buyMode] send_dialog = { time = os.clock() * 1000, id = DdialogId, button = 1, listitem = 0, input = tostring(count) } end return false end if Dtitle:find("Сообщение") and Dtext:find("Стоимость")and Dtext:find("Количество") then if scip == nil then send_dialog = { time = os.clock() * 1000, id = DdialogId, button = 1, listitem = 0, input = "" } end return false end end if DdialogId == 22 and Dstyle == 0 and Dtitle == "Сообщение" and string.find(Dtext, "Бизнес") and string.find(Dtext, "Сколько может купить") then if string.find(Dtext, "Cluc") or string.find(Dtext, "Pizza") or string.find(Dtext, "Cluck") or string.find(Dtext, "Burger") then monArray["food"] = Dtext elseif string.find(Dtext, "24%-7") then monArray["products"] = Dtext elseif string.find(Dtext, "gas") or string.find(Dtext, "Gas") or string.find(Dtext, "Gsa") then monArray["benz"] = Dtext else monArray["alcohol"] = Dtext end if checkMon ~= nil then send_dialog = { time = os.clock() * 1000, id = DdialogId, button = 0, listitem = 0, input = "" } return false end end if checkMon ~= nil then if Dtitle:find("Развозчик продуктов") then if scip == nil then send_dialog = { time = os.clock() * 1000, id = DdialogId, button = 1, listitem = 2, input = "" } end return false end if Dtitle:find("Мониторинг") then if checkMon == "" then checkMon = nil return false end if scip == nil then local arr_sled = { alcohol = "benz", benz = "food", food = "products", products = "" } local arr_button = { alcohol = 0, benz = 1, food = 2, products = 3 } send_dialog = { time = os.clock() * 1000, id = DdialogId, button = 1, listitem = arr_button[checkMon], input = "" } checkMon = arr_sled[checkMon] end return false end end if Dtitle:find("GPS") and bizname ~= nil then local arr_sled = { alcohol = 2, benz = 8, food = 10, products = 9 } send_dialog = { time = os.clock() * 1000, id = DdialogId, button = 1, listitem = arr_sled[monMode], input = "" } return false end if (bizname ~= nil or ( bizname == nil and scip ~= nil)) and (Dtitle:find("Бензозаправки") or Dtitle:find("Магазины") or Dtitle:find("Бары") or Dtitle:find("Закусочные") ) then if scip ~= nil then scip = nil return false end local arr = split(Dtext, "\n") local result = -1 for i = 1, #arr do local str = arr[i]:gsub("%-", " ") local findText = bizname:gsub("%-", " ") if monMode == "benz" and not findText:find("Emerald") and not findText:find("Tierra") then bizname = string.gsub(bizname, " ", "") end if str:gsub("%-", " "):find(findText) then result = i - 1 break end end if result ~= -1 then scip = true send_dialog = { time = os.clock() * 1000, id = DdialogId, button = 1, listitem = result, input = "" } else sampAddChatMessage(bizname, -1) end bizname = nil return false end scip = nil end function samp.onSendDialogResponse(dialogId, button, listboxId, input) end function isCar() if isCharInModel(PLAYER_PED, 455) or isCharInModel(PLAYER_PED, 459) or isCharInModel(PLAYER_PED, 552) or isCharInModel(PLAYER_PED, 414) or isCharInModel(PLAYER_PED, 456) then return true end end -->> RENDER MENU function doRenderMenu() if not isCar() or sampIsDialogActive() or sampIsChatInputActive() or not isKeyDown(2) then if control then sampSetCursorMode(0) end control = false return end if not control then control = true end sampSetCursorMode(3) -->> Render MENU local height = renderGetFontDrawHeight(font) local plus = height + (height / 4) local X, Y = getScreenResolution() Y = ((Y / 2.0) - (height * 3)) local textLength = renderGetFontDrawTextLength(font, "Продать для Закусочной") renderDrawBox((X - textLength), Y, textLength, (plus * 11), 0x80000000) local x, y = (X - textLength) - 72, Y for i = 10, 80 do x = x + 1 local color = string.format("0x%d000000", i) renderDrawBox(x, y, 1, (plus * 11), color) end string = "Купить для Бара" if drawClickableText(string, (X - renderGetFontDrawTextLength(font, string.." ")), Y) then sell = false buyMode = "alcohol" end Y = Y + plus string = "Продать для Бара" if drawClickableText(string, (X - renderGetFontDrawTextLength(font, string.." ")), Y) then sell = true buyMode = "alcohol" end Y = Y + plus + plus string = "Купить для Заправки" if drawClickableText(string, (X - renderGetFontDrawTextLength(font, string.." ")), Y) then sell = false buyMode = "benz" end Y = Y + plus string = "Продать для Заправки" if drawClickableText(string, (X - renderGetFontDrawTextLength(font, string.." ")), Y) then sell = true buyMode = "benz" end Y = Y + plus + plus string = "Купить для Магазина" if drawClickableText(string, (X - renderGetFontDrawTextLength(font, string.." ")), Y) then sell = false buyMode = "products" end Y = Y + plus string = "Продать для Магазина" if drawClickableText(string, (X - renderGetFontDrawTextLength(font, string.." ")), Y) then sell = true buyMode = "products" end Y = Y + plus + plus string = "Купить для Закусочной" if drawClickableText(string, (X - renderGetFontDrawTextLength(font, string.." ")), Y) then sell = false buyMode = "food" end Y = Y + plus string = "Продать для Закусочной" if drawClickableText(string, (X - renderGetFontDrawTextLength(font, string.." ")), Y) then sell = true buyMode = "food" end -->> Render Monitoring local X, Y = getScreenResolution() Y = ((Y / 2.2) - (height * 3)) string = "[Обновить цены]" if drawClickableText(string, (X / 2 - (renderGetFontDrawTextLength(font, string.." ") / 2 )), Y) then checkMon = "alcohol" end Y = Y + plus string = string.format("{%s}Алкоголь {%s}| {%s}Заправки {%s}| {%s}Магазины {%s}| {%s}Закусочные", (monMode == "alcohol" and ini.settings.color2 or ini.settings.color1), ini.settings.color1, (monMode == "benz" and ini.settings.color2 or ini.settings.color1), ini.settings.color1, (monMode == "products" and ini.settings.color2 or ini.settings.color1), ini.settings.color1, (monMode == "food" and ini.settings.color2 or ini.settings.color1) ) if drawClickableText(string, (X / 2 - (renderGetFontDrawTextLength(font, string.." ") / 2 )), Y) then local mode_sled = { alcohol = "benz", benz = "products", products = "food", food = "alcohol" } monMode = mode_sled[monMode] end local delta = getMousewheelDelta() if delta > 0 then local mode_sled = { alcohol = "benz", benz = "products", products = "food", food = "alcohol" } monMode = mode_sled[monMode] elseif delta < 0 then local mode_sled = { alcohol = "food", benz = "alcohol", products = "benz", food = "products" } monMode = mode_sled[monMode] end Y = Y + plus local arr = split(monArray[monMode], "\n") for i = 1, #arr do local string = arr[i] if drawClickableText(string, (X / 2 - (renderGetFontDrawTextLength(font, string.." ") / 2 )), Y) then if string:find("{FFFFFF}(.+) {6AB1FF}%d+ {00A86B}%d+") then bizname = string:match("{FFFFFF}(.+) {6AB1FF}%d+ {00A86B}%d+") local replace = { [" Cluck"] = "", [" Pizza"] = "", [" Burger"] = "", [" 24%-7"] = "", [" Gas"] = "", [" Gsa"] = "", ["Four dragon"] = "Склад бара 4Драконов", ["Caligula"] = "Склад бара Калигулы", [" Bar"] = "", [" bar"] = "", ["Quebrados"] = "Guebrabos" } for k,v in pairs(replace) do bizname = string.gsub(bizname, k, v) end sampSendChat("/gps") end end Y = Y + plus end end -->> BuyMode function doBuyMode() if buyMode == nil or prod[buyMode] == nil then return end if dialogActiveTime == nil then dialogActiveTime = 0 end if sampIsDialogActive() then dialogActiveTime = os.clock() * 1000 return end if os.clock() * 1000 - dialogActiveTime > 500 then dialogActiveTime = os.clock() * 1000 sampSendChat("/prodmenu") end end -->> CHECK MODE function doCheckMonMode() if checkMon == nil then return end if dialogActiveTime == nil then dialogActiveTime = 0 end if sampIsDialogActive() then dialogActiveTime = os.clock() * 1000 return end if os.clock() * 1000 - dialogActiveTime > 500 then dialogActiveTime = os.clock() * 1000 sampSendChat("/prodmenu") end end -->> SEND DIALOG function doSendDialog() if send_dialog == nil then return end if os.clock() * 1000 - send_dialog.time < 300 then return end sampSendDialogResponse(send_dialog.id,send_dialog.button,send_dialog.listitem,send_dialog.input) send_dialog = nil end -->> INIFILES function iniLoad() ini = inicfg.load({ settings = { font_name = "SegoeUI", font_size = 10, font_flag = 13, color1 = "2f72f7", color2 = "ffffff" } }) inicfg.save(ini) prod = { alcohol = 0, benz = 0, products = 0, food = 0 } monMode = "alcohol" monArray = { alcohol = "Пусто", benz = "Пусто", products = "Пусто", food = "Пусто" } end -->> New Func function drawClickableText(text, posX, posY) renderFontDrawText(font, text, posX, posY, '0xFF'..ini.settings.color1) local textLenght = renderGetFontDrawTextLength(font, text) 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, text, posX, posY, '0x70'..ini.settings.color2) if isKeyJustPressed(1) then return true end end end function split(str, delim, plain) local tokens, pos, plain = {}, 1, not (plain == false) --[[ delimiter is plain text by default ]] repeat local npos, epos = string.find(str, delim, pos, plain) table.insert(tokens, string.sub(str, pos, npos and npos - 1)) pos = epos and epos + 1 until not pos return tokens end