Feeks EBS item implementing

From Spheriki

Jump to: navigation, search

This is recommended for those who have read over and did the Feeks easy battle system tutorial. Because you'll need my system to add the items in. Or you can read the explanations and figure it out for your system.

Contents

Remember the script

So you read the last tutorial eh? You wondered why I added the items area and spells area even though I didn't go through with it. Well the answer is simple. It's whole 'nother concept! What is special about items is that they effect the battle, they effect you, and it takes typing time to write it out!

Change the script

So, there was a perticular area that you must have pondered over? Maybe the moving box(which was overkill for the unexperienced). Maybe the layout and positions. well I made the system able for upgrade. This is the items upgrade.

There was a menu code that went much like this:

var options = new Array("Attack","Items","Spells","Flee","Back");
var CurrentOption = 0;
var Gray = CreateColor(175,175,175);

function BattleMenu()
{
  window.drawWindow(sw-67,sh-67,62,64);
  Rectangle(sw-67,sh-64+CurrentOption*12,62,12,Gray);
  for (var i = 0; i < options.length; ++i)
  {
    font.drawText(sw-67,sh-67+i*12,options[i]);
  }
  if (IsKeyPressed(KEY_DOWN) == true && CurrentOption < options.length-1)
  {
    Delay(150); // Finger reflex time
    CurrentOption++;
  }
  if (IsKeyPressed(KEY_UP) == true && CurrentOption > 0)
  {
    Delay(150); // Finger reflex time
    CurrentOption--;
  }
  if (IsKeyPressed(KEY_ENTER) == true)
  {
    if (CurrentOption == 0)
    {
      Delay(150);
      battlemenu = false;
      attack = true;
    }
    if (CurrentOption == 1)
    {
      Delay(150);
      battlemenu = false;
    }
    if (CurrentOption == 2)
    {
      Delay(150);
      battlemenu = false;
    }
    if (CurrentOption == 3)
    {
      battlemenu = false;
      var i = Math.floor(Math.random()*10);
      if (i > 2)
      {
        Delay(250);
        TextMe("You ran away safely!",3,7,sw-6,32);
        Exit();
      }
      if (i < 2)
      {
        Delay(250);
        TextMe("The Enemies have blocked your path!",3,7,sw-6,32);
        enemyattack = true;
      }
    }
    if (CurrentOption == 4)
    {
      Delay(150);
      battlemenu = false;
    }
  }
}

Option 1 was the items menu. Lets think ahead and add some changes. Here are the changes:

if (CurrentOption == 1)
 {
   Delay(150);
   battlemenu = false;
   itemsmenu = true;
 }

'itemsmenu' will be a global that we'll add later. For now if you run the system, don't press the items block.

Add the items

Items, items, items... They are listed. Lets make an array just like enemys or players, lets name it 'items':

var items = new Array();

So what will the function be for setting them up?

item setup

I'm going to make a function for them.

Here will be the function, put this into another script file. Call it 'items.js' keep adding data to 'items.js' until I say otherwise. It's important to do so, so you don't put too much scripts in the main file. It is also a way to organize your thoughts and codes. It also looks proffesional :). :

function item(name,amount)
{
this.name = name
this.ability = null // for now.
this.amount = amount;
this.healamount = 0;
this.damage = 0;
}

In my items array i'll have two perticular items, an item that heals you(the Hpotion), an item that replenishes your mp (the Mpotion) and an item that harms enemies (the fire wand), also a bonus, the revive!

items[0] = new item("HPotion",2);
items[0].healamount = 4;
items[0].ability = heal(items[0].healamount); // select player target

items[1] = new item("MPotion",3);
items[1].healamount = 5;
items[1].ability = replenish(items[1].healamount); // select player target

items[2] = new item("FireWand",5);
items[2].damage = 10; //!!!
items[2].ability = damage(items[2].damage); // select enemy target

items[3] = new item("Revive",1); // select player target
items[3].ability = revive();

inventory setup

arraying the items

using them in battle

Personal tools