Battle engine hell (SOLVED)

Started by Construed, Sat 10/03/2012 21:55:07

Previous topic - Next topic

Construed

This is the room code that makes the monster appear in the room and follow the character and when the character and player collide it transports the player to the battle room:

Code: ags

function room_RepExec()
{

//If goblin character = the alive view and is colliding with player, Display battle message and move player to room 301, the battle room.

if ((goblin.View==88)&&((player.IsCollidingWithChar(goblin) == 1))){
    Display("Hostile intent is evident,  You prepare for battle.");
    player.ChangeRoom(301); 
    goblin.FollowCharacter(null);
}

  }

//Random chance of the monster appearing when the player enters the room.
function room_AfterFadeIn()
{
int ran=Random(7777);
 if (ran==777) goblin.ChangeRoom(21, 279, 121);
}

//Makes the living goblin character follow the character.
function room_FirstLoad()
{
goblin.FollowCharacter(player, 0, 0);
}

//Resets the goblin after he has been killed and the player leaves the room and changes him back to his living view with his beginning amount of life.
function room_Leave()
{
   goblin.ChangeView(88);
   monsterz=35;
   goblin.FollowCharacter(player, 0, 0);
}


This is the battle room code where the battle takes place, then the player is transported back to the previous room he was in afterwards:
Code: ags



function room_AfterFadeIn()
{
//Turns on the monster/player lifebar "monsterui", places the character in the correct position for the battle.
   monsterui.Visible=true; 
   player.PlaceOnWalkableArea();

//changes the object which acts as the characters sword and hand to the correct one
   object[1].SetView(56);
   object[1].Animate(0, 3, eOnce, eBlock);

//makes the goblin character stop following so when the battle is over the goblin corpse wont follow you lol.
   goblin.FollowCharacter(null);
   object[1].SetView(56);
   object[1].Animate(0, 3, eOnce, eBlock);
}

function room_RepExec()
//Depending on which character the player chooses this changes him and the sword/hand object to the correct battle view.
{
 if ((player.View==42)||(player.View==16)) {
  player.ChangeView(85);
  object[0].SetView(82);
}
 else if ((player.View==17)||(player.View==59)) {
    player.ChangeView(87);
    object[0].SetView(84);
  }
 else if ((player.View==18)||(player.View==58)) {
    player.ChangeView(86);
    object[0].SetView(83);
     }
  
  
//animates the sword/hand object 
 if (IsKeyPressed(eKeyUpArrow) == 1)
{
    object[0].Animate(0, 3, eOnce, eBlock);
    object[0].Animate(1, 3, eOnce, eBlock);

//Causes the monster random damage.
    int dmg = Random(5);
    monsterz -= dmg + 1;

//Animates the monster object.
    object[1].SetView(56);
    object[1].Animate(0, 25, eOnce, eBlock);

//Random damage the monster causes
 if (dmg==0)  health-=0;
  else if (dmg==1) health-=1;
   else if (dmg==2) health-=2;
    else if (dmg==3) health-=3;
     else if (dmg==4) health-=4;
      else if (dmg==5) health-=5;
}
 
//if the monster is dead bring the player back to the room he was in before and placeonwalkable.
 else if (monsterz<=0) {
    int p=player.PreviousRoom;
    player.ChangeRoom(p, 160, 120);
    goblin.ChangeRoom(p, 160, 120);
    player.PlaceOnWalkableArea();
  
///Still trying to figure out the best way to decrease the amount of experience gained and stats gained as the player levels
 if (level == 1) {
  
   level++;
   expierance += 15;
   player_maxhealth += 1;
   player_maxmana += 1;
   player_maxstamina += 1;
   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 );

 if (level > 2) 
{
   level++;
   expierance += 12;
   player_maxhealth += 1;
   player_maxmana += 1;
   player_maxstamina += 1;
   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 );
 
 if (level > 3) {
   level++;
   expierance += 10;
   player_maxhealth += 1;
   player_maxmana += 1;
   player_maxstamina += 1;
   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 );

///gives the player a random amount of gold after the battle.
   int win=Random(2);

 if (monsterz <= 0){

  if (win==0)  goldshow += 20;
  
   else if (win==1) goldshow += 10;
  
    else goldshow += 5;
   
               }
            }   
         }
      }
   }
}

///secondary check to make sure the player changes to the correct view for the battle scenedepending on which character he chose.

function room_Load()
{
 if ((player.View==42)||(player.View==16)) {
   player.ChangeView(85);
   object[0].SetView(82);
}
 else if ((player.View==17)||(player.View==59)) {
    player.ChangeView(87);
    object[0].SetView(84);
}
 else if ((player.View==18)||(player.View==58)) {
    player.ChangeView(86);
    object[0].SetView(83);
    }

}

