Gamestudio Links
Zorro Links
Newest Posts
blogherenowcenter
by 3s05bmmc. 06/05/24 06:08
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 742 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19057 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Lightning strike problem #116502
03/11/07 02:46
03/11/07 02:46
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
Sometimes acknex is having fun giving me errors for nothing. Everything works well, then I ran the game again, and I got those errors everytime the storm was trying to make a lightning strikes:



Now, everytime my conditions are good, the storm starts the lightning function, then I get those errors...

I can't get it.. What's wrong?

the code:

Code:

//The blue ents are buildings, the yellow are clouds
/*
var video_mode = 8;
var video_screen = 1;
var d3d_triplebuffer = 1;
*/
var snd_dist = 450; //set range of 3d sounds here
var flash_dist = 6500; //set lightrange of light flash here

var temporary;
var line_length;
var segment_start;
var segment_end;
var segment_length;

var line_start[4];
var line_end[4];
var lightning_on = 1; //turn lightning on or off
var pos_pick;
var neg_pick;
var pos_flag;
var neg_flag;
var num_of_pos_ents = 0; //holds number of positive assigned ents
var num_of_neg_ents = 0;
var counter;
var thunder_choice; //choice variable

bmap bmp = "flash3.tga";
bmap bmp2 = "l.bmp";

sound thunder1 = "thunder1.wav";
sound thunder2 = "thunder2.wav";
sound thunder3 = "thunder3.wav";
sound rain = "rain_loop.wav";
var_nsave rain_handle;

entity* cloud;
entity* not_cloud;

//================================================================================
//
//================================================================================

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
}
}


//================================================================================
// ACTION FOR CLOUDS
//================================================================================
//only the first two lines are important for lightning

action lightning_cloud
{
my.skill1 = 1;
num_of_pos_ents += 1; //this will auto increment keep count of pos ents

my.invisible = on;
my.scale_x = 3;
my.scale_y = 3;
my.scale_z = 0.5;
my.skin = 6;

my.transparent = on;
my.alpha = 35;

while(me)
{
my.pan += 1* time;
c_move(my, vector(2*time,0,0),nullvector, ignore_passable);
wait(1);

}
}

//================================================================================
// ACTION FOR BUILDINGS (lightning targets)
//================================================================================
//only the first two lines are important for lightning

action building
{
my.skill1 = 2;
num_of_neg_ents += 1;

my.invisible = on;
my.scale_z = 5;
my.skin = 5;
}

//================================================================================
//
//================================================================================
var lightning_dist = 5000;

function lightning_strike()
{
//while(1)
{
if (random(1) > 0.985 && lightning_on == 1) //0.9
{

pos_pick = int(random(num_of_pos_ents)+1); //get a random pos ent num
neg_pick = int(random(num_of_neg_ents)+1); //get a random neg ent num


pos_flag = 0;
counter = 1;
you = ent_next(NULL); //get first entity
while(you != 0 && pos_flag == 0)
{
if(you.skill1 == 1 && counter == pos_pick)
{
vec_set(line_start.x, you.x);
pos_flag = 1;
cloud = you;
}
if(you.skill1 == 1 && counter != pos_pick)
{
not_cloud = you;
}
counter += 1;
you = ent_next(YOU); //get next entity
}


neg_flag = 0;
counter = 1;
you = ent_next(NULL); //get first entity
while(you != 0 && neg_flag == 0)
{
if(you.skill1 == 2 && counter == neg_pick)/////
{
vec_set(line_end.x, you.x);
neg_flag = 1;
}
counter += 1;
you = ent_next(YOU); //get next entity
}

if(vec_dist(line_start.x, line_end.x) < 6000)// strike only if closer than 325
{
//create lightning bolt
lightning_effect();

//flash cloud
cloud.red = 127; // set amount of red in flash here
cloud.green = 128; // set amount of green in flash here
cloud.blue = 255; // set amount of blue in flash here
cloud.light = on;
cloud.lightrange = flash_dist;
wait(2);

//play random thunder
thunder_choice = int(random(6)); // returns whole numbers 0 to 5
if(thunder_choice == 0 || thunder_choice == 3){ent_playsound(cloud, thunder1, snd_dist);}
if(thunder_choice == 1 || thunder_choice == 4){ent_playsound(cloud, thunder2, snd_dist);}
if(thunder_choice == 2 || thunder_choice == 5){ent_playsound(cloud, thunder3, snd_dist);}

//turn off cloud flash
cloud.light = off;
cloud.lightrange = 0;
}
}
wait (1);
//}
}




//================================================================================
//
//================================================================================
//rain_handle = snd_loop(rain, 80, 0); //comment out to turn off rain background




Here's where the lightnings are called:
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);
}
if (ObservationConditions == ocGood)
{
rainit();
OpSound(on);
lightning_strike();
}
}
else
{
OpSound(off);
}
wait(1);
}
}




Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Lightning strike problem [Re: Marky Mark] #116503
03/11/07 07:56
03/11/07 07:56
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
I haven't looked through your entire script, but it looks to me like you're dividing by zero. try putting
line_length = 1;
before the line
line_end.x = (line_end.x * 50) / line_length; // create segments every 100 quants

