Characters Attacking Other Chars

Get help using Construct 2

Post » Wed Jun 13, 2012 5:57 am

I'm making a turn based rpg game with white damage, where characters attack a random enemy every so often.

I'm trying to write a set of events which makes any character attack its target whenever it is time to do so.

AttackProgress - How many second has elapsed since this character last attacked.
AttackTime - How many seconds must elapse between attacks (before the next attack, starting from the last time it attacked)
AttackDamage - How much damage is dealt to the target with each attack.
CurrentLocation - The spawn point that the character is occupying in the current combat (this is a number, each character has a unique CurrentLocation).
CurrentTarget - The spawn point (or CurrentLocation, if you prefer) of the enemy that this character will attack.

So, logically, whenever a character's AttackProgress > its AttackTime, it should deal it's AttackDamage to an enemy whose CurrentLocation = the attacker's CurrentTarget.

Here's how I'm currently trying to do this with events:

My first event says that for each Character whose AttackProgress > Self.AttackTime, add information to an array called "TheStack" (yes, I play Magic the Gathering). Set value at Characters.UID,1 to Characters.CurrentTarget, and Set value at Characters.UID,2 to Characters.WhiteDamage.

This gives us an array where for each Character that has AttackProgress > Self.AttackTime there are two values stored at X,1 and X,2, where X = the character's UID. Thus, we've stored the incoming damage amount and targets for each outgoing attack.

However, I can't seem to find a way to compare each character's CurrentLocation to this array for all values of X where Y = 1, then reduce their CurrentHP (another instance variable) by the value at Y = 2 for the same value of X, if there's a match.

Hopefully that all makes sense. If you have any questions, I'll do my best to clear up any confusion. I'm open to doing this other ways too. I'm trying to support a game with multiple party members and multiple enemies, which seems to be my problem.
Posts: 2
Reputation: 704

Post » Wed Jun 13, 2012 3:00 pm

I'm not sure I followed 100%. It would be much easier if you could make a simplified capx that demonstrates the problem.

Would it help if you make use of "temporary" arrays, and loop through TheStack looking, for example, for those UIDs where Y=1 and pushing them onto the new array? That gives you an array with just the qualifying UIDs to look at. Then you could loop through that array, and for each UID compare the character's CurrentLocation to whatever you want to compare it to. When the next turn starts, clear the "temporary" array and start over.

How is CurrentTarget selected for each character?

Posts: 281
Reputation: 11,858

Post » Wed Jun 13, 2012 7:34 pm

Something like this:

Though I wouldn't use the UID to index the array because your array will be much bigger than you need. Instead you could create a queue. Start with a zero sized array and push the attacks onto it. Then when you process the attack you can pop it off.

Posts: 1,520
Reputation: 24,905

Post » Wed Jun 13, 2012 10:29 pm


I ended up doing what Ramones suggested in his post and it's working great.JohnnyJohstneft2012-06-13 22:29:24
Posts: 2
Reputation: 704

Return to How do I....?

Who is online

Users browsing this forum: JonnyBrove, Megavolt, midward, mikelantzelo, MSNbot Media and 24 guests