get an enemy to return fire after being hit

Get help using Construct 2

Post » Wed Feb 19, 2014 10:06 am

Hi,

First time poster, first time Construct 2 users, basically a newb.

I'm currently working with the "Template: Real Time Strategy (RTS)" template. It's excellent for learning from.

I've modified the Event sheet to prevent Friendly and Enemy units from attacking each other (disabled both actions in event 2) and I've made it so that my (selected) Friendly units will only attack Enemy units I click on (inserted a new event under 16 that on mouse left click of an enemy a Friendly target will 'acquire' the enemy). This all works well, and being my first attempt I was surprised at how simple it was

My problem: I want the Enemy I'm attacking to engage the first Friendly it received fire from - returning fire.

I've tried a number of things but I just can't get my head around how to get the enemy to acquire the specific Friendly object that shot it first.

I've read a number of FAQ's on Picking/selecting instances, nothing really helped me.

Any help appreciated.

/Jamie
B
5
S
1
Posts: 34
Reputation: 364

Post » Wed Feb 19, 2014 10:24 am

hrm... found a bug - even if my Friendly units aren't selected they will shoot at (not move) an enemy unit I click on.

Behaviour should be only to engage an Enemy unit if the Friendly is selected.

Investigating...

EDIT

Resolved this by adding another condition to my new event (described in original post) to make sure a Friendly is selected (using the already defined IsSelected var).

EDIT 2

Strike that, 1/2 resolved. If nothing is selected then there is no action. Sweet!

When I have 1 Friendly unit selected and attack a close by Enemy unit, all friendly units attack but any unselected don't move.

I think it's still my 'new' event, which is;
On Left button Clicked on EnemyBases AND FriendlyBases is IsSelected
{
EnemyBases: Set IsTargeted to True
FriendlyTurrets: Turret acquire target EnemyBases
}

Pretty sure "FriendlyTurrets: Turret acquire target EnemyBases" tells ALL FriendlyTurrets to acquire the Enemy... not just the selected instance.

EDIT 3

3/4 Resolved. I disabled the suspect action and added a sub-event to pick a specific instance of a FriendlyTurret based on the TurretUID stored as a var in the FriendlyBase.

It worked!

On Left button Clicked on EnemyBases AND FriendlyBases is IsSelected
{
EnemyBases: Set IsTargeted to True
Pick instance with UID FriendlyBases.TurretUID
{
    FriendlyTurrets: Turret acquire target EnemyBases
}
}

Side-effect: if I select multiple FriendlyBase only the first selected will shoot... think I need to set a new var and throw an ELSE and/or FOR in somewhere

Investigating... jwoods2014-02-19 12:27:00
B
5
S
1
Posts: 34
Reputation: 364

Post » Wed Feb 19, 2014 10:33 am

a much simplified version of what I think you are after

capx
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832

Post » Wed Feb 19, 2014 10:50 am

hrm... I'm getting an error telling me;

---------------------------
Unable to load project
---------------------------
Could not open project because it is from a newer version of Construct 2. The project was saved in release 162 or newer. Your current release is 158.2. Try downloading the latest version of Construct 2 to open this project.
---------------------------
OK   
---------------------------

The version on the site is 158.2?
B
5
S
1
Posts: 34
Reputation: 364

Post » Wed Feb 19, 2014 11:05 am

The last version (beta) is 162 : https://www.scirra.com/construct2/releases/r162

The stable is 158.2 :)
B
39
S
15
G
5
Posts: 295
Reputation: 6,089

Post » Wed Feb 19, 2014 11:06 am

At the very bottom of the page, you will see a link to download the latest beta, r162. Most people update quite often, and you can use this version too if you want to open RamPackWobble's file.
B
17
S
8
G
4
Posts: 461
Reputation: 6,157

Post » Wed Feb 19, 2014 11:11 am

Cheers Joskin and Guizmus.
B
5
S
1
Posts: 34
Reputation: 364


Return to How do I....?

Who is online

Users browsing this forum: Lordshiva1948 and 60 guests