Приветствую Вас, Гость! Регистрация RSS

Мой сайт

Пятница, 03.05.2024
Главная страница форума
[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Форум » MTA | Multi Theft Auto » Lua скриптинг (Уроки, FAQ) » [MTA:SA] Названия текстур
[MTA:SA] Названия текстур
Nanotech_uaДата: Четверг, 08.12.2011, 14:16 | Сообщение # 1
Майор
Группа: Администраторы
Сообщений: 95
Репутация: 4
Статус: :-(


Данный ресурс является лишь инструментом, который ничего не делает красиво. Он показывает список текущих видимых имен текстур, а также освещает выбранные текстуры. Идеально подходит для поиска имени текстуры для использования с engineApplyShaderToWorldTexture.

1) Для начала создадим файл "meta.xml", и в него вставим код:

Code
<meta>
   <info description="Shader - Tex names" version="0.0.1" type="script" />
   <script src="c_key_auto_repeat.lua" type="client" />
   <script src="c_tex_names.lua" type="client" />
   <file src="tex_names.fx" type="client" />
</meta>


2) Создаём файл "c_key_auto_repeat.lua", и вставляем в него код:

Code
--
-- c_key_auto_repeat.lua
--

-------------------------------------------------------------
-- Keyboard auto-repeat
-------------------------------------------------------------
KeyAutoRepeat = {}
KeyAutoRepeat.repeatDelay = 500     -- Wait before 1st repeat
KeyAutoRepeat.repeatRateInitial = 100   -- Delay between repeats (initial)
KeyAutoRepeat.repeatRateMax = 10    -- Delay between repeats (after key held for repeatRateChangeTime)
KeyAutoRepeat.repeatRateChangeTime = 2700  -- Amount of time to move between repeatRateInitial and repeatRateMax
KeyAutoRepeat.keydownInfo = {}

-- Result event - Same parameters as onClientKey
addEvent( "onClientKeyClick" )

-- Update repeats
function KeyAutoRepeat.pulse()
   for key,info in pairs(KeyAutoRepeat.keydownInfo) do
    local age = getTickCount () - info.downStartTime
    age = age - KeyAutoRepeat.repeatDelay    -- Initial delay
    if age > 0 then
     -- Make rate speed up as the key is held
     local ageAlpha = math.unlerpclamped( 0, age, KeyAutoRepeat.repeatRateChangeTime )
     local dynamicRate = math.lerp( KeyAutoRepeat.repeatRateInitial, ageAlpha, KeyAutoRepeat.repeatRateMax )    

     local count = math.floor(age/dynamicRate)    -- Repeat rate
     if count > info.count then
      info.count = count
      triggerEvent("onClientKeyClick", resourceRoot, key )
     end
    end
   end
end
addEventHandler("onClientRender", root, KeyAutoRepeat.pulse )

-- When a key is pressed/release
function KeyAutoRepeat.keyChanged(key,down)
   KeyAutoRepeat.keydownInfo[key] = nil
   if down then
    KeyAutoRepeat.keydownInfo[key] = { downStartTime=getTickCount (), count=0 }
    triggerEvent("onClientKeyClick", resourceRoot, key )
   end
end
addEventHandler("onClientKey", root, KeyAutoRepeat.keyChanged)

-------------------------------------------------------------
-- Math extentions
-------------------------------------------------------------
function math.lerp(from,alpha,to)
      return from + (to-from) * alpha
end

function math.unlerp(from,pos,to)
   if ( to == from ) then
    return 1
   end
   return ( pos - from ) / ( to - from )
end

function math.clamp(low,value,high)
      return math.max(low,math.min(value,high))
end

function math.unlerpclamped(from,pos,to)
   return math.clamp(0,math.unlerp(from,pos,to),1)
end


3) Создаём файл "c_tex_names.lua", и вставляем в него код:

Code
--
-- c_tex_names.lua
--

---------------------------------------
-- Local variables for this file
---------------------------------------
local myShader
local bShowTextureUsage = false
local uiTextureIndex = 1
local m_SelectedTextureName = ""
local scx, scy = guiGetScreenSize ()
local usageInfoList = {}

---------------------------------------
-- Startup
---------------------------------------
addEventHandler( "onClientResourceStart", resourceRoot,
   function()

    -- Version check
    if getVersion ().sortable < "1.1.0" then
     outputChatBox( "Resource is not compatible with this client." )
     return
    end

    -- Create shader
    local tec
    myShader, tec = dxCreateShader ( "tex_names.fx" )

    if not myShader then
     outputChatBox( "Could not create shader. Please use debugscript 3" )
    else
     outputChatBox( "Using technique " .. tec )

     outputChatBox( "Utility to help find world texture names", 255, 255, 0 )

     outputChatBox( "Press num_8 to view list", 0, 255, 255 )
     outputChatBox( "Press num_7 and num_9 to step list", 0, 255, 255 )
     outputChatBox( "Press k to copy texture name to clipboard", 0, 255, 255 )
    end
   end
)

