RPG Battle Scripts

Started by Kreator, Fri 23/03/2007 06:19:00

Previous topic - Next topic

Kreator

I'm working on a game called Azunite's tale, Its an adventure/RPG. I would like to know battle styles you can script with AGS. At the moment, the battle system in my game is turn based. You walk around the maps, and monsters/ enemys aproach and hang around.
    To fight them, you have to equip an item from your inventory and use it on them. In response, this will do damage to them and the enemy will attack you back. I added effects, random damage counters and displayed messages in battle. I also made you do more damage and have a higher maximum health as you gain experiece and level up.

If you want to know the battle script i used, just ask.

If you know any others, Especially freestyle fighting (like zelda) please tell me  :)

If you want to check out my game, go to the "in production forum or visit my website at: http://infernal-softworks.wetpaint.com/

Well i have developed my own turned based battle script. I'd rather make a freestyle battle script like Zelda, but I'm not sure how, so I'll stick with my turn-based method. I'll teach you all i can about my script, so you should hopefully be able to make your own.

First of all, you need global variables to define your health, mana etc. This script goes in the Game Start section of the global script.

Code: ags

  GiveScore(6); //Health. You can also use GlobalInt for this.
SetGlobalInt(2,0); //Mana
SetGlobalInt(3,0); //Exp-Combat.
SetGlobalInt(5,0); //Exp-Magic.
SetGlobalInt(7,1); //Character Level melee.
SetGlobalInt(8,1); //Character Level mana.
SetGlobalInt(9,3); //Wild Dog's HP
SetGlobalInt(10,5); //Tiger's HP
SetGlobalInt(11,2); //Killer bee's HP


to make these visible on the GUI, you have to make another script in the repeatively execute section. This script creates the string name, and uses the global variables (which was the first script). I also shows where the variables will be shown on the GUI.

Code: ags

    string mana;
StrFormat (mana, "%d", GetGlobalInt (2));
SetLabelText (0, 2, mana); //so the mana points will be shown in the GUI 0, Label 2) 
    string melee;
StrFormat (melee, "%d", GetGlobalInt (3));
SetLabelText (0, 7, melee); //so the melee points will be shown in the GUI 0, Label 7) 
    string nature;
StrFormat (magic, "%d", GetGlobalInt (5));
SetLabelText (0, 8, magic); //so the magic points will be shown in the GUI 0, Label  
    string level;
StrFormat (level, "%d", GetGlobalInt (7));
SetLabelText (0, 11, level); //so the level points will be shown in the GUI 0, Label 11) 
    string MLV;
