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

Members Online

»
0 Active | 45 Guests
Online:

LATEST FORUM THREADS

»
run artillery on maps
CoD+UO Map + Mod Releases
Call of DutyŽ: WWII
CoD WW2 General

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 4
Category: CoD4 Scripting
Scripting and coding with Call of Duty 4.
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: How do I make my angle-specific script.... generic?
9837265498
General Member
Since: Nov 6, 2009
Posts: 193
Last: Jan 23, 2012
[view latest posts]
Level 4
Category: CoD4 Scripting
Posted: Sunday, Jan. 23, 2011 08:47 am
I am currently working on a drawbridge script that i want to be "generic" so as to work for any instance of my prefab, no matter if it is rotated yaw in the worldspace.

I have a script origin in the prefab and my simple understanding of scripting tells me it is possible to make the origin's angles the angles of the "Bridge" and then rotate accordingly to what that value is.

I would be easily content if it worked for even just the 4 major directions (0, 90, 180, 270 degrees).

this is what i have so far:

Code:
main()
{
	trigger = getentarray("drawbridge","targetname");
	for(i=0;i<trigger.size;i++)
	trigger[i] thread bridge_think();	
}

bridge_think()
{
	self.bridgemoving = 	false;
	self.bridgeclosed = 	true;
	self.bridge       = 	getent(self.target,"targetname");
	self.bridgenode   = 	getent(self.bridge.target,"targetname");


	self.bridge.angle = 	self.bridgenode.angles;


	while (1)
	{
		self waittill("trigger");
		if(!self.bridgemoving)
		self thread bridge_move();
	}
}

bridge_move()
{
	self.bridgemoving = true;

	if(self.bridgeclosed)
	{

		self.bridge rotateroll(-90,2);
		self.bridge waittill("rotatedone");
		self.bridgeclosed = false;
	}
	else
	{
		self.bridge rotateroll(90,4);
		self.bridge waittill("rotatedone");
		self.bridgeclosed = true;	
	}
	self.bridgemoving = false;
}


This version of bridge_move() is cut down to one direction and i would like to know how i should go about setting it up for all 4. Also is my "self.bridge.angle = self.bridgenode.angles;" usable to make it more efficient?
any and all input is appreciated, ty
Share |
cskiller86
General Member
Since: Nov 23, 2009
Posts: 528
Last: Oct 25, 2011
[view latest posts]
Level 6
Category: CoD4 Scripting
Posted: Sunday, Jan. 23, 2011 09:48 am
You can use this:
Code:
anglesToRight(bridge.angles) //this returns the right angles of "bridge" as a vector; if you need the other angles, use anglesToForward() or anglesToUp

bridge_angle = maps\mp\_utility::vector_scale(anglesToRight(bridge.angles), 90) //this gets the right angles of "bridge" and then multiplies it with 90; so it turns your object 90 degrees, no matter how it's rotated in Radiant


_INSANE_ taught me this, so thank him... if it works :P
Share |
9837265498
General Member
Since: Nov 6, 2009
Posts: 193
Last: Jan 23, 2012
[view latest posts]
Level 4
Category: CoD4 Scripting
Posted: Sunday, Jan. 23, 2011 10:38 am
tyvm cskiller86 and _INSANE_... this looks like it might work. just wondering how exactly i should implement it into my original script. I'll try a few things, but if you or any one else has some pointers as to how i should use it, thanks in advance.
Share |
9837265498
General Member
Since: Nov 6, 2009
Posts: 193
Last: Jan 23, 2012
[view latest posts]
Level 4
Category: CoD4 Scripting
Posted: Sunday, Jan. 23, 2011 11:22 am
I could easily be going about this wrong but my two bridge are no longer responding at all, and the one that is flipped 180 degrees has rotated his bridge to match 0 degrees.... confusion is rampant.

Here is what i tried:
Code:
bridge_think()
{
	self.bridgemoving = 	false;
	self.bridgeclosed = 	true;
	self.bridge       = 	getent(self.target,"targetname");
	self.bridgenode   = 	getent(self.bridge.target,"targetname");
	self.bridge.angles = 	self.bridgenode.angles;
		while (1)
	{
		self waittill("trigger");
		if(!self.bridgemoving)
		self thread bridge_move();
	}
}

