LUA Probabaly the most basic thing I am having a brain fart about - "something_*"
4 replies, posted
So basically, I am making a script for learning purposes - This script displays few things on the player's HUD when the mouse is over any entity that has any other class than "worldspawn" (Which is the world itself). I got the base up and running, now I am just filtering the entities that display actual stuff on the HUD. I am stuck on this part:
[url=http://pastebin.com/7N3en6s8][Lua] LUA halph me - Pastebin.com[/url]
(Pastebin because the website horribly formats the code I paste)
I am basically trying to "whitelist" any entity with class name starting(but ANY ending) on "k_printer_" I thought the "*" will finish the job for me, sadly, nope.
string.find and use ent:GetClass(). You are comparing entity to string and string cant have regex stuff.
Ah I've forgotten - the entity is actually the entity that LocalPlayer():GetEyeTrace() gets -
entity = LocalPlayer():GetEyeTrace().Entity
How would I use the string.find? Can you post an quick example?
whitelisted = string.StartWith(LocalPlayer():GetEyeTrace().Entity:GetClass(),"k_printer_")
or in longer form,
myent = LocalPlayer():GetEyeTrace().Entity
myclass = myent:GetClass()
whitelisted = string.StartWith(myclass,"k_printer_")
whistlisted is a true/false value, true if the entity is one of the printers
I've been fu*king around with the string.find for past hour - and then boom - you! Thank you! Problem solved
PS.: In the short form you've entered a space, it shouldn't be here.
Thank you both for answers, have a nice day and I'm tagging this as solved ;)
Sorry, you need to Log In to post a reply to this thread.