I have managed to get it to work with just one problem detailed at the end..
You need a script_origin for the start point and the end point.
In radiant, place a script_model of the truck you are going to move at the start point origin, Do NOT rotate it it at all, leave it as it comes in radiant.
Now place your script_origin in the centre of the grill of the truck, call it something. I called it truckbumper_origin.
Now create your brush that will act as a the trigger_hurt in the area of hurting, Ie just in front of the truck grill. now create a brush the same dimensions as the script_origin at the same location. Selecting the two brushes, now give them a trigger_hurt entity and a targetname of something, mine being truckbumper. Now give just the smaller of these brushes a origin texture.
Now you can delete the truck model.
In Game, when you spawn this truck, it will spawn in the same direction as it started in radiant. When we link the script_origin to the truck, it and the trigger_hurt will rotate to whatever angle we then tell it to.
Compile the map and now for the scripting.
Now for the scripting.
I have also made an array of clips to clip the player from walking through the truck. My script also moves these as well. The idea being, I can then use all this to allow a player to step on the back and trigger the truck to move taking the player with him, not got there yet though.
Here is the code.
Now for the problem.
I can only make the trigger_hurt move for one pass. Ie when the truck reaches it's destination and is deleted to start again, the trigger_hurt and associated parts to not seem to restart. anyone with any ideas.
Code:
main()
{
// Pre load the truck model.
precachemodel ("xmodel/vehicle_opel_blitz_woodland");
// Get the truck's start position.
level.truckstart = getent ("testtruck1","targetname");
// Get the Truck's end position
level.truckend = getent ("testtruck1_finish","targetname");
// Determine the truck's speed.
level.speed = (100);
// Work out the distance to travel.
level.dist = distance(level.truckstart.origin,level.truckend.origin);
// Work out the time it will take to move the truck.
level.time = (level.dist / level.speed);
// Go and do the operation.
level thread movetruck();
}
movetruck()
{
while (1)
{
// Get the trigger_hurt entity.
truckbumpertrigger = getent("truckbumper", "targetname");
// get the trigger_hurt script_origin entity.
truckbumperorigin = getent("truckbumper_origin", "targetname");
wait 10;
// spawn the truck and set the model and add sound here//
truck = spawn ("script_model",(level.truckstart.origin));
truck setmodel("xmodel/vehicle_opel_blitz_woodland");
//get the speed and heading sorted//
angles =vectortoangles(level.truckend.origin - level.truckstart.origin);//this is no mistake it has to be in this order or the truck will reverse//
//Link the trigger_hurt script_origin to the spawned truck.
truckbumperorigin linkto(truck);
// Rotate the truck to the correct heading
truck rotateto((angles),0.001);
// Track the location of the trigger_hurt script_origin and move the trigger_hurt with it
truckbumpertrigger thread trackpos(truckbumperorigin);
// Move the truck's clip arrary.
thread movetruckclip();
// Play the engine sound
truck playsound ("trucksound");
// Move the truck to it's end location.
truck moveto((level.truckend.origin),level.time);
// Wait until the movement is completed.
truck waittill("movedone");
//delete it and start over again//
wait 0.001;
truck delete();
}
}
trackpos(model)
{
while(1)
{
self.origin = model.origin;
wait(0.1);
}
}
movetruckclip()
{
// Get the truck's clip_player brushes.
truckstart_clip = getentarray("testtruck1_clip","targetname");
if (!isDefined("truckstart_clip"))
return;
{
for(d=0; d < truckstart_clip.size; d++)
{
// Move all the truck's clip_player brushes.
truckstart_clip[d] moveto((level.truckend.origin),level.time);
}
}
wait level.time;
for(d=0; d < truckstart_clip.size; d++)
{
truckstart_clip[d] moveto((level.truckstart.origin),0.001);
}
}