bridge_move()
{
	self.bridgemoving = true;

	if(self.bridgeclosed)
	{

	//	self.bridge rotateroll(-90,2);
	//	self.bridge waittill("rotatedone");
		self.bridge_angles = maps\mp\_utility::vector_scale(anglesToUp(self.bridge.angles), -90); 
		self.bridgeclosed = false;
	}
	else
	{
	//	self.bridge rotateroll(90,4);
	//	self.bridge waittill("rotatedone");
		self.bridge_angles = maps\mp\_utility::vector_scale(anglesToUp(self.bridge.angles), 90); 
		self.bridgeclosed = true;	
	}
	self.bridgemoving = false;
}


what should I change?
Share |
cskiller86
General Member
Since: Nov 23, 2009
Posts: 528
Last: Oct 25, 2011
[view latest posts]
Level 6
Category: CoD4 Scripting
Posted: Monday, Jan. 24, 2011 02:03 am
Oh, wait, you misunderstood me... or maybe I misunderstood. But it would help if I had a picture.

Anyway, the vector_scale command works instantaneous. You still need to do a rotateyaw (or rotateroll) and set the time of rotation.

Here's an example of what I used:
Code:
PlayFX(fordfxfire, fordd.origin + maps\mp\_utility::vector_scale(anglesToRight(fordd.angles), 20) + maps\mp\_utility::vector_scale(anglesToUp(fordd.angles), 10));

I needed to play an FX on a specific point of an xmodel, no matter how that xmodel was rotated in Radiant; so the FX played on a point that was 20 units to the side and 10 units high of the xmodel's origin.

Another way to do it is to have cases, but it won't be 100% general.
pseudocode:
if bridge angle on X axis is 0, do a rotateyaw of 90
else
if bridge angle on X axis is 180, do a rotateyaw of -90
else
if bridge angle on X axis is 90, do a rotateroll of 90
else
if bridge angle on X axis is 270, do a rotateroll of -90
else do nothing

However, your bridge would have to be positioned straight on the horizontal axis.
Share |
.KiLL3R.
General Member
Since: Oct 26, 2006
Posts: 1437
Last: Jul 3, 2017
[view latest posts]
Level 8
Category: CoD4 Scripting
Posted: Monday, Jan. 24, 2011 06:00 am
I'm guessing the bridge is a script_brushmodel, if it is then it's angle always starts at 0 0 0 no matter which why you place it.
To get around it you must manually enter the angle it's meant to be at in its angles property (meaning you'll need a new prefab for each angle you use it at).

So for a bridge at 90 degrees
Code:

Key: angles
Value: 0 90 0


This will have no effect in radiant, but once compiled it will be rotated 90 degrees and your first rotateroll script should work perfectly with it.
Share |
9837265498
General Member
Since: Nov 6, 2009
Posts: 193
Last: Jan 23, 2012
[view latest posts]
Level 4
Category: CoD4 Scripting
Posted: Monday, Jan. 24, 2011 06:52 pm
I am probably not very clear when it come to explaining so maybe this picture will help (attachment).

yes, my bridge is a script_brushmodel within a prefab, and i have multiple instances of my prefab in my test map. I have one facing 0 and another facing 180.

I would like to, at the very least, get my script able to work in the four major directions (0, 90, 180, 270), if not all possible yaw.

cskiller86
Quote:
Another way to do it is to have cases, but it won't be 100% general.
pseudocode:
if bridge angle on X axis is 0, do a rotateyaw of 90
else
if bridge angle on X axis is 180, do a rotateyaw of -90
else
if bridge angle on X axis is 90, do a rotateroll of 90
else
if bridge angle on X axis is 270, do a rotateroll of -90
else do nothing


i believe this should make the 4 major directions work, but i tried this on my own before and it didnt respond. I may have had the "else if" syntax wrong because I just guessed it would be just:

Code:
else if(condition);
{
do stuff
}


is that correct?

