edited December 2014 in ORK Scripting
Hi all

I am really enjoying ORK but have come across a bit of a blocker that has got me scratching my head. I am currently prototyping up a game that combines collectible trading cards with an RPG. I have my own uGUI dialogue with drag and drop cards. These then add appropriate combatants when we click accept which is all working nicely.

However, what i want to do is also start a battle via code when we click accept but cannot seem to work that out from the API (I am still a bit of a beginner when it comes to c# so apologies!). I have a game object with a battle component attached in the scene that I can trigger fine with the ORK event system but not my code.

If anyone could point me in the right direction that would be great.


image

cheers
Matt
Post edited by mattratcliffe on
  • edited December 2014
    Welcome to the forum. That's a wonderful idea. I could swear I found a question here before about starting a battle from a script but can't find it right now. Is this turn-based battle system or other type?

    I'm sure Gil can give you some pointers.
    Post edited by Catacomber on
  • Hi Catacomber

    Thanks for the warm welcome :) .

    It is a turn based battle that I want to trigger. I have drilled down to the gameobject with the battle component:
    public GameObject battleObject1;
    BattleComponent battlecomponent1;


    And tried to start the event via the StartEvent function but to no avail:

    battlecomponent1 = battleObject1.GetComponent<BattleComponent>();
    battlecomponent1.StartEvent(simpleStart);


    If there is another method I need to trigger, or separate class I can't seem to work it out.

    I have also taken a look at the battle class:

    Battle battle1;

    battle1.StartBattle(false);

    But the StartBattle method only allows me to set escape via a boolean. When I use the ORK event system I can trigger a battle via a simple dialogue by first searching for the object with the battle component (which I assume is similar to a gameobject.find in Unity) and the startbattle node triggers the script on the gameobject, this seems to be the bit I am missing!!

    I did take a look through the forums but will do another search to see if I can work it out!

    cheers
    Matt
  • There are multiple ways to start a battle:

    If you have the BattleComponent all set up correctly (i.e. enemies, etc), use this code:
    battleComponent.StartEvent(GameObject startingObject);
    Where the starting object will most likely be the player, which you can get through ORK.Game.ORK.Game.GetPlayer().

    If you want to get notified when the battle is over, implement the IEventStarter interface in your class and call the following function:
    battleComponent.StartEvent(IEventStarter starter);
    Just pass along your class as parameter.

    If you have the battle component without enemies set up, you can start a battle using the StartGroup functions, wich either take one enemy Group or a list of enemy groups. The group of a combatant can be accessed through combatant.Group - so you'll have to set create your combatants (and initialize them) first.

    If you don't have a battle component, you can use this function to create a default battle:
    BattleComponent.CreateBattle(List<Combatant> enemy, IEventStarter starter);
    The enemy list is just a list of combatants (need to be initialized correctly), the starter can also be null if you don't need to be notified when the battle ends.


    Initializing a combatant
    I'll explain it step by step. First, you'll need to create a group using the ID of the faction the enemies should be part of (the ID is the index in the editor list).
    Group group = new Group(int factionID);

    Now, you can create the combatant using the group and the combatant's ID:
    Combatant combatant = ORK.Combatants.Create(int combatantID, Group group);

    You now have a combatant with a basic initialization - you still need to initialize him to the class and level you want, either use the start settings of the combatant:
    combatant.Init();
    Or define a level, class level and class that should be used:
    combatant.Init(int level, int classLevel, int classID);
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited December 2014
    Hi Gil

    Thanks for the extensive answer, I now have that up and running with the following code.

    public GameObject battleObject1;
    BattleComponent battlecomponent1;
    GameObject player;

    player = ORK.Game.GetPlayer();
    battlecomponent1.StartEvent(player);

    cheers
    Matt
    Post edited by mattratcliffe on
Sign In or Register to comment.