Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 17,416 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 3 1 2 3
Re: Lightning strike problem [Re: Grafton] #116522
03/24/07 04:26
03/24/07 04:26
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
Thanks a lot man! It works! Thanks to everyone who helped.


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Lightning strike problem [Re: Marky Mark] #116523
03/30/07 19:33
03/30/07 19:33
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
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!

Last edited by Marky Mark; 03/30/07 19:36.

Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Lightning strike problem [Re: Marky Mark] #116524
04/02/07 00:19
04/02/07 00:19
Joined: Jun 2005
Posts: 656
G
Grafton Offline
User
Grafton  Offline
User
G

Joined: Jun 2005
Posts: 656
Marc, You are calling the "lightning_strike" function directly
in "rainthatshit". This is causing a lightning strike every frame that
"ObservationConditions == ocGood".

The way it is set up, the clouds with the "lightning_cloud" action call that
function if the variable "lightning_on" is equal to 1, and a random number
( 0 to 1), is larger than the "lightning_freq" variable.


1. Change rainthatshit so that it just changes the "lightning_on" flag instead
of using it to call the "lightning_strike" function;

Code:

action rainthatshit
{
my.skill1 = 4000; // Range to scan for rain...
while(1)
{
if (vec_dist(my.x, player.x) < my.skill1)
{
if (ObservationConditions == ocAverage)
{
rainit();
OpSound(on);
}
if (ObservationConditions == ocGood)
{
rainit();
OpSound(on);
lightning_on = 1; // turn lightning on
}
else{ lightning_on = 0;} // turn lightning off
}
else
{
OpSound(off);
}
wait(1);
}
}



2. Attach the "lightning_cloud" action to several clouds or entities in the
sky, the lightning will emit from these clouds origin.

3. Change the variable "lightning_freq = 0.985" to a higher or lower number
to change how often the lightning strikes. (Higher = less)

That ought to fix it. Hope it helps anyway.


Not two, not one.
Re: Lightning strike problem [Re: Grafton] #116525
04/02/07 18:24
04/02/07 18:24
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
I used the code you sent, but the same thing is happening. The lightnings are starting at the beggining of the level instead of when the player is near the cloud..


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Lightning strike problem [Re: Marky Mark] #116526
04/27/07 15:50
04/27/07 15:50
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
No idea?


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Page 3 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1