Working on battle system, need advice please.

Started by Construed, Sun 09/01/2011 09:48:29

Previous topic - Next topic

Construed

edited bad stuff :( sorry
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

#1
edited bad stuff :( sorry
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

#2
edited bad stuff :( sorry
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Matti

Use a variable like so:

Code: ags

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".

Construed

#4
edited bad stuff :( sorry
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

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

Khris

Quote from: GrimReapYou on Sun 09/01/2011 16:53:32
Code: ags
if (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:
Code: ags
  health -= ouch;


Why aren't you using the QFG template?

Construed

#7
edited bad stuff :( sorry
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

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

Construed

#9
edited bad stuff :( sorry
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Matti

Just do it like this:

Code: ags

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.

Construed

#11
edited bad stuff :( sorry
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

#12
edited bad stuff :( sorry
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Khris

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:

Code: ags
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:

Code: ags
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:

Code: ags
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:

Code: ags
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
}

monkey0506

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

Construed

#15
edited bad stuff :( sorry
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

#16
edited bad stuff :( sorry
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Khris

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.

Construed

#18
edited bad stuff :( sorry
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Khris

Ok, and when the potion is the active cursor, what do you click to actually use it?

SMF spam blocked by CleanTalk