Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
1 Active | 29 Guests
Online:

LATEST FORUM THREADS

»
CoD: Battle Royale
CoD+UO Map + Mod Releases
Damaged .pk3's
CoD Mapping
heli to attack ai
CoD4 SP Mapping

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty: World at War
Category: CoDWW Scripting
Scripting and coding with Call of Duty: World at War.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername, novemberdobby
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked
Page
Next Page
subscribe
Author Topic: multiple scripted prefabs
FAFFER
General Member
Since: May 1, 2005
Posts: 647
Last: Sep 17, 2011
[view latest posts]
Level 6
Category: CoDWW Scripting
Posted: Sunday, Dec. 20, 2009 04:42 pm
i need some help....but i need to be a bit vague..

i m a script noob, but i m trying! [crazy]


i found a tutorial that told me how to do something once with origins and triggers and the like, now i ve done this and it works great.....trouble is, i want more than one of these things without having tons of scripts....

i ve saved it all as a prefab, and my gsc is in maps/mp and called from the main gsc.

how can i make it so i can use that prefab lots of times with that same script? a targetname for the prefab? then the script using that targetname aswell?

i assume it needs to be something like the explodable barrel scripts....

help appreciated [thumbs_up]
Share |
Sevenz
General Member
Since: Apr 24, 2006
Posts: 2390
Last: May 10, 2013
[view latest posts]
Level 8
Category: CoDWW Scripting
Posted: Sunday, Dec. 20, 2009 04:50 pm
you can have the same targetname for multiple script objects and access them via script by using getentarray and a for loop.

Getting Started in Scripting (Moving Things)

Arrays

Call of Duty 4: Scripting Reference - Entity::GetEntArray

Call of Duty 5: Scripting Basics
Share |
FAFFER
General Member
Since: May 1, 2005
Posts: 647
Last: Sep 17, 2011
[view latest posts]
Level 6
Category: CoDWW Scripting
Posted: Sunday, Dec. 20, 2009 04:58 pm
any chance u could write one for me to select a prefab targetname "faffer" to stick at the top of my script?

i will go through those....but it will have to be later [thumbs_up]

thanks
Share |
Sevenz
General Member
Since: Apr 24, 2006
Posts: 2390
Last: May 10, 2013
[view latest posts]
Level 8
Category: CoDWW Scripting
Posted: Sunday, Dec. 20, 2009 05:49 pm
note: targetname faffer has to be script_model, script_origin or script_brushmodel. prefabs are no script entity, but can contain such for a more efficient workflow in radiant (duplication)

Code:
faffers = getentarray("faffer", "targetname");

for (i=0; i<faffers.size; i++)
{
	faffers[i] thread faffer_think();
}

// ...

faffer_think()
{

	// some example code

	while(1)
	{
		// self is a faffer entity in faffer_think()

		self rotateyaw(90, 3);
		self waittill("rotatedone");

		wait 1;

		self rotateyaw(-90, 2);
		self waittill("rotatedone");

		wait 2;
	}
}
Share |
FAFFER
General Member
Since: May 1, 2005
Posts: 647
Last: Sep 17, 2011
[view latest posts]
Level 6
Category: CoDWW Scripting
Posted: Sunday, Dec. 20, 2009 06:41 pm
i ve got the script to compile now...but none of my prefabs work now [sad]

i don't understand the "faffers" part....whats the purpose of that part of the script?

"prefabs are no script entity"

if its not in a prefab how can i give the whoel thing a targetname instead of all the pieces seperately?



maybe this is beyond me....
Share |
Sevenz
General Member
Since: Apr 24, 2006
Posts: 2390
Last: May 10, 2013
[view latest posts]
Level 8
Category: CoDWW Scripting
Posted: Sunday, Dec. 20, 2009 08:05 pm
if you want to turn a brushes and patches into a script entity, select all desired objects, richt-click, script > script_brushmodel and give the script_brushmodel the targetname faffer

if you want a misc_model to be a script_entity, script > script_model

you can't turn a misc_prefab directly into a script_brushmodel / script_model. you need to enter the prefab or load the prefab .map

also, you can't turn a model into a script_brushmodel, and brushes & patches not into script_models. so if a prefab has models and map geometry you gotta turn them into script entities separately.

Quote:
if its not in a prefab how can i give the whoel thing a targetname instead of all the pieces seperately?