and you should not get the first error any more...


~"I never let school interfere with my education"~
-Mark Twain
Re: Lightning strike problem [Re: Germanunkol] #116504
03/11/07 17:02
03/11/07 17:02
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
Yeah now i'm only getting the second one about cloud red...


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Lightning strike problem [Re: Marky Mark] #116505
03/11/07 17:24
03/11/07 17: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
It looks like there is a an entity problem. I commented the flash part, just to see if the lightnings without flashes would work, and I'm getting error about the sound now... every time it's about an empty pointer... I think it has something to do with:

Code:

pos_flag = 0;
counter = 1;
you = ent_next(NULL); //get first entity
while(you != 0 && pos_flag == 0)
{
if(you.skill1 == 1 && counter == pos_pick)
{
vec_set(line_start.x, you.x);
pos_flag = 1;
cloud = you;
}
if(you.skill1 == 1 && counter != pos_pick)
{
not_cloud = you;
}
counter += 1;
you = ent_next(YOU); //get next entity
}



It's not finding any entities?


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Lightning strike problem [Re: Marky Mark] #116506
03/11/07 18:33
03/11/07 18:33
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
Deleted...

Nevermind, I missed the "if (you != 0)"

Last edited by xXxGuitar511; 03/11/07 18:35.

xXxGuitar511
- Programmer
Re: Lightning strike problem [Re: xXxGuitar511] #116507
03/11/07 18:39
03/11/07 18:39
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
So I guess you can't find it ? Oh btw i'll send you the game source


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Lightning strike problem [Re: xXxGuitar511] #116508
03/11/07 18:43
03/11/07 18:43
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
The code you posted [imediatly] above is fine, as far as I can see, it's just It's in your if statements...

you.skill1 == 1 && counter == pos_pick

In some cases, this is not always working out to well. I'm guessing that skill1 is used to tell what type of entity it is, but I'm not understanding why you are also needing counter to equal pos_pick...


xXxGuitar511
- Programmer
Re: Lightning strike problem [Re: xXxGuitar511] #116509
03/11/07 18:57
03/11/07 18:57
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
Well, Josiah Worked on it with me, it's him that added the counters. Take a look at his demo level with demo strikes Here .


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

Joined: Jul 2002
Posts: 857
Québec
The source is uploaded. Check out our message board, thanks to help me to find a way to solve the problem


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Lightning strike problem [Re: Marky Mark] #116511
03/17/07 11:13
03/17/07 11:13
Joined: Jun 2005
Posts: 656
G
Grafton Offline
User
Grafton  Offline
User
G

Joined: Jun 2005
Posts: 656
Hello Marc, sorry I didnt get here sooner.

your problem is not with the "lightning_effect" function, but with the distance of the
start/end vectors you are supplying it with, (a distance of zero between them is causing
the error). This is because the cloud vec or target is being used to set both the start
AND end vectors so the distance is zero, or the cloud pointer is null and causing a
similar problem.

