Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Construed on Sun 09/01/2011 09:48:29

Title: Working on battle system, need advice please.
Post by: Construed on Sun 09/01/2011 09:48:29
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 09/01/2011 12:25:12
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 09/01/2011 12:42:11
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Matti on Sun 09/01/2011 13:08:15
Use a variable like so:


int monsterwait=80;

if (monsterwait>0) monsterwait--;

if (monsterwait==0){
  monsterwait=80;
  // Monster attacks
}


In this code the monster would attack every 2 seconds.

Btw:

Display("You hit the enemy for %d  damage!"); doesn't show any number for the actual damage.

Display("You hit the enemy for %d  damage!", damage); will show the variable "damage".
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 09/01/2011 13:31:40
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 09/01/2011 16:53:32
hjkhk
Title: Re: Working on battle system, need advice please.
Post by: Khris on Sun 09/01/2011 17:14:26
Quote from: GrimReapYou on Sun 09/01/2011 16:53:32if (ouch==0) health -= 0;
else if (ouch==1) health -= 1;
else if (ouch==2) health -= 2;
else if (ouch==3) health -= 3;
else if (ouch==4) health -= 4;
else if (ouch==5) health -= 5;
else if (ouch==6) health -= 6;
else if (ouch==7) health -= 7;
else if (ouch==8) health -= 8;
else if (ouch==9) health -= 9;
else if (ouch==10) health -= 10;


That's much more than needed:
  health -= ouch;

Why aren't you using the QFG template?
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 09/01/2011 17:46:04
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 09/01/2011 18:55:00
loves
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 09/01/2011 21:41:21
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Matti on Sun 09/01/2011 23:52:46
Just do it like this:


if (monsterwait==0 && !gDeathGUI.visible){
 monsterwait=80;
 // Monster attacks
}


And please don't double or triple-post. There's a modify button if you need it.
Title: Re: Working on battle system, need advice please.
Post by: Construed on Mon 10/01/2011 00:38:54
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Construed on Thu 13/01/2011 19:43:25
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Khris on Thu 13/01/2011 21:30:23
It's quite exhausting to try and help you; first of all nobody likes to wrestle through that much code, plus it's all pretty messy and buggy. You need to get a better grasp of how to program first, or trying to help you is always going to end up as a big frustrating back and forth.

I'll address the health potion section for now to point out what's wrong with it:

function Button11_OnClick(GUIControl *control, MouseButton button)
{
  if (goldshow < 5)   
  {   
  Display ("you cannot afford the Health potion.");
  goldshow += 5;
  player.LoseInventory(hpot);
weight -= 1;
  }     
 
  if (goldshow > 5){
player.AddInventory(hpot);
weight += 1;

  goldshow -= 5;
  }
}


A golden rule, especially for code others are going to see: use proper indentation.

I assume Button11 is for buying a potion. If the player clicks that with goldshow being less than 5, they get 5 gold and lose a potion only to have that reversed immediately afterwards (which kinda works, not always though, and is unnecessary). What you need is an else, so that the second part doesn't run if the player hasn't enough gold. Also, the second condition should be goldshow >= 5, I don't need 6 gold to buy something that's 5.
Another problem is that assuming the player doesn't have any potions, they won't lose one but then get one for free.

Here's the proper code:

function Button11_OnClick(GUIControl *control, MouseButton button) {

  if (goldshow < 5) Display ("You cannot afford the Health potion.");
  else { 
    player.AddInventory(hpot);
    weight += 1;
    goldshow -= 5;
    Display("Health potion purchased.");
  }
}


Next, there's this:

function hpot_UseInv()
{
  if (health >= 0){
health += 10;
player.LoseInventory(hpot);
weight -= 1;

  }
if(health>20) health = 20;

}


This will get called if you use another inventory item on the potion. It doesn't even matter which one.
What you want is either "interact with inventory item" or maybe the player's "use inv on character", in which case you'd do this:

function cEgo_UseInv() {  // generated by AGS, might not be cEgo but something else for you

  if (player.ActiveInventory == hpot) {
    health += 10;
    if (health > player_maxhealth) health = player_maxhealth;   // player_maxhealth is a global int variable
    player.LoseInventory(hpot);
    weight -= 1;
  }

  ... // other items
}
Title: Re: Working on battle system, need advice please.
Post by: monkey0506 on Fri 14/01/2011 05:23:51
Quote from: Khris on Thu 13/01/2011 21:30:23If the player clicks that with goldshow being less than 5, they get 5 gold and lose a potion only to have that reversed immediately afterwards

