Jump to content

Recommended Posts

Hey there,

I recently updated my factions mod with some new features that required a central storage that is kept up to date for all players. I chose TheWorld to be that component, but apparently I made the wrong choice.
 

local TheWorld = GLOBAL.TheWorld

AddPrefabPostInit("world", function(world)
	if world and world.ismastershard  then
		TheWorld = world
		TheWorld.icons = icons_table
		TheWorld:AddComponent("factions")
		if TheWorld.components.factions then
			print("[FACTIONS] Added Factions Component to TheWorld.")
		end
		TheWorld.components.factions:addFaction("blue", "blue_faction", true)
		TheWorld.components.factions:addFaction("red", "red_faction", true)
	end
end)


-- grant player faction
AddPlayerPostInit(function(player)
	player.theWorld = TheWorld
	player:AddComponent("faction", player)
end)
local faction = Class(
	function(self, parent)
		self.table = {
			name = nil,
			icon = nil,
			alliances = {},
			members = {},
			pvp = nil,
		}
		self.parent = parent
		self.world = parent.theWorld
		self.factions = self.world.components.factions
		print("[FACTIONS][DEBUG] registered factions component to faction", self.factions)
		self:setFaction("neutral")
	end
)

This works fine for the host but, "parent.theWorld" in this example will be nil if a new player joins the server. Why is that so? Is there a better way to store and share information across all players?

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
×
  • Create New...