Fix: crash from get_player_information

master
Coder12a 2021-02-12 20:08:24 -06:00
parent c388c1ca5d
commit 7f54d85a06
4 changed files with 275 additions and 257 deletions

30
api.lua
View File

@ -223,25 +223,29 @@ end
function pvp_revamped.restore_hits(hitdata, name, user)
if hitdata then
local player_lag = get_player_information(name).avg_jitter * 1000000
local timeframe = get_us_time() - player_lag
local info = get_player_information(name)
if info then
local player_lag = info.avg_jitter * 1000000
local timeframe = get_us_time() - player_lag
local count = #hitdata
local count = #hitdata
for i = count, 1, -1 do
local hd = hitdata[i]
if hd.time >= timeframe then
user:set_hp(user:get_hp() + hd.damage)
for i = count, 1, -1 do
local hd = hitdata[i]
hitdata[i] = hitdata[count]
hitdata[count] = nil
if hd.time >= timeframe then
user:set_hp(user:get_hp() + hd.damage)
hitdata[i] = hitdata[count]
hitdata[count] = nil
end
count = count - 1
end
count = count - 1
return hitdata
end
return hitdata
end
end

View File

@ -36,283 +36,287 @@ minetest.register_globalstep(function(dtime)
local check_item = check_item_iterate >= check_item_time
for k, v in pairs(player_data) do
local player_lag = get_player_information(k).avg_jitter * 1000000
local player = get_player_by_name(k)
local time = get_us_time()
local pp_data = player_persistent_data[k]
local active
local info = get_player_information(k)
if v.block and v.aim then
-- Check if the player is holding down the place key.
if floor(player:get_player_control_bits() / 256) % 2 == 1 then
-- Update the block time.
v.block.time = time
end
if info then
local player_lag = info.avg_jitter * 1000000
local player = get_player_by_name(k)
local time = get_us_time()
local pp_data = player_persistent_data[k]
local active
local block = v.block
local aim = v.aim
-- Hand aims forward.
player:set_bone_position(aim.bone, aim.position, aim.rotation)
-- Remove the block table if it's past duration.
-- Or if the guard item is not selected.
if block.time + block.duration + player_lag < time or
(check_item and player:get_wielded_item():get_name() ~= block.name) then
-- Revert the damage texture modifier.
player:set_properties{damage_texture_modifier = pp_data.damage_texture_modifier}
if v.block and v.aim then
-- Check if the player is holding down the place key.
if floor(player:get_player_control_bits() / 256) % 2 == 1 then
-- Update the block time.
v.block.time = time
end
clear_blockdata(v.block, player, k)
end
active = true
elseif not v.block and v.aim then
local aim = v.aim
-- Drop hand.
player:set_bone_position(aim.bone, aim.position, new(-180, 0, 0))
v.aim = nil
active = true
end
if v.shield and v.entity then
-- Check if the player is holding down the place key.
if floor(player:get_player_control_bits() / 256) % 2 == 1 then
-- Update the shield time.
v.shield.time = time
end
local shield = v.shield
-- Remove the shield table if it's past duration.
if shield.time + shield.duration + player_lag < time or
(check_item and not shield.armor_inv and player:get_wielded_item():get_name() ~= shield.name) then
-- Revert the damage texture modifier.
player:set_properties{damage_texture_modifier = pp_data.damage_texture_modifier}
local block = v.block
local aim = v.aim
-- Hand aims forward.
player:set_bone_position(aim.bone, aim.position, aim.rotation)
clear_shielddata(v.shield, player, k)
-- Remove the block table if it's past duration.
-- Or if the guard item is not selected.
if block.time + block.duration + player_lag < time or
(check_item and player:get_wielded_item():get_name() ~= block.name) then
-- Revert the damage texture modifier.
player:set_properties{damage_texture_modifier = pp_data.damage_texture_modifier}
clear_blockdata(v.block, player, k)
end
active = true
elseif not v.block and v.aim then
local aim = v.aim
-- Drop hand.
player:set_bone_position(aim.bone, aim.position, new(-180, 0, 0))
v.aim = nil
active = true
end
local entity = v.entity
-- Point arm forward.
player:set_bone_position(entity.bone, entity.position, entity.rotation)
if v.shield and v.entity then
-- Check if the player is holding down the place key.
if floor(player:get_player_control_bits() / 256) % 2 == 1 then
-- Update the shield time.
v.shield.time = time
end
active = true
elseif not v.shield and v.entity then
local entity = v.entity
-- Drop arms.
player:set_bone_position(entity.bone, entity.position, new(-180, 0, 0))
local shield = v.shield
v.entity.object:remove()
v.entity = nil
active = true
end
-- Remove the shield table if it's past duration.
if shield.time + shield.duration + player_lag < time or
(check_item and not shield.armor_inv and player:get_wielded_item():get_name() ~= shield.name) then
-- Revert the damage texture modifier.
player:set_properties{damage_texture_modifier = pp_data.damage_texture_modifier}
clear_shielddata(v.shield, player, k)
end
if v.throw then
local control_bits = player:get_player_control_bits()
local throw_data = v.throw
local tool_capabilities = throw_data.tool_capabilities
local full_throw = throw_data.time + tool_capabilities.full_throw
-- If neither dig or place is down then throw the item.
if (floor(control_bits / 128) % 2 ~= 1 and
floor(control_bits / 256) % 2 ~= 1 and
floor(control_bits / 512) % 2 ~= 1 and
floor(control_bits / 32) % 2 ~= 1) or
pp_data.active_dodges or
pp_data.active_barrel_rolls then
local entity = v.entity
-- Point arm forward.
player:set_bone_position(entity.bone, entity.position, entity.rotation)
active = true
elseif not v.shield and v.entity then
local entity = v.entity
-- Drop arms.
player:set_bone_position(entity.bone, entity.position, new(-180, 0, 0))
v.entity.object:remove()
v.entity = nil
active = true
end
if v.throw then
local control_bits = player:get_player_control_bits()
local throw_data = v.throw
local tool_capabilities = throw_data.tool_capabilities
local full_throw = throw_data.time + tool_capabilities.full_throw
local pos = player:get_pos()
-- If neither dig or place is down then throw the item.
if (floor(control_bits / 128) % 2 ~= 1 and
floor(control_bits / 256) % 2 ~= 1 and
floor(control_bits / 512) % 2 ~= 1 and
floor(control_bits / 32) % 2 ~= 1) or
pp_data.active_dodges or
pp_data.active_barrel_rolls then
local pos = player:get_pos()
pos.y = pos.y + player:get_properties().eye_height
local obj = add_entity(pos, "pvp_revamped:projectile")
pos.y = pos.y + player:get_properties().eye_height
local obj = add_entity(pos, "pvp_revamped:projectile")
if obj then
local ent = obj:get_luaentity()
if obj then
local ent = obj:get_luaentity()
if ent then
local throw_style = pp_data.throw_style
local throw_speed = tool_capabilities.throw_speed
local damage = tool_capabilities.damage_groups.fleshy
local projectile_gravity = tool_capabilities.projectile_gravity or projectile_gravity
local gravity = projectile_gravity
local projectile_dmg_mul = tool_capabilities.projectile_dmg_mul or projectile_dmg_mul
local projectile_spinning_gravity_mul = tool_capabilities.projectile_spinning_gravity_mul or projectile_spinning_gravity_mul
local projectile_dip_gravity_mul = tool_capabilities.projectile_dip_gravity_mul or projectile_dip_gravity_mul
local spin
if ent then
local throw_style = pp_data.throw_style
local throw_speed = tool_capabilities.throw_speed
local damage = tool_capabilities.damage_groups.fleshy
local projectile_gravity = tool_capabilities.projectile_gravity or projectile_gravity
local gravity = projectile_gravity
local projectile_dmg_mul = tool_capabilities.projectile_dmg_mul or projectile_dmg_mul
local projectile_spinning_gravity_mul = tool_capabilities.projectile_spinning_gravity_mul or projectile_spinning_gravity_mul
local projectile_dip_gravity_mul = tool_capabilities.projectile_dip_gravity_mul or projectile_dip_gravity_mul
local spin
if not throw_data.ready then
local projectile_half_throw_mul = tool_capabilities.projectile_half_throw_mul or projectile_half_throw_mul
local re = (full_throw - time) * projectile_half_throw_mul
if not throw_data.ready then
local projectile_half_throw_mul = tool_capabilities.projectile_half_throw_mul or projectile_half_throw_mul
local re = (full_throw - time) * projectile_half_throw_mul
if re > 0.5 then
damage = damage - re
throw_speed = throw_speed - re
if re > 0.5 then
damage = damage - re
throw_speed = throw_speed - re
end
end
end
if throw_style == projectile_throw_style_spinning then
spin = throw_speed
gravity = gravity * projectile_spinning_gravity_mul
elseif throw_style == projectile_throw_style_dip then
gravity = gravity * projectile_dip_gravity_mul
if throw_style == projectile_throw_style_spinning then
spin = throw_speed
gravity = gravity * projectile_spinning_gravity_mul
elseif throw_style == projectile_throw_style_dip then
gravity = gravity * projectile_dip_gravity_mul
end
ent:set_item(k, throw_data.item)
ent:throw(player, throw_speed, {x = 0, y = gravity, z = 0}, max(damage * projectile_dmg_mul, 1), throw_style, spin)
end
ent:set_item(k, throw_data.item)
ent:throw(player, throw_speed, {x = 0, y = gravity, z = 0}, max(damage * projectile_dmg_mul, 1), throw_style, spin)
end
-- Remove throwing hud.
remove_text_center(player, "pvp_revamped:throw_item")
v.throw = nil
elseif not throw_data.ready and full_throw < time + player_lag then
-- To prevent changing the hud repeatedly.
v.throw.ready = true
create_hud_text_center(player, "pvp_revamped:throw_item", "READY")
end
active = true
end
if v.immobilize then
local immobilize = v.immobilize
-- Check if the immobilize duration expired.
if immobilize.time + immobilize.value + player_lag < time then
-- Restore the player's physics.
get_player_by_name(k):set_physics_override({speed = 1, jump = 1})
v.immobilize = nil
end
active = true
end
if v.barrel_roll then
local active_barrel_rolls = nil
-- Process the player's barrel_roll table cooldown.
for j, l in pairs(v.barrel_roll) do
-- Find if it's aerial or not.
if j > 4 and l.time + barrel_roll_aerial_cooldown + player_lag < time then
v.barrel_roll[j] = nil
elseif j < 5 and l.time + barrel_roll_cooldown + player_lag < time then
v.barrel_roll[j] = nil
elseif l.time + barrel_roll_duration + player_lag > time then
local re_x, re_z = rotate_point(player:get_look_horizontal(), l.x, l.z)
player:add_player_velocity({x = re_x, y = 0, z = re_z})
active_barrel_rolls = true
end
end
-- Remove throwing hud.
remove_text_center(player, "pvp_revamped:throw_item")
v.throw = nil
elseif not throw_data.ready and full_throw < time + player_lag then
-- To prevent changing the hud repeatedly.
v.throw.ready = true
create_hud_text_center(player, "pvp_revamped:throw_item", "READY")
end
active = true
end
if v.immobilize then
local immobilize = v.immobilize
-- Check if the immobilize duration expired.
if immobilize.time + immobilize.value + player_lag < time then
-- Restore the player's physics.
get_player_by_name(k):set_physics_override({speed = 1, jump = 1})
v.immobilize = nil
end
active = true
end
if v.barrel_roll then
local active_barrel_rolls = nil
-- Process the player's barrel_roll table cooldown.
for j, l in pairs(v.barrel_roll) do
-- Find if it's aerial or not.
if j > 4 and l.time + barrel_roll_aerial_cooldown + player_lag < time then
v.barrel_roll[j] = nil
elseif j < 5 and l.time + barrel_roll_cooldown + player_lag < time then
v.barrel_roll[j] = nil
elseif l.time + barrel_roll_duration + player_lag > time then
local re_x, re_z = rotate_point(player:get_look_horizontal(), l.x, l.z)
player:add_player_velocity({x = re_x, y = 0, z = re_z})
active_barrel_rolls = true
if not active_barrel_rolls and player:get_properties().damage_texture_modifier == "" then
-- Revert the damage texture modifier.
player:set_properties{damage_texture_modifier = pp_data.damage_texture_modifier}
end
end
if not active_barrel_rolls and player:get_properties().damage_texture_modifier == "" then
-- Revert the damage texture modifier.
player:set_properties{damage_texture_modifier = pp_data.damage_texture_modifier}
end
-- Store the barrel_roll amount for later use.
player_persistent_data[k].active_barrel_rolls = active_barrel_rolls
-- Store the barrel_roll amount for later use.
player_persistent_data[k].active_barrel_rolls = active_barrel_rolls
-- If this table contains no more barrel_rolls remove it.
if maxn(v.barrel_roll) < 1 then
v.barrel_roll = nil
end
-- Remove un-used barrel roll text.
if not active_barrel_rolls then
remove_text_center(player, "pvp_revamped:barrel_roll")
end
active = true
end
if v.dodge then
local active_dodges = nil
-- Process the player's dodge table cooldown.
for j, l in pairs(v.dodge) do
-- Find if it's aerial or not.
if j > 4 and l + dodge_aerial_cooldown + player_lag < time then
v.dodge[j] = nil
elseif j < 5 and l + dodge_cooldown + player_lag < time then
v.dodge[j] = nil
elseif l + dodge_duration + player_lag > time then
active_dodges = true
-- If this table contains no more barrel_rolls remove it.
if maxn(v.barrel_roll) < 1 then
v.barrel_roll = nil
end
end
if not active_dodges and player:get_properties().damage_texture_modifier == "" then
-- Revert the damage texture modifier.
player:set_properties{damage_texture_modifier = pp_data.damage_texture_modifier}
end
-- Store the dodge amount for later use.
player_persistent_data[k].active_dodges = active_dodges
-- If this table contains no more dodges remove it.
if maxn(v.dodge) < 1 then
v.dodge = nil
end
-- Remove un-used dodge text.
if not active_dodges then
remove_text_center(player, "pvp_revamped:dodge")
end
active = true
end
if v.dash then
-- Process the player's dash table cooldown.
for j, l in pairs(v.dash) do
-- Find if it's aerial or not.
if j > 4 and l + dash_aerial_cooldown + player_lag < time then
v.dash[j] = nil
elseif j < 5 and l + dash_cooldown + player_lag < time then
v.dash[j] = nil
-- Remove un-used barrel roll text.
if not active_barrel_rolls then
remove_text_center(player, "pvp_revamped:barrel_roll")
end
active = true
end
-- If this table contains no more dashes remove it.
if maxn(v.dash) < 1 then
v.dash = nil
end
active = true
end
if v.hit then
local hit_data = v.hit
local count = #hit_data
for i = count, 1, -1 do
local data = hit_data[i]
if data.time + clash_duration + player_lag < time then
hit_data[i] = hit_data[count]
hit_data[count] = nil
count = count - 1
if v.dodge then
local active_dodges = nil
-- Process the player's dodge table cooldown.
for j, l in pairs(v.dodge) do
-- Find if it's aerial or not.
if j > 4 and l + dodge_aerial_cooldown + player_lag < time then
v.dodge[j] = nil
elseif j < 5 and l + dodge_cooldown + player_lag < time then
v.dodge[j] = nil
elseif l + dodge_duration + player_lag > time then
active_dodges = true
end
end
if not active_dodges and player:get_properties().damage_texture_modifier == "" then
-- Revert the damage texture modifier.
player:set_properties{damage_texture_modifier = pp_data.damage_texture_modifier}
end
-- Store the dodge amount for later use.
player_persistent_data[k].active_dodges = active_dodges
-- If this table contains no more dodges remove it.
if maxn(v.dodge) < 1 then
v.dodge = nil
end
-- Remove un-used dodge text.
if not active_dodges then
remove_text_center(player, "pvp_revamped:dodge")
end
active = true
end
-- If this table contains no more hits remove it.
if maxn(hit_data) < 1 then
v.hit = nil
if v.dash then
-- Process the player's dash table cooldown.
for j, l in pairs(v.dash) do
-- Find if it's aerial or not.
if j > 4 and l + dash_aerial_cooldown + player_lag < time then
v.dash[j] = nil
elseif j < 5 and l + dash_cooldown + player_lag < time then
v.dash[j] = nil
end
end
-- If this table contains no more dashes remove it.
if maxn(v.dash) < 1 then
v.dash = nil
end
active = true
end
active = true
end
if v.hit then
local hit_data = v.hit
local count = #hit_data
if not active then
-- Just in case there is still guard pool stuff on screen.
remove_text_center(player, "pvp_revamped:block_pool")
remove_text_center(player, "pvp_revamped:shield_pool")
for i = count, 1, -1 do
local data = hit_data[i]
player_data[k] = nil
if data.time + clash_duration + player_lag < time then
hit_data[i] = hit_data[count]
hit_data[count] = nil
count = count - 1
end
end
-- If this table contains no more hits remove it.
if maxn(hit_data) < 1 then
v.hit = nil
end
active = true
end
if not active then
-- Just in case there is still guard pool stuff on screen.
remove_text_center(player, "pvp_revamped:block_pool")
remove_text_center(player, "pvp_revamped:shield_pool")
player_data[k] = nil
end
end
end

View File

@ -1,4 +1,3 @@
local get_player_information = minetest.get_player_information
local projectile_full_throw_mul = pvp_revamped.config.projectile_full_throw_mul
local projectile_speed_mul = pvp_revamped.config.projectile_speed_mul
local spam_damage = pvp_revamped.config.spam_damage

View File

@ -130,7 +130,12 @@ local function punch(player, hitter, time_from_last_punch, tool_capabilities, di
range = item.range
end
local player_lag = get_player_information(name).avg_jitter
local info = get_player_information(name)
local player_lag = 0
if info then
player_lag = info.avg_jitter
end
-- Get whether this is a full punch.
if tool_capabilities and time_from_last_punch >= tool_capabilities.full_punch_interval - player_lag then
@ -663,7 +668,13 @@ local function punch(player, hitter, time_from_last_punch, tool_capabilities, di
end
if hitter_hitdata then
player_lag = get_player_information(hitter_name).avg_jitter * 1000000
info = get_player_information(hitter_name)
player_lag = 0
if info then
player_lag = info.avg_jitter * 1000000
end
local count = #hitter_hitdata
for i = count, 1, -1 do