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

Members Online

»
0 Active | 59 Guests
Online:

LATEST FORUM THREADS

»
New BF2 Mod
BF2 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: 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 subscribe
Author Topic: brushmodel moving along path of script_origins
RAMIDUS
General Member
Since: Aug 24, 2006
Posts: 91
Last: Nov 17, 2011
[view latest posts]
Level 3
Category: CoDWW Scripting
Posted: Tuesday, Nov. 8, 2011 11:53 am
Hi, thanks to this community I got my tramcar working even with opening doors, linked to the tram when moving

now I sure want to step into having a tram performing a curve:

Assuming I can't simply link my brushmodel to a chain of pathnodes (as it works for models), I made a chain of script_origins.
They're named node0 - node10

Now: Before, it was enough to use this code

Code:

tram _MoveTramFromTo (node0, node1); 
tram _MoveTramFromTo (node1, node2); 
...
tram _MoveTramFromTo (node10, node11);
}
  
_MoveTramFromTo (na, nb) 				// function for moving tram between 2 nodes with constant speed 
{ 
dist = distance(na.origin,nb.origin); 			// finding out what the distance between next 2 nodes is 
time = (dist/250);            				//computing the time needed for moving the tram on given distance with speed 250 units/second 

self MoveTo( nb.origin, time, 0, 0); 
self RotateTo( VectorToAngles( na.origin - nb.origin ), time );
self waittill ("movedone"); 
}


I kept on calling this function to every pair of neighboring nodes until i got to the last node, but this way my code got very long and very unclear - I would like to make a loop that will increase the nodenumber by itself, there are two ways I imagine to do that, but I'm not sure which is better or possible at all:

1)making an array of my nodes (nodes[]) and then adjust my function for abstract entity names:

Code:


 for (i=0, i<nodes.size; i++)
{ 
dist = distance(nodes[i].origin,nodes[i+1].origin); 		
time = (dist/250); 
self MoveTo( nodes[i+1].origin, time, 0, 0); 
self RotateTo( VectorToAngles( nodes[i+1]origin - nodes[i].origin ), time );	 
self waittill ("movedone"); 
}


2) the second method would be better but as far as i have been trying, it seems not possible:

If I can refer to entity's target as to entity.target
and
If I can refer to entity's origin as to entity.origin
then
It would be wonderful if i cound merge this and write entity1.target.origin, meaning "the origin of an entity this entity1 is pointing at":

then I could use something like this

initialnode = node0; // a node I start from in first loop
node_count = 10;

