Scripting Questions, FindByClassnameNearest()
laser_emitter <- Entities.FindByNameNearest("*Rev_Red_Laser",self.GetOrigin(), 32)
target_ent <- Entities.FindByNameNearest("*Rev_Red_Laser_end",self.GetOrigin(),32)
I did this after setting the instance to set a prefix to the name again. When things weren't working as I expected, and I tested with printl(target_ent.GetName()), it gave me the name of the object running the script: "(prefix)-Rev_Red_Laser_start". Does a '*' at the beginning effect the entire string? I would think it would be for just the beginning. I next tried this:
laser_emitter <- FindByClassnameNearest("prop_dynamic", self.GetOrigin(), 32);
target_ent <- FindByClassnameNearest("info_target", self.GetOrigin(), 32);
It however seems like portal doesn't recognize the FindByClassnameNearest() function because after I entered this, it started saying that main() does not exist. (main() is the first function called.) I don't understand why this is giving me so much trouble. Are these functions known to have issues? Is there anything I'm doing that would make these functions not work?
open_nearby_portal_linked_doors.nut
||```
// Execute this script from the console to open nearby prop_portal_linked_doors.
// Intended to be used to traverse maps in order without noclipping to find the next linked map.
ent <- null
if ( ent = Entities.FindByClassnameWithin( ent, "prop_linked_portal_door", player.GetOrigin(), 256 ) )
{
EntFire( ent.GetName(), "Open", "", 0.0, null );
}
```||
The usage of that function makes me think the rest ones are also actually functional....
If you are having fixup difficulties, you can put the instance inside another instance, and set the inner func_instance's fixup mode to "none".
sticky_panels.nut
||```
//
// hmw/sticky_panels.nut
// __________
//
// Script to attach entities to a model's attachment points by proximity,
// rather than by name.
//
// (Example: attach a func_brush surface tile to an animated panel.)
//
// When the model finishes its first animation (to set the bind pose),
// it will look for an entity of class find_class within search_radius
// or less from attachment attach_name, and send a "SetParent" signal,
// followed by "SetParentAttachmentMaintainOffset".
//
// Intended for use by the "entity scripts" attribute.
//
// Entities may modify the default values for find_class, attach_name
// and search_radius.
// __________
find_class <- "func_brush";
attach_name <- "panel_attach";
search_radius <- 2;
function attach_item()
{
local attachment = self.LookupAttachment(attach_name);
local search_origin = self.GetAttachmentOrigin(attachment);
attached_part <- Entities.FindByClassnameNearest(
find_class, search_origin, search_radius);
if(attached_part != null) {
EntFireByHandle(attached_part, "SetParent",
self.GetName(), 0, null, null);
EntFireByHandle(attached_part, "SetParentAttachmentMaintainOffset",
attach_name, 0, null, null);
};
};
EntFireByHandle(self, "AddOutput",
"OnAnimationDone !self:RunScriptCode:attach_item():0:1",
0, null, null);
// vim:set shiftwidth=4 softtabstop=4 expandtab nowrap filetype=squirrel:
```||
Maybe that one could help you out a bit more.
I used the asterisk as wildcard for some I/O in Hammer in the past succesfully... however, you might be having an issue with "finding the nearest" while saying "all entities starting by Rev_Red_Laser_end" (which could be not meaning any), could that be?
greykarel wrote:
blah-blah-blah about some problem with a script
I don't now whay was wrong before but today it works fine.