You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ProdHUD/ProdHUD.lua

409 lines
13 KiB

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