playMaker

Author Topic: Count Enemies Killed In Variable  (Read 4840 times)

ConnersCraft

  • Playmaker Newbie
  • *
  • Posts: 4
Count Enemies Killed In Variable
« on: July 23, 2013, 10:19:59 PM »
I am making an FPS game. The player must kill enemy AI. They are all tagged "enemy". How can I count every time an AI is killed and add 1 to a float variable? Some AI spawn in randomly, so I just need to count the number of times a game object tagged "enemy" is destroyed and store it in a float variable. Thanks for the help.

escpodgames

  • Hero Member
  • *****
  • Posts: 687
    • Assets
Re: Count Enemies Killed In Variable
« Reply #1 on: July 24, 2013, 03:43:49 AM »
when the enemy is destroyed it sends an event to a separate fsm when adds one ... simple as that :)

ConnersCraft

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Count Enemies Killed In Variable
« Reply #2 on: July 24, 2013, 05:31:00 AM »
Yes, but what action can i use to determine if the enemy was destroyed? And when it is destroyed, the FSM attatched is no longer active, because the object is gone. Thanks for the help.

escpodgames

  • Hero Member
  • *****
  • Posts: 687
    • Assets
Re: Count Enemies Killed In Variable
« Reply #3 on: July 24, 2013, 09:12:01 AM »
Would depend how you are destroying the enemy. If you are actually destroying the gameObject just make the event send before you destroy.

For example, enemy_01 gets hit by a bullet, an fsm on the enemy detects this lets say (via collision) the fsm sends an event called ADD_ENEMY_KILL to a manager gameobject which has and FSM with a global event called .... ADD_ENEMY_KILL
in the fsm a state has the global transition of ADD_ENEMY_KILL and it adds an int of 1 to a variable called EnemyKills_int

[do you know about global events?]

Bqlqzs

  • Junior Playmaker
  • **
  • Posts: 52
Re: Count Enemies Killed In Variable
« Reply #4 on: July 24, 2013, 10:58:15 AM »
Hello

In my game, I used Tags for this.
It is very easy...

Make "enemy" Tag for the enemyes and use the Get Tag Count action.

When the enemy killed, and destroyed in game, the counter have -1 enemy Tag...

I hope you understand my english

You can use this with simple example : (GuiLayout Int Label)

// Enemyes: 5/ 2
prefix / int varriable from Get Tag Count action
« Last Edit: July 24, 2013, 11:01:33 AM by Bqlqzs »

blackant

  • Hero Member
  • *****
  • Posts: 521
  • http://blackantmaster.com
    • blackantmaster.com
Re: Count Enemies Killed In Variable
« Reply #5 on: July 24, 2013, 11:44:48 AM »
You can simply Add 1 to a global Int variable you use to store the information before destroy the gameobject

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: Count Enemies Killed In Variable
« Reply #6 on: July 24, 2013, 01:42:48 PM »
Right, if you have a new empty game object called GameManager, you can have a variable there that has the kill count, you can make it global but you can also get the fsm int or float from another fsm to add int or add float before it destroys self. I use this to show how many enemies were defeated or how many are left.
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez