From f155195c0b3e12629b7906b2284f1cdf239758de Mon Sep 17 00:00:00 2001 From: david Date: Fri, 2 Apr 2021 22:55:31 -0400 Subject: [PATCH 1/2] Reduced Warnings I created a different branch for development progress... Please try the current dev branch out... you will see that we blow up in an environment_Step (perhaps this is why we break?) Anyway, I hunted down quite a good deal of warnings and most of them could be easily fixed just by making whatever variable it was into local. (I also littered the code with comments stating the exact WARNING I got from the client) --- cooldown_stuff.lua | 3 +++ init.lua | 43 +++++++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/cooldown_stuff.lua b/cooldown_stuff.lua index 2d6dcd6..9bee3cd 100644 --- a/cooldown_stuff.lua +++ b/cooldown_stuff.lua @@ -26,6 +26,7 @@ local wpn_zoom = w_item:get_definition().weapon_zoom end if w_item:get_definition().weapon_zoom == nil then + local new_zoom_fov = 0 -- Assume a default 0 player:hud_change(scope_hud, "text", "rangedweapons_empty_icon.png") if player:get_inventory():contains_item( "main", "binoculars:binoculars") then @@ -34,6 +35,8 @@ player:hud_change(scope_hud, "text", "rangedweapons_empty_icon.png") player:set_properties({zoom_fov = new_zoom_fov}) end else + -- WARNING: Assignment to undeclared global "new_zoom_fov" inside a function at mods/rangedweapons/cooldown_stuff.lua:37. + -- Solution, at the beginning of all this let's make a local new_zoom_fov new_zoom_fov = 0 if player:get_properties().zoom_fov ~= new_zoom_fov then player:set_properties({zoom_fov = new_zoom_fov}) diff --git a/init.lua b/init.lua index d8064ce..66a9818 100644 --- a/init.lua +++ b/init.lua @@ -56,7 +56,9 @@ end rangedweapons_reload_gun = function(itemstack, player) -GunCaps = itemstack:get_definition().RW_gun_capabilities +-- WARNING: Assignment to undeclared global "GunCaps" inside a function at mods/rangedweapons/init.lua:59. +-- I think GunCaps needs to be local +local GunCaps = itemstack:get_definition().RW_gun_capabilities if GunCaps ~= nil then gun_unload_sound = GunCaps.gun_unload_sound or "" @@ -388,7 +390,9 @@ end local OnCollision = function() end local bulletStack = ItemStack({name = gunMeta:get_string("RW_ammo_name")}) -AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities +-- WARNING: Assignment to undeclared global "AmmoCaps" inside a function at mods/rangedweapons/init.lua:391. +-- Solution, Make local +local AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities local gun_damage = {fleshy=1} local gun_sound = "rangedweapons_glock" @@ -433,6 +437,7 @@ local bullet_glow = 20 if GunCaps ~= nil then +-- Potential Warnings, see line 448 gun_damage = GunCaps.gun_damage or {fleshy=1} gun_sound = GunCaps.gun_sound or "rangedweapons_glock" gun_velocity = GunCaps.gun_velocity or 20 @@ -440,7 +445,8 @@ gun_accuracy = GunCaps.gun_accuracy or 100 gun_cooling = GunCaps.gun_cooling or itemstack:get_name() gun_crit = GunCaps.gun_crit or 0 gun_critEffc = GunCaps.gun_critEffc or 1 -gun_projectiles = GunCaps.gun_projectiles or 1 +-- WARNING: Assignment to undeclared global "gun_projectiles" inside a function at mods/rangedweapons/init.lua:443. +local gun_projectiles = GunCaps.gun_projectiles or 1 gun_mobPen = GunCaps.gun_mob_penetration or 0 gun_nodePen = GunCaps.gun_node_penetration or 0 gun_shell = GunCaps.has_shell or 0 @@ -523,6 +529,11 @@ end --minetest.chat_send_all(minetest.serialize(combined_dmg)) +-- WARNING: Assignment to undeclared global "skill_value" inside a function at mods/rangedweapons/init.lua:527. +-- Solution, making a local with a default + +local skill_value = 1 -- Defaulting to 1 + if gun_skill ~= "" then skill_value = playerMeta:get_int(gun_skill)/100 else @@ -673,6 +684,8 @@ shl:set_properties({ textures = {shellTexture}, visual = shellVisual,}) end +local projectiles = 1 -- Defaults +local rndacc = 0 -- Defaults if smokeSize > 0 then minetest.add_particle({ pos = pos, @@ -686,9 +699,11 @@ if smokeSize > 0 then glow = 5, }) end - + -- WARNING: Assignment to undeclared global "projectiles" inside a function at mods/rangedweapons/init.lua:690. + -- I will add a local above this so it "exists" projectiles = projNum or 1 for i=1,projectiles do + -- Reacurring Warning on line 701 rndacc = (100 - accuracy) or 0 local spawnpos_x = pos.x + (math.random(-rndacc,rndacc)/100) local spawnpos_y = pos.y + (math.random(-rndacc,rndacc)/100) @@ -722,7 +737,9 @@ glow = proj_glow,} ent.timer = 0 + (combined_velocity/2000) ent.wear = proj_wear obj:set_velocity({x=dir.x * combined_velocity, y=dir.y * combined_velocity, z=dir.z * combined_velocity}) - acc = ((( 100 - accuracy ) / 10) / skill_value ) or 0 + -- WARNING: Assignment to undeclared global "acc" inside a function at mods/rangedweapons/init.lua:725. + -- Making local + local acc = ((( 100 - accuracy ) / 10) / skill_value ) or 0 obj:set_acceleration({x=math.random(-acc,acc), y=math.random(-acc,acc)-gravity, z=math.random(-acc,acc)}) obj:set_rotation({x=0,y=yaw + math.pi,z=-svertical}) end end end @@ -922,7 +939,9 @@ minetest.register_abm({ }) minetest.register_on_joinplayer(function(player) - gunammo = + -- WARNING: Assignment to undeclared global "gunammo" inside a function at mods/rangedweapons/init.lua:935 + -- Solution, make it local... not global + local gunammo = player:hud_add({ hud_elem_type = "text", name = "gunammo", @@ -933,7 +952,8 @@ minetest.register_on_joinplayer(function(player) offset = {x = 30, y = 100}, alignment = {x = 0, y = -1} }) - gunimg = + -- Reaccuring Warning see Line 927 + local gunimg = player:hud_add({ hud_elem_type = "image", text = "rangedweapons_empty_icon.png", @@ -942,7 +962,8 @@ minetest.register_on_joinplayer(function(player) offset = {x = 30, y = 100}, alignment = {x = 0, y = -1} }) - ammoimg = + -- Reaccuring Warning see Line 927 + local ammoimg = player:hud_add({ hud_elem_type = "image", text = "rangedweapons_empty_icon.png", @@ -951,7 +972,8 @@ minetest.register_on_joinplayer(function(player) offset = {x = 30, y = 100}, alignment = {x = 0, y = -1} }) - hit = + -- Reaccuring Warning see Line 927 + local hit = player:hud_add({ hud_elem_type = "image", text = "rangedweapons_empty_icon.png", @@ -960,7 +982,8 @@ minetest.register_on_joinplayer(function(player) offset = {x = 0, y = 0}, alignment = {x = 0, y = 0} }) -scope_hud = + -- Reaccuring Warning see Line 927 +local scope_hud = player:hud_add({ hud_elem_type = "image", position = { x=0.5, y=0.5 }, -- 2.30.2 From 59eec8584bd0e8fe70f63cf02b775f2227f6771f Mon Sep 17 00:00:00 2001 From: Beanzilla Date: Fri, 16 Apr 2021 14:50:55 -0400 Subject: [PATCH 2/2] Create README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..411d380 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# rangedweapons-1 +a mod that adds ranged weapons to minetest. + +## What's changed + +* This repo is forked from [daviddoesminetest/rangedweapons](https://github.com/daviddoesminetest/rangedweapons) +* Unpacked the ZIPs so you just select the release you want to have. (Quick deployment) +* Just `git pull` to update if you are on the main branch to automatically update. (Use `git status` to check for updates) +* Added dev branch for developmental states. (Most likely this branch will not even work, but it's a work in progress) -- 2.30.2