SenL Posted February 25, 2015 Share Posted February 25, 2015 I can't find anywhere how to use TheSim:FindEntities()Example on staff.lualocal ents = TheSim:FindEntities(pt.x,pt.y,pt.z, 9000, {"telebase"}) Parameters:1st, 2nd 3rd = initial position4th = distance?5th = prefab names? Thanks. Link to comment https://forums.kleientertainment.com/forums/topic/51428-how-do-you-use-findentities/ Share on other sites More sharing options...
Kzisor Posted February 25, 2015 Share Posted February 25, 2015 @SenL, TheSim:FindEntities(x, y, z, radius, musttags, canttags, mustoneoftags) Link to comment https://forums.kleientertainment.com/forums/topic/51428-how-do-you-use-findentities/#findComment-616493 Share on other sites More sharing options...
SenL Posted February 25, 2015 Author Share Posted February 25, 2015 Thanks, but how did you find out? Link to comment https://forums.kleientertainment.com/forums/topic/51428-how-do-you-use-findentities/#findComment-616497 Share on other sites More sharing options...
Kzisor Posted February 25, 2015 Share Posted February 25, 2015 @SenL, I searched for TheSim:FindEntities Link to comment https://forums.kleientertainment.com/forums/topic/51428-how-do-you-use-findentities/#findComment-616500 Share on other sites More sharing options...
SenL Posted February 25, 2015 Author Share Posted February 25, 2015 I did too but found examples instead of function definition.I also searched for "function FindEntities" but got no hits.I use notepad++. Link to comment https://forums.kleientertainment.com/forums/topic/51428-how-do-you-use-findentities/#findComment-616514 Share on other sites More sharing options...
rezecib Posted February 25, 2015 Share Posted February 25, 2015 @SenL, TheSim is a C++ object, so you won't find its function definitions directly in the Lua code. But the useful code is found in scripts/simutil.lua:function FindEntity(inst, radius, fn, musttags, canttags, mustoneoftags) if inst ~= nil and inst:IsValid() then local x, y, z = inst.Transform:GetWorldPosition() --print("FIND", inst, radius, musttags and #musttags or 0, canttags and #canttags or 0, mustoneoftags and #mustoneoftags or 0) local ents = TheSim:FindEntities(x, y, z, radius, musttags, canttags, mustoneoftags) -- or we could include a flag to the search? for i, v in ipairs(ents) do if v ~= inst and v.entity:IsVisible() and (fn == nil or fn(v, inst)) then return v end end endendWhich I found after ~20s of looking through results from find-in-files for "TheSim:FindEntities" Link to comment https://forums.kleientertainment.com/forums/topic/51428-how-do-you-use-findentities/#findComment-616518 Share on other sites More sharing options...
SenL Posted March 28, 2015 Author Share Posted March 28, 2015 (edited) What's difference between that and FindEntity() In abigail lua retarget fn:return FindEntity(inst, 20, function(guy) return inst._playerlink ~= nil and inst.components.combat:CanTarget(guy) and (guy.components.combat.target == inst._playerlink or inst._playerlink.components.combat.target == guy) end) Edit:Oh, duh .. FindEntity calls TheSim:FindEntities .... nevermind. Edited March 28, 2015 by SenL Link to comment https://forums.kleientertainment.com/forums/topic/51428-how-do-you-use-findentities/#findComment-625517 Share on other sites More sharing options...
Maris Posted March 31, 2015 Share Posted March 31, 2015 musttags - array of tags. All tags are required.canttags - array of tags. All tags are forbidden.mustoneoftags - array of tags. Only one of these tags is needed. For example, if an object has all musttags tags and one of cantstags, it can't be found.If an object has only few of musttags tags, it can't be found.etc Be careful with this function. It can eat huge amount of CPU. Depends on radius.For example, FindEntities(x,y,z,9000) takes a few seconds. Link to comment https://forums.kleientertainment.com/forums/topic/51428-how-do-you-use-findentities/#findComment-626379 Share on other sites More sharing options...
SenL Posted April 2, 2015 Author Share Posted April 2, 2015 Thanks!I ended up using this:for _, v in pairs(AllPlayers) do Does that use a lot of CPU? Link to comment https://forums.kleientertainment.com/forums/topic/51428-how-do-you-use-findentities/#findComment-626984 Share on other sites More sharing options...
Maris Posted April 3, 2015 Share Posted April 3, 2015 for _, v in pairs(AllPlayers) do This is much better for finding (nearest) players. It uses not so lot of CPU. However it depends on how often you use it. Link to comment https://forums.kleientertainment.com/forums/topic/51428-how-do-you-use-findentities/#findComment-627010 Share on other sites More sharing options...
rezecib Posted April 3, 2015 Share Posted April 3, 2015 (edited) @SenL, Yes, if you have a list of the entities that you're checking for, then definitely use that. Especially players, since there are so few of them compared to other entities. Depending on how clever the underlying implementation of FindEntities is (we can't easily tell because it's in the C++ code), it either has to cycle through all entities in the world, calculating a distance, or it has to cycle through all entities with the specified tag, calculating distance. So it's to be avoided whenever possible. Edited April 3, 2015 by rezecib Link to comment https://forums.kleientertainment.com/forums/topic/51428-how-do-you-use-findentities/#findComment-627081 Share on other sites More sharing options...
Maris Posted April 3, 2015 Share Posted April 3, 2015 it either has to cycle through all entities in the world I'm not sure. Seems it depends on radius. I hope it checks sectors of the world. I would have optimized such way, if I was a C++ programmer. Link to comment https://forums.kleientertainment.com/forums/topic/51428-how-do-you-use-findentities/#findComment-627128 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