Jump to content

Global events?


Recommended Posts

So im trying to make a mod, and push an event so that when thing A happens to, say, Ben, Steve would react and do thing B.

So I do something like this

inst:ListenForEvent("PlayerGotNewItem", function(inst,data)
    if BingoMode --[[a mod setting]] == 2 then
      do things
    	if data.namecalled --[[data from push event, gives the name of the player who triggered it]] ~= ThePlayer.name then
      		do stuff
        end
    end
end)

But even the first check only works for me, other players don't pass it, that's what I want to fix

How can I fix this and what am I doing wrong?

Link to comment
Share on other sites

On 8/15/2023 at 11:20 PM, _zwb said:

for _, player in pairs(AllPlayers) do
    print(player.prefab)
end

Every value in this table is a player entity.

Can you help me with this error?

-- PushEvent code
TheWorld:PushEvent("PlayerGotNewItem", {guy = ThePlayer, itemcalled = item, slotcalled = k})
-- Listner code
	TheWorld:ListenForEvent("PlayerGotNewItem", function(inst, data)
		if BingoMode == 2 then
			for _, player in pairs(AllPlayers) do
				if player ~= data.guy then
					for k,v in pairs(player.components.itemTableHandler.globList) do -- This line causes the crash
						if v == data.itemcalled then
							if player.components.itemTableHandler.globTagger[k] ~= -1 then
								player.components.itemTableHandler.globTagger[k] = -1
								player.components.itemTableHandler:evaluateList()
								player.components.talker:Say("Slot #" .. k .. ", " .. v ..", is now locked")
							end
						end
					end
				end
			end
		end
	end)

Снимок экрана 2023-08-29 171629.png

Link to comment
Share on other sites

2 hours ago, _zwb said:

It seems that one of the players don't have the component? How did that happen? Did you forget to add the component to the player?

Can't really be it? Most of the code isn't mine, but even these chunks that I use here are repurpoused from the original code, which works just fine

I've only switched "ThePlayer" to "player"

Maybe it has to do with the fact that the original mod was client based?

Link to comment
Share on other sites

32 minutes ago, Random Guy000 said:

Maybe it has to do with the fact that the original mod was client based?

Aha, I see why it crashed, you cannot access components on the client side unless a replica component is made for clients, so it crashed trying to access a component

Link to comment
Share on other sites

7 minutes ago, _zwb said:

Aha, I see why it crashed, you cannot access components on the client side unless a replica component is made for clients, so it crashed trying to access a component

Ok, so I figured something pretty similar to that

The code that I sent was a part of a class, which was local, so naturally I just cut the local out

It still crashes though, same error and all. Any suggestions on fixing that?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...