///Displays defeat message, changes the player back to his correct non-battle view, sends a message to the server that the players speed has changed and sets the character to walking speed and view.
function room_Leave()
{
   Display("You have triumphed over your enemy!");
 if (player.View==85){
   player.ChangeView(16);
   CafeDo(String.Format("speed is %d %d", 5, 5));
   player.SetWalkSpeed(5, 5);
}
  else if (player.View==86) {
    player.ChangeView(18);
    CafeDo(String.Format("speed is %d %d", 5, 5));
    player.SetWalkSpeed(5, 5);
}
 else if (player.View==87) {
   player.ChangeView(17);
   CafeDo(String.Format("speed is %d %d", 5, 5));
   player.SetWalkSpeed(5, 5);
}
///removes the healthbars.
   monsterui.Visible=false; 
///changes the goblin to the dead corpse view.
   goblin.ChangeView(89);
}






Goblin following character until it collides and starts battle:



Inside the battle room:



It's really messy and some beta testing might be necissary to fully understand it, any help would be greatly appreciated.
If you have any requests on syntax,grammar or explanations please let me know!
But be specific, Remember I am feeble minded  :-\


I need to figure out a better way to tally the expeirance and level ups also probley need some type of adjustment as to how much strength,stamina,health,gold etc.... is added....
It needs ALOT of work :(

PS. I will clean up, organize and format the code as I find time to do so.
I'm not asking anyone to help me with all the problems at once, just give me small little tips here and there, my mind is not advanced enough to handle more than small tidbits at a time.


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

Khris

Code: ags
 int dmg=Random(5);

if (dmg==0)  monsterz-=1;
  

else if (dmg==1) monsterz-=2;

else if (dmg==2) monsterz-=3;

else if (dmg==3) monsterz-=4;

else if (dmg==4) monsterz-=5;

else if (dmg==5) monsterz-=6;


                \/
Code: ags
  int dmg = Random(5);
  monsterz -= dmg + 1;


These two lines will do the same as your seven.
(Just a tidbit for now, until you've cleaned up the code.)

Victor6

Well, straight off your level up code is doubling up from level 4 onwards (4 > 2 & 4 > 3)

You really need an xpnext variable. check if xp > xpnext, if so increase stats, increase xp next.(or, reset xp to 0, and award xp based on level)

Construed

Yes, I am inexperienced with that type of code as of yet and still researching it, It would be greatly helpful if you or some could show me a piece of example code.

Thanks

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

Construed

Quote from: Khris on Sat 10/03/2012 22:54:22
Code: ags
 int dmg=Random(5);

if (dmg==0)  monsterz-=1;
  

else if (dmg==1) monsterz-=2;

else if (dmg==2) monsterz-=3;

else if (dmg==3) monsterz-=4;

else if (dmg==4) monsterz-=5;

else if (dmg==5) monsterz-=6;


                \/
Code: ags
  int dmg = Random(5);
  monsterz -= dmg + 1;


These two lines will do the same as your seven.
(Just a tidbit for now, until you've cleaned up the code.)

Sorry khris, Didn't see your post at first.
I dont exactly understand the logic of that code however I will trust you on it.
I changed it in the above script.
Thanks for the advice :D
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

Ok, I cleaned it up and commented it the best i can.
I really have no clue about formatting the code.

Thanks for taking the time to read,
-Jared
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Victor6

2 quick methods (probably full of coding errors)
Code: ags

// Insert this code when you award xp
experience+=15; // award the xp
if(experience > xpnext){
// Insert your stat changes here.
level++;
xpnext = (5*(level*level))+10; // sets the next xp requirement based on the current level. 
// lvl 1:15, lvl2: 30, lvl3: 55, lvl4 90, etc. levels become progressively harder to gain.
if (experience > xpnext){ experience = xpnext-1; } // not required, but this will prevent double levels.
}

This gives you a classic xp method (like dungeons and dragons). Monsters still award the same xp, you just need to kill more of them to level up again. You might want to introduce a level cap (i.e. if (level < 10){ .... ), to prevent things getting out of hand.

OR
Code: ags

// Insert this code when you award xp
int xp = monster_xpvalue-level // the amount of xp awarded decreases as the player levels up. so you can't farm low level mobs.
if (xp > 0){ // stops negative xp awards
experience+=xp;
}
if(experience > xpnext){
// Insert your stat changes here.
level++;
experience = 0; // set experience to zero again, and you now get less xp per mob.
}

The advantage of this method is that it automatically level caps the player. Players can't farm 6 million boars to reach level 60. Once they reach a certain point even the biggest monsters won't award xp.

You can also scale your stat changes rather than code separate entries;
something like:
Code: ags

int hpgain;
hpgain = 10-level; // so you gain 9hp at lvl 1, 8 at level 2, 7 at 3......
if (hpgain < 0){ hpgain = 0; } // stops negative gains, (maxhp loss).
player_maxhealth+=hpgain;


It's up to you to adjust the formulas to your own design.

Khris

I'm sorry, I was more or less joking. I posted the same thing in the previous thread, which lead to all kinds of silliness, and since you've opened a new thread about this for the third or forth time like nothing ever happened, I played along. (The code is sound though, and always was.)

The thing is, until you can understand why my suggestion does the same thing as your code, this thread is pointless.
Victor6 means well, but snippets like his won't help you at all because you can't implement them properly.

You lack the basics of programming needed for something like a battle engine, and to actually help you, we'd have to basically code it for you in its entirety.

Please accept that at this point, what you should do is either recruit somebody to code the battle engine for you or give up for now and do some programming tutorials. If you don't even know how to indent code properly, you are pretty much unable to use the technical forum for what it's intended.

I know this sounds harsh, but you aren't the first person I'm telling this. It's got nothing to do with you personally, I'm simply stating what I perceive as facts.

Don't get all worked up over this. Maybe others won't see it like that and continue to help you here. But I see myself unable to do anything for you short of coding the entire thing for you (which I don't have the energy nor time for currently).

Construed

Quote from: Victor6 on Sun 11/03/2012 00:17:45
2 quick methods (probably full of coding errors)
Code: ags

// Insert this code when you award xp
experience+=15; // award the xp
if(experience > xpnext){
// Insert your stat changes here.
level++;
xpnext = (5*(level*level))+10; // sets the next xp requirement based on the current level. 
// lvl 1:15, lvl2: 30, lvl3: 55, lvl4 90, etc. levels become progressively harder to gain.
if (experience > xpnext){ experience = xpnext-1; } // not required, but this will prevent double levels.
}


This gives you a classic xp method (like dungeons and dragons). Monsters still award the same xp, you just need to kill more of them to level up again. You might want to introduce a level cap (i.e. if (level < 10){ .... ), to prevent things getting out of hand.

OR
Code: ags

// Insert this code when you award xp
int xp = monster_xpvalue-level // the amount of xp awarded decreases as the player levels up. so you can't farm low level mobs.
if (xp > 0){ // stops negative xp awards
experience+=xp;
}
if(experience > xpnext){
// Insert your stat changes here.
level++;
experience = 0; // set experience to zero again, and you now get less xp per mob.
}

The advantage of this method is that it automatically level caps the player. Players can't farm 6 million boars to reach level 60. Once they reach a certain point even the biggest monsters won't award xp.

You can also scale your stat changes rather than code separate entries;
something like:
Code: ags

int hpgain;
hpgain = 10-level; // so you gain 9hp at lvl 1, 8 at level 2, 7 at 3......
if (hpgain < 0){ hpgain = 0; } // stops negative gains, (maxhp loss).
player_maxhealth+=hpgain;


It's up to you to adjust the formulas to your own design.
Yea, it's going to take awhile for me to figure out how the global vars and ints etc have to be setup with that,
Like I don't know what monster_xpvalue is supposed to be, or xpnext .
However this is the last functions i need for me to be happy with my battle system, If i can figure out how to use this i can implement the system gamewide.
think the expeirance system is a little diffrent, the way i have mine setup mine has a max value of 99999 which the user builds up to per fight.


Quote from: Khris on Sun 11/03/2012 02:53:08
I'm sorry, I was more or less joking. I posted the same thing in the previous thread, which lead to all kinds of silliness, and since you've opened a new thread about this for the third or forth time like nothing ever happened, I played along. (The code is sound though, and always was.)

The thing is, until you can understand why my suggestion does the same thing as your code, this thread is pointless.
Victor6 means well, but snippets like his won't help you at all because you can't implement them properly.

You lack the basics of programming needed for something like a battle engine, and to actually help you, we'd have to basically code it for you in its entirety.

Please accept that at this point, what you should do is either recruit somebody to code the battle engine for you or give up for now and do some programming tutorials. If you don't even know how to indent code properly, you are pretty much unable to use the technical forum for what it's intended.

I know this sounds harsh, but you aren't the first person I'm telling this. It's got nothing to do with you personally, I'm simply stating what I perceive as facts.

Don't get all worked up over this. Maybe others won't see it like that and continue to help you here. But I see myself unable to do anything for you short of coding the entire thing for you (which I don't have the energy nor time for currently).
Yea, In all reality this system shouldn't work as well as it does, but by blessing of god it does, All i need really is as victor posted for the system to be complete.
Hopefully i can figure it out eventually...
Not many coders around are intrested in helping with such a thing.
So i guess its like they say.
If you dont put your foot in the water you'll never learn to swim.

Thanks guys

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

Icey

I don't know if it's been answered yet but I'm gonna take a shot at it. I gonna start by saying that since my RPG's code is different from most people who try to make one in AGS it may be just a tad bit confusing but I will explain to you.
Code: ags

I'm not show what inside the brackets cause I don't wan't everyone to know how my leveling system works.
 
 if(playerLV == 99){
  
  }
  else{
  playerLV += 1;
  }
  
  
  if(playerLV == 1 - 10){

    
  }
  if(playerLV == 11 - 25){

    
  }
  if(playerLV == 26 - 40){

    
  }
  if(playerLV == 41 - 70){

    
  }
  if(playerLV >= 70){
 
    
  }


I have the game check if the play is Lv.99 first. If he is not then move on to the leveling. Now what I have it does it have it check for whether the player is between Lv.1-10 and if they are then give then just a bit of HP/MP+ and increase their base EXP. Now you can put what ever you would like to in there cause I don't include all the stamina stuff as my games goes by a different stat system. I have a few other variable that sting together the stat net. But I don't think I need to show all of those if I'm trying to explain this little chunk.

Hernald

#10
Icey; that code is interesting;
I would have sworn it was the same as having
Code: ags

 if(playerLV != 99){
    playerLV += 1;
  }


if(playerLV ==  -9){

    
  }
  if(playerLV == -14){

    
  }
  if(playerLV == -14){

    
  }
  if(playerLV == -29){

    
  }
  if(playerLV >= 70){
 
    
  }




So I've learned something new!  ;D

Icey

I think you may be pulling my leg but let's say I did use that. What would happen is ist would do some checks between the current level and the End Level. I checking for equals to or in between not player level...something I don't it's to late for me to try to figure that out even if it is simple. All I know is my set currently works for me so I'm gonna stick with until the end. :D

IDK grim, His could work and maybe better than mine so you can try ether one.  ;)

Hernald

#12
Sorry Icey, yes I was being facetious. I don't believe the code you have given will work in the way you think it will.
My version would be:
Code: ags

if(playerLV < 99){
   playerLV++;

   if(playerLV <= 10){

    
   }
   else  if(playerLV <= 25){

    
   }
   else  if(playerLV <= 40){

    
   }
   else  if(playerLV <= 70){

    
   }
   else {
   }
    
}



The "-" character means "subtract" in the context you have given it.  I haven't found anything in the manual about it being used to mean "between". As far as I can see your code would never do anything if presented with a positve value.
But I haven't been working with AGS for long and would welcome input from someone with more experience than me in this.


Hernald

Hi Icey. I wasn't absolutely sure, so I tested your code with every number from -40 to 72.
The results were as I predicted; -29, -14,-14,-9,70,71 and 72 were displayed.
The code may work for you, but I doubt many people would find it useful in the form you showed us.

Icey

#14
ahh I see, thanks for clearing that up. I was at first think I could use the < sign alone but what happens is <= 10 ends up being the only thing read by the game. Same would happen in opposite effect if I used >.

Hernald

#15
Do you mean:
Code: ags

if(playerLV > 98){
   }
else {   
   playerLV++;

   if(playerLV >70){

    
   }
   else  if(playerLV >40){

    
   }
   else  if(playerLV >25){

    
   }
   else  if(playerLV >10){

    
   }
   else {
   }
    
}


?
I'm not sure why this code would behave in the way you seem to be suggesting. If you initialize playerLV to zero then call the code whenever a level-up is required it should go from one case to the next as playerLV is incremented - unless it is being reset to a value below 10 somewhere.

Khris

Icey:
Are you serious? What the hell?

OF COURSE you can use < alone. if (a < 4) does the same as if (a <= 3).
What you can NOT do, and what nobody ever suggested to you, and what sure as hell didn't work for you at any time, and most importantly, what you have no business posting in a help thread made by a guy who doesn't have a clue himself, is if (lvl == 1 - 10).
You can't take shortcuts like that in AGS, you have to use both conditions separately: if (lvl >= 1 && lvl <= 10).

Now stop confusing GrimReapYou and get the hell out of this thread.

Hernald: please don't humor him like that, now we have clutter here and there's probably going to be a fifth thread about this whole sad issue.

Seriously, what the fuck is wrong with you people. I just got out of bed and the first thing I see before breakfast on a Sunday morning is this. ::) :P

Hernald

Sorry Khris. I'll get back to my game.

Khris

It's alright, it's not your fault.

Icey:
Also, the whole point of Victor6 and me posting here was to show that it's bad practice to use lots of else ifs when there's a clear pattern and one can use math instead.
But no, you waltz in here completely oblivious to anything posted before you, posting useless and wrong code.
Argh.
And you think you're ready to go commercial, on Steam? It'd be funny if it weren't so pathetic.

Construed

Well, thanks for trying icy, but yea... you code like me so....
and thanks for the humor hernald,
but yea... we dont need to get too off topic here for sure.

your a good guy khris, I dont care what they say  :=
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

SMF spam blocked by CleanTalk