StrFormat (MLV, "%d", GetGlobalInt ();
SetLabelText (0, 14, MLV); //so the mana level points will be shown in the GUI 0, Label 14) 


This is the death script i have located under the GUI script under repeatively execute.

Code: ags

//DEATH
if (game.score < 1) {
if (cPlayer.room!=2){
StopMusic();
PlaySound(1);
cPlayer.Animate(8, 0, eOnce, eNoBlock, eBackwards);
NewRoom(2);}
}


This defines the maximum HP levels for your character

Code: ags

//Health maximum levels
if (GetGlobalInt(3)<10) { //globalint 3 is melee EXP
  if (game.score >6){
    GiveScore(-1);} // so this means that if your health increases over 6 HP when you have less then 10 EXP in melee, then you will lose one HP. This will keep dropping until your hp is under 7.
  }
  if (GetGlobalInt(3)<30) {
  if (game.score >{
    GiveScore(-1);}
  }
  if (GetGlobalInt(3)<60) {
  if (game.score >10){
    GiveScore(-1);}
  }
  if (GetGlobalInt(3)<100) {
  if (game.score >12){
    GiveScore(-1);}
  }
  if (GetGlobalInt(3)<150) {
  if (game.score >14){
    GiveScore(-1);}
  }
  if (GetGlobalInt(3)<210) {
  if (game.score >16){
    GiveScore(-1);}


Similar story with Mana

Code: ags

  //Mana Maximum Levels
  if (GetGlobalInt(5)<10) {
  if (GetGlobalInt(2)!=0) {
    SetGlobalInt(2,0);}
  }
  if (GetGlobalInt(5)<30) {
   if (GetGlobalInt(2)>=6) {
   SetGlobalInt(2,GetGlobalInt(2)-1);}
  }
  if (GetGlobalInt(5)<60) {
  if (GetGlobalInt(2)>=8) {
    SetGlobalInt(2,GetGlobalInt(2)-1);}


This is how you go up a level in melee

Code: ags

//Level up melee
if (GetGlobalInt(3)>9) {
if (GetGlobalInt(7)==1) {
SetGlobalInt(7,GetGlobalInt(7)+1);
Display("You have gained a level for fighting with melee weapons.");
GiveScore(;}
}
if (GetGlobalInt(3)>29) {
if (GetGlobalInt(7)==2) {
SetGlobalInt(7,GetGlobalInt(7)+1);
Display("You have gained a level for fighting with melee weapons.");
GiveScore(10);
}


BATTLING
this is an example battle script.

Code: ags

object[0].SetView(13); the objects are special effects which animate when you attack.
object[1].SetView(14);
PlaySound(6); // the sound of you attacking
object[0].Animate(0, 0); // the special effect animates
Display ("You attacked the Wild Dog with your fists.");
SetGlobalInt (9, GetGlobalInt(9)-1); //enemy HP is decreased 1 point
SetGlobalInt (3, GetGlobalInt(3)+2);//gained 2 exp. for fighting.

if (GetGlobalInt(9) <= 0) {  //if he has no HP left, he disapears to an empty room, and his corpse from the empty room takes his place in the current room.
PlaySound(7);
cWolf.ChangeRoom(1);
cDeadwolf.ChangeRoom(19, 145, 145);
Display ("You killed the Wild Dog");
RestoreWalkableArea(2); //if the enemy was blocking a bridge or something, the area behind him will become walkable.
GUIOn (;
Wait(250);
GUIOff(;}
else{ // if he still has HP left, the enemy will attack you back
  PlaySound(;
object[1].Animate(0, 0);
Display ("The Wild Dog bites you with its fangs.");
GiveScore(-1);


You can make your attacks or the enemys do random damage with this script

Code: ags

//Random Damage Counter
int ran=Random(3);
if (ran==0)SetGlobalInt (10, GetGlobalInt(10)-1); //enemy HP is decreased 1 point
if (ran==1)SetGlobalInt (10, GetGlobalInt(10)-1); //enemy HP is decreased 2 point
if (ran==2)SetGlobalInt (10, GetGlobalInt(10)-1); //enemy HP is decreased 3 point
if (ran==3)SetGlobalInt (10, GetGlobalInt(10)-1); //enemy HP is decreased 4 point


Different damage counters depending on your melee level

Code: ags

  //Fist Damage lv1
if (GetGlobalInt(7)==1) {
object[0].SetView(13);
object[1].SetView(21);
PlaySound(6);
object[0].Animate(0, 0);
Display ("You attacked the Killer Bee with your fists.");
SetGlobalInt (11, GetGlobalInt(11)-1); //enemy HP is decreased 1 point
SetGlobalInt (3, GetGlobalInt(3)+2);//gained 2 exp. for fighting.
}
//Fist Damage lv2
if (GetGlobalInt(7)==2) {
object[0].SetView(13);
object[1].SetView(21);
PlaySound(6);
object[0].Animate(0, 0);
Display ("You attacked the Killer Bee with your fists.");
//Random Damage Counter
int ran=Random(3);
if (ran==0)SetGlobalInt (11, GetGlobalInt(11)-1); //enemy HP is decreased 1 point
if (ran==1)SetGlobalInt (11, GetGlobalInt(11)-1); //enemy HP is decreased 1 point
if (ran==2)SetGlobalInt (11, GetGlobalInt(11)-1); //enemy HP is decreased 1 point
if (ran==3)SetGlobalInt (11, GetGlobalInt(11)-2); //enemy HP is decreased 2 point
if (ran==3)Display("Critical Hit");
//XP
SetGlobalInt (3, GetGlobalInt(3)+2);//gained 2 exp. for fighting.
}


I hope this helped you, If you know all the basics of AGS scripting you should be right. If you don't then this might be hard to understand. Well i hope i helped anyway. Let us know if it helped you.

And to make my backgrounds, I didn't use a tile program. I drawed my own tiles (and got some from other people) and then saved them to a few big BMPS, and then used windows paint (yes thats right) and copied and pasted the bits together myself.

The paint program i use most often though, is called Paint.Net. Its worth downloading. I also use special effect programs such as light effects. Well i hoped this helps you.

Khris

You can use the code- or the pre-tag to avoid things ending up as smiley.

Btw, you are using GlobalInts as well as old style code, neither is recommended for an up-to-date tutorial.

Kreator

#2
Yes, It isn't very up to date is it. Thanks for letting me know. I actually wrote this script on an older version of AGS some time ago. I have the newer version, perhaps i should write it up again.

SMF spam blocked by CleanTalk