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 (), 18,435 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 2 of 3 1 2 3
Re: Lightning strike problem [Re: Grafton] #116512
03/17/07 12:32
03/17/07 12:32
Joined: Jun 2005
Posts: 656
G
Grafton Offline
User
Grafton  Offline
User
G

Joined: Jun 2005
Posts: 656
Marc, after looking at how you are using the lightning, there might be a more efficient and easier way of doing this.

You could have each cloud check if the variable "lightning" is set, if it is, then a random test would control how frequent a bolt is made. Finally the cloud would call a function to throw a lightning bolt from itself to the nearest designated target.

This would be much simpler and efficient than the current method. No need for entity pointers. Although the target would always be the nearest in the strike range and not a random target in the strike range. I think the result would most times be the same.

Heres how I might do it;

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 thunder_choice; //sound choice variable
sound thunder1 = "thunder1.wav";
sound thunder2 = "thunder2.wav";
sound thunder3 = "thunder3.wav";


//================================================================================
// LIGHTNING CLOUD ACTION
//================================================================================


Action cloud
{
while(me)
{
if(lightning_on == 1)
{
if (random(1) > lightning_freq ) {lightning_strike();}
}
wait(1);
}
}


//================================================================================
// LIGHTNING TARGET ACTION
//================================================================================


Action building //or any lightning target!
{
my.skill1 = 2; // identifies entity as a strike target
}


//================================================================================
// 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;
}
}




You could even change this to find the three or so nearest targets, and randomly pick one, but I believe that real lightning jumps to the nearest target anyway so perhaps this will be fine.

Hope this helps with your project in someway, even if only in new ideas. Keep going!


Not two, not one.
Re: Lightning strike problem [Re: Grafton] #116513
03/18/07 19:57
03/18/07 19: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
Thanks a lot man. It's great to come back from a nice day of snowboarding in 80cm of new snow, and then see this post. I'm going to try it now.


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

Joined: Jul 2002
Posts: 857
Québec
Man, the code is great.. but I'm getting the same errors :|

I can't understand..


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

Joined: Jul 2002
Posts: 857
Québec
Is it because my cloud entities and my building entities are too far from each others?


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

Joined: Jun 2005
Posts: 656
Which code are you using? You are getting the exact same errors as in the first post?


Not two, not one.
Re: Lightning strike problem [Re: Grafton] #116517
03/19/07 21:06
03/19/07 21:06
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'm using the new one you just posted here.. and yeah the exact same errors! :S


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Lightning strike problem [Re: Marky Mark] #116518
03/20/07 01:26
03/20/07 01:26
Joined: Aug 2003
Posts: 180
Reactor Core
NeutronBlue Offline
Member
NeutronBlue  Offline
Member

Joined: Aug 2003
Posts: 180
Reactor Core
I'm just getting back into 3DGS, but:

If it's the "empty pointer" thing on cloud.red

How are you loading the cloud entity?

You'll need to define it's loading action to assign the cloud pointer itself.
Note- the following is only pseudo/partial code (probably using outdated 3DGS commands ):

Ent_Create("MyCloud",MyPosition,LightningInit)


Action LightningInit{
Cloud=me;
// Other Default assignments for this entity,
// including Event actions or other actions.
}

If the Cloud is being loaded by WED (not script) you'll need to get a handle to the entity, I think using the ptr_for_name function.

Perhaps:
Cloud=ptr_for_name("MyCloudEnt")



Been a while - - Hope it helps,

-Neut.

Re: Lightning strike problem [Re: NeutronBlue] #116519
03/20/07 12:19
03/20/07 12:19
Joined: Jun 2005
Posts: 656
G
Grafton Offline
User
Grafton  Offline
User
G

Joined: Jun 2005
Posts: 656
Make sure that you have updated the right files! The latest code I posted dosent use a "cloud" pointer. Perhaps I could make a demo or look at your code. I am having no problems with 22 clouds throwing lightning, maybe its something else?


Not two, not one.
Re: Lightning strike problem [Re: Grafton] #116520
03/23/07 21:26
03/23/07 21: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
Yeah.. i forgot to update correctly. Now, I got those errors:




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

Joined: Jun 2005
Posts: 656
This means you are using these variables when either they are not defined or
before they are defined. These specific variables are used by the
lightning_effect() function, so they are probably defined there and you are
including code that uses them before they are defined.

If not you need this in your code somewhere before you use them;

var line_start[3]; // bolt xyz origin
var line_end[3]; // bolts end xyz

On big projects, I create a file called globals.wdl that contains all global
variables, function definitions, sound, image and entity pointers. I include
"globals.wdl" before any other files. This way everything is defined
before use and it also makes it easy to find.

Page 2 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