Advertisement
MX_Master

MTASA: Walking style of PEDS - my rev 1

Feb 4th, 2012
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Authors:         Kernell, qwerty
  2. -- Version:         1.0.0
  3.  
  4. local ped_states =
  5. {
  6.     stand       = 3; -- The ped is standing still
  7.     walk        = 0; -- The ped is walking
  8.     powerwalk   = 0; -- The ped is walking quickly
  9.     jog         = 1; -- The ped is jogging
  10.     sprint      = 2; -- The ped is sprinting
  11. --  crouch      = NULL; -- The ped is crouching still
  12. };
  13.  
  14. function OnMoveStateChanged( uPed, move_state )
  15.     setPedAnimation( uPed, "PED", "facanger", 0, false, false, false, false );
  16.    
  17.     local ped_state     = ped_states[ move_state ] or -1;
  18.     local anim_group    = GetPedAnimGroup(uPed);
  19.    
  20.     if anim_group then
  21.         local animation = GetAnimation( anim_group, ped_state );
  22.        
  23.         if animation then
  24.             setPedAnimation( uPed, "PED", animation, 1, true, ped_state ~= 3 );
  25.         end
  26.     end
  27. end
  28.  
  29. function OnRender()
  30.     if isDebugViewActive() then
  31.         local x, y = 100, 500;
  32.        
  33.         for k = 1, 4 do
  34.             local a, b, c, d = getPedTask( localPlayer, "primary", k );
  35.            
  36.             dxDrawText( "Primary task #" .. k .. " is " .. tostring( a ) .. " -> " .. tostring( b ) .. " -> " .. tostring( c ) .. " -> " .. tostring( d ) .. " -> ", x, y );
  37.            
  38.             y = y + 15;
  39.         end
  40.        
  41.         y = y + 15;
  42.        
  43.         for k = 1, 5 do
  44.             local a, b, c, d = getPedTask( localPlayer, "secondary", k );
  45.            
  46.             dxDrawText( "Secondary task #" .. k .. " is " .. tostring( a ) .. " -> " .. tostring( b ) .. " -> " .. tostring( c ) .. " -> " .. tostring( d ) .. " -> ", x, y );
  47.            
  48.             y = y + 15;
  49.         end
  50.        
  51.         y = y + 30;
  52.        
  53.         dxDrawText( "Simplest task: " .. tostring( getPedSimplestTask( localPlayer ) ), x, y );
  54.        
  55.         y = y + 30;
  56.        
  57.         dxDrawText( "Move state: " .. tostring( getPedMoveState( localPlayer ) ), x, y );
  58.     end
  59.    
  60.     local tStreamedPlayers = getElementsByType( 'player', root, true )
  61.     local sMove_state = ''
  62.    
  63.     for _, uPlayer in ipairs(tStreamedPlayers) do
  64.         sMove_state = getPedMoveState(uPlayer);
  65.        
  66.         if sMove_state ~= getElementData( uPlayer, 'old_move_state' ) then
  67.             OnMoveStateChanged( uPlayer, sMove_state );
  68.         end
  69.        
  70.         setElementData( uPlayer, 'old_move_state', sMove_state, false )
  71.     end
  72. end
  73.  
  74. addEventHandler( "onClientRender", root, OnRender );
  75.  
  76. -- юзаем вместо переменной old_move_state,
  77. -- чисто клиентский ElementData 'old_move_state' для каждого игрока
  78. addEventHandler( 'onClientResourceStart', resourceRoot,
  79.     function()
  80.         local tPlayers = getElementsByType('player')
  81.         for _, uPlayer in ipairs(tPlayers) do
  82.             setElementData( uPlayer, 'old_move_state', 'NULL', false )
  83.         end
  84.     end
  85. )
  86. addEventHandler( 'onClientPlayerJoin', root,
  87.     function()
  88.         setElementData( source, 'old_move_state', 'NULL', false )    
  89.     end
  90. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement