Jump to content


Photo

Get hit twice to die


  • Please log in to reply
16 replies to this topic

#1 naseem142

naseem142

    GMC Member

  • New Member
  • 100 posts
  • Version:GM8

Posted 02 June 2012 - 03:22 PM

How can i make an enemy object to get killed when it gets hit by a bullet object TWICE In action events not scripts.

Please help

Thanks :)
  • 0

#2 Tobias(NL)

Tobias(NL)

    GMC Member

  • GMC Member
  • 854 posts
  • Version:Unknown

Posted 02 June 2012 - 03:25 PM

I'd recommend using code.

With code:
create event of obj_enemy:
hp=2

collision event of obj_enemy with a bullet or whatever it is:
hp-=1
if hp<1 instance_destroy()

Without code:
in create event of obj_enemy:
:GM072: [fill in: hp=2]

collision event of obj_enemy:
:GM072: [fill in: hp-=1, relative]
then do :GM073: [fill in hp] (if smaller than) 1 and :GM124:

Edited by Tobias(NL), 02 June 2012 - 03:30 PM.

  • 1

#3 Slady01

Slady01

    T-Valley Games

  • New Member
  • 55 posts
  • Version:GM8

Posted 02 June 2012 - 03:25 PM

declare a variable for the enemy to have his own health "my_health" and set it to 2. Then in the collision event with the bullet have each bullet take down only one of the health points.

[edit] Ninja'd

Edited by Slady01, 02 June 2012 - 03:26 PM.

  • 1

#4 Shasoos

Shasoos

    Dead Fish Lover

  • GMC Member
  • 409 posts
  • Version:GM8

Posted 02 June 2012 - 03:34 PM

Ok, this is fairly simple:

In your Create Event:
- Execute code
life = 2

In your collision event with whatever object:
life -= 1;
with other
{
instance_destroy()
}

And in step event:
if life = 0
{
instance_destroy();
}

That should work, if it does, the bottom left of this post there should be a little green button... you can press it.

Edited by nuber43, 02 June 2012 - 03:35 PM.

  • 1

#5 cantavanda

cantavanda

    GMC Member

  • Banned Users
  • 980 posts
  • Version:GM:Studio

Posted 02 June 2012 - 03:46 PM

Do what they said.
If you don't know how to do this you are really bad in it.
Learn proper GML before even considering about starting any game.

#6 naseem142

naseem142

    GMC Member

  • New Member
  • 100 posts
  • Version:GM8

Posted 02 June 2012 - 03:54 PM

Ok, this is fairly simple:

In your Create Event:
- Execute code

life = 2

In your collision event with whatever object:
life -= 1;
with other
{
instance_destroy()
}

And in step event:
if life = 0
{
instance_destroy();
}

That should work, if it does, the bottom left of this post there should be a little green button... you can press it.


I got this error :/



___________________________________________
FATAL ERROR in
action number 1
of Collision Event with object obj_bullet
for object Enemy:

COMPILATION ERROR in code action
Error in code at line 4:
}
^
at position 2: Unexpected symbol in expression.

EDIT:
@cantavanda
I am learning right now by making simple games , and if i don't know something i will ask
Every pro starts a newbie

Edited by naseem142, 02 June 2012 - 03:56 PM.

  • 0

#7 cantavanda

cantavanda

    GMC Member

  • Banned Users
  • 980 posts
  • Version:GM:Studio

Posted 02 June 2012 - 04:00 PM

Okay naseem :thumbsup:
I remember that I didn't knew what a variable was...
That were some stupid old times...
And I remember the happiness when I discovered how to use alarms...
That was a good moment...

#8 cantavanda

cantavanda

    GMC Member

  • Banned Users
  • 980 posts
  • Version:GM:Studio

Posted 02 June 2012 - 04:03 PM

Try this:
Create of enemy:
enemyonelife = 2
Step of enemy:
visible = 1
if (enemyonelife = 0) 
{
instance_destroy()
}
Collision with bullet event of enemy:
enemyonelife -=1
visible=0
instance_destroy(other)

Edited by cantavanda, 02 June 2012 - 04:05 PM.


#9 Tobias(NL)

Tobias(NL)

    GMC Member

  • GMC Member
  • 854 posts
  • Version:Unknown

Posted 02 June 2012 - 04:10 PM

Just use my code, it's dead simple, it's fast and it'll work. Copy and paste work lad, copy and paste work.
  • 1

#10 cantavanda

cantavanda

    GMC Member

  • Banned Users
  • 980 posts
  • Version:GM:Studio

Posted 02 June 2012 - 04:12 PM

But my code has a special effect that the enemy dissepears 1 millisecond after being hit
It makes it more realistic (lol)

#11 naseem142

naseem142

    GMC Member

  • New Member
  • 100 posts
  • Version:GM8

Posted 02 June 2012 - 04:17 PM

Everything worked i just messed up something :P
1+ for everyone
  • 0

#12 Tobias(NL)

Tobias(NL)

    GMC Member

  • GMC Member
  • 854 posts
  • Version:Unknown

Posted 02 June 2012 - 04:17 PM

Hehe. It's his call.
EDIT: Okay, good. Goodluck with the rest of your game.

Edited by Tobias(NL), 02 June 2012 - 04:18 PM.

  • 0

#13 cantavanda

cantavanda

    GMC Member

  • Banned Users
  • 980 posts
  • Version:GM:Studio

Posted 02 June 2012 - 04:19 PM

Everything worked i just messed up something :P
1+ for everyone

Who's code worked?
Mine or tobias's?

#14 naseem142

naseem142

    GMC Member

  • New Member
  • 100 posts
  • Version:GM8

Posted 02 June 2012 - 04:36 PM


Everything worked i just messed up something :P
1+ for everyone

Who's code worked?
Mine or tobias's?


Yours :P but i 1+ too
  • 0

#15 Shasoos

Shasoos

    Dead Fish Lover

  • GMC Member
  • 409 posts
  • Version:GM8

Posted 02 June 2012 - 09:55 PM

What about mine.Posted Image

I would have tested, but i wasnt on my computer
  • 0

#16 naseem142

naseem142

    GMC Member

  • New Member
  • 100 posts
  • Version:GM8

Posted 03 June 2012 - 05:01 AM

What about mine.Posted Image

I would have tested, but i wasnt on my computer


it worked too but somehow they were getting killed by one bullet :S
  • 0

#17 Slady01

Slady01

    T-Valley Games

  • New Member
  • 55 posts
  • Version:GM8

Posted 03 June 2012 - 06:30 PM


What about mine.Posted Image

I would have tested, but i wasnt on my computer


it worked too but somehow they were getting killed by one bullet :S


That was probably due to your point of destruction for the bullet. I assume you let the bullet pass through the enemy. If so it was still making contact and therefore still deducting health points from the enemy object. I made that same mistake when I started building games. To remedy that you can either set the bullet to be destroyed the moment it touches the enemy or if you wish to have the bullet pass through you would need to set up a new variable for the enemy so that it knows it is hurt and give him a short window of invincibility after being hit.

Edited by Slady01, 03 June 2012 - 06:30 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users