you can have script_brushmodels and script_models inside of a prefab and duplicate that prefab as whole for your map.

your map --> prefab --> script_(brush)models


Code:
// retrieve an array (set / field / list) containing all script entities having a targetname of "faffer"
faffers = getentarray("faffer", "targetname");

// execute the for-loop body as many times as script entities were retrieved (faffers is the array, faffers.size is the number of entries in it)
for (i=0; i<faffers.size; i++)
{
	// call the function faffer_think, run it threaded
	(will continue code execution without waiting till the other function is done - code parts will be run simultaneously)

	// also pass on one entity of the faffers array
	// i is a counting variable, the for-loop will increase (increment) it by 1 (i++) on every pass

	// single array entries can be accessed by array_name[n], n has to be a number (or a variable storing a number)
	// note that the first element has the number 0 ( array_name[0] )

	faffers[i] thread faffer_think();
}



without using a for-loop, you'd have to do something like this if you had 4 entities targetname=faffer:
Code:
faffers = getentarray("faffer", "targetname");

faffers[0] thread faffer_think();
faffers[1] thread faffer_think();
faffers[2] thread faffer_think();
faffers[3] thread faffer_think();


lot of work to write and very inflexible. imagine: if you had 100 entities, you'd have to copy, paste and change the number in brackets 99 times! and if you deleted 5 entities in radiant, you would have to update the script or it would 'cause a ingame error since you'd try to access no more existing entities ( faffers[94] to faffers[99] )

so loops are the smart way, 'cause they are flexible. they don't mind how many entities you have, they do the faffer_think() function call as many times as entities you have in your map (thanks to faffers.size which is used as condition in the for-loop, instructing the script how many passes need to be done to handle all entities). loops can help you to perform actions many times without having to code these actions many times. in your case, a for-loop is used to run code for each array element, whereby an element represents a script_entity here.
Share |
FAFFER
General Member
Since: May 1, 2005
Posts: 647
Last: Sep 17, 2011
[view latest posts]
Level 6
Category: CoDWW Scripting
Posted: Sunday, Dec. 20, 2009 08:20 pm
my prefab has more than one script_struct in it so it wont convert to a script_model_brushmodel....

so i think the second ones my only option?


thanks for the detailed reply btw! [cool]

edited on Dec. 20, 2009 03:35 pm by FAFFER


this is what i ve got....

main()
{


faffers = getentarray("faffer", "targetname");


faffers[0] thread "threadname"();
faffers[1] thread "threadname"();


}

"threadname"()
{

etc etc etc

}


i have 2 prefabs with a targetname of "faffer" and i m just getting "undefined is not an entity"....

i only need about 20 so writing it all seperately is not a problem....i just need it to work with more than one the easiest way possible...[cry]
Share |
Sevenz
General Member
Since: Apr 24, 2006
Posts: 2390
Last: May 10, 2013
[view latest posts]
Level 8
Category: CoDWW Scripting
Posted: Sunday, Dec. 20, 2009 09:09 pm
use this instead:

Code:
main()
{
	faffers = getentarray("faffer", "targetname");

	for (i=0; i<faffers.size; i++)
	{
		faffers[i] thread faffer_think();
	}
}

faffer_think()
{
	// dunno what you wanna do here...
}


and it won't work if you give the prefab a targetname, you have to turn something into a script_model or script_brushmodel and give that entity the targetname!

what do you want to do with the faffer entities actually?
Share |
FAFFER
General Member
Since: May 1, 2005
Posts: 647
Last: Sep 17, 2011
[view latest posts]
Level 6
Category: CoDWW Scripting
Posted: Sunday, Dec. 20, 2009 09:18 pm
maybe i cant have more than one then... [sad]

the script structs move the player, and they cant be converted to a scriptmodel/brushmodel....

so unless theres another way to force a player to take a path?
Share |
Sevenz
General Member
Since: Apr 24, 2006
Posts: 2390
Last: May 10, 2013
[view latest posts]
Level 8
Category: CoDWW Scripting
Posted: Sunday, Dec. 20, 2009 10:45 pm
why use script structs to move the player?!

is this for SP, COOP or MP? and why you want/need to force the player to take a specific path?
Share |
Restricted Access Topic is Locked
Page
Next Page
subscribe
MODSonline.com Forums : Call of Duty: World at War : CoDWW Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»