Radiant script/targetname question

Have questions about CoD4 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Radiant script/targetname question

Post by F |Madness| U » August 8th, 2013, 11:40 am

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.
-

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Radiant script/targetname question

Post by Rezil » August 8th, 2013, 12:14 pm

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);
		}
	}
}
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: Radiant script/targetname question

Post by F |Madness| U » August 8th, 2013, 1:08 pm

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?
-

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Radiant script/targetname question

Post by Rezil » August 8th, 2013, 1:49 pm

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.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: Radiant script/targetname question

Post by F |Madness| U » August 8th, 2013, 5:37 pm

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 :x

Edit: Oh my god am I really that stupid, I can just copy the prefab file, rename it slightly different and edit it there.
-

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Radiant script/targetname question

Post by Drofder2004 » August 8th, 2013, 10:42 pm

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

Code: Select all

pr47_auto1
pr48_auto1
pr49_auto1
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: Radiant script/targetname question

Post by F |Madness| U » August 8th, 2013, 11:06 pm

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!
-

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests