Replace global with local variables

This commit is contained in:
Lars 2022-03-04 21:06:22 -08:00
parent e85d06e5f9
commit 369c5c647c
2 changed files with 27 additions and 28 deletions

@ -29,12 +29,12 @@ if w_item:get_definition().weapon_zoom == nil then
player:hud_change(scope_hud, "text", "rangedweapons_empty_icon.png") player:hud_change(scope_hud, "text", "rangedweapons_empty_icon.png")
if player:get_inventory():contains_item( if player:get_inventory():contains_item(
"main", "binoculars:binoculars") then "main", "binoculars:binoculars") then
new_zoom_fov = 10 local new_zoom_fov = 10
if player:get_properties().zoom_fov ~= new_zoom_fov then if player:get_properties().zoom_fov ~= new_zoom_fov then
player:set_properties({zoom_fov = new_zoom_fov}) player:set_properties({zoom_fov = new_zoom_fov})
end end
else else
new_zoom_fov = 0 local new_zoom_fov = 0
if player:get_properties().zoom_fov ~= new_zoom_fov then if player:get_properties().zoom_fov ~= new_zoom_fov then
player:set_properties({zoom_fov = new_zoom_fov}) player:set_properties({zoom_fov = new_zoom_fov})
end end
@ -90,7 +90,7 @@ if player:get_wielded_item():get_definition().rw_next_reload ~= nil then
if itemstack:get_definition().load_sound ~= nil then if itemstack:get_definition().load_sound ~= nil then
minetest.sound_play(itemstack:get_definition().load_sound, {pos = player:get_pos()}) minetest.sound_play(itemstack:get_definition().load_sound, {pos = player:get_pos()})
end end
gunMeta = itemstack:get_meta() local gunMeta = itemstack:get_meta()
u_meta:set_float("rw_cooldown",gunMeta:get_float("RW_reload_delay")) u_meta:set_float("rw_cooldown",gunMeta:get_float("RW_reload_delay"))
itemstack:set_name(player:get_wielded_item():get_definition().rw_next_reload) itemstack:set_name(player:get_wielded_item():get_definition().rw_next_reload)
player:set_wielded_item(itemstack) player:set_wielded_item(itemstack)

