PDA

View Full Version : Weather System


coreys
01-26-2008, 09:13 PM
I have yet to see any decent weather system around Graal, so, after I found some old weather effects I made using the particle system, I decided to make my own and release it.

Main WNPC:

/* Weather System v1
by Abjorn (*coreys)

This script is free to use by all, so long as this comment
block remains intact and unedited and credit is attributed.*/

//#CLIENTSIDE
function onCreated() {
player.attr[9] = "";
this.weather = "";
this.types = {"weather_rain.gani"}; //list of weather ganis
this.chance = {49,51}; /*chance variables
When the weather changes it will
create a random number betwee 0 and
the second number in this array.
If the number is above the first
number in this array, the weather
will be something other than none.*/
this.levels = {}; //List of levels with weather
this.levelstarts = {"mal-"}; //List of level name starts with weather
this.attr = 9; //number of the player.attr[] that will hold
//the weather gani
this.maxtime = 800; //Time period before the weather changes
this.timer = 0;
onTimeOut();
}
function onTimeOut() {
//Check if the players level allows weather
temp.check = false;
for (temp.lvl: this.levelstarts) {
if (player.level.starts(temp.lvl))
temp.check = true;
}
if (player.level in this.levels) temp.check = true;

if (temp.check) {
//Make sure the weather gani is correct
if (player.attr[this.attr] != this.weather)
player.attr[this.attr] = this.weather;
client.weather = this.weather;

if (this.timer < this.maxtime)
this.timer++;
else { //It's time to change weather
this.timer = 0;
temp.change = random(0,this.chance[1]);
if (temp.change > this.chance[0]) //If the weather changes
this.weather = randomstring(this.types);
else this.weather = ""; //Or returns to normal
}
}
else { //Turns weather off if your level doesn't allow it
player.attr[this.attr] = "";
client.weather = "";
}
setTimer(1);
}
//If the weather gani ends the weather manually
function onActionEndWeather(acc) {
if (player.account == acc)
this.timer = this.maxtime;
}

This weather system uses gani's to show weather effects. It's completely clientside, so not every player is going to be experiencing the same weather. I may make a serverwide weather system sometime in the future. The gani is set to a player.attr[], which you can change in the script. I think I've commented it fairly well, so anything you want to change should be easy to figure out.

Here's the gani for the rain effect that I am releasing. It uses the particle engine, as I would suggest everyone use for any weather effects they want to make.

GANI0001

DEFAULTHEAD head19.png
DEFAULTBODY body.png

ANI




ANIEND
SCRIPT
//#CLIENTSIDE
function onCreated() {
with (findImg(401)) {

// Emitter attributes
layer = 2;
x = player.x; y = player.y;
emitter.delaymin = 0.1;
emitter.delaymax = 0.3;
emitter.nrofparticles = 5;
emitter.emissionoffset = {-12, -15, 50};
emitter.checkbelowterrain = true;

// Basic particle attributes
emitter.particle.lifetime = 20;
emitter.particle.zoom = 2;
emitter.particle.image = "particle_rain.gif";
emitter.particle.rotation = -degtorad(10);

// Movement
emitter.particle.zangle = -1;
emitter.particle.speed = 15;
emitter.particle.alpha = 1;
emitter.particle.mode = 0;

emitter.addglobalmodifier("impulse", 0.2, 0.2, "zangle", "multiply", 0.95, 0.95);
emitter.addlocalmodifier("impulse", 0, 20, "zoom", "add", -1.5, .2);
emitter.addlocalmodifier("once", 0, 0, "angle", "replace", degtorad(260), degtorad(230));
emitter.addlocalmodifier("once", 0, 0, "x", "add", -64, 64);
emitter.addlocalmodifier("once", 0, 0, "y", "add", -10, 0);
emitter.addlocalmodifier("once", 0, 0, "zoom", "replace", 0.6, 1.2);
emitter.addlocalmodifier("range", 0, 10, "speed", "add", 1, 3);
emitter.addglobalmodifier("range", 0.1, 25, "angle", "add", -degtorad(45), degtorad(45));
}
this.timer = 0;
this.lifetime = 0;
setTimer(0.05);
}
function onTimeOut() {
temp.i = findImg(401);
temp.i.x = player.x; temp.i.y = player.y;
if (this.timer < .5)
this.timer += .05;
else {
if (this.lifetime < 800) {
if (temp.i.emitter.nrofparticles < 200)
temp.i.emitter.nrofparticles++;
this.timer = 0;
}
}
if (this.lifetime < 800)
this.lifetime += .05;
else {
if (temp.i.emitter.nrofparticles > 0)
temp.i.emitter.nrofparticles--;
else
triggeraction(player.x, player.y, "EndWeather", player.account);
}
hideimg(202);
if (temp.i.nrofparticles > 100) {
temp.chance = int(random(0, 400));
if (temp.chance > 395) {
showpoly(402, {0,0,screenwidth,0,screenwidth,screenheight,0,scre enheight});
changeimgvis(402,4);
changeimgcolors(402,1,1,1,.1);
}
}
setTimer(0.05);
}
SCRIPTEND

