Hey there.
The lightning strikes works, but it looks like its looping too much.. There's like 5 strikes per second... Maybe its a "while.." problem.
Here's where the lightning function is called. I want it to start when the player is near the cloud entity with rainthatshit action (rain also starts in this action)
Code:
action rainthatshit
{
// Range to scan for rain...
my.skill1 = 4000;
//
while(1)
{
if (vec_dist(my.x, player.x) < my.skill1)
{
if (ObservationConditions == ocAverage)
{
rainit();
OpSound(on);
//lightning_strike();
}
if (ObservationConditions == ocGood)
{
rainit();
OpSound(on);
lightning_strike();
}
}
else
{
OpSound(off);
}
wait(1);
}
}
And Here is my lightning strike code.
Code:
//================================================================================
// VARIABLES & SOUNDS
//================================================================================
var lightning_on = 1; // use this variable to turn lightning on or off
var lightning_freq = 0.985; // frequentcy of lightning strikes, 0 = constant, 1 = never
var strike_range = 1000; // how close cloud origin must be to target origin for a strike
var flash_range = 1000; // lightrange for the lightning flash
var thunder_snd_range = 800; // set range of 3d sounds here
var line_start[3]; // bolt xyz origin
var line_end[3]; // bolts end xyz
var thunder_choice; //sound choice variable
sound thunder1 = "thunder1.wav";
sound thunder2 = "thunder2.wav";
sound thunder3 = "thunder3.wav";
//================================================================================
// LIGHTNING CLOUD ACTION
//================================================================================
Action lightning_cloud
{
while(me)
{
if(lightning_on == 1)
{
if (random(1) > lightning_freq ) {lightning_strike();}
}
my.invisible = 1;
wait(1);
}
}
//================================================================================
// LIGHTNING TARGET ACTION
//================================================================================
Action building //or any lightning target!
{
my.skill1 = 2; // identifies entity as a strike target
my.invisible = 1;
}
//================================================================================
// LIGHTNING_EFFECT FUNCTION
//================================================================================
var temporary;
var line_length;
var segment_start;
var segment_end;
var segment_length;
bmap bmp = "flash3.tga";
bmap bmp2 = "l.bmp";
function fade_lightning()
{
my.lifespan = 0;
}
function particle_lightning()
{
temp.x = random(8) - 1;
temp.y = random(8) - 1;
temp.z = random(8) - 1;
vec_set(my.vel_x, temp);
my.bmap = bmp;
my.size = 5;
my.move = on;
my.bright = on;
my.lifespan = random(5)+1; // the particles live for a single frame
my.function = fade_lightning;
}
function particle_lightning2()
{
temp.x = random(8) - 1;
temp.y = random(8) - 1;
temp.z = random(8) - 1;
vec_set(my.vel_x, temp);
my.bmap = bmp2;
my.size = 8;
my.move = on;
my.bright = on;
my.lifespan = random(5)+1; // the particles live for a single frame
my.transparent = on;
my.alpha = 30;
my.function = fade_lightning;
}
function particle_segment()
{
vec_set(temporary, segment_end);
vec_sub(segment_end, segment_start);
segment_length = vec_length(segment_end);
segment_end.x = (segment_end.x * 5) / segment_length; // create particles every 5 quants
segment_end.y = (segment_end.y * 5) / segment_length;
segment_end.z = (segment_end.z * 5) / segment_length;
while(segment_length > 0)
{
effect(particle_lightning, 5, segment_start.x, nullvector);
effect(particle_lightning2, 1, segment_start.x, nullvector);
vec_add(segment_start, segment_end);
segment_length -= 5; // same value here
}
}
function lightning_effect()
{
vec_set(temporary, line_start);
vec_sub(line_end, line_start);
line_length = vec_length(line_end);
line_end.x = (line_end.x * 50) / line_length; // create segments every 100 quants
line_end.y = (line_end.y * 50) / line_length;
line_end.z = (line_end.z * 50) / line_length;
while(line_length > 0)
{
vec_add(line_start, line_end);
vec_set(segment_start, temporary);
vec_set(segment_end, line_start);
segment_end.x += random(40) - 20; // displace the lightning segments (don't make the lightning look like a straight line)
segment_end.y += random(40) - 20;
segment_end.z += random(40) - 20;
particle_segment();
line_length -= 100; // keep the same value here
}
}
//================================================================================
// LIGHTNING_STRIKE FUNCTION
//================================================================================
function lightning_strike()
{
var closest_target;
closest_target = strike_range + 1; // initally set just outside of strike range
vec_set(line_start.x, my.x); // set calling ent as start vec
you = ent_next(null);
while ( you != 0 ) // cycle through entitys
{
if(you.skill1 == 2) // if you are a target
{
temp = vec_dist(my.x, you.x); // get the distance
if(temp < closest_target) // if you are closer than last closest target
{
vec_set(line_end.x, you.x); // set you as end vec
closest_target = temp; // set you as new closest target
}
}
you = ent_next(YOU); // get next entity
}
if(closest_target <= strike_range) // if the closest target is now within range, make lightning
{
lightning_effect();
vec_set(my.blue, vector(255,128,128)); // set amount of blue,green and red in flash here
my.light = on;
my.lightrange = flash_range;
wait(2);
thunder_choice = int(random(6));
if(thunder_choice == 0 || thunder_choice == 3){ent_playsound(my, thunder1, thunder_snd_range);}
if(thunder_choice == 1 || thunder_choice == 4){ent_playsound(my, thunder2, thunder_snd_range);}
if(thunder_choice == 2 || thunder_choice == 5){ent_playsound(my, thunder3, thunder_snd_range);}
my.light = off;
my.lightrange = 0;
}
}
Thanks to help!