Remove items with mod

Place to get help with not working mods / modding interface.
iggyboo
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sun Sep 11, 2016 2:20 am
Contact:

Remove items with mod

Post by iggyboo »

I was wanting to write a quick mod for multiplayer games to remove weapons that can damage other players or items. Turrets would stay so there could be some defence. I've found all over the place where I can add items and recipes, but can't seem to find a way to remove a core item. Not from research, just so players can't go around shooting or blowing each other up. Did I just miss something obvious? Otherwise, maybe I could just change them so they can't use them the same way? Thanks for any help in advance. :)
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Remove items with mod

Post by Nexela »

To remove something you just nil it..... but Deleting them all might be a bad idea also so lets get rid of all ammo categories :)

probably want to do this in data-final-fixes.lua, Keep in mind this will essentially disable vehicle guns as well as player guns. All that will be left is turrets.

Code: Select all

--The democrats have won! All guns now have mandatory unlockable gun locks that prevent them from being loaded.
for _, gun in pairs(data.raw.gun) do
    gun.attack_parameters.ammo_category = ""
end
This still leaves grenades...

Code: Select all

--whole lotta nothing!
	for i, effect in pairs(data.raw["military-2"].effects) do
		if effect.recipe=="grenade" then data.raw.technology["military-2"].effects[i]=nil end
	end
I will leave you to figure out cluster grenades and poison capsules
User avatar
LuziferSenpai
Filter Inserter
Filter Inserter
Posts: 375
Joined: Tue Jul 08, 2014 10:06 am
Contact:

Re: Remove items with mod

Post by LuziferSenpai »

Nexela wrote:To remove something you just nil it..... but Deleting them all might be a bad idea also so lets get rid of all ammo categories :)

probably want to do this in data-final-fixes.lua, Keep in mind this will essentially disable vehicle guns as well as player guns. All that will be left is turrets.

Code: Select all

--The democrats have won! All guns now have mandatory unlockable gun locks that prevent them from being loaded.
for _, gun in pairs(data.raw.gun) do
    gun.attack_parameters.ammo_category = ""
end
This still leaves grenades...

Code: Select all

--whole lotta nothing!
	for i, effect in pairs(data.raw["military-2"].effects) do
		if effect.recipe=="grenade" then data.raw.technology["military-2"].effects[i]=nil end
	end
I will leave you to figure out cluster grenades and poison capsules
The easy way:

Code: Select all

function remove (nama)
data.raw["item"][nama] = nil
data.raw["recipe"]["nama] = nil
end
Than you only need to remove the Recipe from the Tech.
Coding is awesome!
Animes are love!
Factorio is life!

My MODs:
Click

Greetz,

Senpai
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Remove items with mod

Post by Adil »

LuziferSenpai wrote: The easy way:
Nexela intentionally provided more sophisticated way because this "simplest" one will bite you. Because "only" in "Than you only need to remove the Recipe from the Tech." is actually quite a task.

You've set a couple of items to nil, you're smart, but what happens, when loader encounters another recipe, that references those? Or a technology, that now unlocks unexistent recipe?
We've had this discussion before.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
iggyboo
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sun Sep 11, 2016 2:20 am
Contact:

Re: Remove items with mod

Post by iggyboo »

Ah, very nice! I'll try that out tonight and see in how much trouble I can get myself :D

Thanks!
iggyboo
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sun Sep 11, 2016 2:20 am
Contact:

Re: Remove items with mod

Post by iggyboo »

Well, I decided to go even simpler:

Code: Select all

for _,gun in pairs(data.raw.gun) do
  gun.attack_parameters.ammo_category = ""
end


for _,projectile in pairs(data.raw.projectile) do
  if projectile.name=="grenade" or projectile.name=="cluster-grenade" or projectile.name=="poison-capsule" then
    projectile.action=nil    
  end
end
Instead of worrying about changing recipes or tech, I just removed the damage completely from them. I figure this would even be more frustrating for trolls. They spend all the time to make it, but they don't even get the satisfaction of seeing it blow up. I loaded a game with this mod and I couldn't shoot any of my weapons and when I tossed a grenade at my factories, "poof", nothing. Very unsatisfying. :)

I wanted to modify the damage only so the explosion would still happen but I just don't quite grasp how to do that. I think I would have to do some type of "insert table" to change that, right? Still learning lua, but I think I'll keep at it.

Thanks for your help!

[edit] Uploaded mod: https://mods.factorio.com/mods/Iggyboo/TrollControl
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Remove items with mod

Post by Nexela »

I didn't even think about the projectile! Good catch and it is the better way to do.

so I present to you damage free grenades!!!! (there has got to be an easier way to do this!)

Code: Select all

for _,projectile in pairs(data.raw.projectile) do
  for _, action in pairs(projectile.action) do
    if type(action) == "table" then
      if action.type=="area" then
        for _, delivery in pairs(action.action_delivery) do
          if type(delivery) == "table" then
            for _, effects in pairs(delivery) do
              if effects.damage and effects.damage.amount then
                log("damages found for ".. projectile.name)
                effects.damage.amount = 0
              end
            end
          end
        end
      end
    end
  end
end
And Poison (this could be written shorter as it is not guaranteed to catch many mods since I didn't do any loops)

Code: Select all

for _, smoke in pairs(data.raw["smoke-with-trigger"]) do
  if  smoke.action
  and smoke.action.action_delivery
  and smoke.action.action_delivery.target_effects
  and smoke.action.action_delivery.target_effects.action
  and smoke.action.action_delivery.target_effects.action.action_delivery
  and smoke.action.action_delivery.target_effects.action.action_delivery.target_effects
  and smoke.action.action_delivery.target_effects.action.action_delivery.target_effects.damage then
    log ("no poison cloud! ".. smoke.name)
    smoke.action.action_delivery.target_effects.action.action_delivery.target_effects.damage.amount = 0
  end
end

--for just vanilla Could be re-written as 
--data.raw["smoke-with-trigger"]["poison-cloud"].action.action_delivery.target_effects.action.action_delivery.target_effects.damage.amount = 0

iggyboo
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sun Sep 11, 2016 2:20 am
Contact:

Re: Remove items with mod

Post by iggyboo »

Ah, I think I see what you did there. That helps me understand how to modify and find values a bit better. Now that I can modify the damage, I'm digging into finding a way to determine a method to see if a player is damaging another player or player created building and then disable that damage. This way I won't have to modify any item at all if I can just block the problem to being with, or, even better, redirect the damage onto the player doing it. :) That, however, seems to be beyond the scope of this post. I'm going to dig around a bit more and see if I can find it. Otherwise I'll post again. Thanks for all your help.
Post Reply

Return to “Modding help”