That's impressive, I must say. If anyone ever saw any of the code I actually have used in any of my published ..er.. "game" projects, they might just die at how badly it's coded. Then again..a lot of it is entirely intentional..like creating a function called "DoThatEndOfGameSpeechCreditsThingBasedOnTheCurrentPlayerCharacterThatYouLoveToDoSoMuch" (not an actual function name..but stunningly similar :P)..only to create a helper function which only calls that function, with the exact same parameter list, yet titled "do". ::)

Quote from: Khris on Thu 13/01/2011 21:30:23This will get called if you use another inventory item on the potion. It doesn't even matter which one.

Best. Programming. [Slash]. Game. Logic. Ever! ;D
Title: Re: Working on battle system, need advice please.
Post by: Construed on Fri 14/01/2011 07:56:26
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Construed on Fri 14/01/2011 09:53:23
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Khris on Fri 14/01/2011 12:34:38
How are you using the potion in-game? Because by default, hpot_UseInv() is called when you use an arbitrary inventory item on the potion. Do you have a drink-hand as inventory item or something?

Keep in mind that you can't simply change "hpot_UseInv()" to "cA_UseInv()" and be done; this will most likely result in an error since AGS is still trying to find the hpot_UseInv() function.
Title: Re: Working on battle system, need advice please.
Post by: Construed on Fri 14/01/2011 12:38:48
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Khris on Fri 14/01/2011 12:49:19
Ok, and when the potion is the active cursor, what do you click to actually use it?
Title: Re: Working on battle system, need advice please.
Post by: Construed on Fri 14/01/2011 13:07:34
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Construed on Fri 14/01/2011 13:34:11
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Khris on Fri 14/01/2011 13:51:41
Here's what I'do:
Put this in Global.asc:
function player_UseInv() {

  if (player.ActiveInventory == hpot) {
    health += 10;
    if (health > player_maxhealth) health = player_maxhealth;   // player_maxhealth is a global int variable
    player.LoseInventory(hpot);
    weight -= 1;
  }
}


Then put "player_UseInv" in the text field next to "use inv on character" on the events page for every character that's playable.

If you want to be able to take the potion by clicking it, you have to change a setting in General settings:
Set "Override built-in inventory window click handling" to "True".
Then set gInventory's visibility to "Normal, initially off". (this allows custom clicks on the GUI)

Now find on_mouse_click in Global.asc and change the first if line to:
  if (IsGamePaused() == 1 || (gInventory.Visible && GUI.GetAtScreenXY(mouse.x, mouse.y) != gInventory)) {
(this prevents outside clicks from being processed while the inventory GUI is open)

Then add this after right click handling:

  else if (button == eMouseLeftInv) {
    InventoryItem*ai = inventory[game.inv_activated];
    if (ai == hpot) hpot.RunInteraction(eModeInteract);
    else player.ActiveInventory = ai;
  }


Now put what's supposed to happen in "Interact inventory item" for the potion.
Title: Re: Working on battle system, need advice please.
Post by: Construed on Fri 14/01/2011 15:42:40
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Matti on Fri 14/01/2011 16:15:10
As Khris said, you can shorten that part using a single line:

health -= ouch;
Title: Re: Working on battle system, need advice please.
Post by: Construed on Fri 14/01/2011 16:30:32
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Construed on Fri 14/01/2011 21:33:23
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Matti on Fri 14/01/2011 22:51:21
You can do something like this:

health -= Random (damage + strength);

This would lower the health at a random number between 0 and the damage plus the strength variable.

This is all very basic and logical stuff, you should really try to figure this out by yourself, otherwise we need to constantly help you until the game is finished..
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sat 15/01/2011 06:22:45
so
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 16/01/2011 22:44:26
everyone
Title: Re: Working on battle system, need advice please.
Post by: Matti on Sun 16/01/2011 22:56:35
It's very easy again. All you have to do is using a variable.


int wait = 0;

//in the rep-exe:
if (wait > 0) wait --;

function oObject_Interact()
{
if (wait == 0){
 wait = 20;
 // do stuff
}
}


No matter how fast the player clicks, the action will only happen twice a second at most.
Title: Re: Working on battle system, need advice please.
Post by: Construed on Mon 17/01/2011 09:49:07
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Construed on Thu 10/02/2011 14:36:47
exactly
Title: Re: Working on battle system, need advice please.
Post by: Khris on Thu 10/02/2011 15:48:52
I don't mean to be rude (by stating the obvious) but why don't you clean up first, then ask for help?

Also, while you're at it, please indent the code. I'm not going to look at it like that, cleaned up or not.
Title: Re: Working on battle system, need advice please.
Post by: Construed on Thu 10/02/2011 16:37:41
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Construed on Thu 10/02/2011 19:21:11
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sat 12/02/2011 19:00:23
Should i take this to the technical forum?
Title: Re: Working on battle system, need advice please.
Post by: Khris on Sat 12/02/2011 19:20:07
I told Studio3 how (not) to write a battle system here:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=42751.msg567251#msg567251

You are taking a similar approach to coding.

My guess is that people don't really want to get involved helping you fix that mess of code, sorry.
Opening a new thread at the technical forum won't help I'm afraid.
Title: Re: Working on battle system, need advice please.
Post by: Icey on Sat 12/02/2011 20:15:07
However mine consist of two people that are selected out of four people.

His only uses 1 person to fight. But what put's you in a struggle is that you game is Online(Like mine) and your battles consist of 1+ people. With this said, I can enter a battle room at any time but if some one else enters the room when I killed it they might be trapped there after I am sent back.

There is many downfalls to making a (Successful)RPG with ags and it is an even more pan is the ass to try at a online-RPG with ags. Now I am not telling you to stop because you dont get half the stuff. I know I cant stop because I put a lot of effort/thought into this game as it is already.

Dont think I am trying to put you down but I am pretty suer you'll figure away around this. :)
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sat 12/02/2011 23:45:09
you
Title: Re: Working on battle system, need advice please.
Post by: Icey on Sat 12/02/2011 23:50:54
Well it seems you like almost there.

Hope you get it bud. :)
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 13/02/2011 00:03:30
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Khris on Sun 13/02/2011 00:49:20
Quote from: GrimReapYou on Sat 12/02/2011 23:45:09
then i just need to [...] copy/paste this code to multiple rooms, replacing the monster sprites/names/variables.

