MakeSureToKnock Posted May 11, 2024 Share Posted May 11, 2024 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! Link to comment https://forums.kleientertainment.com/forums/topic/156005-getting-prefab-of-newly-spawned-player/ Share on other sites More sharing options...
LeafyFly Posted May 18, 2024 Share Posted May 18, 2024 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. 1 Link to comment https://forums.kleientertainment.com/forums/topic/156005-getting-prefab-of-newly-spawned-player/#findComment-1715193 Share on other sites More sharing options...
MakeSureToKnock Posted May 21, 2024 Author Share Posted May 21, 2024 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! Link to comment https://forums.kleientertainment.com/forums/topic/156005-getting-prefab-of-newly-spawned-player/#findComment-1716006 Share on other sites More sharing options...
Fanky Posted May 21, 2024 Share Posted May 21, 2024 @LeafyFly@MakeSureToKnock How to add listener these events? When I try to use GLOBAL.TheWorld or TheWorld, it says it is a nil value Link to comment https://forums.kleientertainment.com/forums/topic/156005-getting-prefab-of-newly-spawned-player/#findComment-1716022 Share on other sites More sharing options...
MakeSureToKnock Posted May 23, 2024 Author Share Posted May 23, 2024 (edited) 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 May 23, 2024 by MakeSureToKnock Link to comment https://forums.kleientertainment.com/forums/topic/156005-getting-prefab-of-newly-spawned-player/#findComment-1716437 Share on other sites More sharing options...
LeafyFly Posted May 23, 2024 Share Posted May 23, 2024 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. Link to comment https://forums.kleientertainment.com/forums/topic/156005-getting-prefab-of-newly-spawned-player/#findComment-1716499 Share on other sites More sharing options...
MakeSureToKnock Posted May 25, 2024 Author Share Posted May 25, 2024 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. Link to comment https://forums.kleientertainment.com/forums/topic/156005-getting-prefab-of-newly-spawned-player/#findComment-1716881 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now