Lua

enyag

Известный
Автор темы
345
12
Заголовок темы должен отражать суть самого вопроса (никаких "ищу", "помогите" или "как сделать").
как сделать, что бы вместо ника выводило значение, которое находится в /ran?
Lua:
script_name('broadcaster_showcase')
script_version('0.0.1')
script_author('Ranx')

local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local broadcaster = import('lib/broadcaster.lua')

local function showcaseHandler(message)
    sampAddChatMessage('BC Chat >> ' .. u8:decode(message), 0xAAAAAA)
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand('msg', cmdMsg)
    sampRegisterChatCommand("ran", ran)
    sampRegisterChatCommand('gethandlers', function() broadcaster._printHandlers() end)
    sampRegisterChatCommand('getsessions', function() broadcaster._printSessions() end)
    
    wait(100)
    broadcaster.registerHandler('scase', showcaseHandler)

    wait(-1)
end

function cmdMsg(params)
    local idResult, pId = sampGetPlayerIdByCharHandle(PLAYER_PED)
    if idResult then
        local message = u8(('%s[%d]: %s'):format(sampGetPlayerNickname(pId), pId, params))
        local result, returned = pcall(broadcaster.sendMessage, message, 'scase')
        if not result then
            print('error occured while sending msg:\n' .. returned)
        end
    end
end

function onScriptTerminate(scr)
    if scr == thisScript() then
        if broadcaster.unregisterHandler('scase') then
            print('unregistered successfully')
        else
            print('unregisterHandler returned false')
        end
    end
end

function ran(arg)
    if #arg ~= 0 then -- проверяет не пустое ли значение arg
        Value = arg
        sampAddChatMessage("Готово, ваш ранг:"..Value, -1)
    else
        print("Введите ник")
    end
end