UnderwearApp Posted April 5, 2014 Share Posted April 5, 2014 So, I am trying to collect creatures by searching for their tags using FindEntities as follows: local ents = TheSim:FindEntities(x, y, z, 100,creaturetags, creatureno_tags) "ents" is always empty even though I know there are creatures in range with a tag in "creaturetags". As I understood it FindEntities is (x,y,z, radius, musttags, canttags, mustoneoftags) and I am using: local maincharacter = GetPlayer() if maincharacter then local x,y,z = maincharacter.Transform:GetWorldPosition() to set the x,y,z. Would anyone know why it is always empty? Am I just misusing the function, or is it something else? Is there a better way to find creatures repeatedly? Thanks in advance Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/ Share on other sites More sharing options...
debugman18 Posted April 5, 2014 Share Posted April 5, 2014 So, I am trying to collect creatures by searching for their tags using FindEntities as follows: local ents = TheSim:FindEntities(x, y, z, 100,creaturetags, creatureno_tags) "ents" is always empty even though I know there are creatures in range with a tag in "creaturetags". As I understood it FindEntities is (x,y,z, radius, musttags, canttags, mustoneoftags) and I am using: local maincharacter = GetPlayer() if maincharacter then local x,y,z = maincharacter.Transform:GetWorldPosition() to set the x,y,z. Would anyone know why it is always empty? Am I just misusing the function, or is it something else? Is there a better way to find creatures repeatedly? Thanks in advanceThis is the FindEntities function as it appears in simutil.lua: function FindEntity(inst, radius, fn, musttags, canttags, mustoneoftags) if inst 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 k, v in pairs(ents) do if v ~= inst and v.entity:IsValid() and v.entity:IsVisible() and (not fn or fn(v, inst)) then return v end end endend As you can see, the first argument is inst, not x,y,z. It does x,y,z of inst for you in the first line within the if statement. Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/#findComment-445285 Share on other sites More sharing options...
UnderwearApp Posted April 5, 2014 Author Share Posted April 5, 2014 Yes, I know about that, but I see all over the game files entries like this: TheSim:FindEntities(pt.x, pt.y, pt.z, SEE_FOOD_DIST, FOOD_TAGS, NO_TAGS) where they use only the x,y,z, range and tags, so I assumed I could do the same. Is this not the case? Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/#findComment-445297 Share on other sites More sharing options...
debugman18 Posted April 5, 2014 Share Posted April 5, 2014 Yes, I know about that, but I see all over the game files entries like this: TheSim:FindEntities(pt.x, pt.y, pt.z, SEE_FOOD_DIST, FOOD_TAGS, NO_TAGS) where they use only the x,y,z, range and tags, so I assumed I could do the same. Is this not the case?Okay, so I think I misunderstood. Try this: local maincharacter = GetPlayer() if maincharacter then local pt = maincharacter.Transform:GetWorldPosition() and your FindEntities should take that into account: local ents = FindEntities(pt.x, pt.y, pt.z, SEE_FOOD_DIST, FOOD_TAGS, NO_TAGS) The issue with that is you're then going to have to include something like this, since ents is a table: for k,v in pairs(ents) do if v.entity:IsValid() then return v endend when you could just use FindEntity as described, if all you're doing is finding an entity with a tag. What exactly are you trying to do? Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/#findComment-445322 Share on other sites More sharing options...
simplex Posted April 5, 2014 Share Posted April 5, 2014 Yes, I know about that, but I see all over the game files entries like this: TheSim:FindEntities(pt.x, pt.y, pt.z, SEE_FOOD_DIST, FOOD_TAGS, NO_TAGS) where they use only the x,y,z, range and tags, so I assumed I could do the same. Is this not the case? Yes, you can do this, and it's the most general way. Could you post the whole code (or at least the whole function)? Because the snippet you posted in itself is correct. Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/#findComment-445328 Share on other sites More sharing options...
Heavenfall Posted April 5, 2014 Share Posted April 5, 2014 If it's from modmain.lua use GLOBAL.GetPlayer() Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/#findComment-445346 Share on other sites More sharing options...
UnderwearApp Posted April 5, 2014 Author Share Posted April 5, 2014 Okay, so I think I misunderstood. Try this:local maincharacter = GetPlayer() if maincharacter then local pt = maincharacter.Transform:GetWorldPosition()and your FindEntities should take that into account:local ents = FindEntities(pt.x, pt.y, pt.z, SEE_FOOD_DIST, FOOD_TAGS, NO_TAGS)The issue with that is you're then going to have to include something like this, since ents is a table:for k,v in pairs(ents) do if v.entity:IsValid() then return v endendwhen you could just use FindEntity as described, if all you're doing is finding an entity with a tag. What exactly are you trying to do?Thanks, I will try this as it seems to make sense. I am trying to change stats of creatures found with the tag specified, more of a test than anything. Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/#findComment-445384 Share on other sites More sharing options...
debugman18 Posted April 5, 2014 Share Posted April 5, 2014 Thanks, I will try this as it seems to make sense. I am trying to change stats of creatures found with the tag specified, more of a test than anything.Make sure to use GLOBAL.GetPlayer() as Heavenfall suggested, or it won't give you coords since it'll return as nil. Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/#findComment-445388 Share on other sites More sharing options...
UnderwearApp Posted April 5, 2014 Author Share Posted April 5, 2014 Make sure to use GLOBAL.GetPlayer() as Heavenfall suggested, or it won't give you coords since it'll return as nil. Nevermind, I forgot I was already using the same thing you posted but it returns an error trying to index pt, which is a number. It does work if I do for example: local ptx, pty, ptz = maincharacter.Transform:GetWorldPosition() but the ents table still is always empty. Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/#findComment-445531 Share on other sites More sharing options...
Heavenfall Posted April 5, 2014 Share Posted April 5, 2014 Post the whole code. Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/#findComment-445533 Share on other sites More sharing options...
UnderwearApp Posted April 5, 2014 Author Share Posted April 5, 2014 Post the whole code. I think I am going to go a completely different way with this. On that note, when adding a component to something. In the component class, will "inst" always refer to the object that the component is added to? ielocal RPGArmor = Class(function(self, inst) self.inst = instThanks again. Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/#findComment-445551 Share on other sites More sharing options...
Heavenfall Posted April 5, 2014 Share Posted April 5, 2014 (edited) You can refer to the entity which has the component added to it using self.inst as long as it is declared in the component. Merely using inst is not enough in any child function of the component class, unless you pass it to the component child function through an argument. Edited April 5, 2014 by Heavenfall Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/#findComment-445554 Share on other sites More sharing options...
UnderwearApp Posted April 5, 2014 Author Share Posted April 5, 2014 You can refer to the entity which has the component added to it using self.inst as long as it is declared in the component. Merely using inst is not enough in any child function of the component class, unless you pass it to the component child function through an argument. Perfect, thanks. I appreciate the help. Link to comment https://forums.kleientertainment.com/forums/topic/34243-help-with-thesimfindentities/#findComment-445566 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