Ну смотри если в цикле надо проверку на то уперся ли перс в стену то
while true do wait(0)
if isCharTouchingObject(playerPed, id obj) then
--тут действие
end
end
Готовый код
local state = false
function main()
repeat wait(0) until isSampAvailable()
sampRegisterChatCommand('ltp', function()
state = not state
if state then
sampAddChatMessage("on", -1)
else
sampAddChatMessage("off", -1)
end
end)
while true do wait(0)
if state then
if isCharTouchingObject(playerPed, id obj) then
--тут твой код
end
end
end
end