• Using Entity:GetName( ) Appropriately
    19 replies, posted
I want to find a particular entity, so it doesn't take any entity near it [LUA] for _, v in pairs( ents.FindInSphere( self:GetPos(), 20 ) ) do if( v:GetClass() == "class or whatever" ) then -- my function end end [/lua] Can i use v:GetName( ) == ("The entity i want to find") instead of v:GetClass() ?? If i can then HOW?
Experiment. They invented the undo key for a reason. Try it then if it dont work, try a different way.
The problem is that i have tried to do this science yesterday in all kind of ways.
Too be honest. Im not very good with entities so i cant help you here, sorry. If you havent already you could try the wiki. [sp]Inb4 someone says i cant do anything[/sp]
You can use it like GetClass() but i think you have to set the name of an entity for it to pass the if statement. To set the name just use SetName()
[b][url=http://wiki.garrysmod.com/?title=Entity.GetName]Entity.GetName [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] will only return names that were set to the entity through hammer or by [b][url=http://wiki.garrysmod.com/?title=Entity.SetName]Entity.SetName [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]. If it doesn't have a name, it will return "" [b][url=http://wiki.garrysmod.com/?title=Entity.GetClass]Entity.GetClass [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] will always return the classname of the entity. There are other methods to get a specific entity, but I explained what GetName and GetClass does there. You could perhaps use Entity Index or something, but I don't know why you need a specific entity here, so I can't really help you more with this.
[QUOTE=RTM xBEASTx;29068129]Too be honest. Im not very good with [b]lua[/b] so i cant help you here, sorry. If you havent already you could try the wiki. [sp]Inb4 someone says i cant do anything[/sp][/QUOTE] Fixed
I have used the Entity.SetName() on the prop i want to find but it does still not seem to work what if i posted the code? I guess i can't keep it as a secret anymore, well it's actually a cooler for printers i'm working on which increases a DTVar named heat and if it reaches 100% it explodes then you don't need the random explode thing for Darkrp anymore, i hope the DMCA law will protect me now since i told this here before anyone else. [LUA] GenerateHeat = function(ent) local pos = ent:GetPos() if ValidEntity(ent) then for _, v in pairs( ents.FindInSphere( pos, 60 ) ) do if( v:GetName() =="Cooler") then ent.HasCooler = true ent.dt.heat = ent.dt.heat - 5 else ent.HasCooler = false end end end -- the rest of my code [/LUA] This is the part of the code, i think it's because of i can't use self:GetPos and only ent:GetPos that i don't think work.
:siren: Bump Bump :siren:
[lua] local function GenerateHeat( e ) local pos = e:GetPos():ToScreen(); if( ValidEntity( e ) ) then if( ents.FindInSphere(pos, 60) ) do if(e:GetClass() == "nigger plz" || e:GetName() == "nigger plz") then ent.HasCooler = true ent.dt.heat = ent.dt.heat - 5 else ent.HasCooler = false end end end end [/lua]
Hey everyone, how about you ask him why he wants to do it that way instead of guessing it? There is no reason whatsoever to use ent:GetName() to identify a particular entity, the only situation in which this should be used is where you are messing with entity inputs/outputs and entities that are already present in the map when the game starts. Give some more precisions about that cooling system of yours, did you make a particular cooler entity or are you simply using a physics prop instead? And in this situation, when do you decide that a particular prop should be considered as a cooler? [QUOTE=c-unitV2;29082617].[/QUOTE] Stick to "making" aimbots, will you. Pooping out awful code that doesn't work, and zero explanation about how it's supposed to work is not helping, unless you're trying to confuse him on purpose.
I have a cooler entity and a printer entity i'm trying to find the cooler within a range of 20 or whatever. here is the code: [LUA] Has been fixed, at last 10 guys must have copied the code D: [/LUA] I hope it helps.
[lua]self:GetPos()[/lua] Line 12 from your cooler's init.lua. Why are you doing that? Also if your cooler is a scripted entity, there is no reason for you to use GetName instead of GetClass to check that an object is a cooler. If it still doesn't work, check for blue errors popping up in the top right corner of your screen or in the console and post them here. Also indent your code properly, that will make it a lot more readable. The beginning of a block and its matching "end" should always be on the same column, else your code becomes a horrible mess. [lua]function test(x) for i = 1, 10 do if i == 1 then print("a") if x > 0 then print("c") end elseif i == 10 then print("b") end end end[/lua]
Should that help?
[QUOTE=_Kilburn;29086644] [lua]function test(x) for i = 1, 10 do if i == 1 then print("a") if x > 0 then print("c") end elseif i == 10 then print("b") end end end[/lua][/QUOTE] "zero explanation about how it's supposed to work is not helping, unless you're trying to confuse him on purpose"
[QUOTE=c-unitV2;29097786]"zero explanation about how it's supposed to work is not helping, unless you're trying to confuse him on purpose"[/QUOTE] :doh: Did you even read his post? You should try it, makes you look a lot less dumb. Notice the paragraph before the code snippet, the code is meant to be an indentation example.
Also, your cooler still says it's a printer in the notification.
I know that i just made it fast so i took the money printer entity and removed the unneeded parts. Is that a problem? Can i do anything to help you with helping me?
No its not a problem. Im just saying, you dont want your cooler exploding and it saying your printer went boom now, do you.
Thanks guys it's working now, Lua helpers for everyone!
Sorry, you need to Log In to post a reply to this thread.