SHOW:
|
|
- or go back to the newest paste.
1 | - | -- Author: Kernell |
1 | + | -- Authors: Kernell, qwerty |
2 | -- Version: 1.0.0 | |
3 | ||
4 | local ped_states = | |
5 | { | |
6 | - | stand = 3; -- The ped is standing still |
6 | + | stand = 3; -- The ped is standing still |
7 | walk = 0; -- The ped is walking | |
8 | - | powerwalk = 0; -- The ped is walking quickly |
8 | + | powerwalk = 0; -- The ped is walking quickly |
9 | - | jog = 1; -- The ped is jogging |
9 | + | jog = 1; -- The ped is jogging |
10 | - | sprint = 2; -- The ped is sprinting |
10 | + | sprint = 2; -- The ped is sprinting |
11 | - | -- crouch = NULL; -- The ped is crouching still |
11 | + | -- crouch = NULL; -- The ped is crouching still |
12 | }; | |
13 | ||
14 | - | local ped_state = 3; -- 0: walk; 1: run; 2: sprint; 3: idle; 4: roadcross; |
14 | + | function OnMoveStateChanged( uPed, move_state ) |
15 | - | local old_move_state = 'NULL'; |
15 | + | setPedAnimation( uPed, "PED", "facanger", 0, false, false, false, false ); |
16 | ||
17 | - | function OnMoveStateChanged( move_state, old_move_state ) |
17 | + | local ped_state = ped_states[ move_state ] or -1; |
18 | - | triggerServerEvent( "setAnimation", localPlayer, "PED", "facanger", 0, false, false, false, false ); |
18 | + | local anim_group = GetPedAnimGroup(uPed); |
19 | ||
20 | - | local ped_state = ped_states[ move_state ] or -1; |
20 | + | |
21 | - | local anim_group = GetPedAnimGroup( localPlayer ); |
21 | + | |
22 | ||
23 | if animation then | |
24 | setPedAnimation( uPed, "PED", animation, 1, true, ped_state ~= 3 ); | |
25 | end | |
26 | end | |
27 | - | triggerServerEvent( "setAnimation", localPlayer, "PED", animation, 1, true, ped_state ~= 3 ); |
27 | + | |
28 | ||
29 | function OnRender() | |
30 | if isDebugViewActive() then | |
31 | local x, y = 100, 500; | |
32 | - | local function OnRender() |
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 | - | local move_state = getPedMoveState( localPlayer ); |
63 | + | for _, uPlayer in ipairs(tStreamedPlayers) do |
64 | sMove_state = getPedMoveState(uPlayer); | |
65 | - | if move_state ~= old_move_state then |
65 | + | |
66 | - | OnMoveStateChanged( move_state, old_move_state ); |
66 | + | if sMove_state ~= getElementData( uPlayer, 'old_move_state' ) then |
67 | OnMoveStateChanged( uPlayer, sMove_state ); | |
68 | end | |
69 | - | old_move_state = move_state; |
69 | + | |
70 | setElementData( uPlayer, 'old_move_state', sMove_state, false ) | |
71 | end | |
72 | - | addEventHandler( "onClientRender", root, OnRender ); |
72 | + | |
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 | ) |