@ -56,8 +56,9 @@ end
rangedweapons_reload_gun = function(itemstack, player) rangedweapons_reload_gun = function(itemstack, player)
GunCaps = itemstack:get_definition().RW_gun_capabilities local GunCaps = itemstack:get_definition().RW_gun_capabilities
local gun_unload_sound = ""
if GunCaps ~= nil then if GunCaps ~= nil then
gun_unload_sound = GunCaps.gun_unload_sound or "" gun_unload_sound = GunCaps.gun_unload_sound or ""
end end
@ -167,7 +168,7 @@ end
rangedweapons_single_load_gun = function(itemstack, player) rangedweapons_single_load_gun = function(itemstack, player)
GunCaps = itemstack:get_definition().RW_gun_capabilities local GunCaps = itemstack:get_definition().RW_gun_capabilities
if GunCaps ~= nil then if GunCaps ~= nil then
gun_unload_sound = GunCaps.gun_unload_sound or "" gun_unload_sound = GunCaps.gun_unload_sound or ""
@ -335,10 +336,9 @@ if throw_skillChance > 0 and throw_skill ~= "" then
rangedweapons_gain_skill(player,throw_skill,throw_skillChance) rangedweapons_gain_skill(player,throw_skill,throw_skillChance)
end end
local skill_value = 1
if throw_skill ~= "" then if throw_skill ~= "" then
skill_value = playerMeta:get_int(throw_skill)/100 skill_value = playerMeta:get_int(throw_skill)/100
else
skill_value = 1
end end
rangedweapons_launch_projectile(player,throw_projectiles,throw_damage,throw_ent,throw_visual,throw_texture,throw_sound,throw_velocity,throw_accuracy,skill_value,OnCollision,throw_crit,throw_critEffc,throw_mobPen,throw_nodePen,0,"","","",throw_dps,throw_gravity,throw_door_breaking,throw_glass_breaking,throw_particles,throw_sparks,throw_bomb_ignite,throw_size,0,itemstack:get_wear(),throw_glow) rangedweapons_launch_projectile(player,throw_projectiles,throw_damage,throw_ent,throw_visual,throw_texture,throw_sound,throw_velocity,throw_accuracy,skill_value,OnCollision,throw_crit,throw_critEffc,throw_mobPen,throw_nodePen,0,"","","",throw_dps,throw_gravity,throw_door_breaking,throw_glass_breaking,throw_particles,throw_sparks,throw_bomb_ignite,throw_size,0,itemstack:get_wear(),throw_glow)
@ -392,7 +392,7 @@ end
local OnCollision = function() end local OnCollision = function() end
local bulletStack = ItemStack({name = gunMeta:get_string("RW_ammo_name")}) local bulletStack = ItemStack({name = gunMeta:get_string("RW_ammo_name")})
AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities local AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities
local gun_damage = {fleshy=1} local gun_damage = {fleshy=1}
local gun_sound = "rangedweapons_glock" local gun_sound = "rangedweapons_glock"
@ -401,6 +401,7 @@ local gun_accuracy = 100
local gun_cooling = 0 local gun_cooling = 0
local gun_crit = 0 local gun_crit = 0
local gun_critEffc = 1 local gun_critEffc = 1
local gun_projectiles = 1
local gun_mobPen = 0 local gun_mobPen = 0
local gun_nodePen = 0 local gun_nodePen = 0
local gun_shell = 0 local gun_shell = 0
@ -527,10 +528,9 @@ end
--minetest.chat_send_all(minetest.serialize(combined_dmg)) --minetest.chat_send_all(minetest.serialize(combined_dmg))
local skill_value = 1
if gun_skill ~= "" then if gun_skill ~= "" then
skill_value = playerMeta:get_int(gun_skill)/100 skill_value = playerMeta:get_int(gun_skill)/100
else
skill_value = 1
end end
rangedweapons_launch_projectile(player,combined_projNum,combined_dmg,bullet_ent,bullet_visual,bullet_texture,gun_sound,combined_velocity,gun_accuracy,skill_value,OnCollision,combined_crit,combined_critEffc,combined_mobPen,combined_nodePen,gun_shell,bullet_shell_ent,bullet_shell_texture,bullet_shell_visual,combined_dps,combined_gravity,gun_door_breaking,bullet_glass_breaking,bullet_particles,bullet_sparks,bullet_bomb_ignite,bullet_size,gun_smokeSize,0,bullet_glow) rangedweapons_launch_projectile(player,combined_projNum,combined_dmg,bullet_ent,bullet_visual,bullet_texture,gun_sound,combined_velocity,gun_accuracy,skill_value,OnCollision,combined_crit,combined_critEffc,combined_mobPen,combined_nodePen,gun_shell,bullet_shell_ent,bullet_shell_texture,bullet_shell_visual,combined_dps,combined_gravity,gun_door_breaking,bullet_glass_breaking,bullet_particles,bullet_sparks,bullet_bomb_ignite,bullet_size,gun_smokeSize,0,bullet_glow)
@ -636,10 +636,9 @@ if power_skillChance > 0 and power_skill ~= "" then
rangedweapons_gain_skill(player,power_skill,power_skillChance) rangedweapons_gain_skill(player,power_skill,power_skillChance)
end end
local skill_value = 1
if power_skill ~= "" then if power_skill ~= "" then
skill_value = playerMeta:get_int(power_skill)/100 skill_value = playerMeta:get_int(power_skill)/100
else
skill_value = 1
end end
rangedweapons_launch_projectile(player,power_projectiles,power_damage,power_ent,power_visual,power_texture,power_sound,power_velocity,power_accuracy,skill_value,OnCollision,power_crit,power_critEffc,power_mobPen,power_nodePen,0,"","","",power_dps,power_gravity,power_door_breaking,power_glass_breaking,power_particles,power_sparks,power_bomb_ignite,power_size,0,0,power_glow) rangedweapons_launch_projectile(player,power_projectiles,power_damage,power_ent,power_visual,power_texture,power_sound,power_velocity,power_accuracy,skill_value,OnCollision,power_crit,power_critEffc,power_mobPen,power_nodePen,0,"","","",power_dps,power_gravity,power_door_breaking,power_glass_breaking,power_particles,power_sparks,power_bomb_ignite,power_size,0,0,power_glow)
@ -691,7 +690,7 @@ if smokeSize > 0 then
}) })
end end
projectiles = projNum or 1 local projectiles = projNum or 1
for i=1,projectiles do for i=1,projectiles do
local obj = minetest.add_entity(pos, projEnt) local obj = minetest.add_entity(pos, projEnt)
local ent = obj:get_luaentity() local ent = obj:get_luaentity()
@ -720,7 +719,7 @@ glow = proj_glow,}
ent.size = size ent.size = size
ent.timer = 0 + (combined_velocity/2000) ent.timer = 0 + (combined_velocity/2000)
ent.wear = proj_wear ent.wear = proj_wear
acc = ((( 100 - accuracy ) / 10) / skill_value ) or 0 local acc = ((( 100 - accuracy ) / 10) / skill_value ) or 0
obj:set_velocity({x=dir.x * combined_velocity + math.random(-acc,acc), y=dir.y * combined_velocity + math.random(-acc,acc), z=dir.z * combined_velocity + math.random(-acc,acc)}) obj:set_velocity({x=dir.x * combined_velocity + math.random(-acc,acc), y=dir.y * combined_velocity + math.random(-acc,acc), z=dir.z * combined_velocity + math.random(-acc,acc)})
obj:set_acceleration({x=0, y=-gravity, z=0}) obj:set_acceleration({x=0, y=-gravity, z=0})
obj:set_rotation({x=0,y=yaw + math.pi,z=-svertical}) obj:set_rotation({x=0,y=yaw + math.pi,z=-svertical})
@ -746,8 +745,8 @@ minetest.sound_play(rldsound, {pos = pos})
pos.y = pos.y + 1.6 pos.y = pos.y + 1.6
local obj = minetest.add_entity(pos, "rangedweapons:empty_shell") local obj = minetest.add_entity(pos, "rangedweapons:empty_shell")
if AmmoCaps and bulletStack ~= "" then if bulletStack ~= "" then
AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities local AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities
local bullet_shell_visual = "wielditem" local bullet_shell_visual = "wielditem"
local bullet_shell_texture = "rangedweapons:shelldrop" local bullet_shell_texture = "rangedweapons:shelldrop"