New battle system

Started by Construed, Wed 22/02/2012 20:53:33

Previous topic - Next topic

Construed

Looking for positive and constructive replies only please.

Code: ags

// Placed in the actual Fight room 

function room_AfterFadeIn()
{
monsterui.Visible=true; 
player.PlaceOnWalkableArea();
object[1].SetView(84);
object[1].Animate(0, 3, eOnce, eBlock);

}


function room_RepExec()
{
  player.ChangeView(82);
  
 if (IsKeyPressed(eKeyUpArrow) == 1){
   

object[0].SetView(83);
object[0].Animate(0, 3, eOnce, eBlock);
object[0].Animate(1, 3, eOnce, eBlock);
monsterz-=5;


object[1].SetView(84);
object[1].Animate(0, 25, eOnce, eBlock);

health-=5;


 }
 
 else if (monsterz<=0) {
  int p=player.PreviousRoom;
  player.ChangeView(18);
  player.ChangeRoom(p);

 if ((expierance % 1) == 0) {
 level++;
 expierance += 15;
  player_maxhealth += 5;
  player_maxmana += 5;
  player_maxstamina += 5;
  strength += 1; 
  Display ("You have reached level %d And now have, %d strength, %d health, %d mana, %d stamina, %d gold",level, strength, player_maxhealth, player_maxmana,player_maxstamina, goldshow );
 int win=Random(2);
 monsterui.Visible=false; 
if (monsterz <= 0){
monsterz=5;
  

if (win==0)  goldshow += 20;


else if (win==1) goldshow += 10;

 
else goldshow += 5;

}

 }
  
}
 
 
 
}



And the random monster attack code placed in rooms which event shall occur:

Code: ags

function room_RepExec()
{
  
  
  
goblin.FollowCharacter(player, 0, 0);

if (player.IsCollidingWithChar(goblin) == 1){
    player.ChangeRoom(301); 

}




}

function room_AfterFadeIn()
{
 
int ran=Random(500);
if (ran==10) goblin.ChangeRoom(20, 286, 126);
}


I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Atelier

#1
I noticed this:

Code: ags

int p=player.PreviousRoom;
player.ChangeRoom(p);


Whereas you know you can just do:

Code: ags

player.ChangeRoom(player.PreviousRoom);


It does exactly the same thing and you cut out an obsolete line of code.

Also a quick note about indenting brackets, and indentation in general. People may go on and on about this, I had messy scripts when I first started, but once you get into a habit there's something satisfying about organising your code. It will save your life.

Code: ags

}

 }
  
}
 
 
 
}


This is very messy. If you stagger them like this:

Code: ags

               }
          }
     }
 
 }


You get a much better picture of which chunks of code are the 'children' of others, and it will help you to spot errors. For example:

Code: ags

function room_AfterFadeIn()
{
     monsterui.Visible=true; 
     player.PlaceOnWalkableArea();
     object[1].SetView(84);
     object[1].Animate(0, 3, eOnce, eBlock);
}


function room_RepExec()
{
     player.ChangeView(82);
     
     if (IsKeyPressed(eKeyUpArrow) == 1) {
   
          object[0].SetView(83);
          object[0].Animate(0, 3, eOnce, eBlock);
          object[0].Animate(1, 3, eOnce, eBlock);
          monsterz-=5;
          object[1].SetView(84);
          object[1].Animate(0, 25, eOnce, eBlock);
          health-=5;
     }
 
     else if (monsterz<=0) {

          player.ChangeRoom(player.PreviousRoom);

          if ((expierance % 1) == 0) {

               level++;
               expierance += 15;
               player_maxhealth += 5;
               player_maxmana += 5;
               player_maxstamina += 5;
               strength += 1; 
               Display ("You have reached level %d And now have, %d strength, %d health, %d mana, %d stamina, %d gold",level, strength, player_maxhealth, player_maxmana,player_maxstamina, goldshow );
               int win=Random(2);
               monsterui.Visible=false; 

                    if (monsterz <= 0) {

                         monsterz=5;
  
                              if (!win)  goldshow += 20;
                              else if (win) goldshow += 10;
                              else goldshow += 5;

                    }
          }
     }

}


I haven't checked your code at all, just set it out for others to look at...

