cezarica Posted January 30, 2019 Share Posted January 30, 2019 (edited) Hi, is there an easier way to get the "status" of the portal apart than something like: local state = 0 for k,v in pairs(Ents) do if v.prefab == "multiplayer_portal" then state = 1 break elseif v.prefab == "multiplayer_portal_moonrock_constr_plans" then state = 2 break elseif v.prefab == "multiplayer_portal_moonrock" then state = 3 break end end Basically I want to get the prefab of the portal's status at any given time. Edited January 30, 2019 by cezarica Link to comment https://forums.kleientertainment.com/forums/topic/102332-portal-status/ Share on other sites More sharing options...
YakumoYukari Posted January 30, 2019 Share Posted January 30, 2019 Your code looks fine. I think there's not really be the way to improve it. I believe multiplayer_portal is not the 'registered(into TheWorld)' prefab. So I assume that finding the portal via Ents is inevitable. Here's my expression. There's not a big change but Tag finding is a bit faster. local function GetPortalState() local portal for k,v in pairs(Ents) do if v:HasTag("multiplayer_portal") then portal = v break end end if portal ~= nil then if portal:HasTag("constructionsite") then return 2 elseif portal:HasTag("moontrader") then return 3 else return 1 end end return 0 end Link to comment https://forums.kleientertainment.com/forums/topic/102332-portal-status/#findComment-1149208 Share on other sites More sharing options...
cezarica Posted January 31, 2019 Author Share Posted January 31, 2019 (edited) Hi, thanks for your reply. I wanted to get the prefab name because I was actually aiming to get it's position in the world, and thanks to your input I changed my previous code (not the one posted above) to: local function GetPortalPosition() local coords = nil for k,v in pairs(Ents) do if v:HasTag("multiplayer_portal") or v:HasTag("constructionsite") or v:HasTag("moontrader") then coords = Point(v.Transform:GetWorldPosition()) break end end return coords end Tested it and works as expected! Thanks! Now I have to figure out how to store the 'coords' into a global variable so I can access it later from another function where I could be able to read and rewrite it. Any idea how to do that? Edit: Never mind, I figured out. Having a local coords = {} outside any functions did the trick. Happy dance! Edited January 31, 2019 by cezarica Link to comment https://forums.kleientertainment.com/forums/topic/102332-portal-status/#findComment-1149449 Share on other sites More sharing options...
YakumoYukari Posted February 1, 2019 Share Posted February 1, 2019 (edited) for k,v in pairs(Ents) do if v:HasTag("multiplayer_portal") or v:HasTag("constructionsite") or v:HasTag("moontrader") then return Point(v.Transform:GetWorldPosition()) end end This would be enough. If there's no return in Lua's function, will consider as nil. Edited April 4, 2019 by YakumoYukari Link to comment https://forums.kleientertainment.com/forums/topic/102332-portal-status/#findComment-1150022 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