Jump to content

Recommended Posts

Title says it all. I tried out all the spawning events I could find; the ms_"newspawn" events and related. Unfortuantly all of those events return the world prefab and not the player's character prefab.

Alternatively, knowing how to change the spawnpoint of a specfic character would also work,

I technically don't need it for what I'm working on but damn would it cut down on the spaghetti I have right now.

Thanks in advanced!

TheWorld:PushEvent("ms_playerjoined", inst)  -- prefabs/player_common.lua 816

TheWorld:PushEvent("ms_newplayerspawned", inst)  -- prefabs/player_common.lua 1403

"ms_playerjoined" is pushed whenever a player entity is spawned.

"ms_newplayerspawned" is pushed when a new player is spawned or after rerolling.

  • Thanks 1

I see my mistake now. I wasn't allowing enough function arguments so the variable I was checking for was the first given argument, which happened to be the world prefab. After added a second argument and checking what it contained I found the player prefab.

Suppose the real help I needed was to just have someone tell me to "look harder".

Thanks Leafy!

I just tied the events to something that already contained a similar event. For me, I added a new component that contains the listen event to the world prefab file. This works but I bet I'll have problems with it later. To that end I think adding the listen events to something like the multiplauer portal or spawn_point prefab would be better as it already has related events in them.

Edited by MakeSureToKnock
On 5/22/2024 at 12:03 AM, Fanky said:

When I try to use GLOBAL.TheWorld or TheWorld, it says it is a nil value

Where did you use GLOBAL.TheWorld or TheWorld? Use TheWorld in your prefab or component. Use GLOBAL.TheWorld in AddPrefabPostInit in your modmain.lua.

After some more work I used my very applicable and honestly ground breaking advice of looking harder and managed to get the "ms_newplayercharacterspawned" to work in my own prefab. The listen event inside the multiplayer portal prefab, that I'm referencing, has an extra condition at the end called TheWorld. It looks something like this:

									 --\/This here\/
inst:ListenForEvent("ms_newplayercharacterspawned", function(arg1, ...) end, TheWorld)

This is nessesary for the Listen to actually work for this and related events. I haven't tried it but I assume that this would work for componets as well, allowing you to listen for this from anything. Now I can actually change the spawn of my character to the structure I created with minimual spagget.

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...