Lt. Smash

Hey Grim Fandango,
would be nice if you could add comments to your code or tell us what is supposed to happen.
Otherwise it's difficult for me to help you.
A screenshot of the actual fight scene or how it "should" look like could help a lot.

At the moment this doesn't really look like a battle system to me. Everything looks way too static.

I would suggest you to tidy up your code and organize everything in smaller functions/structs.
Idea: You could make a struct Fighter with attributes like strength, health, mana,... and functions like hit(Fighter enemy).
Then you make an array of Fighters and asign each Fighter different strength, mana, etc. Keep Fighter[0] as the player.

Ryan Timothy B

#3
What are you asking for here? I've read through your code, it's very basic and still contains issues.

For instance this:
Code: ags

if (IsKeyPressed(eKeyUpArrow) == 1) {
          //attack monster code
     }
     else if (monsterz<=0) {
          //check if monster is dead
     }

That segment right there. If I were to press and hold the Up arrow to attack the monster it would Never enter the Check if monster is dead segment of code if I were still holding the Up Arrow, because it's an Else If.

Here's pseudo code to it's limits:
If (Up Arrow is pressed) run code
else if (monster is out of health and Up Arrow is not being pressed) kill monster

Then there's this (which wasn't spelled correctly, but that's not the point):
Code: ags

if ((expierance % 1) == 0) {

Do you know what this does? It checks what the remainder of experience divided by 1 is. Everything will result in 0, so there is no need to even have this line of code.

Since 10 divided by 1 has a remainder of 0. 11 divided by 1 has a remainder of 0. Even 0 divided by one will have a remainder of 0. Every number.

This battle code is very poor and leaves me asking "What's the point of it?". As Smash said, it's very static and will result in the same thing if you're on Level 10 or Level 200000. The monster will always die at the same amount of hits as if you're on Level 0.


Edit:
Even this, I have no idea what you're getting at:
Code: ags

int win=Random(2);
if (!win)  goldshow += 20;
     else if (win) goldshow += 10;
          else goldshow += 5;

This is what you've got here:

If (win equals zero) goldshow += 20;
     else if (win is one or higher) goldshow += 10;
          else (This will NEVER run) goldshow += 5;


Not to add to this hatred you believe everyone has for you, but you're WAY out of your league on this one. Take it from someone who could actually program a real RPG with AGS. You're not even close to the level of understanding logic.

It's not meant as an insult. Just being honest. You should learn to crawl before you learn to run. That's how we all had to learn.

Shane 'ProgZmax' Stevens

#4
QuoteThat segment right there. If I were to press and hold the Up arrow to attack the monster it would Never enter the Check if monster is dead segment of code if I were still holding the Up Arrow, because it's an Else If.


There's another obvious problem to this method that Ryan overlooked, and that's the effect of pressing up without imposing a delay between recognizing presses would literally kill anything you came into contact instantly.  Put another way, the way you have it now, pressing up near a creature and holding it for a second will result in as many hits as the engine has cycled during that period.  The solution here is to create your own delay variable for any combat related moves and wrap them inside something like this:

Code: ags


//somewhere in global or in the combat script
int combat_timer=0;


if(combat_timer<=0)
{
     //allow the game to actively search for user input
     if(IsKeyPressed(eKeyUpArrow) == 1)
     {
          //enemy took some damage.  Reset the combat timer so I can't immediately retrigger this event.
          combat_timer=20;

     }

}
else
{
    combat_timer-=1;

}




So long as this code is run freely during combat sequences you'll have a zeroed out combat_timer waiting for your input, but now you'll notice a delay before it will accept further input.  This is something you'll find infinitely useful when doing any kind of interactive game logic because you will often run into events that need timing.


My advice is to try and put together a working demo of what it is you're after and then present us with that along with the source and any questions you may have as right now we're only getting to see pieces of a much larger plan.

Construed

Hey guys, I thank you greatly for your replies, Unfortunately my game.agf had a terrible crash and set the game back weeks, destroying the battle system,1/4 of the views and fragmenting my code to all hell.
And although i though i had it backed up i apparently did not.
But again i thank you guys greatly and i will use this code and your suggestions in my next game if it manages to spawn.
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

SMF spam blocked by CleanTalk