Lostnumber Posted May 20, 2015 Share Posted May 20, 2015 I can't get this function to work. It seems it doesn't hear the playerspawn event at all (while playeractivated works very well). I wrote it like this in modmain.lua: inst:ListenForEvent("ms_playerspawn", OnPlayerSpawn, TheWorld) any suggestions? Link to comment https://forums.kleientertainment.com/forums/topic/54197-problem-with-listenforeventms_playerspawn/ Share on other sites More sharing options...
DarkXero Posted May 20, 2015 Share Posted May 20, 2015 What did you put it into, an AddPrefabPostInit? You sure inst refers to the correct entity?Also, did you put TheWorld = GLOBAL.TheWorld somewhere? Link to comment https://forums.kleientertainment.com/forums/topic/54197-problem-with-listenforeventms_playerspawn/#findComment-639123 Share on other sites More sharing options...
Lostnumber Posted May 20, 2015 Author Share Posted May 20, 2015 I put it into AddPlayerPostInit. inst should be fine, because I have also "inst:ListenForEvent("playeractivated", OnPlayerActivated)" that works fine.When I tried putting TheWorld as GLOBAL I got a crash weirdly. Link to comment https://forums.kleientertainment.com/forums/topic/54197-problem-with-listenforeventms_playerspawn/#findComment-639148 Share on other sites More sharing options...
Lostnumber Posted May 20, 2015 Author Share Posted May 20, 2015 I put TheWorld = GLOBAL.TheWorld as a local variable, but the playerspawn event still isn't heard. Link to comment https://forums.kleientertainment.com/forums/topic/54197-problem-with-listenforeventms_playerspawn/#findComment-639151 Share on other sites More sharing options...
DarkXero Posted May 20, 2015 Share Posted May 20, 2015 (edited) Useinst:ListenForEvent("ms_playerspawn", OnPlayerSpawn, GLOBAL.TheWorld)directly? Or GLOBAL.TheWorld:ListenForEvent("ms_playerspawn", OnPlayerSpawn)with OnPlayerSpawn(world, player)? Edited May 20, 2015 by DarkXero Link to comment https://forums.kleientertainment.com/forums/topic/54197-problem-with-listenforeventms_playerspawn/#findComment-639156 Share on other sites More sharing options...
Lostnumber Posted May 20, 2015 Author Share Posted May 20, 2015 The event continues not to be heard unfortunately Link to comment https://forums.kleientertainment.com/forums/topic/54197-problem-with-listenforeventms_playerspawn/#findComment-639202 Share on other sites More sharing options...
DarkXero Posted May 21, 2015 Share Posted May 21, 2015 The ms_playerspawn event gets setup in line 1523 of player_common:TheWorld:PushEvent("ms_playerspawn", inst)Try with:local function OnPlayerSpawn(world, player) world:DoTaskInTime(0, function() print("Hello", player.prefab, " is in ", world.prefab) end)endAddPrefabPostInit("world", function(inst) inst:ListenForEvent("ms_playerspawn", OnPlayerSpawn)end) Link to comment https://forums.kleientertainment.com/forums/topic/54197-problem-with-listenforeventms_playerspawn/#findComment-639335 Share on other sites More sharing options...
Lostnumber Posted May 21, 2015 Author Share Posted May 21, 2015 it was a good idea, but still the event isn't heard, cause it's not printing "Hello player is in world". Link to comment https://forums.kleientertainment.com/forums/topic/54197-problem-with-listenforeventms_playerspawn/#findComment-639411 Share on other sites More sharing options...
DarkXero Posted May 21, 2015 Share Posted May 21, 2015 @Lostnumber, then you are doing something wrong because I put that like that in the modmain, and I get this image. Upload your modmain or wherever you put the listener. Link to comment https://forums.kleientertainment.com/forums/topic/54197-problem-with-listenforeventms_playerspawn/#findComment-639445 Share on other sites More sharing options...
Lostnumber Posted May 21, 2015 Author Share Posted May 21, 2015 (edited) here is my modmain.lua. Edited May 21, 2015 by Lostnumber Link to comment https://forums.kleientertainment.com/forums/topic/54197-problem-with-listenforeventms_playerspawn/#findComment-639459 Share on other sites More sharing options...
Lostnumber Posted May 21, 2015 Author Share Posted May 21, 2015 (edited) I managed it to work. it wasn't working because i put the code into a big function that was triggered by another post init Thank you for all the help by the way! Edited May 21, 2015 by Lostnumber Link to comment https://forums.kleientertainment.com/forums/topic/54197-problem-with-listenforeventms_playerspawn/#findComment-639461 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