Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- script_name("Search helper")
- script_version("1.0")
- --------------------------------------------------------------------------------
- require "lib.moonloader"
- local json = require 'lib.jsoncfg'
- local mad = require 'MoonAdditions'
- local defaults = {enable = true, showId = true, textPosX = 180, textPosY = 375}
- local players = {{id = 666, nickname = ''}}
- local chatText = ''
- local textMod = {'%/%a+ '}
- local selector = 0
- local nick_textdraw
- local firstDraw = true
- local dispNick, dispId = '', ''
- local oldTimer, timer
- --------------------------------------------------------------------------------
- function main()
- repeat wait(0) until isSampAvailable()
- -- if not doesFileExist(getGameDirectory().."//moonloader//config//proInv//settings.ini") then
- -- local iniBool = inicfg.save(mainCfg, "proInv/settings")
- -- end
- -- iniData = inicfg.load(mainCfg, "proInv/settings")
- if not doesDirectoryExist(getGameDirectory() ..
- '//moonloader//config//search') then
- local resultas = createDirectory(
- getGameDirectory() ..
- '//moonloader//config//search')
- end
- if not doesFileExist(getGameDirectory() ..
- '//moonloader//config//search//settings.json') then
- json.write(getGameDirectory() ..
- '//moonloader//config//search//settings.json', defaults)
- end
- data = json.read(getGameDirectory() ..
- '//moonloader//config//search//settings.json')
- getAllPlayers()
- oldTimer = getGameTimer()
- while true do
- wait(0)
- local cmdResult = sampIsChatCommandDefined("search")
- if not cmdResult then
- local result = sampRegisterChatCommand("search", toggleScript)
- end
- if data.enable then
- if sampIsChatInputActive() then
- chatText = sampGetChatInputText()
- -- printString(chatText, 300)
- toggleSearch(chatText)
- showText(true)
- else
- hideText()
- dispNick, dispId = '', ''
- end
- timer = getGameTimer()
- if timer > oldTimer + 20000 then
- getAllPlayers()
- oldTimer = getGameTimer()
- end
- end
- end
- end
- --------------------------------------------------------------------------------
- -- Komandos registravimas
- function toggleScript()
- data.enable = not data.enable
- if data.enable then
- sampAddChatMessage(ltu("[Search] Greita žaidėjų paieška įjungta."), 0x1cd031)
- else
- sampAddChatMessage(ltu("[Search] Greita žaidėjų paieška {ff0000}išjungta."), 0x1cd031)
- end
- getAllPlayers()
- writeSetting(false)
- end
- function toggleSearch(text)
- for i = 1, #textMod do
- if string.find(text, textMod[i]) then
- local text = string.gsub(text, textMod[i], '')
- -- printString(text, 300)
- -- text = string.gsub(text, ' ', '')
- if text ~= '' then
- -- printString(text, 150)
- searchPlayer(text)
- break
- end
- else
- dispNick, dispId = '', ''
- end
- end
- end
- function searchPlayer(text)
- local text = string.lower(text)
- for i = 1, #players do
- if string.find(string.lower(players[i].nickname), text) then
- -- printString('Radau: ' .. players[i].nickname .. ' id: ' ..
- -- players[i].id, 300)
- dispNick = players[i].nickname
- dispId = players[i].id
- break
- elseif i == #players then
- dispNick, dispId = '', ''
- end
- end
- end
- function showText(showBool)
- if firstDraw and showBool then
- if dispNick ~= '' and dispId ~= '' then
- firstDraw = false
- nick_textdraw = mad.textdraw.new(dispNick .. ' ID: ' .. dispId,
- data.textPosX, data.textPosY)
- nick_textdraw.width = 0.6
- nick_textdraw.height = 0.85
- nick_textdraw:set_text_color(255, 255, 255, 255)
- nick_textdraw.outline = 1
- nick_textdraw.background = false
- nick_textdraw.wrap = 500
- end
- else
- if dispNick ~= '' and dispId ~= '' and nick_textdraw ~= nil then
- nick_textdraw.text = '~r~' .. dispNick .. ' ~w~ID: ~r~' .. dispId
- elseif dispNick == '' and dispId == '' and nick_textdraw ~= nil then
- nick_textdraw.text = ''
- end
- end
- end
- function hideText()
- if not firstDraw and nick_textdraw ~= nil then nick_textdraw.text = '' end
- end
- function getAllPlayers()
- players = {{id = 666, nickname = ''}} -- wipes
- local maxId = sampGetMaxPlayerId(false)
- for i = 0, maxId do
- if sampIsPlayerConnected(i) then
- local nick = sampGetPlayerNickname(i)
- local newEntry = {id = i, nickname = nick}
- table.insert(players, newEntry)
- end
- end
- end
- function getScreenAspect()
- local function gcd(a, b) return b == 0 and a or gcd(b, a % b) end
- local w, h = getScreenResolution()
- local r = gcd(w, h)
- return w / r, h / r
- end
- function sampGetPlayerIdByNickname(nick)
- local result, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
- if nick == sampGetPlayerNickname(id) then return id end
- for i = 0, sampGetMaxPlayerId(false) do
- if sampIsPlayerConnected(i) and sampGetPlayerNickname(i) == nick then
- return i
- end
- end
- end
- --------------------------------------------------------------------------------
- -- writeSetting(false)
- function writeSetting(msgBool)
- json.write(getGameDirectory() ..
- '//moonloader//config//search//settings.json', data)
- if msgBool then
- sampAddChatMessage(ltu("[Search] Nustatymai įrašyti."), 0x1cd031)
- end
- end
- --[[ Colors:
- {ff0000} - raudona
- {1cd031} - default zalia kaip serve
- {16f534} - zalia, ryskesne
- {b88d0f} - oranzine, komandu paaiskinimas
- ]]
- function ltu(text)
- local encoding = require 'encoding'
- encoding.default = 'cp1257'
- local u8 = encoding.UTF8
- local ltu = {
- "\xc4\x85", -- ą
- "\xc4\x8d", "\xc4\x99", "\xc4\x97", "\xc4\xaf", "\xc5\xa1", "\xc5\xb3",
- "\xc5\xab", "\xc5\xbe", "\xc4\x84", "\xc4\x8c", "\xc4\x98", "\xc4\x96",
- "\xc4\xae", "\xc5\xa0", "\xc5\xb2", "\xc5\xaa", "\xc5\xbd"
- }
- -- ąčęėįšųūž ĄČĘĖĮŠŲŪŽ
- if string.find(text, "ą") then text = string.gsub(text, "ą", ltu[1]) end
- if string.find(text, "č") then text = string.gsub(text, "č", ltu[2]) end
- if string.find(text, "ę") then text = string.gsub(text, "ę", ltu[3]) end
- if string.find(text, "ė") then text = string.gsub(text, "ė", ltu[4]) end
- if string.find(text, "į") then text = string.gsub(text, "į", ltu[5]) end
- if string.find(text, "š") then text = string.gsub(text, "š", ltu[6]) end
- if string.find(text, "ų") then text = string.gsub(text, "ų", ltu[7]) end
- if string.find(text, "ū") then text = string.gsub(text, "ū", ltu[8]) end
- if string.find(text, "ž") then text = string.gsub(text, "ž", ltu[9]) end
- if string.find(text, "Ą") then text = string.gsub(text, "Ą", ltu[10]) end
- if string.find(text, "Č") then text = string.gsub(text, "Č", ltu[11]) end
- if string.find(text, "Ę") then text = string.gsub(text, "Ę", ltu[12]) end
- if string.find(text, "Ė") then text = string.gsub(text, "Ė", ltu[13]) end
- if string.find(text, "Į") then text = string.gsub(text, "Į", ltu[14]) end
- if string.find(text, "Š") then text = string.gsub(text, "Š", ltu[15]) end
- if string.find(text, "Ų") then text = string.gsub(text, "Ų", ltu[16]) end
- if string.find(text, "Ū") then text = string.gsub(text, "Ū", ltu[17]) end
- if string.find(text, "Ž") then text = string.gsub(text, "Ž", ltu[18]) end
- text = u8:decode(text)
- return text
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement