Помогите с скриптом lua

Статус
В этой теме нельзя размещать новые ответы.

SamuelGoldie

Участник
Автор темы
72
7
Версия MoonLoader
.026-beta
Подскажите почему вместо указанного ID выводится нулевой ID

lua:
function gh(arg)
    local result, target = getCharPlayerIsTargeting(playerHandle)
    if result then result, playerid = sampGetPlayerIdByCharHandle(target) end
    name = sampGetPlayerNickname(playerid)
    sampSendChat('gethere '..name..'')
    sampAddChatMessage('Вы телепортировалли '..name..'. ID '..id..'')
end
 
Решение
Так мне совсем не это нужно, я хочу сделать команду которая будет телепортировать игрока и писать в sampAddChatMessage его ник и айди
Lua:
sampRegisterChatCommand('gh',function(arg)
    if sampIsPlayerConnected(tonumber(arg)) then 
        sampSendChat('/gethere '..arg)
        sampAddChatMessage('Вы телепортировали игрока '..sampGetPlayerNickname(arg)..' ['..arg..']',-1)
    end
end)

XRLM

Известный
2,574
890
Подскажите почему вместо указанного ID выводится нулевой ID

lua:
function gh(arg)
    local result, target = getCharPlayerIsTargeting(playerHandle)
    if result then result, playerid = sampGetPlayerIdByCharHandle(target) end
    name = sampGetPlayerNickname(playerid)
    sampSendChat('gethere '..name..'')
    sampAddChatMessage('Вы телепортировалли '..name..'. ID '..id..'')
end
где у тебя объявлена переменная id?
 
  • Клоун
Реакции: Air_Official

XRLM

Известный
2,574
890
Ты об этом ?
lua:
name = sampGetPlayerNickname(int, id)
Если да, то в локалах самом верху.
я о том что ты выводишь переменную id, но существует ли она у тебя? крч, у тебя под ид существует переменная playerId, а ты выводишь id, понял ошибку?
 
  • Клоун
Реакции: Air_Official

хуега)

РП игрок
Модератор
2,570
2,274
Подскажите почему вместо указанного ID выводится нулевой ID

lua:
function gh(arg)
    local result, target = getCharPlayerIsTargeting(playerHandle)
    if result then result, playerid = sampGetPlayerIdByCharHandle(target) end
    name = sampGetPlayerNickname(playerid)
    sampSendChat('gethere '..name..'')
    sampAddChatMessage('Вы телепортировалли '..name..'. ID '..id..'')
end
попробуй так
Lua:
function gh(arg)
    local result, target = getCharPlayerIsTargeting(playerHandle)
    if not result then return false end
    local result, playerId = sampGetPlayerIdByCharHandle(target)
    if not result then return false end
    local name = sampGetPlayerNickname(playerId)
    sampSendChat('gethere '..name..'')
    sampAddChatMessage('Вы телепортировалли '..name..'. ID '..playerId..'')
end
 

SamuelGoldie

Участник
Автор темы
72
7
попробуй так
Lua:
function gh(arg)
    local result, target = getCharPlayerIsTargeting(playerHandle)
    if not result then return false end
    local result, playerId = sampGetPlayerIdByCharHandle(target)
    if not result then return false end
    local name = sampGetPlayerNickname(playerId)
    sampSendChat('gethere '..name..'')
    sampAddChatMessage('Вы телепортировалли '..name..'. ID '..playerId..'')
end
Не работает

я о том что ты выводишь переменную id, но существует ли она у тебя? крч, у тебя под ид существует переменная playerId, а ты выводишь id, понял ошибку?
Сделал так,

lua:
function gh(arg)
    local result, target = getCharPlayerIsTargeting(playerHandle)
    if result then result, playerid = sampGetPlayerIdByCharHandle(target) end
    name = sampGetPlayerNickname(playerid)
    sampSendChat('gethere '..name..'')
    sampAddChatMessage('Вы телепортировалли '..name..'. ID '..playerid..'')
end
Все тоже
 

XRLM

Известный
2,574
890
что ты в аргумент функции передаешь?

Lua:
function gh(arg)
    local result, target = getCharPlayerIsTargeting(playerHandle)
    if result then
        local _, playerid = sampGetPlayerIdByCharHandle(target)
        if _ then
            local name = sampGetPlayerNickname(playerid)
            sampSendChat('gethere '..name..'')
            sampAddChatMessage('Вы телепортировалли '..name..'. ID '..playerid..'')
        end
    end
end
 
  • Клоун
Реакции: Air_Official

SamuelGoldie

Участник
Автор темы
72
7
что ты в аргумент функции передаешь?

Lua:
function gh(arg)
    local result, target = getCharPlayerIsTargeting(playerHandle)
    if result then
        local _, playerid = sampGetPlayerIdByCharHandle(target)
        if _ then
            local name = sampGetPlayerNickname(playerid)
            sampSendChat('gethere '..name..'')
            sampAddChatMessage('Вы телепортировалли '..name..'. ID '..playerid..'')
        end
    end
end
Ничего не пишет, при вводе команды ничего, в консоли ошибок нету
 

SamuelGoldie

Участник
Автор темы
72
7
потому что наверно ты не целишь в игрока когда вводишь команду
Так мне совсем не это нужно, я хочу сделать команду которая будет телепортировать игрока и писать в sampAddChatMessage его ник и айди
 
  • Эм
Реакции: MLycoris

MLycoris

Режим чтения
Проверенный
1,831
1,891
Так мне совсем не это нужно, я хочу сделать команду которая будет телепортировать игрока и писать в sampAddChatMessage его ник и айди
Lua:
sampRegisterChatCommand('gh',function(arg)
    if sampIsPlayerConnected(tonumber(arg)) then 
        sampSendChat('/gethere '..arg)
        sampAddChatMessage('Вы телепортировали игрока '..sampGetPlayerNickname(arg)..' ['..arg..']',-1)
    end
end)
 
Статус
В этой теме нельзя размещать новые ответы.