NPC Individual Behavior

0 favourites
  • 4 posts
From the Asset Store
Fantasy RPG Human-NPC assets pack of 15 characters
  • Hello. I looked through the forums and was having a bit of trouble finding anything on the subject;

    I am trying to figure out how to have two NPC's of the same image to follow the events in the list on their own, without being affected by the other's actions.

    Example:

    Miner 1 and Miner 2 go out to mine an asteroid.

    The event states that once there is over or equal to 100 ore in the miner's hold, they should return to starbase and drop it off.

    If Miner 1 finishes early, Miner 2 returns to starbase as well (This is what I don't want).

    I would like them to complete their actions independently, without the hassle of making millions of other NPC's and matching event behaviors.

    Hope this made sense.

  • Hi im actually working on or just finished something similar to what you want. <img src="smileys/smiley4.gif" border="0" align="middle" /> So maybe my solution can help you.

    My initial idea was to use arrays to store whatever order each unit should do, but i find them very confusing in construct 2. And ran into some problems with them doing weird things, so dropped using them.

    Instead i made a list object for each unit as they are created and added a "Unit_ID" variable that holds the UID of the unit it is linked to. This list can be seen as a queue of orders that the unit will perform.

    So in your case it could be.

    Miner.cargo_hold = 0 then Add to list "Go mine".

    Miner.cargo_hold = 100 then Add to list "Return to base".

    And so on.

    Then you can make an event that check each miners order list.

    So if miner1 have "Go mine" as the first item in the list. You can make an event that triggers if a unit have that job.

    In my game two units cant work on the same thing at the time, so I added a function that make the units enter a "wait for job" state. It then goes through each unit one after another, to see if there are anything that needs to be done. And if its the case, that "job" gets locked to that unit.

    Another way that can be useful as well, if you dont want to work with lists, is to add an Text variable to your miners called "Order" or whatever. And as default you set it to "None", if we assume that these miners uses fuel as well. An example could be:

    Event 1:

    Miner.order = "None" then Set Miner.order = "Go mine"

    Miner.fuel = 100

    Event 2:

    Miner.order = "Go mine" then Miner fly nearest mining place.

    etc etc.

    Doing it by adding or updating the miners order each time they reach there goal. Will make it easier to keep track off them i think. Also it will make it easier to check you program if you can show the order of each unit as you test your program.

    Assuming that suddenly one of your miners go crazy while testing, and you keep track of what order it have, will make it a lot easier to see where things might go wrong. For instant if a miner have order "Go mine", when it starts to act crazy. You can easily find the place in your program where it receive that order.

    Also its a good idea to use "For each (ordered)" and then in expression add the <object>.UID, since UID of objects cant be the same, it will go through all objects of that type, one after another and will only pick one at the time.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • hmmm while we are on this topic Just curious can you some how create /spawn Sprite to be have set number but randomly generated. Such as if miner 1 2 3 dies then you want to spawn 4 5 6 and those dies then spawn 1 2 3 again ? Without having to place 6 sprite on layout of UID can you place one sprite on layout and attach UID to each spawn?

  • i think you can use a container and spawn them so you wont have to place 6 sprites on your layout, only if you have an sprite for the animations and a sprite for the collitions.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)