This is precisely what should be avoided.
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 13/02/2011 06:33:02
jhik
Title: Re: Working on battle system, need advice please.
Post by: Dualnames on Sun 13/02/2011 06:48:00
Quote from: GrimReapYou on Sun 13/02/2011 06:33:02
jhik

Quote from: GrimReapYou on Sun 13/02/2011 00:03:30
hjkjhk

wut? Is that some acro I'm not aware of?
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 13/02/2011 16:05:37
Ok after ripping out half my global and functions and hair.......I'm finally able to make a struct....

GLOBAL.ASH

struct characters
{
 int strength;
 int dexterity;
 int stamina;
 int maxstamina;
 int mana;
 int maxmana;
 int health;
 int maxhealth;
 int sword;
 int magic;
 int throwing;
 int climbing;
 int expierance;
 int maxexpierance;
 int weight;
 int archery;
 int gold;
 int silver;
 int copper;
 String name;
};



characters fighter;
fighter.strength = 20;
fighter.dexterity = 10;
fighter.stamina = 50;
fighter.maxstamina = 50;
fighter.mana = 10;
fighter.maxmana  = 10;
fighter.health = 50;
fighter.maxhealth = 50;
fighter.sword = 1;
fighter.magic = 0;
fighter.throwing = 0;
fighter.climbing = 10;
fighter.expierance = 0;
fighter.maxexpierance = 9999999;
fighter.weight = 0;
fighter.archery = 0;
fighter.name = "Fighter";

characters wizard;
wizard.strength = 5;
wizard.dexterity = 5;
wizard.stamina = 20;
wizard.maxstamina = 20;
wizard.mana = 40;
wizard.maxmana = 40;
wizard.health = 40;
wizard.maxhealth = 40;
wizard.sword = 0;
wizard.magic = 1;
wizard.throwing = 0;
wizard.climbing = 0;
wizard.expierance = 0;
wizard.maxexpierance = 9999999;
wizard.weight = 0;
wizard.archery = 0;
wizard.name = "Wizard";

characters thief;
thief.strength = 5;
thief.dexterity = 10;
thief.stamina = 50;
thief.maxstamina = 50;
thief.mana = 5;
thief.maxmana = 5;
thief.health = 60;
thief.maxhealth = 60;
thief.sword = 0;
thief.magic = 0;
thief.throwing = 20;
thief.climbing = 10;
thief.expierance = 0;
thief.maxexpierance = 9999999;
thief.weight = 0;
thief.archery = 1;
thief.name = "thief";

Now how do i put this garbage into action.....

Seems like im increasing the scripting required if anything.
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 13/02/2011 18:18:46
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Khris on Sun 13/02/2011 18:58:27
That's not how you are supposed to use them.

You don't need three instances for the player, you only need one.
Then you'd set the one instance's values to those of the class the player chose.

But you're going to have several different enemies, right?
That's were structs really come in handy.

Say you had a troll, a rat, a dragon and an evil wizard as enemies. They are all going to have different stats so those are what you'd store in structs, like an enemy type database.

