View Single Post
Seren Seren's Avatar

JCF Member

Joined: Feb 2010

Posts: 866

Seren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to all

Feb 2, 2013, 10:03 AM
Seren is offline
Reply With Quote
Day / night cycle
This script will smoothly change tileset palette between day and night. If used in multiplayer, it works for every client locally, meaning that each client will see a different time of the day.
Code:
const uint dnCYCLELENGTH=700;
const uint dnEVERYXTICKS=4;
const uint dnINITIALTICKS=256;
const string dnNIGHTTILESET="Carrot1N.j2t";
jjPAL PaletteNight;

void onLevelLoad()
{
  PaletteNight.load(dnNIGHTTILESET);
}

void onMain()
{
  if(jjGameTicks%dnEVERYXTICKS==0)
  {
    jjPalette=PaletteNight;
    jjPalette.copyFrom(2,252,2,jjBackupPalette,(jjSin(1024*jjGameTicks/dnCYCLELENGTH+dnINITIALTICKS)+1)/2);
    jjPalette.apply();
  }
}
  • dnCYCLELENGTH determines length of a single cycle in game ticks. 70 means one second.
  • dnEVERYXTICKS determines how often the palette should be updated. 1 will give the smoothest effect but can slow down the game. Higher values will save memory but not look as nice.
  • dnINITIALTICKS determines the initial time of the day. 0 means dawn, 256 means noon, 512 means dusk, 768 means midnight and 1024 means dawn again (there will be no difference between setting this constant to 0 and 1024). Of course, values in between are also allowed.
  • dnNIGHTTILESET is name of the tileset whose palette should be used in midnight. Note that the noon palette will be set to the default tileset of the level.
Healing freezer
In team games, this script will let players heal their teammates by shooting ice bullets at them. A single bullet can heal multiple people. Each bullet will heal 1 heart of damage. If freezer is powered-up, it shoots two bullets, so if both hit a player, it heals 2 hearts of damage in total. It won't heal the person who shot the bullet nor members of the opposite team.
Code:
void onPlayer()
{
  for (int i=1;i<jjObjectCount;i++)
  {
    if(jjObjects[i].isActive&&(jjObjects[i].eventID==OBJECT::ICEBULLET||jjObjects[i].eventID==OBJECT::ICEBULLETPU))
    {
      if(jjObjects[i].xPos>p.xPos-12
       &&jjObjects[i].xPos<p.xPos+12
       &&jjObjects[i].yPos>p.yPos-12
       &&jjObjects[i].yPos<p.yPos+12
       &&jjObjects[i].state!=STATE::KILL
       &&jjPlayers[jjObjects[i].creator].playerID!=p.playerID
       &&jjPlayers[jjObjects[i].creator].teamRed==p.teamRed)
      {
        if(p.health<jjMaxHealth)
        {
          p.health=p.health+1;
        }
        jjObjects[i].state=STATE::KILL;
      }
    }
  }
}
This script has no properties to edit.
__________________

I am an official JJ2+ programmer and this has been an official JJ2+ statement.

Last edited by Sir Ementaler; Feb 2, 2013 at 11:09 AM. Reason: Improved day / night cycle script.