Hi GIL,

Been dabbling in scripting, I'm 100% noob but I managed to make some stuff work. Now I'm trying to do a simple script that cycles through all combatants in the player group, and for each combatant it: changes their object variables, change their status values and change the equipped equipment durability on specific bodyparts. After doing a lot of research on the forum I still can't make it work, I know it's some kind of syntax that I'm missing and it's really hard to figure out what I do wrong since I don't know what I'm doing.

using UnityEngine;
using System.Collections.Generic;
using ORKFramework;
using ORKFramework.Behaviours;

public class testing : MonoBehaviour {

public void TestChanges() {

// cycling through all group members

int groupSize = ORK.Game.Group.size;

for(int i=0;i<=groupSize; i++){

//changing status values
Combatant combatant = ComponentHelper.GetCombatant (ORK.Game.ActiveGroup.GetMember (i));
combatant.Status[0].addValue(1);

//changing object variables

combatant.GetComponent<ObjectVariablesComponent>().GetHandler().GetFloat("variableName1");
combatant.variableName1.AddValue(-1);

//changing equipment durability for equipped equipment on bodyparts

combatant.Equipment[0].durability.AddValue(1) ;

}
}
}


  • edited February 28
    Yeah ... that's pretty much all wrong :D

    Here's some working code for this function:

    public void TestChanges()
    {
    // get player group members
    List<Combatant> combatants = ORK.Game.ActiveGroup.GetGroup();
    // or use ORK.Game.ActiveGroup.GetBattle() to only use the battle group members

    for(int i=0; i<combatants.Count; i++)
    {
    //changing status values
    combatants[i].Status[0].AddValue(1, false, true, true, false, true, true);

    //changing object variables
    combatants[i].Variables.ChangeFloat("variableName1", 1, FormulaOperator.Add);

    //changing equipment durability for equipped equipment on bodyparts
    if(combatants[i].Equipment[0].Equipped &&
    combatants[i].Equipment[0].Equipment != null)
    {
    combatants[i].Equipment[0].Equipment.ChangeDurability(combatants[i], 1, SimpleOperator.Sub);
    }
    }
    }
    Post edited by gamingislove on
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Wow... this would have taken me ages to figure out, thanks so much. It worked on first try which is a miracle for me =)

    One last thing, I want to use the result of a formula, or a game var, instead of fixed values. After lots of research (and looking at cryptic nodes code), I think I would add this line :



    float value = (float)ORK.Formulas.Get(formulaID).Calculate(new FormulaCall(0, player, player)); // to call the formula and put the result in the variable value



    Then how do I put the variable value instead of the fixed value for status values, object variables and equipment durability?
  • Usually, when working in an IDE like virtual studio or mono develop, you should get all the functions, fields and properties as suggestions when entering code - you'll have to include the ORKFramework.dll as a reference in your project to get that. This makes it a lot easier to figure these things out :)

    Your code is correct, but you don't need the (float) cast in front of the formula, Calculate already returns a float.
    To use the result of the formula (your value variable), just replace the '1' or whatever value you've used with value. Changing the status value probably needs an int cast (i.e. (int)value).
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Yeah that does help, and also the code works now, so thanks!
  • edited April 24
    Hi GIL,

    I got a question related to this thread.

    I need to change the durability and the object vars of the equipment (weapons and armors) in the group inventory of the player. Each equipment has their own object vars and durability, so I think I need to go equipment by equipment and make the changes.

    I already have a loop, and I think I got the logic right, but how do I access each item in the inventory? If I put the index number, I think it will mean the index number in the ork editor, not the index slot in the inventory?

    Anyways here's my logic:

    int numberOfEquipmentsInInventory = ORK.Game.ActiveGroup.Leader.Inventory.GetCount;
    for(int j=0; j<numberOfEquipmentsInInventory; j++)
    {
    if (ORK.Game.ActiveGroup.Leader.Inventory.Items[j] != null)

    {


    //stuck here, dont know how to do this ORK.Game.ActiveGroup.Leader.Inventory.Items[j].Equipment.ChangeDurability((combatants[1], ORK.Formulas.Get(120).Calculate(new FormulaCall(0, combatants[1], combatants[1])), SimpleOperator.Add);

    //and here ORK.Game.ActiveGroup.Leader.Inventory.Items[j].GetHandler().Set("gameVar", 10);


    }


    Thanks
    Post edited by UserName on
  • Well, that's not exactly how it works :)
    Try this:

    List<EquipShortcut> equipment = new List<EquipShortcut>();
    ORK.Game.ActiveGroup.Leader.Inventory.Weapons.Get(id, int.MaxValue, ref equipment);
    ORK.Game.ActiveGroup.Leader.Inventory.Armors.Get(id, int.MaxValue, ref equipment);

    for(int i=0; i<equipment.Count; i++)
    {
    equipment[i].ChangeDurability(combatant, value, SimpleOperator.Add);
    }


    id is the ID/index of the equipment, the rest should be pretty clear, combatant being the combatant, value the durability change, etc.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited April 26
    Thanks, so I defined maxValue which I guess is a variable, then I put the equipment index 7 just to test, but I get a couple of red errors for the Weapons and Armors.Get. What's the problem?

    List<EquipShortcut> equipment = new List<EquipShortcut>();
    ORK.Game.ActiveGroup.Leader.Inventory.Weapons.Get(7, int.MaxValue, ref equipment);
    ORK.Game.ActiveGroup.Leader.Inventory.Armors.Get(7, int.MaxValue, ref equipment);





    for(int i=0; i<equipment.Count; i++)
    {
    equipment[7].ChangeDurability(combatants[0], 2, SimpleOperator.Set);
    }


    }
    Post edited by UserName on
  • Probably because you use equipment[7] instead of equipment[i] :)
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Well I tried the [i] too, the error is actually at the lines Weapons.Get and Armors.Get, it says

    " error CS1502: The best overloaded method match for `ORKFramework.SubInventory.Get(int, int, ref System.Collections.Generic.List)' has some invalid arguments
    "
    and

    "error CS1503: Argument `#3' cannot convert `ref System.Collections.Generic.List' expression to type `ref System.Collections.Generic.List'

    Something to do with ref equipment?

  • Oh, yeah - try this:

    List<IShortcut> equipment = new List<IShortcut>();
    ORK.Game.ActiveGroup.Leader.Inventory.Weapons.Get(7, int.MaxValue, ref equipment);
    ORK.Game.ActiveGroup.Leader.Inventory.Armors.Get(7, int.MaxValue, ref equipment);





    for(int i=0; i<equipment.Count; i++)
    {
    ((EquipShortcut)equipment[7]).ChangeDurability(combatants[0], 2, SimpleOperator.Set);
    }


    }
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thanks, now the code compiles, but it doesnt work, I get a yellow error "Method call failed, Exception has been thrown by the target of an invocation."

    So I've played a lot with the code and managed to make it semi work, still get the error , it doesn't work for all equipment in the inventory, just some, and btw equipment.count returns 0 so I put a fixed number:

    List<IShortcut> equipment = new List<IShortcut>();
    for(int j=0; j<100; j++)
    {

    ORK.Game.ActiveGroup.Leader.Inventory.Weapons.Get(j, int.MaxValue, ref equipment);
    ORK.Game.ActiveGroup.Leader.Inventory.Armors.Get(j, int.MaxValue, ref equipment);


    }

    for(int k=0; k<100; k++)
    {
    if(((EquipShortcut)equipment[k]) != null)
    {

    ((EquipShortcut)equipment[k]).ChangeDurability(combatants[0], 2, SimpleOperator.Set);
    Debug.Log ("hello");
    }
    }
  • edited May 2
    You should never use a fixed value when going through a list (or array), as you'll in most cases get an index out of array exception :)
    Also, my code was bugged ... used 7 instead of i.

    List<IShortcut> equipment = new List<IShortcut>();
    ORK.Game.ActiveGroup.Leader.Inventory.Weapons.Get(7, int.MaxValue, ref equipment);
    ORK.Game.ActiveGroup.Leader.Inventory.Armors.Get(7, int.MaxValue, ref equipment);

    for(int i=0; i<equipment.Count; i++)
    {
    ((EquipShortcut)equipment[i]).ChangeDurability(combatants[0], 2, SimpleOperator.Set);
    }
    Post edited by gamingislove on
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited May 3
    Ok but I already tested this, and it only affects weapons and armor with ID 7, so do how I cycle through all the IDs? That's what I was attempting to do by adding another loop, here's what I tried : List<IShortcut> equipment = new List<IShortcut>();
    for(int j=0; j<equipment.Count; j++)
    {
    ORK.Game.ActiveGroup.Leader.Inventory.Weapons.Get(j, int.MaxValue, ref equipment);
    ORK.Game.ActiveGroup.Leader.Inventory.Armors.Get(j, int.MaxValue, ref equipment);
    }


    for(int i=0; i<equipment.Count; i++)
    {
    ((EquipShortcut)equipment[i]).ChangeDurability(combatants[0], 2, SimpleOperator.Set);
    }


    But equipment.Count does not work, nothing happens, that's why I tried putting a fixed value of 100.
    Post edited by UserName on
  • List<IShortcut> equipment = new List<IShortcut>();
    for(int j=0; j<ORK.Weapons.Count; j++)
    {
    ORK.Game.ActiveGroup.Leader.Inventory.Weapons.Get(j, int.MaxValue, ref equipment);
    }
    for(int j=0; j<ORK.Armors.Count; j++)
    {
    ORK.Game.ActiveGroup.Leader.Inventory.Armors.Get(j, int.MaxValue, ref equipment);
    }

    for(int i=0; i<equipment.Count; i++)
    {
    ((EquipShortcut)equipment[i]).ChangeDurability(combatants[0], 2, SimpleOperator.Set);
    }
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thanks GIL, that did work! My game's gonna be great :D
Sign In or Register to comment.