---------------------------------------
-- Draw visible texture list
---------------------------------------
addEventHandler( "onClientRender", root,
   function()
    usageInfoList = engineGetVisibleTextureNames ()

    local iXStartPos = scx - 200;
    local iYStartPos = 0;
    local iXOffset = 0;
    local iYOffset = 0;

    if bShowTextureUsage then
     for key, textureName in ipairs(usageInfoList) do

      local bSelected = textureName == m_SelectedTextureName;
      local dwColor = bSelected and tocolor(255,220,128) or tocolor(224,224,224,204)

      if bSelected then
       dxDrawText( textureName, iXStartPos + iXOffset + 1, iYStartPos + iYOffset + 1, 0, 0, tocolor(0,0,0) )
      end
      dxDrawText( textureName, iXStartPos + iXOffset, iYStartPos + iYOffset, 0, 0, dwColor )

      iYOffset = iYOffset + 15
      if iYOffset > scy - 15 then
       iYOffset = 0;
       iXOffset = iXOffset - 200;
      end
     end
    end
   end
)

---------------------------------------
-- Handle keyboard events from KeyAutoRepeat
---------------------------------------
addEventHandler("onClientKeyClick", resourceRoot,
   function(key)
    if key == "num_7" then
     moveCurrentTextureCaret( -1 )
    elseif key == "num_9" then
     moveCurrentTextureCaret( 1 )
    elseif key == "num_8" then
     bShowTextureUsage = not bShowTextureUsage
    elseif key == "k" then
     if m_SelectedTextureName ~= "" then
      setClipboard( m_SelectedTextureName )
      outputChatBox( "'" .. tostring(m_SelectedTextureName) .. "' copied to clipboard" )
     end
    end
   end
)

---------------------------------------
-- Change current texture
---------------------------------------
function moveCurrentTextureCaret( dir )

   if #usageInfoList == 0 then
    return
   end

   -- Validate selection in current texture list, or find closest match
   for key, textureName in ipairs(usageInfoList) do
    if m_SelectedTextureName <= textureName then
     uiTextureIndex = key
     break
    end
   end

   -- Move position in the list
   uiTextureIndex = uiTextureIndex + dir
   uiTextureIndex = ( ( uiTextureIndex - 1 ) % #usageInfoList ) + 1

   -- Change highlighted texture
   engineRemoveShaderFromWorldTexture ( myShader, m_SelectedTextureName )
   m_SelectedTextureName = usageInfoList [ uiTextureIndex ]
   engineApplyShaderToWorldTexture ( myShader, m_SelectedTextureName )

end


4) Создаём файл "tex_names.fx", и вставляем в него код:

Code
//
// tex_names.fx
//

float Time : TIME;

// Make everything all flashy!
float4 GetColor()
{
      return float4( cos(Time*10), cos(Time*7), cos(Time*4), 1 );
}

//-----------------------------------------------------------------------------
// Techniques
//-----------------------------------------------------------------------------
technique tec0
{
      pass P0
      {
          MaterialAmbient = GetColor();
          MaterialDiffuse = GetColor();
          MaterialEmissive = GetColor();
          MaterialSpecular = GetColor();

          AmbientMaterialSource = Material;
          DiffuseMaterialSource = Material;
          EmissiveMaterialSource = Material;
          SpecularMaterialSource = Material;

          ColorOp[0] = SELECTARG1;
          ColorArg1[0] = Diffuse;

          AlphaOp[0] = SELECTARG1;
          AlphaArg1[0] = Diffuse;

          Lighting = true;
      }
}



Вот и всё!
 
Форум » MTA | Multi Theft Auto » Lua скриптинг (Уроки, FAQ) » [MTA:SA] Названия текстур
  • Страница 1 из 1
  • 1
Поиск:

Последние сообщения:
Самые активные:
Лучшая репутация:
Новые пользователи:
1 | Какой жанр музыки вы любите больше всего слушаеть?[Alexandr]

2 | [Урок] Создание макрера[kryuchin_sasha]

3 | [MTA:SA] FAQ По скриптингу в MTA[nebolskaya]

4 | Считаем до 100[mryagotv]

5 | [Урок] Анимация движения объекта по заданной траектории[NEW][mryagotv]

6 | [MTA:SA] FAQ по ресурсам. Куда, и как их ставить/запускать[osnovik123]

7 | [Урок] Настройка voice чата на сервере[Dano_97_]

8 | [Урок] Картинка в левой части экрана[BISMARCK100]

9 | Помогите в создании сервера![Nick]

10 | Видео уроки по скриптингу в мта са.[Tommy]

1 Nanotech_ua (95|0)

2 Fast_C (17|0)

3 S4n_n1 (14|0)

4 Sucre (6|0)

5 eshka (6|0)

6 Onlines (4|0)

7 drako (3|0)

8 startsmart (3|0)

9 Leone1e (3|0)

10 Step_uP (2|0)

11 Nik (2|0)

12 Fani (2|0)

1 Nanotech_ua

2 S4n_n1

3 eshka

4 LM34

5 Nick

6 xYaroslavGTx

7 Tommy

8 мромг

9 убейте

10 Pavlik1505

11 ty4a

12 bwvsana1

1 faradejfeed

2 sackijvalentin5

3 Alexandr

4 guni3310

5 adilgereevarslanbek6

6 vpyti2020

7 stepaskhasid017

8 dobitnormalnoauf

9 faerpro135

10 boltyshev06

11 brawlstarstop1425

12 hambaryansergo