Redfox_2012 Posted February 15, 2022 Share Posted February 15, 2022 Hello. I am writing a mod and I need to determine the coordinates of the portal or the distance to it when the event is triggered. I also don't understand how to search for objects after the world is generated. local function onGiveItemfn(inst2, data) -- "itemget" only work in player inventory. -- here need distance to the multiplayer portal end inst:ListenForEvent("itemget", onGiveItemfn) inst:ListenForEvent("equip", onGiveItemfn) Thanks for the help Link to comment https://forums.kleientertainment.com/forums/topic/137556-how-to-determine-the-distance-to-the-multiplayer-portal/ Share on other sites More sharing options...
Redfox_2012 Posted February 15, 2022 Author Share Posted February 15, 2022 I wrote a similar function. I don't understand what the problem is. by condition, return is triggered, but the player is also teleported. local function onGiveItemfn(inst2, data) -- "itemget" only work in player inventory. local x,y,z = inst2.Transform:GetWorldPosition() print('onGiveItemfn') print(x,y,z) local mp = _G.TheSim:FindEntities(x, y, z, 15, {"multiplayer_portal"}) print('check team', team, #mp, data.item.prefab) -- [00:21:19]: check team nil 0 blue_mushroomhat if #mp == 0 or team then return end if lord_options.tp_item==data.item.prefab then team = 'lord' end if king_options.tp_item==data.item.prefab then team = 'king' end print('selected team', team) -- not print print('onGiveItemfn') -- not print q.SaveOption(inst2,'team',team) inst2:AddTag(team) local spawn = (team == 'king' and king_options.spawn_crd) or lord_options.spawn_crd inst2.Transform:SetPosition(spawn.x,spawn.y,spawn.z) -- this fire end inst:ListenForEvent("gotnewitem", onGiveItemfn) Link to comment https://forums.kleientertainment.com/forums/topic/137556-how-to-determine-the-distance-to-the-multiplayer-portal/#findComment-1540163 Share on other sites More sharing options...
Redfox_2012 Posted February 15, 2022 Author Share Posted February 15, 2022 strange, but it seems that teleportation works first, and then the whole function is performed... Link to comment https://forums.kleientertainment.com/forums/topic/137556-how-to-determine-the-distance-to-the-multiplayer-portal/#findComment-1540164 Share on other sites More sharing options...
Monti18 Posted February 16, 2022 Share Posted February 16, 2022 To answer your original question, I would add a AddPrefabPostInit to the multiplayer_portal which saves it's position in TheWorld or a TUNING value. You will need to delay it a bit as during loading the position will always be (0,0,0) (not sure if 1 frame is enough, you will need to test that). Then you can just use inst:GetDistanceSqToPoint(x,y,z) and enter the saved position of your multiplayer_portal. As for the teleportation firing, that seems really strange, you could try to change it so that everything that happens after the check is in an if case, so instead of returning, you just don't let it run this piece of code. Link to comment https://forums.kleientertainment.com/forums/topic/137556-how-to-determine-the-distance-to-the-multiplayer-portal/#findComment-1540325 Share on other sites More sharing options...
Redfox_2012 Posted February 16, 2022 Author Share Posted February 16, 2022 I made delay 100mc for teleportation and now working normal. but i not know whay here trable... how function triggerin two time, first time without function print, second time after teleport and with checking position. i wrote - local function onGiveItemfn(inst2, data) -- "itemget" only work in player inventory. local x,y,z = inst2.Transform:GetWorldPosition() print('onGiveItemfn') print(x,y,z) local mp = _G.TheSim:FindEntities(x, y, z, 15, {"multiplayer_portal"}) print('check team', team, #mp, data.item.prefab) if #mp == 0 or team then do return end end if lord_options.tp_item==data.item.prefab then team = 'lord' end if king_options.tp_item==data.item.prefab then team = 'king' end print('selected team', team) print('onGiveItemfn') q.SaveOption(inst2,'team',team) inst2:AddTag(team) local spawn = (team == 'king' and king_options.spawn_crd) or lord_options.spawn_crd inst2:DoTaskInTime(0.1, function() --addition daley and now working inst2.Transform:SetPosition(spawn.x,spawn.y,spawn.z) end) end inst:ListenForEvent("gotnewitem", onGiveItemfn) Link to comment https://forums.kleientertainment.com/forums/topic/137556-how-to-determine-the-distance-to-the-multiplayer-portal/#findComment-1540342 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