Модератор раздела "Создание скриптов для читов"
-
Автор темы
- #1
code_language.lua:
local ui = require 'wrapper'
local c_entity = require 'gamesense/entity'
local checkbox = ui.create('animation_fix', 'A'):switch('enable animation fix')
local animation_fix do
animation_fix = {}
animation_fix.anim_data = {
layers = {
[0] = { cycle = 0, weight = 0 }, -- aim_matrix
[1] = { cycle = 0, weight = 0 }, -- weapon_action
[2] = { cycle = 0, weight = 0 }, -- weapon_action_recrouch
[3] = { cycle = 0, weight = 0 }, -- adjust
[4] = { cycle = 0, weight = 0 }, -- movement_move
[5] = { cycle = 0, weight = 0 }, -- movement_strafe
[6] = { cycle = 0, weight = 0 }, -- movement_strafechange
[7] = { cycle = 0, weight = 0 }, -- whole_body
[8] = { cycle = 0, weight = 0 }, -- flashed
[9] = { cycle = 0, weight = 0 }, -- flinch
[10] = { cycle = 0, weight = 0 }, -- aliveloop
[11] = { cycle = 0, weight = 0 }, -- jump
[12] = { cycle = 0, weight = 0 }, -- land
[13] = { cycle = 0, weight = 0 }, -- move_blend_walk
[14] = { cycle = 0, weight = 0 }, -- move_blend_run
[15] = { cycle = 0, weight = 0 }, -- move_blend_crouch
},
server_anim_states = {},
last_sim_time = 0,
last_velocity = 0,
last_duck_amount = 0,
last_weapon = nil,
}
local function lerp(a, b, t)
return a + (b - a) * t
end
animation_fix.setup_command = function(cmd)
if not checkbox:get() then
return
end
local me = entity.get_local_player()
if not me then
return
end
local self_index = c_entity.new(me)
local anim_state = self_index:get_anim_state()
if not anim_state then return end
local sim_time = globals.servertickcount()
local vel_x, vel_y = entity.get_prop(me, "m_vecVelocity")
local velocity = math.sqrt(vel_x * vel_x + vel_y * vel_y)
local duck_amount = entity.get_prop(me, "m_flDuckAmount")
local ducking = entity.get_prop(me, "m_bDucking") == 1
local on_ground = bit.band(entity.get_prop(me, "m_fFlags"), 1) == 1
local current_weapon = entity.get_player_weapon(me)
if velocity < 0.1 then
velocity = 0
end
local server_state = {
time = sim_time,
layers = {},
velocity = velocity,
duck_amount = duck_amount,
ducking = ducking,
on_ground = on_ground,
weapon = current_weapon,
}
for layer_idx, _ in pairs(animation_fix.anim_data.layers) do
local layer = self_index:get_anim_overlay(layer_idx)
if layer then
server_state.layers[layer_idx] = {
cycle = layer.cycle,
weight = layer.weight,
}
end
end
table.insert(animation_fix.anim_data.server_anim_states, server_state)
if #animation_fix.anim_data.server_anim_states > 60 then
table.remove(animation_fix.anim_data.server_anim_states, 1)
end
end
animation_fix.pre_render = function()
if not checkbox:get() then
return
end
local me = entity.get_local_player()
if not me then
return
end
local self_index = c_entity.new(me)
local anim_state = self_index:get_anim_state()
if not anim_state then return end
local current_time = globals.realtime()
local server_states = animation_fix.anim_data.server_anim_states
if #server_states < 2 then
return
end
local state1, state2
for i = #server_states - 1, 1, -1 do
if server_states[i].time <= current_time and server_states[i+1].time >= current_time then
state1 = server_states[i]
state2 = server_states[i+1]
break
end
end
if not state1 or not state2 then
state1 = server_states[#server_states - 1]
state2 = server_states[#server_states]
end
local t = (current_time - state1.time) / (state2.time - state1.time)
t = math.min(1, math.max(0, t))
for layer_idx, _ in pairs(animation_fix.anim_data.layers) do
local layer = self_index:get_anim_overlay(layer_idx)
if layer and state1.layers[layer_idx] and state2.layers[layer_idx] then
local cycle1 = state1.layers[layer_idx].cycle
local cycle2 = state2.layers[layer_idx].cycle
local weight1 = state1.layers[layer_idx].weight
local weight2 = state2.layers[layer_idx].weight
if (layer_idx == 1 or layer_idx == 2) and state1.weapon ~= state2.weapon then
layer.cycle = cycle2
layer.weight = weight2
else
layer.cycle = lerp(cycle1, cycle2, t)
layer.weight = lerp(weight1, weight2, t)
end
end
end
local velocity = lerp(state1.velocity, state2.velocity, t)
local duck_amount = lerp(state1.duck_amount, state2.duck_amount, t)
local ducking = state1.ducking
local on_ground = state1.on_ground
local current_weapon = state1.weapon
animation_fix.anim_data.last_velocity = velocity
animation_fix.anim_data.last_duck_amount = duck_amount
animation_fix.anim_data.last_weapon = current_weapon
end
end
client.set_event_callback('pre_render', function()
animation_fix.pre_render()
end)
client.set_event_callback('setup_command', function(cmd)
animation_fix.setup_command(cmd)
end)