When the player encounters a random enemy, you load the stats data in a player struct and an enemy struct and keep track of the battle by updating the values of those.

But yeah, sure, all this was really a trap to set you back; structs can indeed suck it.
Title: Re: Working on battle system, need advice please.
Post by: Construed on Sun 13/02/2011 19:15:02
I apolagize man, I just didnt know that switching over to structs were going to require an 80% rebuild of what i've done so far.
But you are right, they are alot neater and tidier.
And im sure in the end i will thank you for getting me to switch over when im not buried in a huge pile of unknown global variables.
I suppose i need to drop all other game design aspects for now and focus on structs...
Title: Re: Working on battle system, need advice please.
Post by: Ryan Timothy B on Mon 14/02/2011 01:37:06
Thanks for making this a very productive thread with nothing but edits of "jkdhdfhf", it definitely makes this thread useful to others.  Thanks.

Remind me not to offer help next time you ask a question.
Title: Re: Working on battle system, need advice please.
Post by: ddq on Mon 14/02/2011 01:58:23
Reminder: don't offer help next time he asks a question.
Even if you don't think your old posts are valid, someone could still learn something from them and maybe help you, so editing them to "jklkjkl" is just silly.
Title: Re: Working on battle system, need advice please.
Post by: Construed on Mon 14/02/2011 04:22:59
I apologize for my harshness, but you have no idea the stress i've been under putting in 6-8 hour days of pure game design working on multiple aspects at once.

Besides the destruction of all my global variables bewildered me and caused me to go into a frenzy of brute forcing code which eventually led to me solving the multiplayer follow char problem! users can now equip and use items and the items can be seen by other players!
Title: Re: Working on battle system, need advice please.
Post by: BlueAngel on Mon 14/02/2011 09:59:20
Just want to throw my two cent in here.

Please don’t delete or change old thread, please.   :'(
I still having a hard time learning AGS and the manual are a bit hard to understand so to not ask for many stupid questions I always search the forum first and have found a lot of answers doing so.
Title: Re: Working on battle system, need advice please.
Post by: Knox on Wed 16/02/2011 05:26:20
QuoteBut yeah, sure, all this was really a trap to set you back; structs can indeed suck it

lol! omg...
Title: Re: Working on battle system, need advice please.
Post by: Construed on Wed 16/02/2011 09:10:40
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: Khris on Wed 16/02/2011 12:30:28
Whatever makes you happy. Just don't act like a complete jackass here, you aren't doing yourself a favor.
If you feel "pissy", don't post until you feel normal again.

And I sure as hell didn't leave you hanging; you converted everything to structs without really understanding what they do or how to use them. Then you gave me about 2 hours to get you out of the mess you created by not understanding them, and when I didn't get here in time, you accused me of intentionally misleading you into a trap.
You are a fucking sociopath it seems, you need to chill.

Nobody here is going to think "hey, GrimReapYou wants to fuk a struct, swell guy that", so really, just stop.
Title: Re: Working on battle system, need advice please.
Post by: Dualnames on Wed 16/02/2011 13:08:52
Khris is correct, I mean we've repeated this too many times over on IRC. You need to grasp a basic deal of the programming, before going into advanced stuff.

You have to slow down. Your games suffer from design and coding issues.
Title: Re: Working on battle system, need advice please.
Post by: Ryan Timothy B on Thu 17/02/2011 03:28:41
I wouldn't go any other way than using a struct. So don't think he's teaching you improper or half-arsed methods.
Once you understand a stuct, which shouldn't be too hard if you experimented with using one, it'll save you unbelievable time and you'll NEVER go back.
Title: Re: Working on battle system, need advice please.
Post by: Construed on Wed 01/02/2012 09:52:04
edited bad stuff :( sorry
Title: Re: Working on battle system, need advice please.
Post by: on Wed 01/02/2012 13:11:47
Quote from: GrimReapYou on Wed 01/02/2012 09:52:04
and btw khristhanks for being a man and accepting my apology "not" I hope you burn in hell you godless sack of horse manure...

Thanks for turning a thread that HAD some interesting information into foul gunk. Really, what's that supposed to tell us about you?
Title: Re: Working on battle system, need advice please.
Post by: Gilbert on Wed 01/02/2012 13:17:13
And that's almost a full year necro. Almost. :P
Title: Re: Working on battle system, need advice please.
Post by: Khris on Wed 01/02/2012 13:54:34
Just in case all of you're wondering, the guy put some variation of "jkhlk" in all the posts almost a year ago before they were edited again today.
Title: Re: Working on battle system, need advice please.
Post by: Construed on Fri 03/02/2012 08:34:10
I apologized to khris and he accepted, so hopefully stuff like this wont ever happen again....sorry guys :(