Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Weather System (https://forums.graalonline.com/forums/showthread.php?t=78481)

coreys 01-26-2008 09:13 PM

Weather System
 
1 Attachment(s)
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:
PHP Code:

/* 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.lvlthis.levelstarts) {
    if (
player.level.starts(temp.lvl))
      
temp.check true;
  }
  if (
player.level in this.levelstemp.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.
PHP Code:

GANI0001

DEFAULTHEAD head19
.png
DEFAULTBODY body
.png

ANI




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

    
// Emitter attributes
    
layer 2;
    
player.xplayer.y;
    
emitter.delaymin 0.1;
    
emitter.delaymax 0.3;
    
emitter.nrofparticles 5;
    
emitter.emissionoffset = {-12, -1550};
    
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.20.2"zangle""multiply"0.950.95);
    
emitter.addlocalmodifier("impulse"020"zoom""add", -1.5.2);
    
emitter.addlocalmodifier("once"00"angle""replace"degtorad(260), degtorad(230));
    
emitter.addlocalmodifier("once"00"x""add", -6464);
    
emitter.addlocalmodifier("once"00"y""add", -100);
    
emitter.addlocalmodifier("once"00"zoom""replace"0.61.2);
    
emitter.addlocalmodifier("range"010"speed""add"13);
    
emitter.addglobalmodifier("range"0.125"angle""add", -degtorad(45), degtorad(45));
  }
  
this.timer 0;
  
this.lifetime 0;
  
setTimer(0.05);
}
function 
onTimeOut() {
  
temp.findImg(401);
  
temp.i.player.xtemp.i.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.xplayer.y"EndWeather"player.account);
  }
  
hideimg(202);
  if (
temp.i.nrofparticles 100) {
    
temp.chance int(random(0400));
    if (
temp.chance 395) {
      
showpoly(402, {0,0,screenwidth,0,screenwidth,screenheight,0,screenheight});
      
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

Quote:

Originally Posted by coreys (Post 1372076)
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

Quote:

Originally Posted by Inverness (Post 1372213)
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.

Quote:

Originally Posted by coreys (Post 1372242)
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

Quote:

Originally Posted by Bolivian (Post 1372333)
O.o o.O

Lol

What is wrong with you?

Inverness 01-28-2008 04:06 AM

Quote:

Originally Posted by coreys (Post 1372242)
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

Quote:

Originally Posted by TheFisherman (Post 1372319)
Could you show any screenshots? :)

!pissed!

Rufus 01-29-2008 12:38 AM

Quote:

Originally Posted by TheFisherman (Post 1372461)
!pissed!

Or a video.


All times are GMT +2. The time now is 07:54 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.