Page 1 of 1
Radiant script/targetname question
Posted: August 8th, 2013, 11:40 am
by F |Madness| U
The scenario is this: if I make a prefab with a script_brushmode and give it a targetname of "block" for example. If I then create a script_origin, with a targetname of "gohere", and lastly give the script_brushmodel a target of "gohere" (so they are `linked` in Radiant).
Now say I place 2 of these prefabs over my map, I obviously want each block to move to their desired script_origin when needed to.
Code: Select all
motionBlocks()
{
blocks = getentarray("block","targetname");
if(isdefined(blocks))
{
for(i=0;i<blocks.size;i++)
{
blocks[i] thread block_logic(i);
}
}
}
block_logic(num)
{
target = getent(self.target,"targetname");
self moveto(target.origin,1.0);
}
In this code, how do I know that "target = getent(self.target,"targetname");" is going to return the desired script_origin, since both script_origins have the same targetname?
If there is no way to get around this in script, does anybody know how to place a prefab in the map, and then edit it,
without editing the prefab file. Thanks if you can help.
Re: Radiant script/targetname question
Posted: August 8th, 2013, 12:14 pm
by Rezil
Well it should return the correct origin. If it doesn't you could create a separate(unlinked) script_origin in the same prefab, give it a targetname and access it using getEntArray the same way you do with your brushmodel.
Code: Select all
motionBlocks()
{
blocks = getentarray("block","targetname");
origins = getentarray("origin","targetname");
if(isDefined(blocks) && isDefined(origins) && blocks.size==origins.size)
{
for(i=0;i<blocks.size;i++)
{
blocks[i] moveTo(origins[i].origin, 1.0);
}
}
}
Re: Radiant script/targetname question
Posted: August 8th, 2013, 1:08 pm
by F |Madness| U
I understand what you're saying, I'm just doubting the ability of getEntArray(). Because for the case which I'm using, each prefab has a script_origin (targetname "mpdoor"), and 8 script_brushmodels, all with targetname "part".
If do your method, say I use 3 prefabs in my map. There will be an array mpdoor of size 3, and an array parts of size 24.
I then need to get mpdoor[0] and it's 8 relevant parts, etc.
If there is a way to place a prefab in a map, and then edit it (without entering prefab and editing the actual prefab) I think I would do so I can give each door a different targetname, as to avoid the confusion. I don't suppose you know if this is possible?
Re: Radiant script/targetname question
Posted: August 8th, 2013, 1:49 pm
by Rezil
getEntArray works exactly the way it should. It returnes all the entities which correspond to the proper K/V pair. The order in which they're returned shouldn't matter to you if you're using the function properly.
(If you need to know, they're indexed in the absolute order they're created in Radiant ie. if you delete entites you've created earlier, the new entities won't assume their index but will increment normally)
For your case you would simply create a prefab made out of 1 origin and 8 brushmodels and tweak the function to check if origins.size*8==brushmodels.size. And it's important to use prefabs, otherwise the order of the entities might be wrong when you use getEntArray.
Re: Radiant script/targetname question
Posted: August 8th, 2013, 5:37 pm
by F |Madness| U
Thanks very much for the help so far, I will try it later.
Not meaning to sound rude, but as I asked previously do you know of a way to place a prefab in a map, and then edit it (without entering prefab and editing the actual prefab)? It would make sense that there would be a way, for example a window prefab copied many times throughout your map but then you may want to edit one of them to be slightly different from the others. If there's not, then that sucks
Edit: Oh my god am I really that stupid, I can just copy the prefab file, rename it slightly different and edit it there.
Re: Radiant script/targetname question
Posted: August 8th, 2013, 10:42 pm
by Drofder2004
Use "auto" targetnames and prefabbing is fine.
Create two entities.
Give the first one a targetname.
Do NOT give the second one a targetname.
Select entity 1, then entity 2.
Press W.
The target now has an auto name.
Now, make these a prefab and create many of them in your map.
Code: Select all
Â
main()
{
  ents = getEntArray("ent", "targetname");
  for(i=0;i<ents.size;i++)
  {
   tgt = getEnt(ents[i].target, "targetname");
   iPrintln(tgt.targetname);
  }
}
You will see something along the lines of
Re: Radiant script/targetname question
Posted: August 8th, 2013, 11:06 pm
by F |Madness| U
Oh nice, that's very useful. I've already written code using arrays within an array (un-tested on more than 1 prefab atm) but I shall be sure to use that if it fails (and for the future) so thanks!