.KiLL3R
Quote:
To get around it you must manually enter the angle it's meant to be at in its angles property (meaning you'll need a new prefab for each angle you use it at).


by this do you mean I set that value in the the prefab's angles?

Or do i make 4 different prefabs with different angle setting within the script_brushmodel (bridge0, bridge90, bridge180, bridge270)?

Or are you saying to do away with the prefab and have them script_brushmodels all in the same "level" of my map, non-prefabed?

thank you for your timely responses and for all the help so far[thumbs_up].
Share |
9837265498
General Member
Since: Nov 6, 2009
Posts: 193
Last: Jan 23, 2012
[view latest posts]
Level 4
Category: CoD4 Scripting
Posted: Monday, Jan. 24, 2011 06:54 pm
attachment: image(202.1Kb)
srry... attachment*
Share |
.KiLL3R.
General Member
Since: Oct 26, 2006
Posts: 1437
Last: Jul 3, 2017
[view latest posts]
Level 8
Category: CoD4 Scripting
Posted: Monday, Jan. 24, 2011 06:56 pm
9837265498 writes...
Quote:

Or do i make 4 different prefabs with different angle setting within the script_brushmodel (bridge0, bridge90, bridge180, bridge270)?


This :p
Share |
9837265498
General Member
Since: Nov 6, 2009
Posts: 193
Last: Jan 23, 2012
[view latest posts]
Level 4
Category: CoD4 Scripting
Posted: Monday, Jan. 24, 2011 08:56 pm
i have a version of the prefab each with their differnt angles kvp's.

I have modified the script to this:
Code:
main()
{
	trigger = getentarray("drawbridge","targetname");
	for(i=0;i<trigger.size;i++)
	trigger[i] thread bridge_think();	
}

bridge_think()
{
	self.bridgemoving = 	false;
	self.bridgeclosed = 	true;
	self.bridge       = 	getent(self.target,"targetname");

		while (1)
	{
		self waittill("trigger");
		if(!self.bridgemoving)
		self thread bridge_move();
	}
}

bridge_move()
{
	self.bridgemoving = true;

	if(self.bridgeclosed)
	{
		if(self.bridge.angles == 0)
		{
			self.bridge rotateroll(-90,2);
			self.bridge waittill("rotatedone");
			self.bridgeclosed = false;
		}
		else if(self.bridge.angles == 90)
		{
			self.bridge rotatepitch(-90,2);
			self.bridge waittill("rotatedone");
			self.bridgeclosed = false;
		}
		else if(self.bridge.angles == 180)
		{
			self.bridge rotateroll(90,2);
			self.bridge waittill("rotatedone");
			self.bridgeclosed = false;
		}
		else if(self.bridge.angles == 270)
		{
			self.bridge rotatepitch(90,2);
			self.bridge waittill("rotatedone");
			self.bridgeclosed = false;
		}
		else
		{
	}

	}
	else
	{
		if(self.bridge.angles == 0)
		{
			self.bridge rotateroll(90,2);
			self.bridge waittill("rotatedone");
			self.bridgeclosed = true;
		}
		else if(self.bridge.angles == 90)
		{
			self.bridge rotatepitch(90,2);
			self.bridge waittill("rotatedone");
			self.bridgeclosed = true;
		}
		else if(self.bridge.angles == 180)
		{
			self.bridge rotateroll(-90,2);
			self.bridge waittill("rotatedone");
			self.bridgeclosed = true;
		}
		else if(self.bridge.angles == 270)
		{
			self.bridge rotatepitch(-90,2);
			self.bridge waittill("rotatedone");
			self.bridgeclosed = true;
		}
		else
		{

		}
	}
	self.bridgemoving = false;
}


errors:
-on play the bridges are forced all to look at one direction regardless of their kvp's
-3 of the bridge dont do anything on trigger
-the 4th one, bridge0, rotates in the wrong direction

i get how to fix the 3rd (roll to pitch OR pitch to roll)

the other things are throwing me for a loop...

any ideas?


Share |
Restricted Access Topic is Locked
Page
Next Page
subscribe
MODSonline.com Forums : Call of Duty 4 : CoD4 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

»