for (i=0 ; i {
dist = distance(initialnode.origin,initialnode.target.origin); //since in Radiant, I made my node0 be targetting to node1 etc., node0.target would be node1 and I could make referrence directly to its origin
time = (dist/250);
self MoveTo( initialnode.target.origin, time, 0, 0);
self RotateTo( VectorToAngles( initialnode.target.origin - intitialnode.origin ), time );
self waittill ("movedone");

initialnode = initialnode.target // by this, I transform the target from last
loop into the initialnode for the next loop (for first loop, preset node0 would change to node1 and so on) This way, I move along the path...

}

in spite of the fact this code is a bit confusing for the human (or for myself, definitely), it would move the tram safely along the entire path, if targetnames and targets are set properly... the only thing left to do for the user would be setting the total number of nodes making the path to ensure appropriate number of loops

unfortunately, although the script doesn't issue any bad syntax errors, it doesn't work either,
but still, there is some hope for it to work...

I only somehow stopped believing that "entity.target.origin" is valid expression for adressing the origin of an entity, that is syntactically nothing more than a target to some another entity. Is that possible or not?

also, when I used the old way - calling the function on a pair of nodes with increasing number - the tram stopped for a moment on each node before the speed of next move was computed - it totally broke the otherwise sufficient result - I would need something like

time = 1; //having time set for the first move

function()
{
-using pre-set time (1) to move and rotate from node0 to node1 (with no waittill ("movedone");)
-computing time for moving the following section (node1 to node2)
-wait until the movement ends
-move to next section with time already known, rewriting the initial time = 1 or another values, computed in previous loops ...
}

since my map is nothing more than a Stalingrad's worker going to night shift the day the Battle for Stalingrad started and commutes there by a tram, finetuning this script is crucial...

thanks for any help

Ramidus

edited on Nov. 8, 2011 01:56 pm by RAMIDUS

edited on Nov. 8, 2011 01:57 pm by RAMIDUS
Share |
Sevenz
General Member
Since: Apr 24, 2006
Posts: 2390
Last: May 10, 2013
[view latest posts]
Level 8
Category: CoDWW Scripting
Posted: Wednesday, Nov. 9, 2011 10:33 am
This should work:
Code:
target_ent = ent.target // .target is a property of ent, make target_ent refer to ent's target
target_ent.origin // .origin is a property of target_ent


instead of self waittill("movedone");
try wait time;

my approach would be:

Code:
tram = getent("tram", "targetname");
tram thread _MoveTram();

_MoveTram()
{
    node = getent("initial_node", "targetname");

    while (isdefined(node.target))
    {
        target_node = node.target;
        self _MoveTramFromTo(node, target_node);
    }
}

_MoveTramFromTo (from, to)
{ 
    dist = distance(from.origin, to.origin);
    time = (dist / 250);
    self MoveTo( to.origin, time, 0, 0); 
    self RotateTo( VectorToAngles(from.origin - to.origin), time );
    wait time; 
}
Share |
RAMIDUS
General Member
Since: Aug 24, 2006
Posts: 91
Last: Nov 17, 2011
[view latest posts]
Level 3
Category: CoDWW Scripting
Posted: Thursday, Nov. 10, 2011 08:16 am
Yes, it should, but it doesn't...

when I write simply:

next = node0.target;
tram moveto (next.origin, 5, 0, 0);

it compiles, but nothing happens...
Share |
3st0nian
General Member
Since: Jan 14, 2008
Posts: 291
Last: Dec 4, 2017
[view latest posts]
Level 5
Im a fan of MODSonair
Category: CoDWW Scripting
Posted: Thursday, Nov. 10, 2011 01:15 pm
Shouldn't it be
next = getent (node0.target, "targetname");
Share |
Sevenz
General Member
Since: Apr 24, 2006
Posts: 2390
Last: May 10, 2013
[view latest posts]
Level 8
Category: CoDWW Scripting
Posted: Thursday, Nov. 10, 2011 04:35 pm
doh!
probably yes, ent.target is basically a string. so getent() should give us the actual entity reference.

thanks estonian!

Code:
_MoveTram()
{
    node = getent("initial_node", "targetname");

    while (isdefined(node.target))
    {
        target_node = getent(node.target, "targetname");
        if (isdefined(target_node)) {
            self _MoveTramFromTo(node, target_node);
            node = target_node;
        } else {
            break;
        }
    }
}
Share |
RAMIDUS
General Member
Since: Aug 24, 2006
Posts: 91
Last: Nov 17, 2011
[view latest posts]
Level 3
Category: CoDWW Scripting
Posted: Friday, Nov. 11, 2011 08:21 am
well, it didn't work at the beginning, so I was getting a bit desperate, but suddenly just *click* and it works like Swiss watch...
Thank you guys, you rock [thumbs_up]

On the other hand, there is another thing that every tram must be able to perform: stops.
So now, lets proceed to Level 3 :-D

I thought what I want to do now is just an analogy to what you have written, but again I'm not very familiar with this entity/target/origin/substituted_entity mess.

I have a node targetnamed "stopnode" on the spot where I want the tram to stop - so I need to have something like

If (target_node == stopnode)
{
- keep slowing down so the tramcar stops at the stopnode
- call a thread to open, wait, and close the door (depending on which side the platform is) So we will call either _DoorLeft or _DoorRight (these are already done and work)
- continue, speed up and perform the next part of path to the next stopnode
}
else
{
perform normal _MoveTramFromTo routine
}

I hope you understand what I have in mind
I simply need some way to compare targetnames and decide whether they are equal or not...

Again, many thanks for your help!
You have your place in credits if I ever publish the map [casanova]
Share |
Sevenz
General Member
Since: Apr 24, 2006
Posts: 2390
Last: May 10, 2013
[view latest posts]
Level 8
Category: CoDWW Scripting
Posted: Friday, Nov. 11, 2011 03:27 pm
I haven't tested this code, give it a try and tell me if it's working!

You need to add the open/close door code (see the code)

In Radiant, give nodes where you want the tram to stop a KVP of

Key: script_noteworthy
Value: a number, e.g. 10 for a total holding time of 10 seconds

Code:
_MoveTram()
{
    node = getent("initial_node", "targetname");
    
    // set default values for these global vars
    speedup = true;
    speeddown = false;
    has_held = true;
    holdtime = 0;

    // Loop until we run out of nodes
    while (isdefined(node.target))
    {
        // Get the next node entity
        target_node = getent(node.target, "targetname");
        
        if (isdefined(target_node)) {
        
            // Is there a node after next?
            if (!isdefined(target_node.target) {
            
                // No, schedule the final stop
                speeddown = true;
            }
            
            // Retrieve holding time if it was set in Radiant
            if (isdefined(target_node.script_noteworthy)) {
                time = target_node.script_noteworthy;
                
                // Has to be a minimum time of...
                if (time > 0) {
                    holdtime = time;
                    
                    // If there is a holding time set, that node is a station
                    speeddown = true;
                } else {
                    holdtime = 0;
                }
            } else {
                holdtime = 0;
            }
            
            // Are we standing at a station?
            if (has_held) {
            
                // Currently not moving, so accelerate smoothly
                speedup = true;
            }
            
            self _MoveTramFromTo(node, target_node, speedup, speeddown, holdtime);
            
            // Keep track of whether tram is moving or not
            if (speeddown) {
                has_held = true;
            } else {
                has_held = false;
                
            // Prepare next iteration
            node = target_node;
            speedup = false;
            speeddown = false;
            
        // No next target to go
        } else {
            break;
        }
    }
}

_MoveTramFromTo (from, to, speedup, speeddown, holdtime)
{ 
    dist = distance(from.origin, to.origin);
    time = (dist / 250);
    
    // Acceleration / deacceleration times
    tween = 0.5;
    speedup_time = 0;
    speeddown_time = 0;
    
    // If tram is currently holding, accelerate smoothly
    if (speedup) {
        if (speeddown) {
            // Cannot last longer than the total travel time, if a stop is planned even less
            speedup_time = min(tween, time / 2);
        } else {
            speedup_time = min(tween, time);
        }
    }
    
    // If a stop is planned, deaccelerate smoothly
    if (speeddown) {
        if (speedup) {
            speeddown_time = min(tween, time / 2);
        } else {
            speeddown_time = min(tween, time);
        }
    }

    self MoveTo( to.origin, time, speedup_time, speeddown_time); 
    self RotateTo( VectorToAngles(from.origin - to.origin), time, speedup_time, speeddown_time );
    
    // wait until move/rotate is done
    wait time;
    
    // Hold and keep doors closed if holdtime is too little.
    // Otherwise hold, open doors and wait so that all together == holdtime
    if (holdtime > 4) {
        // YOUR ADDITIONAL CODE HERE!
        // open doors 1 sec
        // wait holdtime - 2
        // close doors 1 sec
    } else {
        wait holdtime;
    }
}
Share |
RAMIDUS
General Member
Since: Aug 24, 2006
Posts: 91
Last: Nov 17, 2011
[view latest posts]
Level 3
Category: CoDWW Scripting
Posted: Wednesday, Nov. 16, 2011 04:30 pm
Whoa, I spent a while trying to understand what your code actually says, but finally got inspired to write my own, simpler, I think:

Code:
   
   while (isdefined(node.target))  //while this node is not the last one
    {
        target_node = getent(node.target, "targetname");
        if (isdefined(target_node))
	{
	if(isdefined(target_node.script_noteworthy)) 		//value of 1 = right side, value of 0 = left side
		{ 
                side = target_node.script_noteworthy; 
 		self MoveTo(target_node.origin, 3, 0, 2); //move to and stop in the node with script_noteworthy defined = stopnode
		self waittill ("movedone");
		_Door(side);     // performing door opening routine, taking      into account the value of script_noteworthy, which sets on which side the doors will open 
		AfterStop = getent(target_node.target, "targetname");                           // now we need to accelerate to next node and get the speed of the rest of the path (distance stopnode - Afterstop = 512 units
		self MoveTo (AfterStop.origin, 3, 3, 0);
		self waittill ("movedone");
		node = AfterStop;	                                         //here we turn this AfterStop into an initial node to continue the normal script from
		}
	else 
		{	
         		self _MoveFromTo(node, target_node);
            		node = target_node;
		}
	}
        else 
	{
            	break;
        	}
    }
}

_Door(side)
{
door_rl = GetEnt ("door_rl", "targetname");
door_rr = GetEnt ("door_rr", "targetname");
door_fl = GetEnt ("door_fl", "targetname");
door_fr = GetEnt ("door_fr", "targetname");
tram = GetEnt ("tram","targetname");

if(side == 0)                                                  //if script_noteworthy was set to 0, door will open on left side, otherwise on right side
	{
	wait (1);
	door_fl RotateRoll (-90, 1, 0, 0);   //front left door, roll axis
	door_rl RotatePitch(90, 1, 0, 0);   //rear right door, pitch axis
	wait(11);
	door_fl RotateRoll (90, 1, 0, 0);     
	door_rl RotatePitch(-90, 1, 0, 0);
	wait (2);
	}
	else
	{
	wait (1);
	door_fr RotateRoll (90, 1, 0, 0);      //front right door, roll axis
	door_rr RotatePitch(90, 1, 0, 0);     //rear right door, pitch axis
	wait(11);
	door_fr RotateRoll (-90, 1, 0, 0);
	door_rr RotatePitch(-90, 1, 0, 0);
	wait (2);
	}
}


Explanation: I made nodes with script_noteworthy (value 0 or 1) where I want the tram to stop.;
If script detects script_noteworthy defined for next node, tram slows down, stops, executes _Door(side) function, where there is a value of script_noteworthy stored in the variable side - if it's 0, left door will open, if it's 1 (or anything else actually), right door will open - then it defines AfterStop node, which is a node targetted by stopnode, and proceeds from this node further.

the move of the tram works perfectly - it comes, stops, accelerates and continues to second stop, where it works perfectly, too... only one thing is wrong - like if _Door(side) function wouldn't come into action at all - no door open and the stop only lasts 2 seconds - I wonder if the

Code:
side = target_node.script_noteworthy; 


line is valid...

Even if I didn't initiate the support variable side and reffered directly to script_noteworthy further in the script, the doors don't react...

when I tried your script, it worked, but had the same issue - nothing happened when tram was stationed... just a few seconds delay and moving on...

I had my script_noteworthy values set to 10 as you suggest...

also, in both scripts, there is a quick, short movement backwards, when the tram stops... it looks weird but can't find a line in the code that causes it...

It's strange that our codes are so different and work so same in these conditions...

edited on Nov. 16, 2011 06:31 pm by RAMIDUS
Share |
Sevenz
General Member
Since: Apr 24, 2006
Posts: 2390
Last: May 10, 2013
[view latest posts]
Level 8
Category: CoDWW Scripting
Posted: Thursday, Nov. 17, 2011 12:18 am
hm, well, i think i know why script_noteworthy isn't working. The struct is not initialized automatically, you need to add this line at the very top of your script:

#include common_scripts\utility;

no need to call the struct_class_init(); function, it's called by the stock _load.gsc files (sp & mp)
Share |
RAMIDUS
General Member
Since: Aug 24, 2006
Posts: 91
Last: Nov 17, 2011
[view latest posts]
Level 3
Category: CoDWW Scripting
Posted: Thursday, Nov. 17, 2011 06:38 am
I found out this line already is there...
Share |
Restricted Access Topic is Locked 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

»