This is probably caused in part by the line "not_cloud = you". This was an editing
mistake I overlooked. it should have been "cloud != you".

I would keep the lightning effect function as is. If you want to prevent zero errors,
(which you shouldnt have anymore anyway), instead of using "line_length = 1;" insert
a check after the line_length is calculated like this;

Code:
 
line_length = vec_length(line_end); // total length of bolt
if(line_length == 0){line_length = 1;} // NEW LINE GOES HERE



I edited the original code a little to fix the problems and added some comments to explain
it better. Here is the result;


Code:
  

//================================================================================
// Lightning Strike Function
//================================================================================

var strike_dist = 325; // maximun distance in quants lightning will strike,(how close the cloud must be)
var flash_dist = 300; // set lightrange of light flash here
var snd_dist = 800; // set range of 3d sounds here

var pos_pick;
var neg_pick;
var num_of_pos_ents = 0; //holds number of positive assigned ents
var num_of_neg_ents = 0;

var thunder_choice; //sound choice variable
sound thunder1 = "thunder1.wav";
sound thunder2 = "thunder2.wav";
sound thunder3 = "thunder3.wav";

entity* cloud;


function lightning_strike()
{
var counter;
pos_pick = int(random(num_of_pos_ents)+1); //get a random pos ent number (pick a cloud #)
neg_pick = int(random(num_of_neg_ents)+1); //get a random neg ent number (pick a building #)

counter = 1;
//cycle through entitys until all clouds are processed
you = ent_next(null); //get first entity
while(you != 0 && (counter <= num_of_pos_ents))
{
if(you.skill1 == 1) //if you are a pos ent (cloud)
{
if(counter == pos_pick)//if you are our picked cloud
{
vec_set(line_start.x, you.x); //set you as the start vec
cloud = you; // we make you current cloud
}
else //you are NOT our picked cloud
{
cloud != you; //remove pointer if assign previously
}
counter += 1; // increment pos counter
}
you = ent_next(YOU); //get next entity
}

counter = 1; //reset counter
//cycle through entitys untill all neg ents are processed
you = ent_next(NULL); //get first entity
while(you != 0 && (counter <= num_of_neg_ents))
{
if(you.skill1 == 2 )// if you are a neg ent
{
if(counter == neg_pick) //if you are our picked target
{
vec_set(line_end.x, you.x); //set you as the end vec
counter = num_of_neg_ents; //set counter so loop ends
}
counter += 1; // increment neg counter
}
you = ent_next(YOU); //get next entity
}

if(cloud) //avoid an empty pointer
{
if(vec_dist(line_start.x, line_end.x) < strike_dist )// strike only if closer than strike_dist
{
//create lightning bolt
lightning_effect();
//flash cloud
vec_set(cloud.blue, vector(255,128,128));// set amount of blue,green and red in flash here
cloud.light = on;
cloud.lightrange = flash_dist;
wait(2);

//play random thunder
thunder_choice = int(random(6)); // returns whole numbers 0 to 5
if(thunder_choice == 0 || thunder_choice == 3){ent_playsound(cloud, thunder1, snd_dist);}
if(thunder_choice == 1 || thunder_choice == 4){ent_playsound(cloud, thunder2, snd_dist);}
if(thunder_choice == 2 || thunder_choice == 5){ent_playsound(cloud, thunder3, snd_dist);}

//turn off cloud flash
cloud.light = off;
cloud.lightrange = 0;
}
}
}




I commented some lines to help explain it.
You may have some of the variables already defined, so you wont need to redefine them. However, with this rewrite, you dont need these any longer.

entity * not_cloud;
var lightning_on = 1;
var strike_freq = 0.8;
var pos_flag;
var neg_flag;

You could call this new function something like this
Code:
 
while(1)
{
if (random(1) > 0.95 ) // higher number less chance of a bolt
{
lightning_strike();
}
wait(1);
}



And if a cloud and building are chosen that are closer than the variable "strike_dist" , a bolt(s) will be thrown between them.

Hope this is all clear?


Not two, not one.
Page 1 of 3 1 2 3

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

Gamestudio download | chip programmers | 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