And attached I have a rain particle GFX.

Enjoy!

Chompy
01-26-2008, 09:52 PM
Nice Vash :)

coreys
01-26-2008, 10:12 PM
Well, it seems I'm having some unforeseen problems with this.
For some reason every player can see someones weather effect. I've tried everything I could think of to make it so it doesn't show globally, but I can't figure it out. I'm using image indexes over 200...I even tried well over that, but I can't figure it out.

Halp D:

cbk1994
01-27-2008, 03:17 AM
Well, it seems I'm having some unforeseen problems with this.
For some reason every player can see someones weather effect. I've tried everything I could think of to make it so it doesn't show globally, but I can't figure it out. I'm using image indexes over 200...I even tried well over that, but I can't figure it out.

Halp D:
You can't set the player attribute x_x

I would do a showani or something. If you set the player attribute, of course everyone can see it. That's how a lot of name systems, chat systems, etc are done.

DustyPorViva
01-27-2008, 03:57 AM
Yes, showani with an index >200. If you set an attr as a gani, everyone else will be able to see your gani. That's where the problems arise, I believe.

Inverness
01-27-2008, 01:53 PM
My brain crashed at the part where you said you used a gani to display the weather.

cbk1994
01-27-2008, 04:14 PM
My brain crashed at the part where you said you used a gani to display the weather.

CTRL+ALT+DELETE

coreys
01-27-2008, 06:00 PM
I chose ganis and attributes, because otherwise, when you move, the weather effect will lag behind you.

zokemon
01-27-2008, 10:53 PM
I made a weather system on GK a while ago. People usually just turn it off though as having it combined with the terrain and a bunch of other particle effects from monsters and other players was not the friendliest thing on people's CPUs and graphics cards, especially when the rain was on "heavy".

It had different settings of rain, snow and leaves (for autumn) that would do very very slow transitions when the settings changed. Each setting also had a light and a heavy version. No one really knows about the transitions though as they usually take about a half hour to complete :P.

I chose ganis and attributes, because otherwise, when you move, the weather effect will lag behind you.

Just put have findimg(i).attachtoowner = true;

TheFisherman
01-28-2008, 01:10 AM
Could you show any screenshots? :)

Bolivian
01-28-2008, 02:07 AM
O.o o.O

Lol

Rapidwolve24
01-28-2008, 03:33 AM
O.o o.O

Lol

What is wrong with you?

Inverness
01-28-2008, 04:06 AM
I chose ganis and attributes, because otherwise, when you move, the weather effect will lag behind you.What Zero said.
There is also the GUI layer.

TheFisherman
01-29-2008, 12:38 AM
Could you show any screenshots? :)

!pissed!

Rufus
01-29-2008, 12:38 AM
!pissed!

Or a video.