1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
|
///////////////////////////////////////////////////////////
// Dynamic Foliage v.1 for CoD:WaW & CoD:MW
// Coded by Zweimann ( zweimann@helipollos.es )
// This code has been written to enhance the ingame experience,
// adding dynamic scenarios instead of static ones.
///////////////////////////////////////////////////////////
#include maps\mp\_utility;
#include common_scripts\utility;
// ---------------------------------------------------------------------
// Init Script
// ---------------------------------------------------------------------
initdfs()
{
println("^1Initializing Zweimann's Dynamic Foliage System");
// There should be three different script_models: trees, foliage and grass, because they're
// treated in a different way.
// Consider Grass to grass (obviously) and to very small foliage elements
// Consider Foliage to midsize foliage
// classname: script_model
// targetname: <name>
// These names were used in Burma 1.1. Change them to whatever you want
level.dfs_tree_sm_name = "mytrees";
level.dfs_foliage_sm_name = "myfoliages";
level.dfs_grass_sm_name = "mygrass";
// You must set up here Strength of Wind, to simulate higher or lower sway
// on foliage and trees.
// 0 means no wind @ all
// 10 means A HURRICANE : )
// Recommended values: 0.3 to 0.6. Optimal value: 0.5;
// Obviously you can setup a dvar or whatever for this
level.dfs_wind_strength = 0.5;
// Let's start
foliage_animation();
grass_animation();
tree_animation();
}
// -----------------------------------------------------------------
// Main Scripts
// -----------------------------------------------------------------
tree_animation()
{
level endon("game_ended");
// Sway animation for Trees
// Slower, softer
entities = getentarray( level.dfs_tree_sm_name, "targetname" );
vpoint = level.dfs_wind_strength / 1.4;
vangles = level.dfs_wind_strength / 1.5;
vtime = ( 6 * ( 1 - level.dfs_wind_strength ) );
for( i = 0; i < entities.size; i++ )
{
factor = randomIntRange( 0, 10 );
if ( factor >= 5 )
mmfactor = 1;
else
mmfactor = -1;
vibvector = entities[i].origin + ( ( vpoint * mmfactor ), 0, 0 );
entities[i] vibrate( vibvector, vangles * mmfactor , vtime, ( ( level.timelimit * 1.2 ) * 60 ) );
// Tree is damageable now
entities[i] setcandamage(true);
// Trees are destroyable, so let's start their threads
entities[i] thread treethreads();
wait 0.005;
}
}
foliage_animation()
{
level endon("game_ended");
// Sway animation for Foliage
// Stronger
entities = getentarray( level.dfs_foliage_sm_name, "targetname" );
vpoint = level.dfs_wind_strength * 1.5;
vangles = level.dfs_wind_strength * 2;
vtime = ( ( 1 - level.dfs_wind_strength ) ) * 5;
mmfactor = 1;
for( i = 0; i < entities.size; i++ )
{
mmfactor *= -1;
vibvector = entities[i].origin + ( randomFloatRange( 0,90 ) * mmfactor , 0, 0 );
entities[i] vibrate( vibvector, ( vangles * mmfactor ) , vtime, ( ( level.timelimit * 1.2 ) * 60 ) );
wait 0.005;
}
}
grass_animation()
{
level endon("game_ended");
// Sway animation for Grass
// Strongest
entities = getentarray( level.dfs_grass_sm_name, "targetname" );
vpoint = level.dfs_wind_strength * 2;
vangles = level.dfs_wind_strength * 4;
vtime = ( ( 1 - level.dfs_wind_strength ) ) * 2.5;
mmfactor = 1;
for( i = 0; i < entities.size; i++ )
{
mmfactor *= -1;
vibvector = entities[i].origin + ( ( vpoint * mmfactor ), 0, 0 );
entities[i] vibrate( vibvector, ( vangles * mmfactor ) , vtime, ( ( level.timelimit * 1.2 ) * 60 ) );
wait 0.005;
}
}
treethreads()
{
level endon("game_ended");
self endon("broken");
while( !isDefined(self.broken) )
{
// You can even play with tagName if you place Trees/Palms with more than one tag
// Trees could be burned, broken and more.
// By the moment, they're destroyed and sunk down
self waittill("damage", damage, attacker, direction_vec, point, mod, modelName, tagName);
if ( mod != "MOD_RIFLE_BULLET" && mod != "MOD_PISTOL_BULLET" && mod != "MOD_MELEE" )
if ( damage > 50 )
self treefall();
}
}
// Code below is originally from CoD:WaW scripts
// Modified by Zweimann to fit our requirements
treefall()
{
yaw = randomint(360);
break_angles = (self.angles[0], yaw, self.angles[2]);
break_vector = anglesToForward(break_angles);
break_vector = vectorScale(break_vector, 100);
start = (self.origin + break_vector) + (0, 0, 512);
end = start + (0, 0, -1024);
trace = bulletTrace(start, end, false, self);
dist_vector = ((self.origin + break_vector) - trace["position"]);
dist = dist_vector[2];
velocity = 0;
travelled = 0;
lasttravelled = travelled;
count = 0;
lastcount = count;
while(travelled < dist)
{
velocity = velocity + 340;
lasttravelled = travelled;
travelled = travelled + velocity;
lastcount = count;
count++;
}
remainder = lasttravelled - dist;
if(remainder < 0)
remainder = remainder * -1;
if ( velocity != 0 )
time = lastcount + (remainder / velocity);
else
time = lastcount;
self moveGravity(break_vector, time);
self waittill("movedone");
vec = vectorNormalize(break_vector);
vec = vectorScale(vec, 320);
start = (self.origin + vec) + (0, 0, 1024);
end = start + (0, 0, -1024);
trace = bulletTrace(start, end, false, self);
ground = trace["position"];
treeup_vector = anglesToUp(self.angles);
treeup_angles = vectortoangles(treeup_vector);
rest_vector = ground - self.origin;
rest_angles = vectorToAngles(rest_vector);
treeorg = spawn("script_origin", self.origin);
treeorg.origin = self.origin;
treeorg.angles = (treeup_angles[0], rest_angles[1], rest_angles[2]);
self linkto(treeorg);
treeorg rotateTo(rest_angles, 1.15, .5, 0);
treeorg waittill("rotatedone");
treeorg rotatepitch(-2.5,.21,.05,.15);
treeorg waittill("rotatedone");
treeorg rotatepitch(2.5,.26,.15,.1);
treeorg waittill("rotatedone");
self unlink();
self.broken = 1;
self notify("broken");
self setcandamage(false);
}
|