Jump to content

Variables for a function (need help)


Recommended Posts

Hello everyone!

I have a specific function.
I need it to work for objects with defined prefabs, but for the rest it was not used.
Someone can tell me how to implement this?

AddComponentPostInit("burnable", function(self)
	local _StartWildfire = self.StartWildfire
	self.StartWildfire = function(self)
	end
end)

Thank you for attention!

Link to comment
Share on other sites

 

--you could make a table for your specific prefabs
local burnables = {
	grass = true,
	sapling = true,
	reeds = true,
}
AddComponentPostInit("burnable", function(self)
	local _StartWildfire = self.StartWildfire
	self.StartWildfire = function(self)
          if burnables[self.inst.prefab] then
              	_StartWildfire(self)
          end
	end
end)

I don't have time to test this atm, but its what I assume you are asking for

Edited by IronHunter
Link to comment
Share on other sites

On 31.03.2018 at 9:35 AM, IronHunter said:

 


--you could make a table for your specific prefabs
local burnables = {
	grass = true,
	sapling = true,
	reeds = true,
}
AddComponentPostInit("burnable", function(self)
	local _StartWildfire = self.StartWildfire
	self.StartWildfire = function(self)
          if burnables[self.inst.prefab] then
              	_StartWildfire(self)
          end
	end
end)

I don't have time to test this atm, but its what I assume you are asking for

Thanks you very much, this code works without errors.
But is it possible to do the opposite, so that function works only for specific prefabs?
Or is it too difficult?

Link to comment
Share on other sites

If you want to exclude specific prefabs you could put a not in front of burnables[self.inst.prefab]

I am not sure what function you are refering to. But you could also do elseif or else for additional precision on what you want it to do.

Link to comment
Share on other sites

20 minutes ago, IronHunter said:

If you want to exclude specific prefabs you could put a not in front of burnables[self.inst.prefab]

I am not sure what function you are refering to. But you could also do elseif or else for additional precision on what you want it to do.

    AddComponentPostInit("burnable", function(self)
        local _StartWildfire = self.StartWildfire
        self.StartWildfire = function(self)
        end
    end)

I tried to change the code, but I did not succeed.
I want this function to work only for special prefabs.
And for everything else, it was ignored.

Link to comment
Share on other sites

The code I provided is suppose to do that. It enables wildfires for specific prefabs in the table, anything not in your list is excluded automatically. Just change the prefabs in the table to your custom ones. I just populated it with vanilla ones as an example.

Link to comment
Share on other sites

10 minutes ago, IronHunter said:

The code I provided is suppose to do that. It enables wildfires for specific prefabs in the table, anything not in your list is excluded automatically. Just change the prefabs in the table to your custom ones. I just populated it with vanilla ones as an example.

I need other effect.
I want that the things specified in the prefabs are protected from fires, and everything else is burnt.
Is this code difficult to write?

Link to comment
Share on other sites

11 hours ago, IronHunter said:

Use not to exclude those prefabs like I mentioned in earlier post.

If not burnables[self.inst.prefab] then etc.

Hmm...
This it was very easy.
It was necessary to add only "not" =)

	local burnables = 
	{
		sapling = true,
		grass = true,
	}
	AddComponentPostInit("burnable", function(self)
		local _StartWildfire = self.StartWildfire
		self.StartWildfire = function(self)
			if not burnables[self.inst.prefab] then
				_StartWildfire(self)
			end
		end
	end)

Thanks you for help, I hope now my mod will become even more useful.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...